1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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::uno
;
31 namespace oox::drawingml
{
37 : public ContextHandler2
40 CxnListContext( ContextHandler2Helper
const & rParent
,
41 svx::diagram::Connections
& aConnections
)
42 : ContextHandler2( rParent
)
43 , mrConnection( aConnections
)
47 virtual ContextHandlerRef
48 onCreateContext( sal_Int32 aElementToken
,
49 const AttributeList
& rAttribs
) override
51 switch( aElementToken
)
53 case DGM_TOKEN( cxn
):
55 mrConnection
.emplace_back( );
56 svx::diagram::Connection
& rConnection
=mrConnection
.back();
58 rConnection
.mnXMLType
= static_cast<svx::diagram::TypeConstant
>(rAttribs
.getToken( XML_type
, XML_parOf
));
59 rConnection
.msModelId
= rAttribs
.getStringDefaulted( XML_modelId
);
60 rConnection
.msSourceId
= rAttribs
.getStringDefaulted( XML_srcId
);
61 rConnection
.msDestId
= rAttribs
.getStringDefaulted( XML_destId
);
62 rConnection
.msPresId
= rAttribs
.getStringDefaulted( XML_presId
);
63 rConnection
.msSibTransId
= rAttribs
.getStringDefaulted( XML_sibTransId
);
64 rConnection
.msParTransId
= rAttribs
.getStringDefaulted( XML_parTransId
);
65 rConnection
.mnSourceOrder
= rAttribs
.getInteger( XML_srcOrd
, 0 );
66 rConnection
.mnDestOrder
= rAttribs
.getInteger( XML_destOrd
, 0 );
78 svx::diagram::Connections
& mrConnection
;
82 class PresLayoutVarsContext
83 : public ContextHandler2
86 PresLayoutVarsContext( ContextHandler2Helper
const & rParent
,
87 svx::diagram::Point
& rPoint
) :
88 ContextHandler2( rParent
),
92 virtual ContextHandlerRef
93 onCreateContext( sal_Int32 aElementToken
,
94 const AttributeList
& rAttribs
) override
96 switch( aElementToken
)
99 case DGM_TOKEN( animLvl
):
100 case DGM_TOKEN( animOne
):
102 case DGM_TOKEN( bulletEnabled
):
103 mrPoint
.mbBulletEnabled
= rAttribs
.getBool( XML_val
, false );
105 case DGM_TOKEN( chMax
):
106 mrPoint
.mnMaxChildren
= rAttribs
.getInteger( XML_val
, -1 );
108 case DGM_TOKEN( chPref
):
109 mrPoint
.mnPreferredChildren
= rAttribs
.getInteger( XML_val
, -1 );
111 case DGM_TOKEN( dir
):
112 mrPoint
.mnDirection
= rAttribs
.getToken( XML_val
, XML_norm
);
114 case DGM_TOKEN( hierBranch
):
116 // need to convert from oox::OptValue to std::optional since 1st is not available in svx
117 const std::optional
< sal_Int32
> aOptVal(rAttribs
.getToken( XML_val
));
118 if(aOptVal
.has_value())
119 mrPoint
.moHierarchyBranch
= aOptVal
.value();
122 case DGM_TOKEN( orgChart
):
123 mrPoint
.mbOrgChartEnabled
= rAttribs
.getBool( XML_val
, false );
125 case DGM_TOKEN( resizeHandles
):
126 mrPoint
.mnResizeHandles
= rAttribs
.getToken( XML_val
, XML_rel
);
136 svx::diagram::Point
& mrPoint
;
140 class PropertiesContext
141 : public ContextHandler2
144 PropertiesContext( ContextHandler2Helper
const & rParent
,
145 svx::diagram::Point
& rPoint
,
146 const AttributeList
& rAttribs
) :
147 ContextHandler2( rParent
),
150 mrPoint
.msColorTransformCategoryId
= rAttribs
.getStringDefaulted( XML_csCatId
);
151 mrPoint
.msColorTransformTypeId
= rAttribs
.getStringDefaulted( XML_csTypeId
);
152 mrPoint
.msLayoutCategoryId
= rAttribs
.getStringDefaulted( XML_loCatId
);
153 mrPoint
.msLayoutTypeId
= rAttribs
.getStringDefaulted( XML_loTypeId
);
154 mrPoint
.msPlaceholderText
= rAttribs
.getStringDefaulted( XML_phldrT
);
155 mrPoint
.msPresentationAssociationId
= rAttribs
.getStringDefaulted( XML_presAssocID
);
156 mrPoint
.msPresentationLayoutName
= rAttribs
.getStringDefaulted( XML_presName
);
157 mrPoint
.msPresentationLayoutStyleLabel
= rAttribs
.getStringDefaulted( XML_presStyleLbl
);
158 mrPoint
.msQuickStyleCategoryId
= rAttribs
.getStringDefaulted( XML_qsCatId
);
159 mrPoint
.msQuickStyleTypeId
= rAttribs
.getStringDefaulted( XML_qsTypeId
);
161 mrPoint
.mnCustomAngle
= rAttribs
.getInteger( XML_custAng
, -1 );
162 mrPoint
.mnPercentageNeighbourWidth
= rAttribs
.getInteger( XML_custLinFactNeighborX
, -1 );
163 mrPoint
.mnPercentageNeighbourHeight
= rAttribs
.getInteger( XML_custLinFactNeighborY
, -1 );
164 mrPoint
.mnPercentageOwnWidth
= rAttribs
.getInteger( XML_custLinFactX
, -1 );
165 mrPoint
.mnPercentageOwnHeight
= rAttribs
.getInteger( XML_custLinFactY
, -1 );
166 mrPoint
.mnIncludeAngleScale
= rAttribs
.getInteger( XML_custRadScaleInc
, -1 );
167 mrPoint
.mnRadiusScale
= rAttribs
.getInteger( XML_custRadScaleRad
, -1 );
168 mrPoint
.mnWidthScale
= rAttribs
.getInteger( XML_custScaleX
, -1 );
169 mrPoint
.mnHeightScale
= rAttribs
.getInteger( XML_custScaleY
, -1 );
170 mrPoint
.mnWidthOverride
= rAttribs
.getInteger( XML_custSzX
, -1 );
171 mrPoint
.mnHeightOverride
= rAttribs
.getInteger( XML_custSzY
, -1 );
172 mrPoint
.mnLayoutStyleCount
= rAttribs
.getInteger( XML_presStyleCnt
, -1 );
173 mrPoint
.mnLayoutStyleIndex
= rAttribs
.getInteger( XML_presStyleIdx
, -1 );
175 mrPoint
.mbCoherent3DOffset
= rAttribs
.getBool( XML_coherent3DOff
, false );
176 mrPoint
.mbCustomHorizontalFlip
= rAttribs
.getBool( XML_custFlipHor
, false );
177 mrPoint
.mbCustomVerticalFlip
= rAttribs
.getBool( XML_custFlipVert
, false );
178 mrPoint
.mbCustomText
= rAttribs
.getBool( XML_custT
, false );
179 mrPoint
.mbIsPlaceholder
= rAttribs
.getBool( XML_phldr
, false );
182 virtual ContextHandlerRef
183 onCreateContext( sal_Int32 aElementToken
,
184 const AttributeList
& ) override
186 switch( aElementToken
)
188 case DGM_TOKEN( presLayoutVars
):
189 return new PresLayoutVarsContext( *this, mrPoint
);
190 case DGM_TOKEN( style
):
191 // skip CT_shapeStyle
200 svx::diagram::Point
& mrPoint
;
205 : public ContextHandler2
208 PtContext( ContextHandler2Helper
const& rParent
,
209 const AttributeList
& rAttribs
,
210 svx::diagram::Point
& rPoint
,
211 DiagramData
& rDiagramData
):
212 ContextHandler2( rParent
),
214 mrDiagramData( rDiagramData
)
216 mrPoint
.msModelId
= rAttribs
.getStringDefaulted( XML_modelId
);
218 // the default type is XML_node
219 const sal_Int32 nType
= rAttribs
.getToken( XML_type
, XML_node
);
220 mrPoint
.mnXMLType
= static_cast<svx::diagram::TypeConstant
>(nType
);
222 // ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer
223 if( ( nType
== XML_parTrans
) || ( nType
== XML_sibTrans
) )
224 mrPoint
.msCnxId
= rAttribs
.getStringDefaulted( XML_cxnId
);
227 virtual ContextHandlerRef
228 onCreateContext( sal_Int32 aElementToken
,
229 const AttributeList
& rAttribs
) override
231 switch( aElementToken
)
233 case DGM_TOKEN( extLst
):
235 case DGM_TOKEN( prSet
):
236 return new PropertiesContext( *this, mrPoint
, rAttribs
);
237 case DGM_TOKEN( spPr
):
239 Shape
* pShape(mrDiagramData
.getOrCreateAssociatedShape(mrPoint
, true));
240 return new ShapePropertiesContext( *this, *pShape
);
244 Shape
* pShape(mrDiagramData
.getOrCreateAssociatedShape(mrPoint
, true));
245 TextBodyPtr xTextBody
= std::make_shared
<TextBody
>();
246 pShape
->setTextBody( xTextBody
);
247 return new TextBodyContext( *this, *xTextBody
);
256 svx::diagram::Point
& mrPoint
;
257 DiagramData
& mrDiagramData
;
262 : public ContextHandler2
265 PtListContext( ContextHandler2Helper
const & rParent
, svx::diagram::Points
& rPoints
, DiagramData
& rDiagramData
) :
266 ContextHandler2( rParent
),
268 mrDiagramData( rDiagramData
)
270 virtual ContextHandlerRef
271 onCreateContext( sal_Int32 aElementToken
,
272 const AttributeList
& rAttribs
) override
274 switch( aElementToken
)
276 case DGM_TOKEN( pt
):
279 mrPoints
.emplace_back( );
280 return new PtContext( *this, rAttribs
, mrPoints
.back(), mrDiagramData
);
289 svx::diagram::Points
& mrPoints
;
290 DiagramData
& mrDiagramData
;
293 // CT_BackgroundFormatting
294 class BackgroundFormattingContext
295 : public ContextHandler2
298 BackgroundFormattingContext( ContextHandler2Helper
const & rParent
, OoxDiagramDataPtr
const& pModel
)
299 : ContextHandler2( rParent
)
300 , mpDataModel( pModel
)
302 assert( pModel
&& "the data model MUST NOT be NULL" );
305 virtual ContextHandlerRef
306 onCreateContext( sal_Int32 aElementToken
,
307 const AttributeList
& rAttribs
) override
309 switch( aElementToken
)
311 case A_TOKEN( blipFill
):
312 case A_TOKEN( gradFill
):
313 case A_TOKEN( grpFill
):
314 case A_TOKEN( noFill
):
315 case A_TOKEN( pattFill
):
316 case A_TOKEN( solidFill
):
318 return FillPropertiesContext::createFillContext(*this, aElementToken
, rAttribs
, *mpDataModel
->getBackgroundShapeFillProperties(), nullptr);
319 case A_TOKEN( effectDag
):
320 case A_TOKEN( effectLst
):
322 // EG_EffectProperties
330 OoxDiagramDataPtr mpDataModel
;
335 DataModelContext::DataModelContext( ContextHandler2Helper
const& rParent
,
336 const OoxDiagramDataPtr
& pDataModel
)
337 : ContextHandler2( rParent
)
338 , mpDataModel( pDataModel
)
340 assert( pDataModel
&& "Data Model must not be NULL" );
343 DataModelContext::~DataModelContext()
350 DataModelContext::onCreateContext( ::sal_Int32 aElement
,
351 const AttributeList
& rAttribs
)
355 case DGM_TOKEN( cxnLst
):
357 return new CxnListContext( *this, mpDataModel
->getConnections() );
358 case DGM_TOKEN( ptLst
):
360 return new PtListContext( *this, mpDataModel
->getPoints(), *mpDataModel
);
361 case DGM_TOKEN( bg
):
362 // CT_BackgroundFormatting
363 return new BackgroundFormattingContext( *this, mpDataModel
);
364 case DGM_TOKEN( whole
):
365 // CT_WholeE2oFormatting
368 case DGM_TOKEN( extLst
):
371 case DSP_TOKEN( dataModelExt
):
372 mpDataModel
->getExtDrawings().push_back( rAttribs
.getStringDefaulted( XML_relId
) );
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */