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 "constraintlistcontext.hxx"
26 #include "rulelistcontext.hxx"
27 #include <oox/token/namespaces.hxx>
28 #include <oox/token/tokens.hxx>
29 #include <sal/log.hxx>
32 using namespace ::oox::core
;
34 namespace oox::drawingml
{
39 : public LayoutNodeContext
42 IfContext( ContextHandler2Helper
const & rParent
,
43 const AttributeList
& rAttribs
,
44 const ConditionAtomPtr
& pAtom
)
45 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
49 class AlgorithmContext
50 : public ContextHandler2
53 AlgorithmContext( ContextHandler2Helper
const & 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 sal_Int32 nType
= rAttribs
.getToken(XML_type
, 0);
74 mpNode
->setAspectRatio(rAttribs
.getDouble(XML_val
, 0));
77 const sal_Int32 nValTok
= rAttribs
.getToken(XML_val
, 0);
78 mpNode
->addParam(nType
, nValTok
> 0 ? nValTok
79 : rAttribs
.getInteger(XML_val
, 0));
97 : public ContextHandler2
100 ChooseContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, LayoutAtomPtr pNode
)
101 : ContextHandler2( rParent
)
102 , mpNode(std::move( pNode
))
104 msName
= rAttribs
.getStringDefaulted( XML_name
);
107 virtual ContextHandlerRef
108 onCreateContext( ::sal_Int32 aElement
,
109 const AttributeList
& rAttribs
) override
113 case DGM_TOKEN( if ):
116 ConditionAtomPtr pNode
= std::make_shared
<ConditionAtom
>(mpNode
->getLayoutNode(), false, rAttribs
.getFastAttributeList());
117 LayoutAtom::connect(mpNode
, pNode
);
118 return new IfContext( *this, rAttribs
, pNode
);
120 case DGM_TOKEN( else ):
123 ConditionAtomPtr pNode
= std::make_shared
<ConditionAtom
>(mpNode
->getLayoutNode(), true, rAttribs
.getFastAttributeList());
124 LayoutAtom::connect(mpNode
, pNode
);
125 return new IfContext( *this, rAttribs
, pNode
);
135 LayoutAtomPtr mpNode
;
139 : public LayoutNodeContext
142 ForEachContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, const ForEachAtomPtr
& pAtom
)
143 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
145 pAtom
->setRef(rAttribs
.getStringDefaulted(XML_ref
));
146 pAtom
->iterator().loadFromXAttr( rAttribs
.getFastAttributeList() );
148 LayoutAtomMap
& rLayoutAtomMap
= pAtom
->getLayoutNode().getDiagram().getLayout()->getLayoutAtomMap();
149 rLayoutAtomMap
[pAtom
->getName()] = pAtom
;
153 // CT_LayoutVariablePropertySet
154 class LayoutVariablePropertySetContext
155 : public ContextHandler2
158 LayoutVariablePropertySetContext( ContextHandler2Helper
const & rParent
, LayoutNode::VarMap
& aVar
)
159 : ContextHandler2( rParent
)
164 virtual ContextHandlerRef
onCreateContext( ::sal_Int32 aElement
, const AttributeList
& rAttribs
) override
166 mVariables
[ getBaseToken(aElement
) ] = rAttribs
.getStringDefaulted( XML_val
);
170 LayoutNode::VarMap
& mVariables
;
176 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper
const & rParent
,
177 const AttributeList
& rAttribs
,
178 const LayoutAtomPtr
& pAtom
)
179 : ContextHandler2( rParent
)
182 assert( pAtom
&& "Node must NOT be NULL" );
183 mpNode
->setName( rAttribs
.getStringDefaulted( XML_name
) );
186 LayoutNodeContext::~LayoutNodeContext()
191 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement
,
192 const AttributeList
& rAttribs
)
196 case DGM_TOKEN( layoutNode
):
198 LayoutNodePtr pNode
= std::make_shared
<LayoutNode
>(mpNode
->getLayoutNode().getDiagram());
199 LayoutAtom::connect(mpNode
, pNode
);
201 if (rAttribs
.hasAttribute(XML_chOrder
))
203 pNode
->setChildOrder(rAttribs
.getToken(XML_chOrder
, XML_b
));
207 for (LayoutAtomPtr pAtom
= mpNode
; pAtom
; pAtom
= pAtom
->getParent())
209 auto pLayoutNode
= dynamic_cast<LayoutNode
*>(pAtom
.get());
212 pNode
->setChildOrder(pLayoutNode
->getChildOrder());
218 pNode
->setMoveWith( rAttribs
.getStringDefaulted( XML_moveWith
) );
219 pNode
->setStyleLabel( rAttribs
.getStringDefaulted( XML_styleLbl
) );
220 return new LayoutNodeContext( *this, rAttribs
, pNode
);
222 case DGM_TOKEN( shape
):
226 if( rAttribs
.hasAttribute( XML_type
) )
228 pShape
= std::make_shared
<Shape
>("com.sun.star.drawing.CustomShape");
229 if (!rAttribs
.getBool(XML_hideGeom
, false))
231 const sal_Int32
nType(rAttribs
.getToken( XML_type
, XML_obj
));
232 pShape
->setSubType( nType
);
233 pShape
->getCustomShapeProperties()->setShapePresetType( nType
);
238 pShape
= std::make_shared
<Shape
>("com.sun.star.drawing.GroupShape");
241 pShape
->setDiagramRotation(rAttribs
.getInteger(XML_rot
, 0) * PER_DEGREE
);
243 pShape
->setZOrderOff(rAttribs
.getInteger(XML_zOrderOff
, 0));
245 ShapeAtomPtr pAtom
= std::make_shared
<ShapeAtom
>(mpNode
->getLayoutNode(), pShape
);
246 LayoutAtom::connect(mpNode
, pAtom
);
247 return new ShapeContext( *this, ShapePtr(), std::move(pShape
) );
249 case DGM_TOKEN( extLst
):
251 case DGM_TOKEN( alg
):
254 AlgAtomPtr pAtom
= std::make_shared
<AlgAtom
>(mpNode
->getLayoutNode());
255 LayoutAtom::connect(mpNode
, pAtom
);
256 return new AlgorithmContext( *this, rAttribs
, pAtom
);
258 case DGM_TOKEN( choose
):
261 LayoutAtomPtr pAtom
= std::make_shared
<ChooseAtom
>(mpNode
->getLayoutNode());
262 LayoutAtom::connect(mpNode
, pAtom
);
263 return new ChooseContext( *this, rAttribs
, std::move(pAtom
) );
265 case DGM_TOKEN( forEach
):
268 ForEachAtomPtr pAtom
= std::make_shared
<ForEachAtom
>(mpNode
->getLayoutNode(), rAttribs
.getFastAttributeList());
269 LayoutAtom::connect(mpNode
, pAtom
);
270 return new ForEachContext( *this, rAttribs
, pAtom
);
272 case DGM_TOKEN( constrLst
):
274 return new ConstraintListContext( *this, mpNode
);
275 case DGM_TOKEN( presOf
):
279 IteratorAttr aIterator
;
280 aIterator
.loadFromXAttr(rAttribs
.getFastAttributeList());
283 case DGM_TOKEN( ruleLst
):
285 return new RuleListContext( *this, mpNode
);
286 case DGM_TOKEN( varLst
):
288 LayoutNodePtr
pNode(std::dynamic_pointer_cast
<LayoutNode
>(mpNode
));
291 return new LayoutVariablePropertySetContext( *this, pNode
->variables() );
295 SAL_WARN("oox", "OOX: encountered a varLst in a non layoutNode context" );
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */