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