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
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::xml::sax
;
36 namespace oox::drawingml
{
41 : public LayoutNodeContext
44 IfContext( ContextHandler2Helper
const & rParent
,
45 const AttributeList
& rAttribs
,
46 const ConditionAtomPtr
& pAtom
)
47 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
51 class AlgorithmContext
52 : public ContextHandler2
55 AlgorithmContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, const AlgAtomPtr
& pNode
)
56 : ContextHandler2( rParent
)
60 mnRevision
= rAttribs
.getInteger( XML_rev
, 0 );
61 pNode
->setType(rAttribs
.getToken(XML_type
, 0));
64 virtual ContextHandlerRef
65 onCreateContext( ::sal_Int32 aElement
,
66 const AttributeList
& rAttribs
) override
70 case DGM_TOKEN( param
):
72 sal_Int32 nType
= rAttribs
.getToken(XML_type
, 0);
76 mpNode
->setAspectRatio(rAttribs
.getDouble(XML_val
, 0));
79 const sal_Int32 nValTok
= rAttribs
.getToken(XML_val
, 0);
80 mpNode
->addParam(nType
, nValTok
> 0 ? nValTok
81 : rAttribs
.getInteger(XML_val
, 0));
99 : public ContextHandler2
102 ChooseContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, LayoutAtomPtr pNode
)
103 : ContextHandler2( rParent
)
104 , mpNode(std::move( pNode
))
106 msName
= rAttribs
.getStringDefaulted( XML_name
);
109 virtual ContextHandlerRef
110 onCreateContext( ::sal_Int32 aElement
,
111 const AttributeList
& rAttribs
) override
115 case DGM_TOKEN( if ):
118 ConditionAtomPtr pNode
= std::make_shared
<ConditionAtom
>(mpNode
->getLayoutNode(), false, rAttribs
.getFastAttributeList());
119 LayoutAtom::connect(mpNode
, pNode
);
120 return new IfContext( *this, rAttribs
, pNode
);
122 case DGM_TOKEN( else ):
125 ConditionAtomPtr pNode
= std::make_shared
<ConditionAtom
>(mpNode
->getLayoutNode(), true, rAttribs
.getFastAttributeList());
126 LayoutAtom::connect(mpNode
, pNode
);
127 return new IfContext( *this, rAttribs
, pNode
);
137 LayoutAtomPtr mpNode
;
141 : public LayoutNodeContext
144 ForEachContext( ContextHandler2Helper
const & rParent
, const AttributeList
& rAttribs
, const ForEachAtomPtr
& pAtom
)
145 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
147 pAtom
->setRef(rAttribs
.getStringDefaulted(XML_ref
));
148 pAtom
->iterator().loadFromXAttr( rAttribs
.getFastAttributeList() );
150 LayoutAtomMap
& rLayoutAtomMap
= pAtom
->getLayoutNode().getDiagram().getLayout()->getLayoutAtomMap();
151 rLayoutAtomMap
[pAtom
->getName()] = pAtom
;
155 // CT_LayoutVariablePropertySet
156 class LayoutVariablePropertySetContext
157 : public ContextHandler2
160 LayoutVariablePropertySetContext( ContextHandler2Helper
const & rParent
, LayoutNode::VarMap
& aVar
)
161 : ContextHandler2( rParent
)
166 virtual ContextHandlerRef
onCreateContext( ::sal_Int32 aElement
, const AttributeList
& rAttribs
) override
168 mVariables
[ getBaseToken(aElement
) ] = rAttribs
.getStringDefaulted( XML_val
);
172 LayoutNode::VarMap
& mVariables
;
178 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper
const & rParent
,
179 const AttributeList
& rAttribs
,
180 const LayoutAtomPtr
& pAtom
)
181 : ContextHandler2( rParent
)
184 assert( pAtom
&& "Node must NOT be NULL" );
185 mpNode
->setName( rAttribs
.getStringDefaulted( XML_name
) );
188 LayoutNodeContext::~LayoutNodeContext()
193 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement
,
194 const AttributeList
& rAttribs
)
198 case DGM_TOKEN( layoutNode
):
200 LayoutNodePtr pNode
= std::make_shared
<LayoutNode
>(mpNode
->getLayoutNode().getDiagram());
201 LayoutAtom::connect(mpNode
, pNode
);
203 if (rAttribs
.hasAttribute(XML_chOrder
))
205 pNode
->setChildOrder(rAttribs
.getToken(XML_chOrder
, XML_b
));
209 for (LayoutAtomPtr pAtom
= mpNode
; pAtom
; pAtom
= pAtom
->getParent())
211 auto pLayoutNode
= dynamic_cast<LayoutNode
*>(pAtom
.get());
214 pNode
->setChildOrder(pLayoutNode
->getChildOrder());
220 pNode
->setMoveWith( rAttribs
.getStringDefaulted( XML_moveWith
) );
221 pNode
->setStyleLabel( rAttribs
.getStringDefaulted( XML_styleLbl
) );
222 return new LayoutNodeContext( *this, rAttribs
, pNode
);
224 case DGM_TOKEN( shape
):
228 if( rAttribs
.hasAttribute( XML_type
) )
230 pShape
= std::make_shared
<Shape
>("com.sun.star.drawing.CustomShape");
231 if (!rAttribs
.getBool(XML_hideGeom
, false))
233 const sal_Int32
nType(rAttribs
.getToken( XML_type
, XML_obj
));
234 pShape
->setSubType( nType
);
235 pShape
->getCustomShapeProperties()->setShapePresetType( nType
);
240 pShape
= std::make_shared
<Shape
>("com.sun.star.drawing.GroupShape");
243 pShape
->setDiagramRotation(rAttribs
.getInteger(XML_rot
, 0) * PER_DEGREE
);
245 pShape
->setZOrderOff(rAttribs
.getInteger(XML_zOrderOff
, 0));
247 ShapeAtomPtr pAtom
= std::make_shared
<ShapeAtom
>(mpNode
->getLayoutNode(), pShape
);
248 LayoutAtom::connect(mpNode
, pAtom
);
249 return new ShapeContext( *this, ShapePtr(), pShape
);
251 case DGM_TOKEN( extLst
):
253 case DGM_TOKEN( alg
):
256 AlgAtomPtr pAtom
= std::make_shared
<AlgAtom
>(mpNode
->getLayoutNode());
257 LayoutAtom::connect(mpNode
, pAtom
);
258 return new AlgorithmContext( *this, rAttribs
, pAtom
);
260 case DGM_TOKEN( choose
):
263 LayoutAtomPtr pAtom
= std::make_shared
<ChooseAtom
>(mpNode
->getLayoutNode());
264 LayoutAtom::connect(mpNode
, pAtom
);
265 return new ChooseContext( *this, rAttribs
, pAtom
);
267 case DGM_TOKEN( forEach
):
270 ForEachAtomPtr pAtom
= std::make_shared
<ForEachAtom
>(mpNode
->getLayoutNode(), rAttribs
.getFastAttributeList());
271 LayoutAtom::connect(mpNode
, pAtom
);
272 return new ForEachContext( *this, rAttribs
, pAtom
);
274 case DGM_TOKEN( constrLst
):
276 return new ConstraintListContext( *this, mpNode
);
277 case DGM_TOKEN( presOf
):
281 IteratorAttr aIterator
;
282 aIterator
.loadFromXAttr(rAttribs
.getFastAttributeList());
285 case DGM_TOKEN( ruleLst
):
287 return new RuleListContext( *this, mpNode
);
288 case DGM_TOKEN( varLst
):
290 LayoutNodePtr
pNode(std::dynamic_pointer_cast
<LayoutNode
>(mpNode
));
293 return new LayoutVariablePropertySetContext( *this, pNode
->variables() );
297 SAL_WARN("oox", "OOX: encountered a varLst in a non layoutNode context" );
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */