Branch data 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 "datamodelcontext.hxx"
21 : : #include "oox/helper/attributelist.hxx"
22 : : #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
23 : : #include "oox/drawingml/shapepropertiescontext.hxx"
24 : : #include "oox/drawingml/textbodycontext.hxx"
25 : :
26 : : using namespace ::oox::core;
27 : : using namespace ::com::sun::star::xml::sax;
28 : : using namespace ::com::sun::star::uno;
29 : : using ::rtl::OUString;
30 : :
31 : : namespace oox { namespace drawingml {
32 : :
33 : : // CT_CxnList
34 [ - + ]: 6 : class CxnListContext
35 : : : public ContextHandler
36 : : {
37 : : public:
38 : 3 : CxnListContext( ContextHandler& rParent,
39 : : dgm::Connections & aConnections )
40 : : : ContextHandler( rParent )
41 : 3 : , mrConnection( aConnections )
42 : : {
43 : 3 : }
44 : :
45 : : virtual Reference< XFastContextHandler > SAL_CALL
46 : 42 : createFastChildContext( sal_Int32 aElementToken,
47 : : const Reference< XFastAttributeList >& xAttribs )
48 : : throw (SAXException, RuntimeException)
49 : : {
50 : 42 : Reference< XFastContextHandler > xRet;
51 : :
52 [ + - ]: 42 : switch( aElementToken )
53 : : {
54 : : case DGM_TOKEN( cxn ):
55 : : {
56 [ + - ]: 42 : mrConnection.push_back( dgm::Connection() );
57 [ + - ]: 42 : dgm::Connection& rConnection=mrConnection.back();
58 : :
59 [ + - ][ + - ]: 42 : const sal_Int32 nType = xAttribs->getOptionalValueToken( XML_type, XML_parOf );
60 : 42 : rConnection.mnType = nType;
61 [ + - ][ + - ]: 42 : rConnection.msModelId = xAttribs->getOptionalValue( XML_modelId );
62 [ + - ][ + - ]: 42 : rConnection.msSourceId = xAttribs->getOptionalValue( XML_srcId );
63 [ + - ][ + - ]: 42 : rConnection.msDestId = xAttribs->getOptionalValue( XML_destId );
64 [ + - ][ + - ]: 42 : rConnection.msPresId = xAttribs->getOptionalValue( XML_presId );
65 [ + - ][ + - ]: 42 : rConnection.msSibTransId = xAttribs->getOptionalValue( XML_sibTransId );
66 [ + - ][ + - ]: 42 : rConnection.msParTransId = xAttribs->getOptionalValue( XML_parTransId );
67 [ + - ]: 42 : const AttributeList attribs( xAttribs );
68 [ + - ]: 42 : rConnection.mnSourceOrder = attribs.getInteger( XML_srcOrd, 0 );
69 [ + - ]: 42 : rConnection.mnDestOrder = attribs.getInteger( XML_destOrd, 0 );
70 : :
71 : : // skip CT_extLst
72 [ + - ]: 42 : return xRet;
73 : : }
74 : : default:
75 : 0 : break;
76 : : }
77 [ # # ]: 0 : if( !xRet.is() )
78 [ # # ]: 0 : xRet.set( this );
79 : 42 : return xRet;
80 : : }
81 : : private:
82 : : dgm::Connections& mrConnection;
83 : : };
84 : :
85 : :
86 : : // CT_presLayoutVars
87 [ - + ]: 24 : class PresLayoutVarsContext
88 : : : public ContextHandler
89 : : {
90 : : public:
91 : 12 : PresLayoutVarsContext( ContextHandler& rParent,
92 : : dgm::Point & rPoint ) :
93 : : ContextHandler( rParent ),
94 : 12 : mrPoint( rPoint )
95 : : {
96 : 12 : }
97 : : virtual Reference< XFastContextHandler > SAL_CALL
98 : 15 : createFastChildContext( sal_Int32 aElementToken,
99 : : const Reference< XFastAttributeList >& xAttribs )
100 : : throw (SAXException, RuntimeException)
101 : : {
102 : 15 : Reference< XFastContextHandler > xRet;
103 [ + - ]: 15 : AttributeList aAttribs( xAttribs );
104 : :
105 [ - + - - : 15 : switch( aElementToken )
+ - - +
- ]
106 : : {
107 : : // TODO
108 : : case DGM_TOKEN( animLvl ):
109 : : case DGM_TOKEN( animOne ):
110 : 0 : break;
111 : : case DGM_TOKEN( bulletEnabled ):
112 [ + - ]: 9 : mrPoint.mbBulletEnabled = aAttribs.getBool( XML_val, false );
113 : 9 : break;
114 : : case DGM_TOKEN( chMax ):
115 [ # # ]: 0 : mrPoint.mnMaxChildren = aAttribs.getInteger( XML_val, -1 );
116 : 0 : break;
117 : : case DGM_TOKEN( chPref ):
118 [ # # ]: 0 : mrPoint.mnPreferredChildren = aAttribs.getInteger( XML_val, -1 );
119 : 0 : break;
120 : : case DGM_TOKEN( dir ):
121 [ + - ]: 3 : mrPoint.mnDirection = aAttribs.getToken( XML_val, XML_norm );
122 : 3 : break;
123 : : case DGM_TOKEN( hierBranch ):
124 [ # # ]: 0 : mrPoint.mnHierarchyBranch = aAttribs.getToken( XML_val, XML_std );
125 : 0 : break;
126 : : case DGM_TOKEN( orgChart ):
127 [ # # ]: 0 : mrPoint.mbOrgChartEnabled = aAttribs.getBool( XML_val, false );
128 : 0 : break;
129 : : case DGM_TOKEN( resizeHandles ):
130 [ + - ]: 3 : mrPoint.mnResizeHandles = aAttribs.getToken( XML_val, XML_rel );
131 : 3 : break;
132 : : default:
133 : 0 : break;
134 : : }
135 [ + - ]: 15 : if( !xRet.is() )
136 [ + - ]: 15 : xRet.set( this );
137 [ + - ]: 15 : return xRet;
138 : : }
139 : :
140 : : private:
141 : : dgm::Point& mrPoint;
142 : : };
143 : :
144 : :
145 : : // CT_prSet
146 [ - + ]: 108 : class PropertiesContext
147 : : : public ContextHandler
148 : : {
149 : : public:
150 : 54 : PropertiesContext( ContextHandler& rParent,
151 : : dgm::Point & rPoint,
152 : : const Reference< XFastAttributeList >& xAttribs ) :
153 : : ContextHandler( rParent ),
154 : 54 : mrPoint( rPoint )
155 : : {
156 : 54 : OUString aEmptyStr;
157 [ + - ]: 54 : AttributeList aAttribs( xAttribs );
158 : :
159 [ + - ]: 54 : mrPoint.msColorTransformCategoryId = aAttribs.getString( XML_csCatId, aEmptyStr );
160 [ + - ]: 54 : mrPoint.msColorTransformTypeId = aAttribs.getString( XML_csTypeId, aEmptyStr );
161 [ + - ]: 54 : mrPoint.msLayoutCategoryId = aAttribs.getString( XML_loCatId, aEmptyStr );
162 [ + - ]: 54 : mrPoint.msLayoutTypeId = aAttribs.getString( XML_loTypeId, aEmptyStr );
163 [ + - ]: 54 : mrPoint.msPlaceholderText = aAttribs.getString( XML_phldrT, aEmptyStr );
164 [ + - ]: 54 : mrPoint.msPresentationAssociationId = aAttribs.getString( XML_presAssocID, aEmptyStr );
165 [ + - ]: 54 : mrPoint.msPresentationLayoutName = aAttribs.getString( XML_presName, aEmptyStr );
166 [ + - ]: 54 : mrPoint.msPresentationLayoutStyleLabel = aAttribs.getString( XML_presStyleLbl, aEmptyStr );
167 [ + - ]: 54 : mrPoint.msQuickStyleCategoryId = aAttribs.getString( XML_qsCatId, aEmptyStr );
168 [ + - ]: 54 : mrPoint.msQuickStyleTypeId = aAttribs.getString( XML_qsTypeId, aEmptyStr );
169 : :
170 [ + - ]: 54 : mrPoint.mnCustomAngle = aAttribs.getInteger( XML_custAng, -1 );
171 [ + - ]: 54 : mrPoint.mnPercentageNeighbourWidth = aAttribs.getInteger( XML_custLinFactNeighborX, -1 );
172 [ + - ]: 54 : mrPoint.mnPercentageNeighbourHeight = aAttribs.getInteger( XML_custLinFactNeighborY, -1 );
173 [ + - ]: 54 : mrPoint.mnPercentageOwnWidth = aAttribs.getInteger( XML_custLinFactX, -1 );
174 [ + - ]: 54 : mrPoint.mnPercentageOwnHeight = aAttribs.getInteger( XML_custLinFactY, -1 );
175 [ + - ]: 54 : mrPoint.mnIncludeAngleScale = aAttribs.getInteger( XML_custRadScaleInc, -1 );
176 [ + - ]: 54 : mrPoint.mnRadiusScale = aAttribs.getInteger( XML_custRadScaleRad, -1 );
177 [ + - ]: 54 : mrPoint.mnWidthScale = aAttribs.getInteger( XML_custScaleX, -1 );
178 [ + - ]: 54 : mrPoint.mnHeightScale = aAttribs.getInteger( XML_custScaleY, -1 );
179 [ + - ]: 54 : mrPoint.mnWidthOverride = aAttribs.getInteger( XML_custSzX, -1 );
180 [ + - ]: 54 : mrPoint.mnHeightOverride = aAttribs.getInteger( XML_custSzY, -1 );
181 [ + - ]: 54 : mrPoint.mnLayoutStyleCount = aAttribs.getInteger( XML_presStyleCnt, -1 );
182 [ + - ]: 54 : mrPoint.mnLayoutStyleIndex = aAttribs.getInteger( XML_presStyleIdx, -1 );
183 : :
184 [ + - ]: 54 : mrPoint.mbCoherent3DOffset = aAttribs.getBool( XML_coherent3DOff, false );
185 [ + - ]: 54 : mrPoint.mbCustomHorizontalFlip = aAttribs.getBool( XML_custFlipHor, false );
186 [ + - ]: 54 : mrPoint.mbCustomVerticalFlip = aAttribs.getBool( XML_custFlipVert, false );
187 [ + - ]: 54 : mrPoint.mbCustomText = aAttribs.getBool( XML_custT, false );
188 [ + - ][ + - ]: 54 : mrPoint.mbIsPlaceholder = aAttribs.getBool( XML_phldr, false );
189 : 54 : }
190 : :
191 : : virtual Reference< XFastContextHandler > SAL_CALL
192 : 12 : createFastChildContext( sal_Int32 aElementToken,
193 : : const Reference< XFastAttributeList >& )
194 : : throw (SAXException, RuntimeException)
195 : : {
196 : 12 : Reference< XFastContextHandler > xRet;
197 : :
198 [ + - - ]: 12 : switch( aElementToken )
199 : : {
200 : : case DGM_TOKEN( presLayoutVars ):
201 : : {
202 [ + - ][ + - ]: 12 : xRet.set( new PresLayoutVarsContext( *this, mrPoint ) );
[ + - ]
203 : 12 : break;
204 : : }
205 : : case DGM_TOKEN( style ):
206 : : {
207 : : // TODO
208 : : // skip CT_shapeStyle
209 : 0 : return xRet;
210 : : }
211 : : default:
212 : 0 : break;
213 : : }
214 [ - + ]: 12 : if( !xRet.is() )
215 [ # # ]: 0 : xRet.set( this );
216 : 12 : return xRet;
217 : : }
218 : :
219 : : private:
220 : : dgm::Point& mrPoint;
221 : : };
222 : :
223 : :
224 : : // CL_Pt
225 [ - + ]: 108 : class PtContext
226 : : : public ContextHandler
227 : : {
228 : : public:
229 : 54 : PtContext( ContextHandler& rParent,
230 : : const Reference< XFastAttributeList >& xAttribs,
231 : : dgm::Point & rPoint):
232 : : ContextHandler( rParent ),
233 : 54 : mrPoint( rPoint )
234 : : {
235 [ + - ][ + - ]: 54 : mrPoint.msModelId = xAttribs->getOptionalValue( XML_modelId );
236 : :
237 : : // the default type is XML_node
238 [ + - ][ + - ]: 54 : const sal_Int32 nType = xAttribs->getOptionalValueToken( XML_type, XML_node );
239 : 54 : mrPoint.mnType = nType;
240 : :
241 : : // ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer
242 [ + + ][ + + ]: 54 : if( ( nType == XML_parTrans ) || ( nType == XML_sibTrans ) )
243 [ + - ][ + - ]: 18 : mrPoint.msCnxId = xAttribs->getOptionalValue( XML_cxnId );
244 : 54 : }
245 : :
246 : :
247 : : virtual Reference< XFastContextHandler > SAL_CALL
248 : 123 : createFastChildContext( sal_Int32 aElementToken,
249 : : const Reference< XFastAttributeList >& xAttribs )
250 : : throw (SAXException, RuntimeException)
251 : : {
252 : 123 : Reference< XFastContextHandler > xRet;
253 : :
254 [ - + + + : 123 : switch( aElementToken )
- ]
255 : : {
256 : : case DGM_TOKEN( extLst ):
257 : 0 : return xRet;
258 : : case DGM_TOKEN( prSet ):
259 : : OSL_TRACE( "diagram property set for point");
260 [ + - ][ + - ]: 54 : xRet = new PropertiesContext( *this, mrPoint, xAttribs );
[ + - ]
261 : 54 : break;
262 : : case DGM_TOKEN( spPr ):
263 : : OSL_TRACE( "shape props for point");
264 [ + - ]: 54 : if( !mrPoint.mpShape )
265 [ + - ][ + - ]: 54 : mrPoint.mpShape.reset( new Shape() );
[ + - ]
266 [ + - ][ + - ]: 54 : xRet = new ShapePropertiesContext( *this, *(mrPoint.mpShape) );
[ + - ]
267 : 54 : break;
268 : : case DGM_TOKEN( t ):
269 : : {
270 : : OSL_TRACE( "shape text body for point");
271 [ + - ][ + - ]: 15 : TextBodyPtr xTextBody( new TextBody );
[ + - ]
272 [ - + ]: 15 : if( !mrPoint.mpShape )
273 [ # # ][ # # ]: 0 : mrPoint.mpShape.reset( new Shape() );
[ # # ]
274 [ + - ]: 15 : mrPoint.mpShape->setTextBody( xTextBody );
275 [ + - ][ + - ]: 15 : xRet = new TextBodyContext( *this, *xTextBody );
[ + - ]
276 [ + - ]: 15 : break;
277 : : }
278 : : default:
279 : 0 : break;
280 : : }
281 [ - + ]: 123 : if( !xRet.is() )
282 [ # # ]: 0 : xRet.set( this );
283 : 123 : return xRet;
284 : : }
285 : :
286 : : private:
287 : : dgm::Point& mrPoint;
288 : : };
289 : :
290 : :
291 : :
292 : : // CT_PtList
293 [ - + ]: 6 : class PtListContext
294 : : : public ContextHandler
295 : : {
296 : : public:
297 : 3 : PtListContext( ContextHandler& rParent, dgm::Points& rPoints) :
298 : : ContextHandler( rParent ),
299 : 3 : mrPoints( rPoints )
300 : 3 : {}
301 : : virtual Reference< XFastContextHandler > SAL_CALL
302 : 54 : createFastChildContext( sal_Int32 aElementToken,
303 : : const Reference< XFastAttributeList >& xAttribs )
304 : : throw (SAXException, RuntimeException)
305 : : {
306 : 54 : Reference< XFastContextHandler > xRet;
307 : :
308 [ + - ]: 54 : switch( aElementToken )
309 : : {
310 : : case DGM_TOKEN( pt ):
311 : : {
312 : : // CT_Pt
313 [ + - ][ + - ]: 54 : mrPoints.push_back( dgm::Point() );
[ + - ]
314 [ + - ][ + - ]: 54 : xRet.set( new PtContext( *this, xAttribs, mrPoints.back() ) );
[ + - ][ + - ]
315 : 54 : break;
316 : : }
317 : : default:
318 : 0 : break;
319 : : }
320 [ - + ]: 54 : if( !xRet.is() )
321 [ # # ]: 0 : xRet.set( this );
322 : 54 : return xRet;
323 : : }
324 : :
325 : : private:
326 : : dgm::Points& mrPoints;
327 : : };
328 : :
329 : : // CT_BackgroundFormatting
330 [ + - ][ - + ]: 6 : class BackgroundFormattingContext
331 : : : public ContextHandler
332 : : {
333 : : public:
334 : 3 : BackgroundFormattingContext( ContextHandler& rParent, DiagramDataPtr & pModel )
335 : : : ContextHandler( rParent )
336 [ + - ]: 3 : , mpDataModel( pModel )
337 : : {
338 : : OSL_ENSURE( pModel, "the data model MUST NOT be NULL" );
339 : 3 : }
340 : :
341 : : virtual Reference< XFastContextHandler > SAL_CALL
342 : 0 : createFastChildContext( sal_Int32 aElementToken,
343 : : const Reference< XFastAttributeList >& xAttribs )
344 : : throw (SAXException, RuntimeException)
345 : : {
346 : 0 : Reference< XFastContextHandler > xRet;
347 : :
348 [ # # # ]: 0 : switch( aElementToken )
349 : : {
350 : : case A_TOKEN( blipFill ):
351 : : case A_TOKEN( gradFill ):
352 : : case A_TOKEN( grpFill ):
353 : : case A_TOKEN( noFill ):
354 : : case A_TOKEN( pattFill ):
355 : : case A_TOKEN( solidFill ):
356 : : // EG_FillProperties
357 : : xRet.set( FillPropertiesContext::createFillContext(
358 [ # # ][ # # ]: 0 : *this, aElementToken, xAttribs, *mpDataModel->getFillProperties() ) );
359 : 0 : break;
360 : : case A_TOKEN( effectDag ):
361 : : case A_TOKEN( effectLst ):
362 : : // TODO
363 : : // EG_EffectProperties
364 : 0 : break;
365 : : default:
366 : 0 : break;
367 : : }
368 [ # # ]: 0 : if( !xRet.is() )
369 [ # # ]: 0 : xRet.set( this );
370 : 0 : return xRet;
371 : : }
372 : : private:
373 : : DiagramDataPtr mpDataModel;
374 : : };
375 : :
376 : :
377 : :
378 : 3 : DataModelContext::DataModelContext( ContextHandler& rParent,
379 : : const DiagramDataPtr & pDataModel )
380 : : : ContextHandler( rParent )
381 [ + - ]: 3 : , mpDataModel( pDataModel )
382 : : {
383 : : OSL_ENSURE( pDataModel, "Data Model must not be NULL" );
384 : 3 : }
385 : :
386 : :
387 [ + - ]: 3 : DataModelContext::~DataModelContext()
388 : : {
389 : : // some debug
390 [ + - ]: 3 : mpDataModel->dump();
391 [ - + ]: 6 : }
392 : :
393 : : Reference< XFastContextHandler > SAL_CALL
394 : 21 : DataModelContext::createFastChildContext( ::sal_Int32 aElement,
395 : : const Reference< XFastAttributeList >& xAttribs )
396 : : throw ( SAXException, RuntimeException)
397 : : {
398 : 21 : Reference< XFastContextHandler > xRet;
399 : :
400 [ + + + + : 21 : switch( aElement )
+ + - ]
401 : : {
402 : : case DGM_TOKEN( cxnLst ):
403 : : // CT_CxnList
404 [ + - ][ + - ]: 3 : xRet.set( new CxnListContext( *this, mpDataModel->getConnections() ) );
[ + - ]
405 : 3 : break;
406 : : case DGM_TOKEN( ptLst ):
407 : : // CT_PtList
408 [ + - ][ + - ]: 3 : xRet.set( new PtListContext( *this, mpDataModel->getPoints() ) );
[ + - ]
409 : 3 : break;
410 : : case DGM_TOKEN( bg ):
411 : : // CT_BackgroundFormatting
412 [ + - ][ + - ]: 3 : xRet.set( new BackgroundFormattingContext( *this, mpDataModel ) );
[ + - ]
413 : 3 : break;
414 : : case DGM_TOKEN( whole ):
415 : : // CT_WholeE2oFormatting
416 : : // TODO
417 : 3 : return xRet;
418 : : case DGM_TOKEN( extLst ):
419 : : case A_TOKEN( ext ):
420 : 6 : break;
421 : : case DSP_TOKEN( dataModelExt ):
422 [ + - ][ + - ]: 3 : mpDataModel->getExtDrawings().push_back( xAttribs->getOptionalValue( XML_relId ) );
[ + - ]
423 : 3 : break;
424 : : default:
425 : 0 : break;
426 : : }
427 : :
428 [ + + ]: 18 : if( !xRet.is() )
429 [ + - ]: 9 : xRet.set( this );
430 : :
431 : 21 : return xRet;
432 : : }
433 : :
434 [ + - ][ + - ]: 285 : } }
435 : :
436 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|