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 "drawingml/diagram/diagram.hxx"
24 #include "oox/drawingml/shapecontext.hxx"
25 #include "drawingml/customshapeproperties.hxx"
26 #include "diagramdefinitioncontext.hxx"
27 #include "constraintlistcontext.hxx"
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
30 #include <osl/diagnose.h>
32 using namespace ::oox::core
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::xml::sax
;
36 namespace oox
{ namespace drawingml
{
39 : public LayoutNodeContext
42 IfContext( ContextHandler2Helper
& rParent
,
43 const AttributeList
& rAttribs
,
44 const ConditionAtomPtr
& pAtom
)
45 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
49 class AlgorithmContext
50 : public ContextHandler2
53 AlgorithmContext( ContextHandler2Helper
& rParent
, const AttributeList
& rAttribs
, const AlgAtomPtr
& pNode
)
54 : ContextHandler2( rParent
)
58 mnRevision
= rAttribs
.getInteger( XML_rev
, 0 );
59 pNode
->setType(rAttribs
.getToken(XML_type
, 0));
62 virtual ContextHandlerRef
63 onCreateContext( ::sal_Int32 aElement
,
64 const AttributeList
& rAttribs
) override
68 case DGM_TOKEN( param
):
70 const sal_Int32 nValTok
= rAttribs
.getToken( XML_val
, 0 );
72 rAttribs
.getToken( XML_type
, 0 ),
73 nValTok
>0 ? nValTok
: rAttribs
.getInteger( XML_val
, 0 ) );
89 : public ContextHandler2
92 ChooseContext( ContextHandler2Helper
& rParent
, const AttributeList
& rAttribs
, const LayoutAtomPtr
& pNode
)
93 : ContextHandler2( rParent
)
96 msName
= rAttribs
.getString( XML_name
).get();
99 virtual ContextHandlerRef
100 onCreateContext( ::sal_Int32 aElement
,
101 const AttributeList
& rAttribs
) override
105 case DGM_TOKEN( if ):
108 mpConditionNode
.reset( new ConditionAtom(rAttribs
.getFastAttributeList()) );
109 mpNode
->addChild( mpConditionNode
);
110 return new IfContext( *this, rAttribs
, mpConditionNode
);
112 case DGM_TOKEN( else ):
114 if( mpConditionNode
)
116 mpConditionNode
->readElseBranch();
117 ContextHandlerRef xRet
= new IfContext( *this, rAttribs
, mpConditionNode
);
118 mpConditionNode
.reset();
123 SAL_WARN("oox", "ignoring second else clause" );
134 LayoutAtomPtr mpNode
;
135 ConditionAtomPtr mpConditionNode
;
139 : public LayoutNodeContext
142 ForEachContext( ContextHandler2Helper
& rParent
, const AttributeList
& rAttribs
, const ForEachAtomPtr
& pAtom
)
143 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
145 rAttribs
.getString( XML_ref
);
146 pAtom
->iterator().loadFromXAttr( rAttribs
.getFastAttributeList() );
150 // CT_LayoutVariablePropertySet
151 class LayoutVariablePropertySetContext
152 : public ContextHandler2
155 LayoutVariablePropertySetContext( ContextHandler2Helper
& rParent
, LayoutNode::VarMap
& aVar
)
156 : ContextHandler2( rParent
)
161 virtual ContextHandlerRef
onCreateContext( ::sal_Int32 aElement
, const AttributeList
& rAttribs
) override
163 sal_Int32 nIdx
= LayoutNodeContext::tagToVarIdx( getBaseToken( aElement
) );
166 mVariables
[ nIdx
] <<= rAttribs
.getString( XML_val
).get();
172 LayoutNode::VarMap
& mVariables
;
176 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper
& rParent
,
177 const AttributeList
& rAttribs
,
178 const LayoutAtomPtr
& pAtom
)
179 : ContextHandler2( rParent
)
182 OSL_ENSURE( pAtom
, "Node must NOT be NULL" );
183 mpNode
->setName( rAttribs
.getString( XML_name
).get() );
186 LayoutNodeContext::~LayoutNodeContext()
190 /** convert the XML tag to a variable index in the array
191 * @param aTag the tag, without namespace
192 * @return the variable index. -1 is an error
194 sal_Int32
LayoutNodeContext::tagToVarIdx( sal_Int32 aTag
)
199 case DGM_TOKEN( animLvl
):
200 nIdx
= LayoutNode::VAR_animLvl
;
202 case DGM_TOKEN( animOne
):
203 nIdx
= LayoutNode::VAR_animOne
;
205 case DGM_TOKEN( bulletEnabled
):
206 nIdx
= LayoutNode::VAR_bulletEnabled
;
208 case DGM_TOKEN( chMax
):
209 nIdx
= LayoutNode::VAR_chMax
;
211 case DGM_TOKEN( chPref
):
212 nIdx
= LayoutNode::VAR_chPref
;
214 case DGM_TOKEN( dir
):
215 nIdx
= LayoutNode::VAR_dir
;
217 case DGM_TOKEN( hierBranch
):
218 nIdx
= LayoutNode::VAR_hierBranch
;
220 case DGM_TOKEN( orgChart
):
221 nIdx
= LayoutNode::VAR_orgChart
;
223 case DGM_TOKEN( resizeHandles
):
224 nIdx
= LayoutNode::VAR_resizeHandles
;
233 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement
,
234 const AttributeList
& rAttribs
)
238 case DGM_TOKEN( layoutNode
):
240 LayoutNodePtr
pNode( new LayoutNode() );
241 mpNode
->addChild( pNode
);
242 pNode
->setChildOrder( rAttribs
.getToken( XML_chOrder
, XML_b
) );
243 pNode
->setMoveWith( rAttribs
.getString( XML_moveWith
).get() );
244 pNode
->setStyleLabel( rAttribs
.getString( XML_styleLbl
).get() );
245 return new LayoutNodeContext( *this, rAttribs
, pNode
);
247 case DGM_TOKEN( shape
):
249 LayoutNodePtr
pNode(std::dynamic_pointer_cast
<LayoutNode
>(mpNode
));
254 if( rAttribs
.hasAttribute( XML_type
) )
256 pShape
.reset( new Shape("com.sun.star.drawing.CustomShape") );
257 const sal_Int32
nType(rAttribs
.getToken( XML_type
, XML_obj
));
258 pShape
->setSubType( nType
);
259 pShape
->getCustomShapeProperties()->setShapePresetType( nType
);
263 pShape
.reset( new Shape("com.sun.star.drawing.GroupShape") );
266 pNode
->setShape( pShape
);
267 return new ShapeContext( *this, ShapePtr(), pShape
);
271 SAL_WARN("oox", "OOX: encountered a shape in a non layoutNode context" );
275 case DGM_TOKEN( extLst
):
277 case DGM_TOKEN( alg
):
280 AlgAtomPtr
pAtom( new AlgAtom
);
281 mpNode
->addChild( pAtom
);
282 return new AlgorithmContext( *this, rAttribs
, pAtom
);
284 case DGM_TOKEN( choose
):
287 LayoutAtomPtr
pAtom( new ChooseAtom
);
288 mpNode
->addChild( pAtom
);
289 return new ChooseContext( *this, rAttribs
, pAtom
);
291 case DGM_TOKEN( forEach
):
294 ForEachAtomPtr
pAtom( new ForEachAtom(rAttribs
.getFastAttributeList()) );
295 mpNode
->addChild( pAtom
);
296 return new ForEachContext( *this, rAttribs
, pAtom
);
298 case DGM_TOKEN( constrLst
):
300 return new ConstraintListContext( *this, mpNode
);
301 case DGM_TOKEN( presOf
):
305 rAttribs
.getString( XML_axis
);
306 rAttribs
.getString( XML_cnt
);
307 rAttribs
.getString( XML_hideLastTrans
);
308 rAttribs
.getString( XML_ptType
);
309 rAttribs
.getString( XML_st
);
310 rAttribs
.getString( XML_step
);
313 case DGM_TOKEN( ruleLst
):
317 case DGM_TOKEN( varLst
):
319 LayoutNodePtr
pNode(std::dynamic_pointer_cast
<LayoutNode
>(mpNode
));
322 return new LayoutVariablePropertySetContext( *this, pNode
->variables() );
326 SAL_WARN("oox", "OOX: encountered a varLst in a non layoutNode context" );
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */