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