1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
{
37 : public LayoutNodeContext
40 IfContext( ContextHandler2Helper
& rParent
,
41 const AttributeList
& rAttribs
,
42 const ConditionAtomPtr
& pAtom
)
43 : LayoutNodeContext( rParent
, rAttribs
, pAtom
)
47 class AlgorithmContext
48 : public ContextHandler2
51 AlgorithmContext( ContextHandler2Helper
& rParent
, const AttributeList
& rAttribs
, const AlgAtomPtr
& pNode
)
52 : ContextHandler2( rParent
)
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
66 case DGM_TOKEN( param
):
68 const sal_Int32 nValTok
= rAttribs
.getToken( XML_val
, 0 );
70 rAttribs
.getToken( XML_type
, 0 ),
71 nValTok
>0 ? nValTok
: rAttribs
.getInteger( XML_val
, 0 ) );
87 : public ContextHandler2
90 ChooseContext( ContextHandler2Helper
& rParent
, const AttributeList
& rAttribs
, const LayoutAtomPtr
& pNode
)
91 : ContextHandler2( rParent
)
94 msName
= rAttribs
.getString( XML_name
).get();
97 virtual ContextHandlerRef
98 onCreateContext( ::sal_Int32 aElement
,
99 const AttributeList
& rAttribs
) SAL_OVERRIDE
103 case DGM_TOKEN( if ):
106 mpConditionNode
.reset( new ConditionAtom(rAttribs
.getFastAttributeList()) );
107 mpNode
->addChild( mpConditionNode
);
108 return new IfContext( *this, rAttribs
, mpConditionNode
);
110 case DGM_TOKEN( else ):
112 if( mpConditionNode
)
114 mpConditionNode
->readElseBranch();
115 ContextHandlerRef xRet
= new IfContext( *this, rAttribs
, mpConditionNode
);
116 mpConditionNode
.reset();
121 OSL_TRACE( "ignoring second else clause" );
132 LayoutAtomPtr mpNode
;
133 ConditionAtomPtr mpConditionNode
;
137 : public LayoutNodeContext
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
153 LayoutVariablePropertySetContext( ContextHandler2Helper
& rParent
, LayoutNode::VarMap
& aVar
)
154 : ContextHandler2( rParent
)
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
) );
169 mVariables
[ nIdx
] = makeAny( rAttribs
.getString( XML_val
).get() );
175 LayoutNode::VarMap
& mVariables
;
179 LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper
& rParent
,
180 const AttributeList
& rAttribs
,
181 const LayoutAtomPtr
& pAtom
)
182 : ContextHandler2( rParent
)
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
)
202 case DGM_TOKEN( animLvl
):
203 nIdx
= LayoutNode::VAR_animLvl
;
205 case DGM_TOKEN( animOne
):
206 nIdx
= LayoutNode::VAR_animOne
;
208 case DGM_TOKEN( bulletEnabled
):
209 nIdx
= LayoutNode::VAR_bulletEnabled
;
211 case DGM_TOKEN( chMax
):
212 nIdx
= LayoutNode::VAR_chMax
;
214 case DGM_TOKEN( chPref
):
215 nIdx
= LayoutNode::VAR_chPref
;
217 case DGM_TOKEN( dir
):
218 nIdx
= LayoutNode::VAR_dir
;
220 case DGM_TOKEN( hierBranch
):
221 nIdx
= LayoutNode::VAR_hierBranch
;
223 case DGM_TOKEN( orgChart
):
224 nIdx
= LayoutNode::VAR_orgChart
;
226 case DGM_TOKEN( resizeHandles
):
227 nIdx
= LayoutNode::VAR_resizeHandles
;
236 LayoutNodeContext::onCreateContext( ::sal_Int32 aElement
,
237 const AttributeList
& rAttribs
)
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
) );
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
);
266 pShape
.reset( new Shape("com.sun.star.drawing.GroupShape") );
269 pNode
->setShape( pShape
);
270 return new ShapeContext( *this, ShapePtr(), pShape
);
274 OSL_TRACE( "OOX: encountered a shape in a non layoutNode context" );
278 case DGM_TOKEN( extLst
):
280 case DGM_TOKEN( alg
):
283 AlgAtomPtr
pAtom( new AlgAtom
);
284 mpNode
->addChild( pAtom
);
285 return new AlgorithmContext( *this, rAttribs
, pAtom
);
287 case DGM_TOKEN( choose
):
290 LayoutAtomPtr
pAtom( new ChooseAtom
);
291 mpNode
->addChild( pAtom
);
292 return new ChooseContext( *this, rAttribs
, pAtom
);
294 case DGM_TOKEN( forEach
):
297 ForEachAtomPtr
pAtom( new ForEachAtom(rAttribs
.getFastAttributeList()) );
298 mpNode
->addChild( pAtom
);
299 return new ForEachContext( *this, rAttribs
, pAtom
);
301 case DGM_TOKEN( constrLst
):
303 return new ConstraintListContext( *this, rAttribs
, mpNode
);
304 case DGM_TOKEN( presOf
):
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
);
316 case DGM_TOKEN( ruleLst
):
320 case DGM_TOKEN( varLst
):
322 LayoutNodePtr
pNode( boost::dynamic_pointer_cast
< LayoutNode
>( mpNode
) );
325 return new LayoutVariablePropertySetContext( *this, pNode
->variables() );
329 OSL_TRACE( "OOX: encountered a varLst in a non layoutNode context" );
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */