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::xml::sax
;
30 using namespace ::com::sun::star::uno
;
32 namespace oox
{ namespace drawingml
{
36 : public ContextHandler2
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 );
77 dgm::Connections
& mrConnection
;
81 class PresLayoutVarsContext
82 : public ContextHandler2
85 PresLayoutVarsContext( ContextHandler2Helper
const & rParent
,
86 dgm::Point
& rPoint
) :
87 ContextHandler2( rParent
),
91 virtual ContextHandlerRef
92 onCreateContext( sal_Int32 aElementToken
,
93 const AttributeList
& rAttribs
) override
95 switch( aElementToken
)
98 case DGM_TOKEN( animLvl
):
99 case DGM_TOKEN( animOne
):
101 case DGM_TOKEN( bulletEnabled
):
102 mrPoint
.mbBulletEnabled
= rAttribs
.getBool( XML_val
, false );
104 case DGM_TOKEN( chMax
):
105 mrPoint
.mnMaxChildren
= rAttribs
.getInteger( XML_val
, -1 );
107 case DGM_TOKEN( chPref
):
108 mrPoint
.mnPreferredChildren
= rAttribs
.getInteger( XML_val
, -1 );
110 case DGM_TOKEN( dir
):
111 mrPoint
.mnDirection
= rAttribs
.getToken( XML_val
, XML_norm
);
113 case DGM_TOKEN( hierBranch
):
114 mrPoint
.moHierarchyBranch
= rAttribs
.getToken( XML_val
);
116 case DGM_TOKEN( orgChart
):
117 mrPoint
.mbOrgChartEnabled
= rAttribs
.getBool( XML_val
, false );
119 case DGM_TOKEN( resizeHandles
):
120 mrPoint
.mnResizeHandles
= rAttribs
.getToken( XML_val
, XML_rel
);
134 class PropertiesContext
135 : public ContextHandler2
138 PropertiesContext( ContextHandler2Helper
const & rParent
,
140 const AttributeList
& rAttribs
) :
141 ContextHandler2( rParent
),
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
199 : public ContextHandler2
202 PtContext( ContextHandler2Helper
const & rParent
,
203 const AttributeList
& rAttribs
,
204 dgm::Point
& rPoint
):
205 ContextHandler2( rParent
),
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
):
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
) );
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
);
253 : public ContextHandler2
256 PtListContext( ContextHandler2Helper
const & rParent
, dgm::Points
& rPoints
) :
257 ContextHandler2( rParent
),
260 virtual ContextHandlerRef
261 onCreateContext( sal_Int32 aElementToken
,
262 const AttributeList
& rAttribs
) override
264 switch( aElementToken
)
266 case DGM_TOKEN( pt
):
269 mrPoints
.emplace_back( );
270 return new PtContext( *this, rAttribs
, mrPoints
.back() );
279 dgm::Points
& mrPoints
;
282 // CT_BackgroundFormatting
283 class BackgroundFormattingContext
284 : public ContextHandler2
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
):
307 return FillPropertiesContext::createFillContext(
308 *this, aElementToken
, rAttribs
, *mpDataModel
->getFillProperties() );
309 case A_TOKEN( effectDag
):
310 case A_TOKEN( effectLst
):
312 // EG_EffectProperties
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()
338 DataModelContext::onCreateContext( ::sal_Int32 aElement
,
339 const AttributeList
& rAttribs
)
343 case DGM_TOKEN( cxnLst
):
345 return new CxnListContext( *this, mpDataModel
->getConnections() );
346 case DGM_TOKEN( ptLst
):
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
356 case DGM_TOKEN( extLst
):
359 case DSP_TOKEN( dataModelExt
):
360 mpDataModel
->getExtDrawings().push_back( rAttribs
.getString( XML_relId
).get() );
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */