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