Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / diagram / layoutnodecontext.cxx
blob3547aad28a7a4e2d9e0ca2c52dbae0c9966ffeda
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 "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 {
37 class IfContext
38 : public LayoutNodeContext
40 public:
41 IfContext( ContextHandler2Helper const & rParent,
42 const AttributeList& rAttribs,
43 const ConditionAtomPtr& pAtom )
44 : LayoutNodeContext( rParent, rAttribs, pAtom )
48 class AlgorithmContext
49 : public ContextHandler2
51 public:
52 AlgorithmContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, const AlgAtomPtr & pNode )
53 : ContextHandler2( rParent )
54 , mnRevision( 0 )
55 , mpNode( pNode )
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
65 switch( aElement )
67 case DGM_TOKEN( param ):
69 sal_Int32 nType = rAttribs.getToken(XML_type, 0);
70 switch (nType)
72 case XML_ar:
73 mpNode->setAspectRatio(rAttribs.getDouble(XML_val, 0));
74 break;
75 default:
76 const sal_Int32 nValTok = rAttribs.getToken(XML_val, 0);
77 mpNode->addParam(nType, nValTok > 0 ? nValTok
78 : rAttribs.getInteger(XML_val, 0));
79 break;
81 break;
83 default:
84 break;
87 return this;
90 private:
91 sal_Int32 mnRevision;
92 AlgAtomPtr mpNode;
95 class ChooseContext
96 : public ContextHandler2
98 public:
99 ChooseContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, const LayoutAtomPtr & pNode )
100 : ContextHandler2( rParent )
101 , mpNode( pNode )
103 msName = rAttribs.getString( XML_name ).get();
106 virtual ContextHandlerRef
107 onCreateContext( ::sal_Int32 aElement,
108 const AttributeList& rAttribs ) override
110 switch( aElement )
112 case DGM_TOKEN( if ):
114 // CT_When
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 ):
121 // CT_Otherwise
122 ConditionAtomPtr pNode( new ConditionAtom(mpNode->getLayoutNode(), true, rAttribs.getFastAttributeList()) );
123 LayoutAtom::connect(mpNode, pNode);
124 return new IfContext( *this, rAttribs, pNode );
126 default:
127 break;
130 return this;
132 private:
133 OUString msName;
134 LayoutAtomPtr mpNode;
137 class ForEachContext
138 : public LayoutNodeContext
140 public:
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
156 public:
157 LayoutVariablePropertySetContext( ContextHandler2Helper const & rParent, LayoutNode::VarMap & aVar )
158 : ContextHandler2( rParent )
159 , mVariables( aVar )
163 virtual ContextHandlerRef onCreateContext( ::sal_Int32 aElement, const AttributeList& rAttribs ) override
165 mVariables[ getBaseToken(aElement) ] = rAttribs.getString( XML_val ).get();
166 return this;
168 private:
169 LayoutNode::VarMap & mVariables;
172 // CT_LayoutNode
173 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper const & rParent,
174 const AttributeList& rAttribs,
175 const LayoutAtomPtr& pAtom )
176 : ContextHandler2( rParent )
177 , mpNode( pAtom )
179 assert( pAtom && "Node must NOT be NULL" );
180 mpNode->setName( rAttribs.getString( XML_name ).get() );
183 LayoutNodeContext::~LayoutNodeContext()
187 ContextHandlerRef
188 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
189 const AttributeList& rAttribs )
191 switch( aElement )
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 ):
204 ShapePtr pShape;
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 );
216 else
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 ):
230 return nullptr;
231 case DGM_TOKEN( alg ):
233 // CT_Algorithm
234 AlgAtomPtr pAtom( new AlgAtom(mpNode->getLayoutNode()) );
235 LayoutAtom::connect(mpNode, pAtom);
236 return new AlgorithmContext( *this, rAttribs, pAtom );
238 case DGM_TOKEN( choose ):
240 // CT_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 ):
247 // CT_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 ):
253 // CT_Constraints
254 return new ConstraintListContext( *this, mpNode );
255 case DGM_TOKEN( presOf ):
257 // CT_PresentationOf
258 // TODO
259 IteratorAttr aIterator;
260 aIterator.loadFromXAttr(rAttribs.getFastAttributeList());
261 break;
263 case DGM_TOKEN( ruleLst ):
264 // CT_Rules
265 // TODO
266 break;
267 case DGM_TOKEN( varLst ):
269 LayoutNodePtr pNode(std::dynamic_pointer_cast<LayoutNode>(mpNode));
270 if( pNode )
272 return new LayoutVariablePropertySetContext( *this, pNode->variables() );
274 else
276 SAL_WARN("oox", "OOX: encountered a varLst in a non layoutNode context" );
278 break;
280 default:
281 break;
284 return this;
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */