1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/drawingml/diagram/diagramlayoutatoms.hxx"
25 
26 #include <functional>
27 #include <boost/bind.hpp>
28 
29 #include "oox/helper/attributelist.hxx"
30 #include "layoutnodecontext.hxx"
31 
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::xml::sax;
34 using namespace ::oox::core;
35 
36 namespace oox { namespace drawingml {
37 
38 
IteratorAttr()39 IteratorAttr::IteratorAttr( )
40 	: mnAxis( 0 )
41 	, mnCnt( 0 )
42 	, mbHideLastTrans( false )
43 	, mnPtType( 0 )
44 	, mnSt( 0 )
45 	, mnStep( 1 )
46 {
47 }
48 
loadFromXAttr(const Reference<XFastAttributeList> & xAttr)49 void IteratorAttr::loadFromXAttr( const Reference< XFastAttributeList >& xAttr )
50 {
51 	AttributeList attr( xAttr );
52 	mnAxis = xAttr->getOptionalValueToken( XML_axis, 0 );
53 	mnCnt = attr.getInteger( XML_cnt, 0 );
54 	mbHideLastTrans = attr.getBool( XML_hideLastTrans, false );
55 	mnPtType = xAttr->getOptionalValueToken( XML_ptType, 0 );
56 	mnSt = attr.getInteger( XML_st, 0 );
57 	mnStep = attr.getInteger( XML_step, 1 );
58 }
59 
60 
61 
ConditionAttr()62 ConditionAttr::ConditionAttr()
63 	: mnFunc( 0 )
64 	, mnArg( 0 )
65 	, mnOp( 0 )
66 {
67 
68 }
69 
70 
loadFromXAttr(const Reference<XFastAttributeList> & xAttr)71 void ConditionAttr::loadFromXAttr( const Reference< XFastAttributeList >& xAttr )
72 {
73 	mnFunc = xAttr->getOptionalValueToken( XML_func, 0 );
74 	// mnArg will be -1 for "none" or any other unknown value
75 	mnArg = LayoutNodeContext::tagToVarIdx( xAttr->getOptionalValueToken( XML_arg, XML_none ) );
76 	mnOp = xAttr->getOptionalValueToken( XML_op, 0 );
77 	msVal = xAttr->getOptionalValue( XML_val );
78 }
79 
80 
dump(int level)81 void LayoutAtom::dump(int level)
82 {
83 	OSL_TRACE( "level = %d - %s of type %s", level,
84 			   OUSTRING_TO_CSTR( msName ),
85 			   typeid(*this).name() );
86 	std::for_each( mpChildNodes.begin(), mpChildNodes.end(),
87 				  boost::bind( &LayoutAtom::dump, _1, level + 1 ) );
88 }
89 
90 
processAtom()91 void ForEachAtom::processAtom()
92 {
93 	// TODO there is likely some conditions
94 	std::for_each( mpChildNodes.begin(), mpChildNodes.end(),
95 				   boost::bind( &LayoutAtom::processAtom, _1 ) );
96 }
97 
98 /** call ConditionAtom::test() if pAtom is one
99  * if it is not a ConditionAtom, then return false.
100  */
_test_atom(const LayoutAtomPtr & pAtom)101 static bool _test_atom( const LayoutAtomPtr & pAtom)
102 {
103 	try {
104 		bool bResult = false;
105 		const ConditionAtomPtr pCond = boost::dynamic_pointer_cast< ConditionAtom >(pAtom);
106 		if( pCond )
107 		{
108 			bResult = pCond->test();
109 		}
110 		return bResult;
111 	}
112 	catch(...)
113 	{
114 	}
115 	return false;
116 }
117 
processAtom()118 void ChooseAtom::processAtom()
119 {
120 	std::vector< LayoutAtomPtr >::iterator
121 		iter = std::find_if( mpChildNodes.begin(), mpChildNodes.end(),
122 							 boost::bind( &_test_atom, _1 ) );
123 	if( iter != mpChildNodes.end() )
124 	{
125 		// TODO do something
126 		(*iter)->processAtom();
127 	}
128 }
129 
test()130 bool ConditionAtom::test()
131 {
132 	// TODO
133 	return false;
134 }
135 
136 
137 } }
138