1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "layoutnodecontext.hxx"
22 #include "oox/helper/attributelist.hxx"
23 #include "oox/drawingml/diagram/diagram.hxx"
24 #include "oox/drawingml/shapecontext.hxx"
25 #include "oox/drawingml/customshapeproperties.hxx"
26 #include "diagramdefinitioncontext.hxx"
27 #include "constraintlistcontext.hxx"
29 using namespace ::oox::core
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::xml::sax
;
33 namespace oox
{ namespace drawingml
{
36 : public LayoutNodeContext
39 IfContext( ContextHandler
& rParent
,
40 const Reference
< XFastAttributeList
>& xAttribs
,
41 const ConditionAtomPtr
& pAtom
)
42 : LayoutNodeContext( rParent
, xAttribs
, pAtom
)
48 class AlgorithmContext
49 : public ContextHandler
52 AlgorithmContext( ContextHandler
& rParent
, const Reference
< XFastAttributeList
>& xAttribs
, const AlgAtomPtr
& pNode
)
53 : ContextHandler( rParent
)
57 AttributeList
aAttribs( xAttribs
);
58 mnRevision
= aAttribs
.getInteger( XML_rev
, 0 );
59 pNode
->setType(xAttribs
->getOptionalValueToken(XML_type
, 0));
62 virtual Reference
< XFastContextHandler
> SAL_CALL
63 createFastChildContext( ::sal_Int32 aElement
,
64 const Reference
< XFastAttributeList
>& xAttribs
)
65 throw (SAXException
, RuntimeException
)
67 Reference
< XFastContextHandler
> xRet
;
71 case DGM_TOKEN( param
):
73 AttributeList
aAttribs( xAttribs
);
74 const sal_Int32 nValTok
=aAttribs
.getToken( XML_val
, 0 );
76 aAttribs
.getToken( XML_type
, 0 ),
77 nValTok
>0 ? nValTok
: aAttribs
.getInteger( XML_val
, 0 ) );
97 : public ContextHandler
100 ChooseContext( ContextHandler
& rParent
, const Reference
< XFastAttributeList
>& xAttribs
, const LayoutAtomPtr
& pNode
)
101 : ContextHandler( rParent
)
104 msName
= xAttribs
->getOptionalValue( XML_name
);
107 virtual Reference
< XFastContextHandler
> SAL_CALL
108 createFastChildContext( ::sal_Int32 aElement
,
109 const Reference
< XFastAttributeList
>& xAttribs
)
110 throw (SAXException
, RuntimeException
)
112 Reference
< XFastContextHandler
> xRet
;
116 case DGM_TOKEN( if ):
119 mpConditionNode
.reset( new ConditionAtom(xAttribs
) );
120 mpNode
->addChild( mpConditionNode
);
121 xRet
.set( new IfContext( *this, xAttribs
, mpConditionNode
) );
124 case DGM_TOKEN( else ):
126 if( mpConditionNode
)
128 mpConditionNode
->readElseBranch();
129 xRet
.set( new IfContext( *this, xAttribs
, mpConditionNode
) );
130 mpConditionNode
.reset();
134 OSL_TRACE( "ignoring second else clause" );
148 LayoutAtomPtr mpNode
;
149 ConditionAtomPtr mpConditionNode
;
156 : public LayoutNodeContext
159 ForEachContext( ContextHandler
& rParent
, const Reference
< XFastAttributeList
>& xAttribs
, const ForEachAtomPtr
& pAtom
)
160 : LayoutNodeContext( rParent
, xAttribs
, pAtom
)
162 xAttribs
->getOptionalValue( XML_ref
);
163 pAtom
->iterator().loadFromXAttr( xAttribs
);
168 // CT_LayoutVariablePropertySet
169 class LayoutVariablePropertySetContext
170 : public ContextHandler
173 LayoutVariablePropertySetContext( ContextHandler
& rParent
, LayoutNode::VarMap
& aVar
)
174 : ContextHandler( rParent
)
179 virtual ~LayoutVariablePropertySetContext()
183 virtual Reference
< XFastContextHandler
> SAL_CALL
createFastChildContext( ::sal_Int32 aElement
, const Reference
< XFastAttributeList
>& xAttribs
)
184 throw (SAXException
, RuntimeException
)
186 Reference
< XFastContextHandler
> xRet
;
188 sal_Int32 nIdx
= LayoutNodeContext::tagToVarIdx( getBaseToken( aElement
) );
191 mVariables
[ nIdx
] = makeAny( xAttribs
->getOptionalValue( XML_val
) );
199 LayoutNode::VarMap
& mVariables
;
204 LayoutNodeContext::LayoutNodeContext( ContextHandler
& rParent
,
205 const Reference
< XFastAttributeList
>& xAttribs
,
206 const LayoutAtomPtr
& pAtom
)
207 : ContextHandler( rParent
)
210 OSL_ENSURE( pAtom
, "Node must NOT be NULL" );
211 mpNode
->setName( xAttribs
->getOptionalValue( XML_name
) );
215 LayoutNodeContext::~LayoutNodeContext()
219 void SAL_CALL
LayoutNodeContext::endFastElement( ::sal_Int32
)
220 throw (SAXException
, RuntimeException
)
225 /** convert the XML tag to a variable index in the array
226 * @param aTag the tag, without namespace
227 * @return the variable index. -1 is an error
229 sal_Int32
LayoutNodeContext::tagToVarIdx( sal_Int32 aTag
)
234 case DGM_TOKEN( animLvl
):
235 nIdx
= LayoutNode::VAR_animLvl
;
237 case DGM_TOKEN( animOne
):
238 nIdx
= LayoutNode::VAR_animOne
;
240 case DGM_TOKEN( bulletEnabled
):
241 nIdx
= LayoutNode::VAR_bulletEnabled
;
243 case DGM_TOKEN( chMax
):
244 nIdx
= LayoutNode::VAR_chMax
;
246 case DGM_TOKEN( chPref
):
247 nIdx
= LayoutNode::VAR_chPref
;
249 case DGM_TOKEN( dir
):
250 nIdx
= LayoutNode::VAR_dir
;
252 case DGM_TOKEN( hierBranch
):
253 nIdx
= LayoutNode::VAR_hierBranch
;
255 case DGM_TOKEN( orgChart
):
256 nIdx
= LayoutNode::VAR_orgChart
;
258 case DGM_TOKEN( resizeHandles
):
259 nIdx
= LayoutNode::VAR_resizeHandles
;
268 Reference
< XFastContextHandler
> SAL_CALL
269 LayoutNodeContext::createFastChildContext( ::sal_Int32 aElement
,
270 const Reference
< XFastAttributeList
>& xAttribs
)
271 throw (SAXException
, RuntimeException
)
273 Reference
< XFastContextHandler
> xRet
;
277 case DGM_TOKEN( layoutNode
):
279 LayoutNodePtr
pNode( new LayoutNode() );
280 mpNode
->addChild( pNode
);
281 pNode
->setChildOrder( xAttribs
->getOptionalValueToken( XML_chOrder
, XML_b
) );
282 pNode
->setMoveWith( xAttribs
->getOptionalValue( XML_moveWith
) );
283 pNode
->setStyleLabel( xAttribs
->getOptionalValue( XML_styleLbl
) );
284 xRet
.set( new LayoutNodeContext( *this, xAttribs
, pNode
) );
287 case DGM_TOKEN( shape
):
289 LayoutNodePtr
pNode( boost::dynamic_pointer_cast
< LayoutNode
>( mpNode
) );
294 if( xAttribs
->hasAttribute( XML_type
) )
296 pShape
.reset( new Shape("com.sun.star.drawing.CustomShape") );
297 const sal_Int32
nType(xAttribs
->getOptionalValueToken( XML_type
, XML_obj
));
298 pShape
->setSubType( nType
);
299 pShape
->getCustomShapeProperties()->setShapePresetType( nType
);
303 pShape
.reset( new Shape("com.sun.star.drawing.GroupShape") );
306 pNode
->setShape( pShape
);
307 xRet
.set( new ShapeContext( *this, ShapePtr(), pShape
) );
311 OSL_TRACE( "OOX: encountered a shape in a non layoutNode context" );
315 case DGM_TOKEN( extLst
):
317 case DGM_TOKEN( alg
):
320 AlgAtomPtr
pAtom( new AlgAtom
);
321 mpNode
->addChild( pAtom
);
322 xRet
.set( new AlgorithmContext( *this, xAttribs
, pAtom
) );
325 case DGM_TOKEN( choose
):
328 LayoutAtomPtr
pAtom( new ChooseAtom
);
329 mpNode
->addChild( pAtom
);
330 xRet
.set( new ChooseContext( *this, xAttribs
, pAtom
) );
333 case DGM_TOKEN( forEach
):
336 ForEachAtomPtr
pAtom( new ForEachAtom(xAttribs
) );
337 mpNode
->addChild( pAtom
);
338 xRet
.set( new ForEachContext( *this, xAttribs
, pAtom
) );
341 case DGM_TOKEN( constrLst
):
343 xRet
.set( new ConstraintListContext( *this, xAttribs
, mpNode
) );
345 case DGM_TOKEN( presOf
):
349 xAttribs
->getOptionalValue( XML_axis
);
350 xAttribs
->getOptionalValue( XML_cnt
);
351 xAttribs
->getOptionalValue( XML_hideLastTrans
);
352 xAttribs
->getOptionalValue( XML_ptType
);
353 xAttribs
->getOptionalValue( XML_st
);
354 xAttribs
->getOptionalValue( XML_step
);
357 case DGM_TOKEN( ruleLst
):
361 case DGM_TOKEN( varLst
):
363 LayoutNodePtr
pNode( boost::dynamic_pointer_cast
< LayoutNode
>( mpNode
) );
366 xRet
.set( new LayoutVariablePropertySetContext( *this, pNode
->variables() ) );
370 OSL_TRACE( "OOX: encountered a varLst in a non layoutNode context" );
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */