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 
28 using namespace ::oox::core;
29 using namespace ::com::sun::star::xml::sax;
30 using namespace ::com::sun::star::uno;
31 
32 namespace oox::drawingml {
33 
34 namespace {
35 
36 // CT_CxnList
37 class CxnListContext
38  : public ContextHandler2
39 {
40 public:
41  CxnListContext( ContextHandler2Helper const & rParent,
42  dgm::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  dgm::Connection& rConnection=mrConnection.back();
58 
59  rConnection.mnType = rAttribs.getToken( XML_type, XML_parOf );
60  rConnection.msModelId = rAttribs.getString( XML_modelId ).get();
61  rConnection.msSourceId = rAttribs.getString( XML_srcId ).get();
62  rConnection.msDestId = rAttribs.getString( XML_destId ).get();
63  rConnection.msPresId = rAttribs.getString( XML_presId ).get();
64  rConnection.msSibTransId = rAttribs.getString( XML_sibTransId ).get();
65  rConnection.msParTransId = rAttribs.getString( XML_parTransId ).get();
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  }
78 private:
80 };
81 
82 // CT_presLayoutVars
83 class PresLayoutVarsContext
84  : public ContextHandler2
85 {
86 public:
87  PresLayoutVarsContext( ContextHandler2Helper const & rParent,
88  dgm::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  mrPoint.moHierarchyBranch = rAttribs.getToken( XML_val );
117  break;
118  case DGM_TOKEN( orgChart ):
119  mrPoint.mbOrgChartEnabled = rAttribs.getBool( XML_val, false );
120  break;
121  case DGM_TOKEN( resizeHandles ):
122  mrPoint.mnResizeHandles = rAttribs.getToken( XML_val, XML_rel );
123  break;
124  default:
125  break;
126  }
127 
128  return this;
129  }
130 
131 private:
132  dgm::Point& mrPoint;
133 };
134 
135 // CT_prSet
136 class PropertiesContext
137  : public ContextHandler2
138 {
139 public:
140  PropertiesContext( ContextHandler2Helper const & rParent,
141  dgm::Point & rPoint,
142  const AttributeList& rAttribs ) :
143  ContextHandler2( rParent ),
144  mrPoint( rPoint )
145  {
146  mrPoint.msColorTransformCategoryId = rAttribs.getString( XML_csCatId, "" );
147  mrPoint.msColorTransformTypeId = rAttribs.getString( XML_csTypeId, "" );
148  mrPoint.msLayoutCategoryId = rAttribs.getString( XML_loCatId, "" );
149  mrPoint.msLayoutTypeId = rAttribs.getString( XML_loTypeId, "" );
150  mrPoint.msPlaceholderText = rAttribs.getString( XML_phldrT, "" );
151  mrPoint.msPresentationAssociationId = rAttribs.getString( XML_presAssocID, "" );
152  mrPoint.msPresentationLayoutName = rAttribs.getString( XML_presName, "" );
153  mrPoint.msPresentationLayoutStyleLabel = rAttribs.getString( XML_presStyleLbl, "" );
154  mrPoint.msQuickStyleCategoryId = rAttribs.getString( XML_qsCatId, "" );
155  mrPoint.msQuickStyleTypeId = rAttribs.getString( XML_qsTypeId, "" );
156 
157  mrPoint.mnCustomAngle = rAttribs.getInteger( XML_custAng, -1 );
158  mrPoint.mnPercentageNeighbourWidth = rAttribs.getInteger( XML_custLinFactNeighborX, -1 );
159  mrPoint.mnPercentageNeighbourHeight = rAttribs.getInteger( XML_custLinFactNeighborY, -1 );
160  mrPoint.mnPercentageOwnWidth = rAttribs.getInteger( XML_custLinFactX, -1 );
161  mrPoint.mnPercentageOwnHeight = rAttribs.getInteger( XML_custLinFactY, -1 );
162  mrPoint.mnIncludeAngleScale = rAttribs.getInteger( XML_custRadScaleInc, -1 );
163  mrPoint.mnRadiusScale = rAttribs.getInteger( XML_custRadScaleRad, -1 );
164  mrPoint.mnWidthScale = rAttribs.getInteger( XML_custScaleX, -1 );
165  mrPoint.mnHeightScale = rAttribs.getInteger( XML_custScaleY, -1 );
166  mrPoint.mnWidthOverride = rAttribs.getInteger( XML_custSzX, -1 );
167  mrPoint.mnHeightOverride = rAttribs.getInteger( XML_custSzY, -1 );
168  mrPoint.mnLayoutStyleCount = rAttribs.getInteger( XML_presStyleCnt, -1 );
169  mrPoint.mnLayoutStyleIndex = rAttribs.getInteger( XML_presStyleIdx, -1 );
170 
171  mrPoint.mbCoherent3DOffset = rAttribs.getBool( XML_coherent3DOff, false );
172  mrPoint.mbCustomHorizontalFlip = rAttribs.getBool( XML_custFlipHor, false );
173  mrPoint.mbCustomVerticalFlip = rAttribs.getBool( XML_custFlipVert, false );
174  mrPoint.mbCustomText = rAttribs.getBool( XML_custT, false );
175  mrPoint.mbIsPlaceholder = rAttribs.getBool( XML_phldr, false );
176  }
177 
178  virtual ContextHandlerRef
179  onCreateContext( sal_Int32 aElementToken,
180  const AttributeList& ) override
181  {
182  switch( aElementToken )
183  {
184  case DGM_TOKEN( presLayoutVars ):
185  return new PresLayoutVarsContext( *this, mrPoint );
186  case DGM_TOKEN( style ):
187  // skip CT_shapeStyle
188  return nullptr;
189  default:
190  break;
191  }
192  return this;
193  }
194 
195 private:
196  dgm::Point& mrPoint;
197 };
198 
199 // CL_Pt
200 class PtContext
201  : public ContextHandler2
202 {
203 public:
204  PtContext( ContextHandler2Helper const & rParent,
205  const AttributeList& rAttribs,
206  dgm::Point & rPoint):
207  ContextHandler2( rParent ),
208  mrPoint( rPoint )
209  {
210  mrPoint.msModelId = rAttribs.getString( XML_modelId ).get();
211 
212  // the default type is XML_node
213  const sal_Int32 nType = rAttribs.getToken( XML_type, XML_node );
214  mrPoint.mnType = nType;
215 
216  // ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer
217  if( ( nType == XML_parTrans ) || ( nType == XML_sibTrans ) )
218  mrPoint.msCnxId = rAttribs.getString( XML_cxnId ).get();
219  }
220 
221  virtual ContextHandlerRef
222  onCreateContext( sal_Int32 aElementToken,
223  const AttributeList& rAttribs ) override
224  {
225  switch( aElementToken )
226  {
227  case DGM_TOKEN( extLst ):
228  return nullptr;
229  case DGM_TOKEN( prSet ):
230  return new PropertiesContext( *this, mrPoint, rAttribs );
231  case DGM_TOKEN( spPr ):
232  if( !mrPoint.mpShape )
234  return new ShapePropertiesContext( *this, *(mrPoint.mpShape) );
235  case DGM_TOKEN( t ):
236  {
237  TextBodyPtr xTextBody = std::make_shared<TextBody>();
238  if( !mrPoint.mpShape )
239  mrPoint.mpShape = std::make_shared<Shape>();
240  mrPoint.mpShape->setTextBody( xTextBody );
241  return new TextBodyContext( *this, *xTextBody );
242  }
243  default:
244  break;
245  }
246  return this;
247  }
248 
249 private:
250  dgm::Point& mrPoint;
251 };
252 
253 // CT_PtList
254 class PtListContext
255  : public ContextHandler2
256 {
257 public:
258  PtListContext( ContextHandler2Helper const & rParent, dgm::Points& rPoints) :
259  ContextHandler2( rParent ),
260  mrPoints( rPoints )
261  {}
262  virtual ContextHandlerRef
263  onCreateContext( sal_Int32 aElementToken,
264  const AttributeList& rAttribs ) override
265  {
266  switch( aElementToken )
267  {
268  case DGM_TOKEN( pt ):
269  {
270  // CT_Pt
271  mrPoints.emplace_back( );
272  return new PtContext( *this, rAttribs, mrPoints.back() );
273  }
274  default:
275  break;
276  }
277  return this;
278  }
279 
280 private:
282 };
283 
284 // CT_BackgroundFormatting
285 class BackgroundFormattingContext
286  : public ContextHandler2
287 {
288 public:
289  BackgroundFormattingContext( ContextHandler2Helper const & rParent, DiagramDataPtr const & pModel )
290  : ContextHandler2( rParent )
291  , mpDataModel( pModel )
292  {
293  assert( pModel && "the data model MUST NOT be NULL" );
294  }
295 
296  virtual ContextHandlerRef
297  onCreateContext( sal_Int32 aElementToken,
298  const AttributeList& rAttribs ) override
299  {
300  switch( aElementToken )
301  {
302  case A_TOKEN( blipFill ):
303  case A_TOKEN( gradFill ):
304  case A_TOKEN( grpFill ):
305  case A_TOKEN( noFill ):
306  case A_TOKEN( pattFill ):
307  case A_TOKEN( solidFill ):
308  // EG_FillProperties
309  return FillPropertiesContext::createFillContext(
310  *this, aElementToken, rAttribs, *mpDataModel->getFillProperties() );
311  case A_TOKEN( effectDag ):
312  case A_TOKEN( effectLst ):
313  // TODO
314  // EG_EffectProperties
315  break;
316  default:
317  break;
318  }
319  return this;
320  }
321 private:
323 };
324 
325 }
326 
328  const DiagramDataPtr & pDataModel )
329  : ContextHandler2( rParent )
330  , mpDataModel( pDataModel )
331 {
332  assert( pDataModel && "Data Model must not be NULL" );
333 }
334 
336 {
337  // some debug
338  mpDataModel->dump();
339 }
340 
342 DataModelContext::onCreateContext( ::sal_Int32 aElement,
343  const AttributeList& rAttribs )
344 {
345  switch( aElement )
346  {
347  case DGM_TOKEN( cxnLst ):
348  // CT_CxnList
349  return new CxnListContext( *this, mpDataModel->getConnections() );
350  case DGM_TOKEN( ptLst ):
351  // CT_PtList
352  return new PtListContext( *this, mpDataModel->getPoints() );
353  case DGM_TOKEN( bg ):
354  // CT_BackgroundFormatting
355  return new BackgroundFormattingContext( *this, mpDataModel );
356  case DGM_TOKEN( whole ):
357  // CT_WholeE2oFormatting
358  // TODO
359  return nullptr;
360  case DGM_TOKEN( extLst ):
361  case A_TOKEN( ext ):
362  break;
363  case DSP_TOKEN( dataModelExt ):
364  mpDataModel->getExtDrawings().push_back( rAttribs.getString( XML_relId ).get() );
365  break;
366  default:
367  break;
368  }
369 
370  return this;
371 }
372 
373 }
374 
375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< DiagramData > DiagramDataPtr
Definition: datamodel.hxx:199
DiagramDataPtr mpDataModel
dgm::Points & mrPoints
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
std::shared_ptr< T > make_shared(Args &&...args)
Shape
const Type & get() const
Definition: helper.hxx:185
dgm::Point & mrPoint
DataModelContext(::oox::core::ContextHandler2Helper const &rParent, const DiagramDataPtr &pDataModelPtr)
std::vector< Point > Points
Definition: datamodel.hxx:141
std::shared_ptr< TextBody > TextBodyPtr
Provides access to attribute values of an element.
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
::rtl::Reference< ContextHandler > ContextHandlerRef
QPRO_FUNC_TYPE nType
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
sal_Int32 getToken(const Context &rContext, const char *pToken)
std::vector< Connection > Connections
Definition: datamodel.hxx:61
dgm::Connections & mrConnection
Helper class that provides a context stack.
AnimatableShapeSharedPtr mpShape