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/shapecontext.hxx>
24 #include <drawingml/customshapeproperties.hxx>
25 #include "diagramdefinitioncontext.hxx"
26 #include "constraintlistcontext.hxx"
27 #include <oox/token/namespaces.hxx>
28 #include <oox/token/tokens.hxx>
29 #include <sal/log.hxx>
31 using namespace ::oox::core
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::xml::sax
;
35 namespace oox
{ namespace drawingml
{
38 : public LayoutNodeContext
41 IfContext( ContextHandler2Helper
const & rParent
,
42 const AttributeList
& rAttribs
,
43 const ConditionAtomPtr
& pAtom
)
44 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
48 class AlgorithmContext
49 : public ContextHandler2
52 AlgorithmContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, const AlgAtomPtr
& pNode
)
53 : ContextHandler2( rParent
)
57 mnRevision
= rAttribs
.getInteger( XML_rev
, 0 );
58 pNode
->setType(rAttribs
.getToken(XML_type
, 0));
61 virtual ContextHandlerRef
62 onCreateContext( ::sal_Int32 aElement
,
63 const AttributeList
& rAttribs
) override
67 case DGM_TOKEN( param
):
69 sal_Int32 nType
= rAttribs
.getToken(XML_type
, 0);
73 mpNode
->setAspectRatio(rAttribs
.getDouble(XML_val
, 0));
76 const sal_Int32 nValTok
= rAttribs
.getToken(XML_val
, 0);
77 mpNode
->addParam(nType
, nValTok
> 0 ? nValTok
78 : rAttribs
.getInteger(XML_val
, 0));
96 : public ContextHandler2
99 ChooseContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, const LayoutAtomPtr
& pNode
)
100 : ContextHandler2( rParent
)
103 msName
= rAttribs
.getString( XML_name
).get();
106 virtual ContextHandlerRef
107 onCreateContext( ::sal_Int32 aElement
,
108 const AttributeList
& rAttribs
) override
112 case DGM_TOKEN( if ):
115 ConditionAtomPtr
pNode( new ConditionAtom(mpNode
->getLayoutNode(), false, rAttribs
.getFastAttributeList()) );
116 LayoutAtom::connect(mpNode
, pNode
);
117 return new IfContext( *this, rAttribs
, pNode
);
119 case DGM_TOKEN( else ):
122 ConditionAtomPtr
pNode( new ConditionAtom(mpNode
->getLayoutNode(), true, rAttribs
.getFastAttributeList()) );
123 LayoutAtom::connect(mpNode
, pNode
);
124 return new IfContext( *this, rAttribs
, pNode
);
134 LayoutAtomPtr mpNode
;
138 : public LayoutNodeContext
141 ForEachContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, const ForEachAtomPtr
& pAtom
)
142 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
144 pAtom
->setRef(rAttribs
.getString(XML_ref
).get());
145 pAtom
->iterator().loadFromXAttr( rAttribs
.getFastAttributeList() );
147 LayoutAtomMap
& rLayoutAtomMap
= pAtom
->getLayoutNode().getDiagram().getLayout()->getLayoutAtomMap();
148 rLayoutAtomMap
[pAtom
->getName()] = pAtom
;
152 // CT_LayoutVariablePropertySet
153 class LayoutVariablePropertySetContext
154 : public ContextHandler2
157 LayoutVariablePropertySetContext( ContextHandler2Helper
const & rParent
, LayoutNode::VarMap
& aVar
)
158 : ContextHandler2( rParent
)
163 virtual ContextHandlerRef
onCreateContext( ::sal_Int32 aElement
, const AttributeList
& rAttribs
) override
165 mVariables
[ getBaseToken(aElement
) ] = rAttribs
.getString( XML_val
).get();
169 LayoutNode::VarMap
& mVariables
;
173 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper
const & rParent
,
174 const AttributeList
& rAttribs
,
175 const LayoutAtomPtr
& pAtom
)
176 : ContextHandler2( rParent
)
179 assert( pAtom
&& "Node must NOT be NULL" );
180 mpNode
->setName( rAttribs
.getString( XML_name
).get() );
183 LayoutNodeContext::~LayoutNodeContext()
188 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement
,
189 const AttributeList
& rAttribs
)
193 case DGM_TOKEN( layoutNode
):
195 LayoutNodePtr
pNode( new LayoutNode(mpNode
->getLayoutNode().getDiagram()) );
196 LayoutAtom::connect(mpNode
, pNode
);
197 pNode
->setChildOrder( rAttribs
.getToken( XML_chOrder
, XML_b
) );
198 pNode
->setMoveWith( rAttribs
.getString( XML_moveWith
).get() );
199 pNode
->setStyleLabel( rAttribs
.getString( XML_styleLbl
).get() );
200 return new LayoutNodeContext( *this, rAttribs
, pNode
);
202 case DGM_TOKEN( shape
):
206 if( rAttribs
.hasAttribute( XML_type
) )
208 pShape
.reset( new Shape("com.sun.star.drawing.CustomShape") );
209 if (!rAttribs
.getBool(XML_hideGeom
, false))
211 const sal_Int32
nType(rAttribs
.getToken( XML_type
, XML_obj
));
212 pShape
->setSubType( nType
);
213 pShape
->getCustomShapeProperties()->setShapePresetType( nType
);
218 pShape
.reset( new Shape("com.sun.star.drawing.GroupShape") );
221 pShape
->setDiagramRotation(rAttribs
.getInteger(XML_rot
, 0) * PER_DEGREE
);
223 pShape
->setZOrderOff(rAttribs
.getInteger(XML_zOrderOff
, 0));
225 ShapeAtomPtr
pAtom( new ShapeAtom(mpNode
->getLayoutNode(), pShape
) );
226 LayoutAtom::connect(mpNode
, pAtom
);
227 return new ShapeContext( *this, ShapePtr(), pShape
);
229 case DGM_TOKEN( extLst
):
231 case DGM_TOKEN( alg
):
234 AlgAtomPtr
pAtom( new AlgAtom(mpNode
->getLayoutNode()) );
235 LayoutAtom::connect(mpNode
, pAtom
);
236 return new AlgorithmContext( *this, rAttribs
, pAtom
);
238 case DGM_TOKEN( choose
):
241 LayoutAtomPtr
pAtom( new ChooseAtom(mpNode
->getLayoutNode()) );
242 LayoutAtom::connect(mpNode
, pAtom
);
243 return new ChooseContext( *this, rAttribs
, pAtom
);
245 case DGM_TOKEN( forEach
):
248 ForEachAtomPtr
pAtom( new ForEachAtom(mpNode
->getLayoutNode(), rAttribs
.getFastAttributeList()) );
249 LayoutAtom::connect(mpNode
, pAtom
);
250 return new ForEachContext( *this, rAttribs
, pAtom
);
252 case DGM_TOKEN( constrLst
):
254 return new ConstraintListContext( *this, mpNode
);
255 case DGM_TOKEN( presOf
):
259 IteratorAttr aIterator
;
260 aIterator
.loadFromXAttr(rAttribs
.getFastAttributeList());
263 case DGM_TOKEN( ruleLst
):
267 case DGM_TOKEN( varLst
):
269 LayoutNodePtr
pNode(std::dynamic_pointer_cast
<LayoutNode
>(mpNode
));
272 return new LayoutVariablePropertySetContext( *this, pNode
->variables() );
276 SAL_WARN("oox", "OOX: encountered a varLst in a non layoutNode context" );
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */