fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / drawingml / diagram / layoutnodecontext.cxx
blob5c0103836f0bce2a7e53fa649bab4731e690559e
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/diagram/diagram.hxx"
24 #include "oox/drawingml/shapecontext.hxx"
25 #include "oox/drawingml/customshapeproperties.hxx"
26 #include "diagramdefinitioncontext.hxx"
27 #include "constraintlistcontext.hxx"
29 using namespace ::oox::core;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::xml::sax;
33 namespace oox { namespace drawingml {
35 class IfContext
36 : public LayoutNodeContext
38 public:
39 IfContext( ContextHandler& rParent,
40 const Reference< XFastAttributeList >& xAttribs,
41 const ConditionAtomPtr& pAtom )
42 : LayoutNodeContext( rParent, xAttribs, pAtom )
48 class AlgorithmContext
49 : public ContextHandler
51 public:
52 AlgorithmContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const AlgAtomPtr & pNode )
53 : ContextHandler( rParent )
54 , mnRevision( 0 )
55 , mpNode( pNode )
57 AttributeList aAttribs( xAttribs );
58 mnRevision = aAttribs.getInteger( XML_rev, 0 );
59 pNode->setType(xAttribs->getOptionalValueToken(XML_type, 0));
62 virtual Reference< XFastContextHandler > SAL_CALL
63 createFastChildContext( ::sal_Int32 aElement,
64 const Reference< XFastAttributeList >& xAttribs )
65 throw (SAXException, RuntimeException)
67 Reference< XFastContextHandler > xRet;
69 switch( aElement )
71 case DGM_TOKEN( param ):
73 AttributeList aAttribs( xAttribs );
74 const sal_Int32 nValTok=aAttribs.getToken( XML_val, 0 );
75 mpNode->addParam(
76 aAttribs.getToken( XML_type, 0 ),
77 nValTok>0 ? nValTok : aAttribs.getInteger( XML_val, 0 ) );
78 break;
80 default:
81 break;
84 if( !xRet.is() )
85 xRet.set(this);
87 return xRet;
90 private:
91 sal_Int32 mnRevision;
92 AlgAtomPtr mpNode;
96 class ChooseContext
97 : public ContextHandler
99 public:
100 ChooseContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const LayoutAtomPtr & pNode )
101 : ContextHandler( rParent )
102 , mpNode( pNode )
104 msName = xAttribs->getOptionalValue( XML_name );
107 virtual Reference< XFastContextHandler > SAL_CALL
108 createFastChildContext( ::sal_Int32 aElement,
109 const Reference< XFastAttributeList >& xAttribs )
110 throw (SAXException, RuntimeException)
112 Reference< XFastContextHandler > xRet;
114 switch( aElement )
116 case DGM_TOKEN( if ):
118 // CT_When
119 mpConditionNode.reset( new ConditionAtom(xAttribs) );
120 mpNode->addChild( mpConditionNode );
121 xRet.set( new IfContext( *this, xAttribs, mpConditionNode ) );
122 break;
124 case DGM_TOKEN( else ):
125 // CT_Otherwise
126 if( mpConditionNode )
128 mpConditionNode->readElseBranch();
129 xRet.set( new IfContext( *this, xAttribs, mpConditionNode ) );
130 mpConditionNode.reset();
132 else
134 OSL_TRACE( "ignoring second else clause" );
136 break;
137 default:
138 break;
141 if( !xRet.is() )
142 xRet.set(this);
144 return xRet;
146 private:
147 OUString msName;
148 LayoutAtomPtr mpNode;
149 ConditionAtomPtr mpConditionNode;
155 class ForEachContext
156 : public LayoutNodeContext
158 public:
159 ForEachContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, const ForEachAtomPtr& pAtom )
160 : LayoutNodeContext( rParent, xAttribs, pAtom )
162 xAttribs->getOptionalValue( XML_ref );
163 pAtom->iterator().loadFromXAttr( xAttribs );
168 // CT_LayoutVariablePropertySet
169 class LayoutVariablePropertySetContext
170 : public ContextHandler
172 public:
173 LayoutVariablePropertySetContext( ContextHandler& rParent, LayoutNode::VarMap & aVar )
174 : ContextHandler( rParent )
175 , mVariables( aVar )
179 virtual ~LayoutVariablePropertySetContext()
183 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs )
184 throw (SAXException, RuntimeException)
186 Reference< XFastContextHandler > xRet;
188 sal_Int32 nIdx = LayoutNodeContext::tagToVarIdx( getBaseToken( aElement ) );
189 if( nIdx != -1 )
191 mVariables[ nIdx ] = makeAny( xAttribs->getOptionalValue( XML_val ) );
193 if( !xRet.is() )
194 xRet.set(this);
196 return xRet;
198 private:
199 LayoutNode::VarMap & mVariables;
203 // CT_LayoutNode
204 LayoutNodeContext::LayoutNodeContext( ContextHandler& rParent,
205 const Reference< XFastAttributeList >& xAttribs,
206 const LayoutAtomPtr& pAtom )
207 : ContextHandler( rParent )
208 , mpNode( pAtom )
210 OSL_ENSURE( pAtom, "Node must NOT be NULL" );
211 mpNode->setName( xAttribs->getOptionalValue( XML_name ) );
215 LayoutNodeContext::~LayoutNodeContext()
219 void SAL_CALL LayoutNodeContext::endFastElement( ::sal_Int32 )
220 throw (SAXException, RuntimeException)
225 /** convert the XML tag to a variable index in the array
226 * @param aTag the tag, without namespace
227 * @return the variable index. -1 is an error
229 sal_Int32 LayoutNodeContext::tagToVarIdx( sal_Int32 aTag )
231 sal_Int32 nIdx = -1;
232 switch( aTag )
234 case DGM_TOKEN( animLvl ):
235 nIdx = LayoutNode::VAR_animLvl;
236 break;
237 case DGM_TOKEN( animOne ):
238 nIdx = LayoutNode::VAR_animOne;
239 break;
240 case DGM_TOKEN( bulletEnabled ):
241 nIdx = LayoutNode::VAR_bulletEnabled;
242 break;
243 case DGM_TOKEN( chMax ):
244 nIdx = LayoutNode::VAR_chMax;
245 break;
246 case DGM_TOKEN( chPref ):
247 nIdx = LayoutNode::VAR_chPref;
248 break;
249 case DGM_TOKEN( dir ):
250 nIdx = LayoutNode::VAR_dir;
251 break;
252 case DGM_TOKEN( hierBranch ):
253 nIdx = LayoutNode::VAR_hierBranch;
254 break;
255 case DGM_TOKEN( orgChart ):
256 nIdx = LayoutNode::VAR_orgChart;
257 break;
258 case DGM_TOKEN( resizeHandles ):
259 nIdx = LayoutNode::VAR_resizeHandles;
260 break;
261 default:
262 break;
264 return nIdx;
268 Reference< XFastContextHandler > SAL_CALL
269 LayoutNodeContext::createFastChildContext( ::sal_Int32 aElement,
270 const Reference< XFastAttributeList >& xAttribs )
271 throw (SAXException, RuntimeException)
273 Reference< XFastContextHandler > xRet;
275 switch( aElement )
277 case DGM_TOKEN( layoutNode ):
279 LayoutNodePtr pNode( new LayoutNode() );
280 mpNode->addChild( pNode );
281 pNode->setChildOrder( xAttribs->getOptionalValueToken( XML_chOrder, XML_b ) );
282 pNode->setMoveWith( xAttribs->getOptionalValue( XML_moveWith ) );
283 pNode->setStyleLabel( xAttribs->getOptionalValue( XML_styleLbl ) );
284 xRet.set( new LayoutNodeContext( *this, xAttribs, pNode ) );
285 break;
287 case DGM_TOKEN( shape ):
289 LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
290 if( pNode )
292 ShapePtr pShape;
294 if( xAttribs->hasAttribute( XML_type ) )
296 pShape.reset( new Shape("com.sun.star.drawing.CustomShape") );
297 const sal_Int32 nType(xAttribs->getOptionalValueToken( XML_type, XML_obj ));
298 pShape->setSubType( nType );
299 pShape->getCustomShapeProperties()->setShapePresetType( nType );
301 else
303 pShape.reset( new Shape("com.sun.star.drawing.GroupShape") );
306 pNode->setShape( pShape );
307 xRet.set( new ShapeContext( *this, ShapePtr(), pShape ) );
309 else
311 OSL_TRACE( "OOX: encountered a shape in a non layoutNode context" );
313 break;
315 case DGM_TOKEN( extLst ):
316 return xRet;
317 case DGM_TOKEN( alg ):
319 // CT_Algorithm
320 AlgAtomPtr pAtom( new AlgAtom );
321 mpNode->addChild( pAtom );
322 xRet.set( new AlgorithmContext( *this, xAttribs, pAtom ) );
323 break;
325 case DGM_TOKEN( choose ):
327 // CT_Choose
328 LayoutAtomPtr pAtom( new ChooseAtom );
329 mpNode->addChild( pAtom );
330 xRet.set( new ChooseContext( *this, xAttribs, pAtom ) );
331 break;
333 case DGM_TOKEN( forEach ):
335 // CT_ForEach
336 ForEachAtomPtr pAtom( new ForEachAtom(xAttribs) );
337 mpNode->addChild( pAtom );
338 xRet.set( new ForEachContext( *this, xAttribs, pAtom ) );
339 break;
341 case DGM_TOKEN( constrLst ):
342 // CT_Constraints
343 xRet.set( new ConstraintListContext( *this, xAttribs, mpNode ) );
344 break;
345 case DGM_TOKEN( presOf ):
347 // CT_PresentationOf
348 // TODO
349 xAttribs->getOptionalValue( XML_axis );
350 xAttribs->getOptionalValue( XML_cnt );
351 xAttribs->getOptionalValue( XML_hideLastTrans );
352 xAttribs->getOptionalValue( XML_ptType );
353 xAttribs->getOptionalValue( XML_st );
354 xAttribs->getOptionalValue( XML_step );
355 break;
357 case DGM_TOKEN( ruleLst ):
358 // CT_Rules
359 // TODO
360 break;
361 case DGM_TOKEN( varLst ):
363 LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
364 if( pNode )
366 xRet.set( new LayoutVariablePropertySetContext( *this, pNode->variables() ) );
368 else
370 OSL_TRACE( "OOX: encountered a varLst in a non layoutNode context" );
372 break;
374 default:
375 break;
377 if( !xRet.is() )
378 xRet.set(this);
380 return xRet;
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */