Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / diagram / datamodelcontext.cxx
blobb98d0ee87ccf088e550dc9829219a1583804e31a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "datamodelcontext.hxx"
21 #include <oox/helper/attributelist.hxx>
22 #include <drawingml/misccontexts.hxx>
23 #include <drawingml/shapepropertiescontext.hxx>
24 #include <drawingml/textbodycontext.hxx>
25 #include <oox/token/namespaces.hxx>
26 #include <oox/token/tokens.hxx>
28 using namespace ::oox::core;
29 using namespace ::com::sun::star::xml::sax;
30 using namespace ::com::sun::star::uno;
32 namespace oox { namespace drawingml {
34 // CT_CxnList
35 class CxnListContext
36 : public ContextHandler2
38 public:
39 CxnListContext( ContextHandler2Helper const & rParent,
40 dgm::Connections & aConnections )
41 : ContextHandler2( rParent )
42 , mrConnection( aConnections )
46 virtual ContextHandlerRef
47 onCreateContext( sal_Int32 aElementToken,
48 const AttributeList& rAttribs ) override
50 switch( aElementToken )
52 case DGM_TOKEN( cxn ):
54 mrConnection.emplace_back( );
55 dgm::Connection& rConnection=mrConnection.back();
57 rConnection.mnType = rAttribs.getToken( XML_type, XML_parOf );
58 rConnection.msModelId = rAttribs.getString( XML_modelId ).get();
59 rConnection.msSourceId = rAttribs.getString( XML_srcId ).get();
60 rConnection.msDestId = rAttribs.getString( XML_destId ).get();
61 rConnection.msPresId = rAttribs.getString( XML_presId ).get();
62 rConnection.msSibTransId = rAttribs.getString( XML_sibTransId ).get();
63 rConnection.msParTransId = rAttribs.getString( XML_parTransId ).get();
64 rConnection.mnSourceOrder = rAttribs.getInteger( XML_srcOrd, 0 );
65 rConnection.mnDestOrder = rAttribs.getInteger( XML_destOrd, 0 );
67 // skip CT_extLst
68 return nullptr;
70 default:
71 break;
74 return this;
76 private:
77 dgm::Connections& mrConnection;
80 // CT_presLayoutVars
81 class PresLayoutVarsContext
82 : public ContextHandler2
84 public:
85 PresLayoutVarsContext( ContextHandler2Helper const & rParent,
86 dgm::Point & rPoint ) :
87 ContextHandler2( rParent ),
88 mrPoint( rPoint )
91 virtual ContextHandlerRef
92 onCreateContext( sal_Int32 aElementToken,
93 const AttributeList& rAttribs ) override
95 switch( aElementToken )
97 // TODO
98 case DGM_TOKEN( animLvl ):
99 case DGM_TOKEN( animOne ):
100 break;
101 case DGM_TOKEN( bulletEnabled ):
102 mrPoint.mbBulletEnabled = rAttribs.getBool( XML_val, false );
103 break;
104 case DGM_TOKEN( chMax ):
105 mrPoint.mnMaxChildren = rAttribs.getInteger( XML_val, -1 );
106 break;
107 case DGM_TOKEN( chPref ):
108 mrPoint.mnPreferredChildren = rAttribs.getInteger( XML_val, -1 );
109 break;
110 case DGM_TOKEN( dir ):
111 mrPoint.mnDirection = rAttribs.getToken( XML_val, XML_norm );
112 break;
113 case DGM_TOKEN( hierBranch ):
114 mrPoint.moHierarchyBranch = rAttribs.getToken( XML_val );
115 break;
116 case DGM_TOKEN( orgChart ):
117 mrPoint.mbOrgChartEnabled = rAttribs.getBool( XML_val, false );
118 break;
119 case DGM_TOKEN( resizeHandles ):
120 mrPoint.mnResizeHandles = rAttribs.getToken( XML_val, XML_rel );
121 break;
122 default:
123 break;
126 return this;
129 private:
130 dgm::Point& mrPoint;
133 // CT_prSet
134 class PropertiesContext
135 : public ContextHandler2
137 public:
138 PropertiesContext( ContextHandler2Helper const & rParent,
139 dgm::Point & rPoint,
140 const AttributeList& rAttribs ) :
141 ContextHandler2( rParent ),
142 mrPoint( rPoint )
144 mrPoint.msColorTransformCategoryId = rAttribs.getString( XML_csCatId, "" );
145 mrPoint.msColorTransformTypeId = rAttribs.getString( XML_csTypeId, "" );
146 mrPoint.msLayoutCategoryId = rAttribs.getString( XML_loCatId, "" );
147 mrPoint.msLayoutTypeId = rAttribs.getString( XML_loTypeId, "" );
148 mrPoint.msPlaceholderText = rAttribs.getString( XML_phldrT, "" );
149 mrPoint.msPresentationAssociationId = rAttribs.getString( XML_presAssocID, "" );
150 mrPoint.msPresentationLayoutName = rAttribs.getString( XML_presName, "" );
151 mrPoint.msPresentationLayoutStyleLabel = rAttribs.getString( XML_presStyleLbl, "" );
152 mrPoint.msQuickStyleCategoryId = rAttribs.getString( XML_qsCatId, "" );
153 mrPoint.msQuickStyleTypeId = rAttribs.getString( XML_qsTypeId, "" );
155 mrPoint.mnCustomAngle = rAttribs.getInteger( XML_custAng, -1 );
156 mrPoint.mnPercentageNeighbourWidth = rAttribs.getInteger( XML_custLinFactNeighborX, -1 );
157 mrPoint.mnPercentageNeighbourHeight = rAttribs.getInteger( XML_custLinFactNeighborY, -1 );
158 mrPoint.mnPercentageOwnWidth = rAttribs.getInteger( XML_custLinFactX, -1 );
159 mrPoint.mnPercentageOwnHeight = rAttribs.getInteger( XML_custLinFactY, -1 );
160 mrPoint.mnIncludeAngleScale = rAttribs.getInteger( XML_custRadScaleInc, -1 );
161 mrPoint.mnRadiusScale = rAttribs.getInteger( XML_custRadScaleRad, -1 );
162 mrPoint.mnWidthScale = rAttribs.getInteger( XML_custScaleX, -1 );
163 mrPoint.mnHeightScale = rAttribs.getInteger( XML_custScaleY, -1 );
164 mrPoint.mnWidthOverride = rAttribs.getInteger( XML_custSzX, -1 );
165 mrPoint.mnHeightOverride = rAttribs.getInteger( XML_custSzY, -1 );
166 mrPoint.mnLayoutStyleCount = rAttribs.getInteger( XML_presStyleCnt, -1 );
167 mrPoint.mnLayoutStyleIndex = rAttribs.getInteger( XML_presStyleIdx, -1 );
169 mrPoint.mbCoherent3DOffset = rAttribs.getBool( XML_coherent3DOff, false );
170 mrPoint.mbCustomHorizontalFlip = rAttribs.getBool( XML_custFlipHor, false );
171 mrPoint.mbCustomVerticalFlip = rAttribs.getBool( XML_custFlipVert, false );
172 mrPoint.mbCustomText = rAttribs.getBool( XML_custT, false );
173 mrPoint.mbIsPlaceholder = rAttribs.getBool( XML_phldr, false );
176 virtual ContextHandlerRef
177 onCreateContext( sal_Int32 aElementToken,
178 const AttributeList& ) override
180 switch( aElementToken )
182 case DGM_TOKEN( presLayoutVars ):
183 return new PresLayoutVarsContext( *this, mrPoint );
184 case DGM_TOKEN( style ):
185 // skip CT_shapeStyle
186 return nullptr;
187 default:
188 break;
190 return this;
193 private:
194 dgm::Point& mrPoint;
197 // CL_Pt
198 class PtContext
199 : public ContextHandler2
201 public:
202 PtContext( ContextHandler2Helper const & rParent,
203 const AttributeList& rAttribs,
204 dgm::Point & rPoint):
205 ContextHandler2( rParent ),
206 mrPoint( rPoint )
208 mrPoint.msModelId = rAttribs.getString( XML_modelId ).get();
210 // the default type is XML_node
211 const sal_Int32 nType = rAttribs.getToken( XML_type, XML_node );
212 mrPoint.mnType = nType;
214 // ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer
215 if( ( nType == XML_parTrans ) || ( nType == XML_sibTrans ) )
216 mrPoint.msCnxId = rAttribs.getString( XML_cxnId ).get();
219 virtual ContextHandlerRef
220 onCreateContext( sal_Int32 aElementToken,
221 const AttributeList& rAttribs ) override
223 switch( aElementToken )
225 case DGM_TOKEN( extLst ):
226 return nullptr;
227 case DGM_TOKEN( prSet ):
228 return new PropertiesContext( *this, mrPoint, rAttribs );
229 case DGM_TOKEN( spPr ):
230 if( !mrPoint.mpShape )
231 mrPoint.mpShape.reset( new Shape() );
232 return new ShapePropertiesContext( *this, *(mrPoint.mpShape) );
233 case DGM_TOKEN( t ):
235 TextBodyPtr xTextBody( new TextBody );
236 if( !mrPoint.mpShape )
237 mrPoint.mpShape.reset( new Shape() );
238 mrPoint.mpShape->setTextBody( xTextBody );
239 return new TextBodyContext( *this, *xTextBody );
241 default:
242 break;
244 return this;
247 private:
248 dgm::Point& mrPoint;
251 // CT_PtList
252 class PtListContext
253 : public ContextHandler2
255 public:
256 PtListContext( ContextHandler2Helper const & rParent, dgm::Points& rPoints) :
257 ContextHandler2( rParent ),
258 mrPoints( rPoints )
260 virtual ContextHandlerRef
261 onCreateContext( sal_Int32 aElementToken,
262 const AttributeList& rAttribs ) override
264 switch( aElementToken )
266 case DGM_TOKEN( pt ):
268 // CT_Pt
269 mrPoints.emplace_back( );
270 return new PtContext( *this, rAttribs, mrPoints.back() );
272 default:
273 break;
275 return this;
278 private:
279 dgm::Points& mrPoints;
282 // CT_BackgroundFormatting
283 class BackgroundFormattingContext
284 : public ContextHandler2
286 public:
287 BackgroundFormattingContext( ContextHandler2Helper const & rParent, DiagramDataPtr const & pModel )
288 : ContextHandler2( rParent )
289 , mpDataModel( pModel )
291 assert( pModel && "the data model MUST NOT be NULL" );
294 virtual ContextHandlerRef
295 onCreateContext( sal_Int32 aElementToken,
296 const AttributeList& rAttribs ) override
298 switch( aElementToken )
300 case A_TOKEN( blipFill ):
301 case A_TOKEN( gradFill ):
302 case A_TOKEN( grpFill ):
303 case A_TOKEN( noFill ):
304 case A_TOKEN( pattFill ):
305 case A_TOKEN( solidFill ):
306 // EG_FillProperties
307 return FillPropertiesContext::createFillContext(
308 *this, aElementToken, rAttribs, *mpDataModel->getFillProperties() );
309 case A_TOKEN( effectDag ):
310 case A_TOKEN( effectLst ):
311 // TODO
312 // EG_EffectProperties
313 break;
314 default:
315 break;
317 return this;
319 private:
320 DiagramDataPtr mpDataModel;
323 DataModelContext::DataModelContext( ContextHandler2Helper const & rParent,
324 const DiagramDataPtr & pDataModel )
325 : ContextHandler2( rParent )
326 , mpDataModel( pDataModel )
328 assert( pDataModel && "Data Model must not be NULL" );
331 DataModelContext::~DataModelContext()
333 // some debug
334 mpDataModel->dump();
337 ContextHandlerRef
338 DataModelContext::onCreateContext( ::sal_Int32 aElement,
339 const AttributeList& rAttribs )
341 switch( aElement )
343 case DGM_TOKEN( cxnLst ):
344 // CT_CxnList
345 return new CxnListContext( *this, mpDataModel->getConnections() );
346 case DGM_TOKEN( ptLst ):
347 // CT_PtList
348 return new PtListContext( *this, mpDataModel->getPoints() );
349 case DGM_TOKEN( bg ):
350 // CT_BackgroundFormatting
351 return new BackgroundFormattingContext( *this, mpDataModel );
352 case DGM_TOKEN( whole ):
353 // CT_WholeE2oFormatting
354 // TODO
355 return nullptr;
356 case DGM_TOKEN( extLst ):
357 case A_TOKEN( ext ):
358 break;
359 case DSP_TOKEN( dataModelExt ):
360 mpDataModel->getExtDrawings().push_back( rAttribs.getString( XML_relId ).get() );
361 break;
362 default:
363 break;
366 return this;
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */