Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / diagram / layoutnodecontext.cxx
blobd96a49b0529ef8f86a603b9bf51561bf6e8e1f57
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 "drawingml/diagram/diagram.hxx"
24 #include "oox/drawingml/shapecontext.hxx"
25 #include "drawingml/customshapeproperties.hxx"
26 #include "diagramdefinitioncontext.hxx"
27 #include "constraintlistcontext.hxx"
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
30 #include <osl/diagnose.h>
32 using namespace ::oox::core;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::xml::sax;
36 namespace oox { namespace drawingml {
38 class IfContext
39 : public LayoutNodeContext
41 public:
42 IfContext( ContextHandler2Helper& rParent,
43 const AttributeList& rAttribs,
44 const ConditionAtomPtr& pAtom )
45 : LayoutNodeContext( rParent, rAttribs, pAtom )
49 class AlgorithmContext
50 : public ContextHandler2
52 public:
53 AlgorithmContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const AlgAtomPtr & pNode )
54 : ContextHandler2( rParent )
55 , mnRevision( 0 )
56 , mpNode( pNode )
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
66 switch( aElement )
68 case DGM_TOKEN( param ):
70 const sal_Int32 nValTok = rAttribs.getToken( XML_val, 0 );
71 mpNode->addParam(
72 rAttribs.getToken( XML_type, 0 ),
73 nValTok>0 ? nValTok : rAttribs.getInteger( XML_val, 0 ) );
74 break;
76 default:
77 break;
80 return this;
83 private:
84 sal_Int32 mnRevision;
85 AlgAtomPtr mpNode;
88 class ChooseContext
89 : public ContextHandler2
91 public:
92 ChooseContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const LayoutAtomPtr & pNode )
93 : ContextHandler2( rParent )
94 , mpNode( pNode )
96 msName = rAttribs.getString( XML_name ).get();
99 virtual ContextHandlerRef
100 onCreateContext( ::sal_Int32 aElement,
101 const AttributeList& rAttribs ) override
103 switch( aElement )
105 case DGM_TOKEN( if ):
107 // CT_When
108 mpConditionNode.reset( new ConditionAtom(rAttribs.getFastAttributeList()) );
109 mpNode->addChild( mpConditionNode );
110 return new IfContext( *this, rAttribs, mpConditionNode );
112 case DGM_TOKEN( else ):
113 // CT_Otherwise
114 if( mpConditionNode )
116 mpConditionNode->readElseBranch();
117 ContextHandlerRef xRet = new IfContext( *this, rAttribs, mpConditionNode );
118 mpConditionNode.reset();
119 return xRet;
121 else
123 SAL_WARN("oox", "ignoring second else clause" );
125 break;
126 default:
127 break;
130 return this;
132 private:
133 OUString msName;
134 LayoutAtomPtr mpNode;
135 ConditionAtomPtr mpConditionNode;
138 class ForEachContext
139 : public LayoutNodeContext
141 public:
142 ForEachContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const ForEachAtomPtr& pAtom )
143 : LayoutNodeContext( rParent, rAttribs, pAtom )
145 rAttribs.getString( XML_ref );
146 pAtom->iterator().loadFromXAttr( rAttribs.getFastAttributeList() );
150 // CT_LayoutVariablePropertySet
151 class LayoutVariablePropertySetContext
152 : public ContextHandler2
154 public:
155 LayoutVariablePropertySetContext( ContextHandler2Helper& rParent, LayoutNode::VarMap & aVar )
156 : ContextHandler2( rParent )
157 , mVariables( aVar )
161 virtual ContextHandlerRef onCreateContext( ::sal_Int32 aElement, const AttributeList& rAttribs ) override
163 sal_Int32 nIdx = LayoutNodeContext::tagToVarIdx( getBaseToken( aElement ) );
164 if( nIdx != -1 )
166 mVariables[ nIdx ] <<= rAttribs.getString( XML_val ).get();
169 return this;
171 private:
172 LayoutNode::VarMap & mVariables;
175 // CT_LayoutNode
176 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper& rParent,
177 const AttributeList& rAttribs,
178 const LayoutAtomPtr& pAtom )
179 : ContextHandler2( rParent )
180 , mpNode( pAtom )
182 OSL_ENSURE( pAtom, "Node must NOT be NULL" );
183 mpNode->setName( rAttribs.getString( XML_name ).get() );
186 LayoutNodeContext::~LayoutNodeContext()
190 /** convert the XML tag to a variable index in the array
191 * @param aTag the tag, without namespace
192 * @return the variable index. -1 is an error
194 sal_Int32 LayoutNodeContext::tagToVarIdx( sal_Int32 aTag )
196 sal_Int32 nIdx = -1;
197 switch( aTag )
199 case DGM_TOKEN( animLvl ):
200 nIdx = LayoutNode::VAR_animLvl;
201 break;
202 case DGM_TOKEN( animOne ):
203 nIdx = LayoutNode::VAR_animOne;
204 break;
205 case DGM_TOKEN( bulletEnabled ):
206 nIdx = LayoutNode::VAR_bulletEnabled;
207 break;
208 case DGM_TOKEN( chMax ):
209 nIdx = LayoutNode::VAR_chMax;
210 break;
211 case DGM_TOKEN( chPref ):
212 nIdx = LayoutNode::VAR_chPref;
213 break;
214 case DGM_TOKEN( dir ):
215 nIdx = LayoutNode::VAR_dir;
216 break;
217 case DGM_TOKEN( hierBranch ):
218 nIdx = LayoutNode::VAR_hierBranch;
219 break;
220 case DGM_TOKEN( orgChart ):
221 nIdx = LayoutNode::VAR_orgChart;
222 break;
223 case DGM_TOKEN( resizeHandles ):
224 nIdx = LayoutNode::VAR_resizeHandles;
225 break;
226 default:
227 break;
229 return nIdx;
232 ContextHandlerRef
233 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
234 const AttributeList& rAttribs )
236 switch( aElement )
238 case DGM_TOKEN( layoutNode ):
240 LayoutNodePtr pNode( new LayoutNode() );
241 mpNode->addChild( pNode );
242 pNode->setChildOrder( rAttribs.getToken( XML_chOrder, XML_b ) );
243 pNode->setMoveWith( rAttribs.getString( XML_moveWith ).get() );
244 pNode->setStyleLabel( rAttribs.getString( XML_styleLbl ).get() );
245 return new LayoutNodeContext( *this, rAttribs, pNode );
247 case DGM_TOKEN( shape ):
249 LayoutNodePtr pNode(std::dynamic_pointer_cast<LayoutNode>(mpNode));
250 if( pNode )
252 ShapePtr pShape;
254 if( rAttribs.hasAttribute( XML_type ) )
256 pShape.reset( new Shape("com.sun.star.drawing.CustomShape") );
257 const sal_Int32 nType(rAttribs.getToken( XML_type, XML_obj ));
258 pShape->setSubType( nType );
259 pShape->getCustomShapeProperties()->setShapePresetType( nType );
261 else
263 pShape.reset( new Shape("com.sun.star.drawing.GroupShape") );
266 pNode->setShape( pShape );
267 return new ShapeContext( *this, ShapePtr(), pShape );
269 else
271 SAL_WARN("oox", "OOX: encountered a shape in a non layoutNode context" );
273 break;
275 case DGM_TOKEN( extLst ):
276 return nullptr;
277 case DGM_TOKEN( alg ):
279 // CT_Algorithm
280 AlgAtomPtr pAtom( new AlgAtom );
281 mpNode->addChild( pAtom );
282 return new AlgorithmContext( *this, rAttribs, pAtom );
284 case DGM_TOKEN( choose ):
286 // CT_Choose
287 LayoutAtomPtr pAtom( new ChooseAtom );
288 mpNode->addChild( pAtom );
289 return new ChooseContext( *this, rAttribs, pAtom );
291 case DGM_TOKEN( forEach ):
293 // CT_ForEach
294 ForEachAtomPtr pAtom( new ForEachAtom(rAttribs.getFastAttributeList()) );
295 mpNode->addChild( pAtom );
296 return new ForEachContext( *this, rAttribs, pAtom );
298 case DGM_TOKEN( constrLst ):
299 // CT_Constraints
300 return new ConstraintListContext( *this, mpNode );
301 case DGM_TOKEN( presOf ):
303 // CT_PresentationOf
304 // TODO
305 rAttribs.getString( XML_axis );
306 rAttribs.getString( XML_cnt );
307 rAttribs.getString( XML_hideLastTrans );
308 rAttribs.getString( XML_ptType );
309 rAttribs.getString( XML_st );
310 rAttribs.getString( XML_step );
311 break;
313 case DGM_TOKEN( ruleLst ):
314 // CT_Rules
315 // TODO
316 break;
317 case DGM_TOKEN( varLst ):
319 LayoutNodePtr pNode(std::dynamic_pointer_cast<LayoutNode>(mpNode));
320 if( pNode )
322 return new LayoutVariablePropertySetContext( *this, pNode->variables() );
324 else
326 SAL_WARN("oox", "OOX: encountered a varLst in a non layoutNode context" );
328 break;
330 default:
331 break;
334 return this;
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */