Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / oox / source / drawingml / diagram / layoutnodecontext.cxx
blob45756e20bd23705b623efcad811ebaeca925d276
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 #include <utility>
32 using namespace ::oox::core;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::xml::sax;
36 namespace oox::drawingml {
38 namespace {
40 class IfContext
41 : public LayoutNodeContext
43 public:
44 IfContext( ContextHandler2Helper const & rParent,
45 const AttributeList& rAttribs,
46 const ConditionAtomPtr& pAtom )
47 : LayoutNodeContext( rParent, rAttribs, pAtom )
51 class AlgorithmContext
52 : public ContextHandler2
54 public:
55 AlgorithmContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, const AlgAtomPtr & pNode )
56 : ContextHandler2( rParent )
57 , mnRevision( 0 )
58 , mpNode( pNode )
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
68 switch( aElement )
70 case DGM_TOKEN( param ):
72 sal_Int32 nType = rAttribs.getToken(XML_type, 0);
73 switch (nType)
75 case XML_ar:
76 mpNode->setAspectRatio(rAttribs.getDouble(XML_val, 0));
77 break;
78 default:
79 const sal_Int32 nValTok = rAttribs.getToken(XML_val, 0);
80 mpNode->addParam(nType, nValTok > 0 ? nValTok
81 : rAttribs.getInteger(XML_val, 0));
82 break;
84 break;
86 default:
87 break;
90 return this;
93 private:
94 sal_Int32 mnRevision;
95 AlgAtomPtr mpNode;
98 class ChooseContext
99 : public ContextHandler2
101 public:
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
113 switch( aElement )
115 case DGM_TOKEN( if ):
117 // CT_When
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 ):
124 // CT_Otherwise
125 ConditionAtomPtr pNode = std::make_shared<ConditionAtom>(mpNode->getLayoutNode(), true, rAttribs.getFastAttributeList());
126 LayoutAtom::connect(mpNode, pNode);
127 return new IfContext( *this, rAttribs, pNode );
129 default:
130 break;
133 return this;
135 private:
136 OUString msName;
137 LayoutAtomPtr mpNode;
140 class ForEachContext
141 : public LayoutNodeContext
143 public:
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
159 public:
160 LayoutVariablePropertySetContext( ContextHandler2Helper const & rParent, LayoutNode::VarMap & aVar )
161 : ContextHandler2( rParent )
162 , mVariables( aVar )
166 virtual ContextHandlerRef onCreateContext( ::sal_Int32 aElement, const AttributeList& rAttribs ) override
168 mVariables[ getBaseToken(aElement) ] = rAttribs.getStringDefaulted( XML_val );
169 return this;
171 private:
172 LayoutNode::VarMap & mVariables;
177 // CT_LayoutNode
178 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper const & rParent,
179 const AttributeList& rAttribs,
180 const LayoutAtomPtr& pAtom )
181 : ContextHandler2( rParent )
182 , mpNode( pAtom )
184 assert( pAtom && "Node must NOT be NULL" );
185 mpNode->setName( rAttribs.getStringDefaulted( XML_name ) );
188 LayoutNodeContext::~LayoutNodeContext()
192 ContextHandlerRef
193 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
194 const AttributeList& rAttribs )
196 switch( aElement )
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));
207 else
209 for (LayoutAtomPtr pAtom = mpNode; pAtom; pAtom = pAtom->getParent())
211 auto pLayoutNode = dynamic_cast<LayoutNode*>(pAtom.get());
212 if (pLayoutNode)
214 pNode->setChildOrder(pLayoutNode->getChildOrder());
215 break;
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 ):
226 ShapePtr pShape;
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 );
238 else
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 ):
252 return nullptr;
253 case DGM_TOKEN( alg ):
255 // CT_Algorithm
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 ):
262 // CT_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 ):
269 // CT_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 ):
275 // CT_Constraints
276 return new ConstraintListContext( *this, mpNode );
277 case DGM_TOKEN( presOf ):
279 // CT_PresentationOf
280 // TODO
281 IteratorAttr aIterator;
282 aIterator.loadFromXAttr(rAttribs.getFastAttributeList());
283 break;
285 case DGM_TOKEN( ruleLst ):
286 // CT_Rules
287 return new RuleListContext( *this, mpNode );
288 case DGM_TOKEN( varLst ):
290 LayoutNodePtr pNode(std::dynamic_pointer_cast<LayoutNode>(mpNode));
291 if( pNode )
293 return new LayoutVariablePropertySetContext( *this, pNode->variables() );
295 else
297 SAL_WARN("oox", "OOX: encountered a varLst in a non layoutNode context" );
299 break;
301 default:
302 break;
305 return this;
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */