1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "oox/drawingml/diagram/diagramlayoutatoms.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <functional>
31*cdf0e10cSrcweir #include <boost/bind.hpp>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
34*cdf0e10cSrcweir #include "layoutnodecontext.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
38*cdf0e10cSrcweir using namespace ::oox::core;
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace oox { namespace drawingml {
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir IteratorAttr::IteratorAttr( )
44*cdf0e10cSrcweir 	: mnAxis( 0 )
45*cdf0e10cSrcweir 	, mnCnt( 0 )
46*cdf0e10cSrcweir 	, mbHideLastTrans( false )
47*cdf0e10cSrcweir 	, mnPtType( 0 )
48*cdf0e10cSrcweir 	, mnSt( 0 )
49*cdf0e10cSrcweir 	, mnStep( 1 )
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir }
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir void IteratorAttr::loadFromXAttr( const Reference< XFastAttributeList >& xAttr )
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir 	AttributeList attr( xAttr );
56*cdf0e10cSrcweir 	mnAxis = xAttr->getOptionalValueToken( XML_axis, 0 );
57*cdf0e10cSrcweir 	mnCnt = attr.getInteger( XML_cnt, 0 );
58*cdf0e10cSrcweir 	mbHideLastTrans = attr.getBool( XML_hideLastTrans, false );
59*cdf0e10cSrcweir 	mnPtType = xAttr->getOptionalValueToken( XML_ptType, 0 );
60*cdf0e10cSrcweir 	mnSt = attr.getInteger( XML_st, 0 );
61*cdf0e10cSrcweir 	mnStep = attr.getInteger( XML_step, 1 );
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir ConditionAttr::ConditionAttr()
67*cdf0e10cSrcweir 	: mnFunc( 0 )
68*cdf0e10cSrcweir 	, mnArg( 0 )
69*cdf0e10cSrcweir 	, mnOp( 0 )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir void ConditionAttr::loadFromXAttr( const Reference< XFastAttributeList >& xAttr )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir 	mnFunc = xAttr->getOptionalValueToken( XML_func, 0 );
78*cdf0e10cSrcweir 	// mnArg will be -1 for "none" or any other unknown value
79*cdf0e10cSrcweir 	mnArg = LayoutNodeContext::tagToVarIdx( xAttr->getOptionalValueToken( XML_arg, XML_none ) );
80*cdf0e10cSrcweir 	mnOp = xAttr->getOptionalValueToken( XML_op, 0 );
81*cdf0e10cSrcweir 	msVal = xAttr->getOptionalValue( XML_val );
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir void LayoutAtom::dump(int level)
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 	OSL_TRACE( "level = %d - %s of type %s", level,
88*cdf0e10cSrcweir 			   OUSTRING_TO_CSTR( msName ),
89*cdf0e10cSrcweir 			   typeid(*this).name() );
90*cdf0e10cSrcweir 	std::for_each( mpChildNodes.begin(), mpChildNodes.end(),
91*cdf0e10cSrcweir 				  boost::bind( &LayoutAtom::dump, _1, level + 1 ) );
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir void ForEachAtom::processAtom()
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir 	// TODO there is likely some conditions
98*cdf0e10cSrcweir 	std::for_each( mpChildNodes.begin(), mpChildNodes.end(),
99*cdf0e10cSrcweir 				   boost::bind( &LayoutAtom::processAtom, _1 ) );
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir /** call ConditionAtom::test() if pAtom is one
103*cdf0e10cSrcweir  * if it is not a ConditionAtom, then return false.
104*cdf0e10cSrcweir  */
105*cdf0e10cSrcweir static bool _test_atom( const LayoutAtomPtr & pAtom)
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir 	try {
108*cdf0e10cSrcweir 		bool bResult = false;
109*cdf0e10cSrcweir 		const ConditionAtomPtr pCond = boost::dynamic_pointer_cast< ConditionAtom >(pAtom);
110*cdf0e10cSrcweir 		if( pCond )
111*cdf0e10cSrcweir 		{
112*cdf0e10cSrcweir 			bResult = pCond->test();
113*cdf0e10cSrcweir 		}
114*cdf0e10cSrcweir 		return bResult;
115*cdf0e10cSrcweir 	}
116*cdf0e10cSrcweir 	catch(...)
117*cdf0e10cSrcweir 	{
118*cdf0e10cSrcweir 	}
119*cdf0e10cSrcweir 	return false;
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir void ChooseAtom::processAtom()
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	std::vector< LayoutAtomPtr >::iterator
125*cdf0e10cSrcweir 		iter = std::find_if( mpChildNodes.begin(), mpChildNodes.end(),
126*cdf0e10cSrcweir 							 boost::bind( &_test_atom, _1 ) );
127*cdf0e10cSrcweir 	if( iter != mpChildNodes.end() )
128*cdf0e10cSrcweir 	{
129*cdf0e10cSrcweir 		// TODO do something
130*cdf0e10cSrcweir 		(*iter)->processAtom();
131*cdf0e10cSrcweir 	}
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir bool ConditionAtom::test()
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir 	// TODO
137*cdf0e10cSrcweir 	return false;
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir } }
142