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