fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / drawingml / diagram / layoutnodecontext.cxx
blobc92070648d736e2be2125d351041d03e9857b42b
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 <osl/diagnose.h>
30 using namespace ::oox::core;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::xml::sax;
34 namespace oox { namespace drawingml {
36 class IfContext
37 : public LayoutNodeContext
39 public:
40 IfContext( ContextHandler2Helper& rParent,
41 const AttributeList& rAttribs,
42 const ConditionAtomPtr& pAtom )
43 : LayoutNodeContext( rParent, rAttribs, pAtom )
47 class AlgorithmContext
48 : public ContextHandler2
50 public:
51 AlgorithmContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const AlgAtomPtr & pNode )
52 : ContextHandler2( rParent )
53 , mnRevision( 0 )
54 , mpNode( pNode )
56 mnRevision = rAttribs.getInteger( XML_rev, 0 );
57 pNode->setType(rAttribs.getToken(XML_type, 0));
60 virtual ContextHandlerRef
61 onCreateContext( ::sal_Int32 aElement,
62 const AttributeList& rAttribs ) SAL_OVERRIDE
64 switch( aElement )
66 case DGM_TOKEN( param ):
68 const sal_Int32 nValTok = rAttribs.getToken( XML_val, 0 );
69 mpNode->addParam(
70 rAttribs.getToken( XML_type, 0 ),
71 nValTok>0 ? nValTok : rAttribs.getInteger( XML_val, 0 ) );
72 break;
74 default:
75 break;
78 return this;
81 private:
82 sal_Int32 mnRevision;
83 AlgAtomPtr mpNode;
86 class ChooseContext
87 : public ContextHandler2
89 public:
90 ChooseContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const LayoutAtomPtr & pNode )
91 : ContextHandler2( rParent )
92 , mpNode( pNode )
94 msName = rAttribs.getString( XML_name ).get();
97 virtual ContextHandlerRef
98 onCreateContext( ::sal_Int32 aElement,
99 const AttributeList& rAttribs ) SAL_OVERRIDE
101 switch( aElement )
103 case DGM_TOKEN( if ):
105 // CT_When
106 mpConditionNode.reset( new ConditionAtom(rAttribs.getFastAttributeList()) );
107 mpNode->addChild( mpConditionNode );
108 return new IfContext( *this, rAttribs, mpConditionNode );
110 case DGM_TOKEN( else ):
111 // CT_Otherwise
112 if( mpConditionNode )
114 mpConditionNode->readElseBranch();
115 ContextHandlerRef xRet = new IfContext( *this, rAttribs, mpConditionNode );
116 mpConditionNode.reset();
117 return xRet;
119 else
121 OSL_TRACE( "ignoring second else clause" );
123 break;
124 default:
125 break;
128 return this;
130 private:
131 OUString msName;
132 LayoutAtomPtr mpNode;
133 ConditionAtomPtr mpConditionNode;
136 class ForEachContext
137 : public LayoutNodeContext
139 public:
140 ForEachContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const ForEachAtomPtr& pAtom )
141 : LayoutNodeContext( rParent, rAttribs, pAtom )
143 rAttribs.getString( XML_ref );
144 pAtom->iterator().loadFromXAttr( rAttribs.getFastAttributeList() );
148 // CT_LayoutVariablePropertySet
149 class LayoutVariablePropertySetContext
150 : public ContextHandler2
152 public:
153 LayoutVariablePropertySetContext( ContextHandler2Helper& rParent, LayoutNode::VarMap & aVar )
154 : ContextHandler2( rParent )
155 , mVariables( aVar )
159 virtual ~LayoutVariablePropertySetContext()
163 virtual ContextHandlerRef onCreateContext( ::sal_Int32 aElement, const AttributeList& rAttribs )
164 throw (SAXException, RuntimeException) SAL_OVERRIDE
166 sal_Int32 nIdx = LayoutNodeContext::tagToVarIdx( getBaseToken( aElement ) );
167 if( nIdx != -1 )
169 mVariables[ nIdx ] = makeAny( rAttribs.getString( XML_val ).get() );
172 return this;
174 private:
175 LayoutNode::VarMap & mVariables;
178 // CT_LayoutNode
179 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper& rParent,
180 const AttributeList& rAttribs,
181 const LayoutAtomPtr& pAtom )
182 : ContextHandler2( rParent )
183 , mpNode( pAtom )
185 OSL_ENSURE( pAtom, "Node must NOT be NULL" );
186 mpNode->setName( rAttribs.getString( XML_name ).get() );
189 LayoutNodeContext::~LayoutNodeContext()
193 /** convert the XML tag to a variable index in the array
194 * @param aTag the tag, without namespace
195 * @return the variable index. -1 is an error
197 sal_Int32 LayoutNodeContext::tagToVarIdx( sal_Int32 aTag )
199 sal_Int32 nIdx = -1;
200 switch( aTag )
202 case DGM_TOKEN( animLvl ):
203 nIdx = LayoutNode::VAR_animLvl;
204 break;
205 case DGM_TOKEN( animOne ):
206 nIdx = LayoutNode::VAR_animOne;
207 break;
208 case DGM_TOKEN( bulletEnabled ):
209 nIdx = LayoutNode::VAR_bulletEnabled;
210 break;
211 case DGM_TOKEN( chMax ):
212 nIdx = LayoutNode::VAR_chMax;
213 break;
214 case DGM_TOKEN( chPref ):
215 nIdx = LayoutNode::VAR_chPref;
216 break;
217 case DGM_TOKEN( dir ):
218 nIdx = LayoutNode::VAR_dir;
219 break;
220 case DGM_TOKEN( hierBranch ):
221 nIdx = LayoutNode::VAR_hierBranch;
222 break;
223 case DGM_TOKEN( orgChart ):
224 nIdx = LayoutNode::VAR_orgChart;
225 break;
226 case DGM_TOKEN( resizeHandles ):
227 nIdx = LayoutNode::VAR_resizeHandles;
228 break;
229 default:
230 break;
232 return nIdx;
235 ContextHandlerRef
236 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
237 const AttributeList& rAttribs )
239 switch( aElement )
241 case DGM_TOKEN( layoutNode ):
243 LayoutNodePtr pNode( new LayoutNode() );
244 mpNode->addChild( pNode );
245 pNode->setChildOrder( rAttribs.getToken( XML_chOrder, XML_b ) );
246 pNode->setMoveWith( rAttribs.getString( XML_moveWith ).get() );
247 pNode->setStyleLabel( rAttribs.getString( XML_styleLbl ).get() );
248 return new LayoutNodeContext( *this, rAttribs, pNode );
250 case DGM_TOKEN( shape ):
252 LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
253 if( pNode )
255 ShapePtr pShape;
257 if( rAttribs.hasAttribute( XML_type ) )
259 pShape.reset( new Shape("com.sun.star.drawing.CustomShape") );
260 const sal_Int32 nType(rAttribs.getToken( XML_type, XML_obj ));
261 pShape->setSubType( nType );
262 pShape->getCustomShapeProperties()->setShapePresetType( nType );
264 else
266 pShape.reset( new Shape("com.sun.star.drawing.GroupShape") );
269 pNode->setShape( pShape );
270 return new ShapeContext( *this, ShapePtr(), pShape );
272 else
274 OSL_TRACE( "OOX: encountered a shape in a non layoutNode context" );
276 break;
278 case DGM_TOKEN( extLst ):
279 return 0;
280 case DGM_TOKEN( alg ):
282 // CT_Algorithm
283 AlgAtomPtr pAtom( new AlgAtom );
284 mpNode->addChild( pAtom );
285 return new AlgorithmContext( *this, rAttribs, pAtom );
287 case DGM_TOKEN( choose ):
289 // CT_Choose
290 LayoutAtomPtr pAtom( new ChooseAtom );
291 mpNode->addChild( pAtom );
292 return new ChooseContext( *this, rAttribs, pAtom );
294 case DGM_TOKEN( forEach ):
296 // CT_ForEach
297 ForEachAtomPtr pAtom( new ForEachAtom(rAttribs.getFastAttributeList()) );
298 mpNode->addChild( pAtom );
299 return new ForEachContext( *this, rAttribs, pAtom );
301 case DGM_TOKEN( constrLst ):
302 // CT_Constraints
303 return new ConstraintListContext( *this, rAttribs, mpNode );
304 case DGM_TOKEN( presOf ):
306 // CT_PresentationOf
307 // TODO
308 rAttribs.getString( XML_axis );
309 rAttribs.getString( XML_cnt );
310 rAttribs.getString( XML_hideLastTrans );
311 rAttribs.getString( XML_ptType );
312 rAttribs.getString( XML_st );
313 rAttribs.getString( XML_step );
314 break;
316 case DGM_TOKEN( ruleLst ):
317 // CT_Rules
318 // TODO
319 break;
320 case DGM_TOKEN( varLst ):
322 LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
323 if( pNode )
325 return new LayoutVariablePropertySetContext( *this, pNode->variables() );
327 else
329 OSL_TRACE( "OOX: encountered a varLst in a non layoutNode context" );
331 break;
333 default:
334 break;
337 return this;
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */