xref: /AOO41X/main/oox/source/drawingml/diagram/layoutnodecontext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "layoutnodecontext.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
31*cdf0e10cSrcweir #include "oox/drawingml/diagram/diagram.hxx"
32*cdf0e10cSrcweir #include "oox/drawingml/shapecontext.hxx"
33*cdf0e10cSrcweir #include "diagramdefinitioncontext.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir using namespace ::oox::core;
36*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
38*cdf0e10cSrcweir using ::rtl::OUString;
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace oox { namespace drawingml {
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir class IfContext
43*cdf0e10cSrcweir 	: public LayoutNodeContext
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir public:
46*cdf0e10cSrcweir     IfContext( ContextHandler& rParent,
47*cdf0e10cSrcweir 			   const Reference< XFastAttributeList >& xAttribs,
48*cdf0e10cSrcweir 			   const LayoutAtomPtr & pNode )
49*cdf0e10cSrcweir         : LayoutNodeContext( rParent, xAttribs, pNode )
50*cdf0e10cSrcweir 		{
51*cdf0e10cSrcweir 			ConditionAtomPtr pAtom( boost::dynamic_pointer_cast< ConditionAtom >(pNode) );
52*cdf0e10cSrcweir 			OSL_ENSURE( pAtom, "Must pass a ConditionAtom" );
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 			pAtom->iterator().loadFromXAttr( xAttribs );
55*cdf0e10cSrcweir 			pAtom->cond().loadFromXAttr( xAttribs );
56*cdf0e10cSrcweir 		}
57*cdf0e10cSrcweir };
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir class AlgorithmContext
62*cdf0e10cSrcweir     : public ContextHandler
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir public:
65*cdf0e10cSrcweir     AlgorithmContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const LayoutAtomPtr & pNode )
66*cdf0e10cSrcweir         : ContextHandler( rParent )
67*cdf0e10cSrcweir 		, mnRevision( 0 )
68*cdf0e10cSrcweir 		, mnType( 0 )
69*cdf0e10cSrcweir 		, mpNode( pNode )
70*cdf0e10cSrcweir 		{
71*cdf0e10cSrcweir 			AttributeList aAttribs( xAttribs );
72*cdf0e10cSrcweir 			mnRevision = aAttribs.getInteger( XML_rev, 0 );
73*cdf0e10cSrcweir 			mnType = xAttribs->getOptionalValueToken( XML_type, 0 );
74*cdf0e10cSrcweir 		}
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir private:
77*cdf0e10cSrcweir 	sal_Int32     mnRevision;
78*cdf0e10cSrcweir 	sal_Int32     mnType;
79*cdf0e10cSrcweir 	LayoutAtomPtr mpNode;
80*cdf0e10cSrcweir };
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir class ChooseContext
84*cdf0e10cSrcweir     : public ContextHandler
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir public:
87*cdf0e10cSrcweir     ChooseContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const LayoutAtomPtr & pNode )
88*cdf0e10cSrcweir         : ContextHandler( rParent )
89*cdf0e10cSrcweir 		, mbHasElse( false )
90*cdf0e10cSrcweir 		, mpNode( pNode )
91*cdf0e10cSrcweir 		{
92*cdf0e10cSrcweir 			msName = xAttribs->getOptionalValue( XML_name );
93*cdf0e10cSrcweir 		}
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	virtual Reference< XFastContextHandler > SAL_CALL
96*cdf0e10cSrcweir 	createFastChildContext( ::sal_Int32 aElement,
97*cdf0e10cSrcweir 							const Reference< XFastAttributeList >& xAttribs )
98*cdf0e10cSrcweir 		throw (SAXException, RuntimeException)
99*cdf0e10cSrcweir 		{
100*cdf0e10cSrcweir 			Reference< XFastContextHandler > xRet;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 			switch( aElement )
103*cdf0e10cSrcweir 			{
104*cdf0e10cSrcweir 			case XML_if:
105*cdf0e10cSrcweir 			{
106*cdf0e10cSrcweir 				// CT_When
107*cdf0e10cSrcweir 				LayoutAtomPtr pAtom( new ConditionAtom( false ) );
108*cdf0e10cSrcweir 				mpNode->addChild( pAtom );
109*cdf0e10cSrcweir                 xRet.set( new IfContext( *this, xAttribs, pAtom ) );
110*cdf0e10cSrcweir 				break;
111*cdf0e10cSrcweir 			}
112*cdf0e10cSrcweir 			case XML_else:
113*cdf0e10cSrcweir 				// CT_Otherwise
114*cdf0e10cSrcweir 				if( !mbHasElse )
115*cdf0e10cSrcweir 				{
116*cdf0e10cSrcweir 					LayoutAtomPtr pAtom( new ConditionAtom( true ) );
117*cdf0e10cSrcweir 					mpNode->addChild( pAtom );
118*cdf0e10cSrcweir                     xRet.set( new IfContext( *this, xAttribs, pAtom ) );
119*cdf0e10cSrcweir 					mbHasElse = true;
120*cdf0e10cSrcweir 				}
121*cdf0e10cSrcweir 				else
122*cdf0e10cSrcweir 				{
123*cdf0e10cSrcweir 					OSL_TRACE( "ignoring second else clause" );
124*cdf0e10cSrcweir 				}
125*cdf0e10cSrcweir 				break;
126*cdf0e10cSrcweir 			default:
127*cdf0e10cSrcweir 				break;
128*cdf0e10cSrcweir 			}
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 			if( !xRet.is() )
131*cdf0e10cSrcweir 				xRet.set(this);
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 			return xRet;
134*cdf0e10cSrcweir 		}
135*cdf0e10cSrcweir private:
136*cdf0e10cSrcweir 	bool     mbHasElse;
137*cdf0e10cSrcweir 	OUString msName;
138*cdf0e10cSrcweir 	LayoutAtomPtr mpNode;
139*cdf0e10cSrcweir };
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir class ForEachContext
145*cdf0e10cSrcweir 	: public LayoutNodeContext
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir public:
148*cdf0e10cSrcweir     ForEachContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const LayoutAtomPtr & pNode )
149*cdf0e10cSrcweir         : LayoutNodeContext( rParent, xAttribs, pNode )
150*cdf0e10cSrcweir 		{
151*cdf0e10cSrcweir 			ForEachAtomPtr pAtom( boost::dynamic_pointer_cast< ForEachAtom >(pNode) );
152*cdf0e10cSrcweir 			OSL_ENSURE( pAtom, "Must pass a ForEachAtom" );
153*cdf0e10cSrcweir 			xAttribs->getOptionalValue( XML_ref );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 			pAtom->iterator().loadFromXAttr( xAttribs );
156*cdf0e10cSrcweir 		}
157*cdf0e10cSrcweir };
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir // CT_LayoutVariablePropertySet
161*cdf0e10cSrcweir class LayoutVariablePropertySetContext
162*cdf0e10cSrcweir     : public ContextHandler
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir public:
165*cdf0e10cSrcweir     LayoutVariablePropertySetContext( ContextHandler& rParent, LayoutNode::VarMap & aVar )
166*cdf0e10cSrcweir         : ContextHandler( rParent )
167*cdf0e10cSrcweir 		, mVariables( aVar )
168*cdf0e10cSrcweir 		{
169*cdf0e10cSrcweir 		}
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	virtual ~LayoutVariablePropertySetContext()
172*cdf0e10cSrcweir 		{
173*cdf0e10cSrcweir 		}
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs )
176*cdf0e10cSrcweir 		throw (SAXException, RuntimeException)
177*cdf0e10cSrcweir 		{
178*cdf0e10cSrcweir 			Reference< XFastContextHandler > xRet;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir             sal_Int32 nIdx =  LayoutNodeContext::tagToVarIdx( getBaseToken( aElement ) );
181*cdf0e10cSrcweir 			if( nIdx != -1 )
182*cdf0e10cSrcweir 			{
183*cdf0e10cSrcweir 				mVariables[ nIdx ] = makeAny( xAttribs->getOptionalValue( XML_val ) );
184*cdf0e10cSrcweir 			}
185*cdf0e10cSrcweir 			if( !xRet.is() )
186*cdf0e10cSrcweir 				xRet.set(this);
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 			return xRet;
189*cdf0e10cSrcweir 		}
190*cdf0e10cSrcweir private:
191*cdf0e10cSrcweir 	LayoutNode::VarMap & mVariables;
192*cdf0e10cSrcweir };
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // CT_LayoutNode
196*cdf0e10cSrcweir LayoutNodeContext::LayoutNodeContext( ContextHandler& rParent,
197*cdf0e10cSrcweir 									  const Reference< XFastAttributeList >& xAttribs,
198*cdf0e10cSrcweir 									  const LayoutAtomPtr &pNode )
199*cdf0e10cSrcweir     : ContextHandler( rParent )
200*cdf0e10cSrcweir 	, mpNode( pNode )
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir 	OSL_ENSURE( pNode, "Node must NOT be NULL" );
203*cdf0e10cSrcweir 	mpNode->setName( xAttribs->getOptionalValue( XML_name ) );
204*cdf0e10cSrcweir 	// TODO shall we even bother?
205*cdf0e10cSrcweir 	// b or t
206*cdf0e10cSrcweir //	sal_Int32 nChOrder = xAttributes->getOptionalValueToken( XML_chOrder, XML_b );
207*cdf0e10cSrcweir //	OUString sMoveWith = xAttributes->getOptionalValue( XML_moveWith );
208*cdf0e10cSrcweir //	OUString sStyleLbl = xAttributes->getOptionalValue( XML_styleLbl );
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir LayoutNodeContext::~LayoutNodeContext()
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir void SAL_CALL LayoutNodeContext::endFastElement( ::sal_Int32 )
217*cdf0e10cSrcweir 	throw (SAXException, RuntimeException)
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir /** convert the XML tag to a variable index in the array
223*cdf0e10cSrcweir  * @param aTag the tag, wihout namespace
224*cdf0e10cSrcweir  * @return the variable index. -1 is an error
225*cdf0e10cSrcweir  */
226*cdf0e10cSrcweir sal_Int32 LayoutNodeContext::tagToVarIdx( sal_Int32 aTag )
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir 	sal_Int32 nIdx = -1;
229*cdf0e10cSrcweir 	switch( aTag )
230*cdf0e10cSrcweir 	{
231*cdf0e10cSrcweir 	case DGM_TOKEN( animLvl ):
232*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_animLvl;
233*cdf0e10cSrcweir 		break;
234*cdf0e10cSrcweir 	case DGM_TOKEN( animOne ):
235*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_animOne;
236*cdf0e10cSrcweir 		break;
237*cdf0e10cSrcweir 	case DGM_TOKEN( bulletEnabled ):
238*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_bulletEnabled;
239*cdf0e10cSrcweir 		break;
240*cdf0e10cSrcweir 	case DGM_TOKEN( chMax ):
241*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_chMax;
242*cdf0e10cSrcweir 		break;
243*cdf0e10cSrcweir 	case DGM_TOKEN( chPref ):
244*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_chPref;
245*cdf0e10cSrcweir 		break;
246*cdf0e10cSrcweir 	case DGM_TOKEN( dir ):
247*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_dir;
248*cdf0e10cSrcweir 		break;
249*cdf0e10cSrcweir 	case DGM_TOKEN( hierBranch ):
250*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_hierBranch;
251*cdf0e10cSrcweir 		break;
252*cdf0e10cSrcweir 	case DGM_TOKEN( orgChart ):
253*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_orgChart;
254*cdf0e10cSrcweir 		break;
255*cdf0e10cSrcweir 	case DGM_TOKEN( resizeHandles ):
256*cdf0e10cSrcweir 		nIdx = LayoutNode::VAR_resizeHandles;
257*cdf0e10cSrcweir 		break;
258*cdf0e10cSrcweir 	default:
259*cdf0e10cSrcweir 		break;
260*cdf0e10cSrcweir 	}
261*cdf0e10cSrcweir 	return nIdx;
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir Reference< XFastContextHandler > SAL_CALL
266*cdf0e10cSrcweir LayoutNodeContext::createFastChildContext( ::sal_Int32 aElement,
267*cdf0e10cSrcweir 												  const Reference< XFastAttributeList >& xAttribs )
268*cdf0e10cSrcweir 	throw (SAXException, RuntimeException)
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir 	Reference< XFastContextHandler > xRet;
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 	switch( aElement )
273*cdf0e10cSrcweir 	{
274*cdf0e10cSrcweir 	case DGM_TOKEN( layoutNode ):
275*cdf0e10cSrcweir 	{
276*cdf0e10cSrcweir 		LayoutNodePtr pNode( new LayoutNode() );
277*cdf0e10cSrcweir 		mpNode->addChild( pNode );
278*cdf0e10cSrcweir         xRet.set( new LayoutNodeContext( *this, xAttribs, pNode ) );
279*cdf0e10cSrcweir 		break;
280*cdf0e10cSrcweir 	}
281*cdf0e10cSrcweir 	case DGM_TOKEN( shape ):
282*cdf0e10cSrcweir 	{
283*cdf0e10cSrcweir 		ShapePtr pShape( new Shape() );
284*cdf0e10cSrcweir         xRet.set( new ShapeContext( *this, ShapePtr(), pShape ) );
285*cdf0e10cSrcweir 		break;
286*cdf0e10cSrcweir 	}
287*cdf0e10cSrcweir 	case DGM_TOKEN( extLst ):
288*cdf0e10cSrcweir         return xRet;
289*cdf0e10cSrcweir 	case DGM_TOKEN( alg ):
290*cdf0e10cSrcweir 	{
291*cdf0e10cSrcweir 		// CT_Algorithm
292*cdf0e10cSrcweir 		LayoutAtomPtr pAtom( new AlgAtom );
293*cdf0e10cSrcweir 		mpNode->addChild( pAtom );
294*cdf0e10cSrcweir         xRet.set( new AlgorithmContext( *this, xAttribs, pAtom ) );
295*cdf0e10cSrcweir 		break;
296*cdf0e10cSrcweir 	}
297*cdf0e10cSrcweir 	case DGM_TOKEN( choose ):
298*cdf0e10cSrcweir 	{
299*cdf0e10cSrcweir 		// CT_Choose
300*cdf0e10cSrcweir 		LayoutAtomPtr pAtom( new ChooseAtom );
301*cdf0e10cSrcweir 		mpNode->addChild( pAtom );
302*cdf0e10cSrcweir         xRet.set( new ChooseContext( *this, xAttribs, pAtom ) );
303*cdf0e10cSrcweir  		break;
304*cdf0e10cSrcweir 	}
305*cdf0e10cSrcweir 	case DGM_TOKEN( forEach ):
306*cdf0e10cSrcweir 	{
307*cdf0e10cSrcweir 		// CT_ForEach
308*cdf0e10cSrcweir 		LayoutAtomPtr pAtom( new ForEachAtom );
309*cdf0e10cSrcweir 		mpNode->addChild( pAtom );
310*cdf0e10cSrcweir         xRet.set( new ForEachContext( *this, xAttribs, pAtom ) );
311*cdf0e10cSrcweir 		break;
312*cdf0e10cSrcweir 	}
313*cdf0e10cSrcweir 	case DGM_TOKEN( constrLst ):
314*cdf0e10cSrcweir 		// CT_Constraints
315*cdf0e10cSrcweir 		// TODO
316*cdf0e10cSrcweir 		break;
317*cdf0e10cSrcweir 	case DGM_TOKEN( presOf ):
318*cdf0e10cSrcweir 	{
319*cdf0e10cSrcweir 		// CT_PresentationOf
320*cdf0e10cSrcweir 		// TODO
321*cdf0e10cSrcweir 		xAttribs->getOptionalValue( XML_axis );
322*cdf0e10cSrcweir 		xAttribs->getOptionalValue( XML_cnt );
323*cdf0e10cSrcweir 		xAttribs->getOptionalValue( XML_hideLastTrans );
324*cdf0e10cSrcweir 		xAttribs->getOptionalValue( XML_ptType );
325*cdf0e10cSrcweir 		xAttribs->getOptionalValue( XML_st );
326*cdf0e10cSrcweir 		xAttribs->getOptionalValue( XML_step );
327*cdf0e10cSrcweir 		break;
328*cdf0e10cSrcweir 	}
329*cdf0e10cSrcweir 	case DGM_TOKEN( ruleLst ):
330*cdf0e10cSrcweir 		// CT_Rules
331*cdf0e10cSrcweir 		// TODO
332*cdf0e10cSrcweir 		break;
333*cdf0e10cSrcweir 	case DGM_TOKEN( varLst ):
334*cdf0e10cSrcweir 	{
335*cdf0e10cSrcweir 		LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
336*cdf0e10cSrcweir 		if( pNode )
337*cdf0e10cSrcweir 		{
338*cdf0e10cSrcweir             xRet.set( new LayoutVariablePropertySetContext( *this, pNode->variables() ) );
339*cdf0e10cSrcweir 		}
340*cdf0e10cSrcweir 		else
341*cdf0e10cSrcweir 		{
342*cdf0e10cSrcweir 			OSL_TRACE( "OOX: encountered a varLst in a non layoutNode context" );
343*cdf0e10cSrcweir 		}
344*cdf0e10cSrcweir 		break;
345*cdf0e10cSrcweir 	}
346*cdf0e10cSrcweir 	default:
347*cdf0e10cSrcweir 		break;
348*cdf0e10cSrcweir 	}
349*cdf0e10cSrcweir 	if( !xRet.is() )
350*cdf0e10cSrcweir 		xRet.set(this);
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 	return xRet;
353*cdf0e10cSrcweir }
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir } }
357