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