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