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