Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "layoutnodecontext.hxx"
21 :
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 :
29 : using namespace ::oox::core;
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::xml::sax;
32 :
33 : namespace oox { namespace drawingml {
34 :
35 152 : class IfContext
36 : : public LayoutNodeContext
37 : {
38 : public:
39 76 : IfContext( ContextHandler2Helper& rParent,
40 : const AttributeList& rAttribs,
41 : const ConditionAtomPtr& pAtom )
42 76 : : LayoutNodeContext( rParent, rAttribs, pAtom )
43 76 : {}
44 : };
45 :
46 268 : class AlgorithmContext
47 : : public ContextHandler2
48 : {
49 : public:
50 134 : AlgorithmContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const AlgAtomPtr & pNode )
51 : : ContextHandler2( rParent )
52 : , mnRevision( 0 )
53 134 : , mpNode( pNode )
54 : {
55 134 : mnRevision = rAttribs.getInteger( XML_rev, 0 );
56 134 : pNode->setType(rAttribs.getToken(XML_type, 0));
57 134 : }
58 :
59 : virtual ContextHandlerRef
60 160 : onCreateContext( ::sal_Int32 aElement,
61 : const AttributeList& rAttribs ) SAL_OVERRIDE
62 : {
63 160 : switch( aElement )
64 : {
65 : case DGM_TOKEN( param ):
66 : {
67 160 : const sal_Int32 nValTok = rAttribs.getToken( XML_val, 0 );
68 : mpNode->addParam(
69 : rAttribs.getToken( XML_type, 0 ),
70 160 : nValTok>0 ? nValTok : rAttribs.getInteger( XML_val, 0 ) );
71 160 : break;
72 : }
73 : default:
74 0 : break;
75 : }
76 :
77 160 : return this;
78 : }
79 :
80 : private:
81 : sal_Int32 mnRevision;
82 : AlgAtomPtr mpNode;
83 : };
84 :
85 76 : class ChooseContext
86 : : public ContextHandler2
87 : {
88 : public:
89 38 : ChooseContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const LayoutAtomPtr & pNode )
90 : : ContextHandler2( rParent )
91 38 : , mpNode( pNode )
92 : {
93 38 : msName = rAttribs.getString( XML_name ).get();
94 38 : }
95 :
96 : virtual ContextHandlerRef
97 76 : onCreateContext( ::sal_Int32 aElement,
98 : const AttributeList& rAttribs ) SAL_OVERRIDE
99 : {
100 76 : switch( aElement )
101 : {
102 : case DGM_TOKEN( if ):
103 : {
104 : // CT_When
105 38 : mpConditionNode.reset( new ConditionAtom(rAttribs.getFastAttributeList()) );
106 38 : mpNode->addChild( mpConditionNode );
107 38 : return new IfContext( *this, rAttribs, mpConditionNode );
108 : }
109 : case DGM_TOKEN( else ):
110 : // CT_Otherwise
111 38 : if( mpConditionNode )
112 : {
113 38 : mpConditionNode->readElseBranch();
114 38 : ContextHandlerRef xRet = new IfContext( *this, rAttribs, mpConditionNode );
115 38 : mpConditionNode.reset();
116 38 : return xRet;
117 : }
118 : else
119 : {
120 : OSL_TRACE( "ignoring second else clause" );
121 : }
122 0 : break;
123 : default:
124 0 : break;
125 : }
126 :
127 0 : return this;
128 : }
129 : private:
130 : OUString msName;
131 : LayoutAtomPtr mpNode;
132 : ConditionAtomPtr mpConditionNode;
133 : };
134 :
135 80 : class ForEachContext
136 : : public LayoutNodeContext
137 : {
138 : public:
139 40 : ForEachContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, const ForEachAtomPtr& pAtom )
140 40 : : LayoutNodeContext( rParent, rAttribs, pAtom )
141 : {
142 40 : rAttribs.getString( XML_ref );
143 40 : pAtom->iterator().loadFromXAttr( rAttribs.getFastAttributeList() );
144 40 : }
145 : };
146 :
147 : // CT_LayoutVariablePropertySet
148 : class LayoutVariablePropertySetContext
149 : : public ContextHandler2
150 : {
151 : public:
152 46 : LayoutVariablePropertySetContext( ContextHandler2Helper& rParent, LayoutNode::VarMap & aVar )
153 : : ContextHandler2( rParent )
154 46 : , mVariables( aVar )
155 : {
156 46 : }
157 :
158 92 : virtual ~LayoutVariablePropertySetContext()
159 46 : {
160 92 : }
161 :
162 66 : virtual ContextHandlerRef onCreateContext( ::sal_Int32 aElement, const AttributeList& rAttribs )
163 : throw (SAXException, RuntimeException) SAL_OVERRIDE
164 : {
165 66 : sal_Int32 nIdx = LayoutNodeContext::tagToVarIdx( getBaseToken( aElement ) );
166 66 : if( nIdx != -1 )
167 : {
168 0 : mVariables[ nIdx ] = makeAny( rAttribs.getString( XML_val ).get() );
169 : }
170 :
171 66 : return this;
172 : }
173 : private:
174 : LayoutNode::VarMap & mVariables;
175 : };
176 :
177 : // CT_LayoutNode
178 230 : LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper& rParent,
179 : const AttributeList& rAttribs,
180 : const LayoutAtomPtr& pAtom )
181 : : ContextHandler2( rParent )
182 230 : , mpNode( pAtom )
183 : {
184 : OSL_ENSURE( pAtom, "Node must NOT be NULL" );
185 230 : mpNode->setName( rAttribs.getString( XML_name ).get() );
186 230 : }
187 :
188 344 : LayoutNodeContext::~LayoutNodeContext()
189 : {
190 344 : }
191 :
192 : /** convert the XML tag to a variable index in the array
193 : * @param aTag the tag, without namespace
194 : * @return the variable index. -1 is an error
195 : */
196 104 : sal_Int32 LayoutNodeContext::tagToVarIdx( sal_Int32 aTag )
197 : {
198 104 : sal_Int32 nIdx = -1;
199 104 : switch( aTag )
200 : {
201 : case DGM_TOKEN( animLvl ):
202 0 : nIdx = LayoutNode::VAR_animLvl;
203 0 : break;
204 : case DGM_TOKEN( animOne ):
205 0 : nIdx = LayoutNode::VAR_animOne;
206 0 : break;
207 : case DGM_TOKEN( bulletEnabled ):
208 0 : nIdx = LayoutNode::VAR_bulletEnabled;
209 0 : break;
210 : case DGM_TOKEN( chMax ):
211 0 : nIdx = LayoutNode::VAR_chMax;
212 0 : break;
213 : case DGM_TOKEN( chPref ):
214 0 : nIdx = LayoutNode::VAR_chPref;
215 0 : break;
216 : case DGM_TOKEN( dir ):
217 0 : nIdx = LayoutNode::VAR_dir;
218 0 : break;
219 : case DGM_TOKEN( hierBranch ):
220 0 : nIdx = LayoutNode::VAR_hierBranch;
221 0 : break;
222 : case DGM_TOKEN( orgChart ):
223 0 : nIdx = LayoutNode::VAR_orgChart;
224 0 : break;
225 : case DGM_TOKEN( resizeHandles ):
226 0 : nIdx = LayoutNode::VAR_resizeHandles;
227 0 : break;
228 : default:
229 104 : break;
230 : }
231 104 : return nIdx;
232 : }
233 :
234 : ContextHandlerRef
235 858 : LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
236 : const AttributeList& rAttribs )
237 : {
238 858 : switch( aElement )
239 : {
240 : case DGM_TOKEN( layoutNode ):
241 : {
242 94 : LayoutNodePtr pNode( new LayoutNode() );
243 94 : mpNode->addChild( pNode );
244 94 : pNode->setChildOrder( rAttribs.getToken( XML_chOrder, XML_b ) );
245 94 : pNode->setMoveWith( rAttribs.getString( XML_moveWith ).get() );
246 94 : pNode->setStyleLabel( rAttribs.getString( XML_styleLbl ).get() );
247 94 : return new LayoutNodeContext( *this, rAttribs, pNode );
248 : }
249 : case DGM_TOKEN( shape ):
250 : {
251 120 : LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
252 120 : if( pNode )
253 : {
254 108 : ShapePtr pShape;
255 :
256 108 : if( rAttribs.hasAttribute( XML_type ) )
257 : {
258 38 : pShape.reset( new Shape("com.sun.star.drawing.CustomShape") );
259 38 : const sal_Int32 nType(rAttribs.getToken( XML_type, XML_obj ));
260 38 : pShape->setSubType( nType );
261 38 : pShape->getCustomShapeProperties()->setShapePresetType( nType );
262 : }
263 : else
264 : {
265 70 : pShape.reset( new Shape("com.sun.star.drawing.GroupShape") );
266 : }
267 :
268 108 : pNode->setShape( pShape );
269 108 : return new ShapeContext( *this, ShapePtr(), pShape );
270 : }
271 : else
272 : {
273 : OSL_TRACE( "OOX: encountered a shape in a non layoutNode context" );
274 : }
275 12 : break;
276 : }
277 : case DGM_TOKEN( extLst ):
278 0 : return 0;
279 : case DGM_TOKEN( alg ):
280 : {
281 : // CT_Algorithm
282 134 : AlgAtomPtr pAtom( new AlgAtom );
283 134 : mpNode->addChild( pAtom );
284 134 : return new AlgorithmContext( *this, rAttribs, pAtom );
285 : }
286 : case DGM_TOKEN( choose ):
287 : {
288 : // CT_Choose
289 38 : LayoutAtomPtr pAtom( new ChooseAtom );
290 38 : mpNode->addChild( pAtom );
291 38 : return new ChooseContext( *this, rAttribs, pAtom );
292 : }
293 : case DGM_TOKEN( forEach ):
294 : {
295 : // CT_ForEach
296 40 : ForEachAtomPtr pAtom( new ForEachAtom(rAttribs.getFastAttributeList()) );
297 40 : mpNode->addChild( pAtom );
298 40 : return new ForEachContext( *this, rAttribs, pAtom );
299 : }
300 : case DGM_TOKEN( constrLst ):
301 : // CT_Constraints
302 120 : return new ConstraintListContext( *this, rAttribs, mpNode );
303 : case DGM_TOKEN( presOf ):
304 : {
305 : // CT_PresentationOf
306 : // TODO
307 114 : rAttribs.getString( XML_axis );
308 114 : rAttribs.getString( XML_cnt );
309 114 : rAttribs.getString( XML_hideLastTrans );
310 114 : rAttribs.getString( XML_ptType );
311 114 : rAttribs.getString( XML_st );
312 114 : rAttribs.getString( XML_step );
313 114 : break;
314 : }
315 : case DGM_TOKEN( ruleLst ):
316 : // CT_Rules
317 : // TODO
318 114 : break;
319 : case DGM_TOKEN( varLst ):
320 : {
321 46 : LayoutNodePtr pNode( boost::dynamic_pointer_cast< LayoutNode >( mpNode ) );
322 46 : if( pNode )
323 : {
324 46 : return new LayoutVariablePropertySetContext( *this, pNode->variables() );
325 : }
326 : else
327 : {
328 : OSL_TRACE( "OOX: encountered a varLst in a non layoutNode context" );
329 : }
330 0 : break;
331 : }
332 : default:
333 38 : break;
334 : }
335 :
336 278 : return this;
337 : }
338 :
339 408 : } }
340 :
341 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|