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>
27 #include <osl/diagnose.h>
29 using namespace ::oox::core
;
30 using namespace ::com::sun::star::xml::sax
;
31 using namespace ::com::sun::star::uno
;
33 namespace oox
{ namespace drawingml
{
37 : public ContextHandler2
40 CxnListContext( ContextHandler2Helper
& rParent
,
41 dgm::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
.push_back( dgm::Connection() );
56 dgm::Connection
& rConnection
=mrConnection
.back();
58 const sal_Int32 nType
= rAttribs
.getToken( XML_type
, XML_parOf
);
59 rConnection
.mnType
= nType
;
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 );
79 dgm::Connections
& mrConnection
;
83 class PresLayoutVarsContext
84 : public ContextHandler2
87 PresLayoutVarsContext( ContextHandler2Helper
& rParent
,
88 dgm::Point
& rPoint
) :
89 ContextHandler2( rParent
),
93 virtual ContextHandlerRef
94 onCreateContext( sal_Int32 aElementToken
,
95 const AttributeList
& rAttribs
) override
97 switch( aElementToken
)
100 case DGM_TOKEN( animLvl
):
101 case DGM_TOKEN( animOne
):
103 case DGM_TOKEN( bulletEnabled
):
104 mrPoint
.mbBulletEnabled
= rAttribs
.getBool( XML_val
, false );
106 case DGM_TOKEN( chMax
):
107 mrPoint
.mnMaxChildren
= rAttribs
.getInteger( XML_val
, -1 );
109 case DGM_TOKEN( chPref
):
110 mrPoint
.mnPreferredChildren
= rAttribs
.getInteger( XML_val
, -1 );
112 case DGM_TOKEN( dir
):
113 mrPoint
.mnDirection
= rAttribs
.getToken( XML_val
, XML_norm
);
115 case DGM_TOKEN( hierBranch
):
116 mrPoint
.mnHierarchyBranch
= rAttribs
.getToken( XML_val
, XML_std
);
118 case DGM_TOKEN( orgChart
):
119 mrPoint
.mbOrgChartEnabled
= rAttribs
.getBool( XML_val
, false );
121 case DGM_TOKEN( resizeHandles
):
122 mrPoint
.mnResizeHandles
= rAttribs
.getToken( XML_val
, XML_rel
);
136 class PropertiesContext
137 : public ContextHandler2
140 PropertiesContext( ContextHandler2Helper
& rParent
,
142 const AttributeList
& rAttribs
) :
143 ContextHandler2( rParent
),
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
, "" );
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 );
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 );
178 virtual ContextHandlerRef
179 onCreateContext( sal_Int32 aElementToken
,
180 const AttributeList
& ) override
182 switch( aElementToken
)
184 case DGM_TOKEN( presLayoutVars
):
185 return new PresLayoutVarsContext( *this, mrPoint
);
186 case DGM_TOKEN( style
):
187 // skip CT_shapeStyle
201 : public ContextHandler2
204 PtContext( ContextHandler2Helper
& rParent
,
205 const AttributeList
& rAttribs
,
206 dgm::Point
& rPoint
):
207 ContextHandler2( rParent
),
210 mrPoint
.msModelId
= rAttribs
.getString( XML_modelId
).get();
212 // the default type is XML_node
213 const sal_Int32 nType
= rAttribs
.getToken( XML_type
, XML_node
);
214 mrPoint
.mnType
= nType
;
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();
221 virtual ContextHandlerRef
222 onCreateContext( sal_Int32 aElementToken
,
223 const AttributeList
& rAttribs
) override
225 switch( aElementToken
)
227 case DGM_TOKEN( extLst
):
229 case DGM_TOKEN( prSet
):
230 return new PropertiesContext( *this, mrPoint
, rAttribs
);
231 case DGM_TOKEN( spPr
):
232 if( !mrPoint
.mpShape
)
233 mrPoint
.mpShape
.reset( new Shape() );
234 return new ShapePropertiesContext( *this, *(mrPoint
.mpShape
) );
237 TextBodyPtr
xTextBody( new TextBody
);
238 if( !mrPoint
.mpShape
)
239 mrPoint
.mpShape
.reset( new Shape() );
240 mrPoint
.mpShape
->setTextBody( xTextBody
);
241 return new TextBodyContext( *this, *xTextBody
);
255 : public ContextHandler2
258 PtListContext( ContextHandler2Helper
& rParent
, dgm::Points
& rPoints
) :
259 ContextHandler2( rParent
),
262 virtual ContextHandlerRef
263 onCreateContext( sal_Int32 aElementToken
,
264 const AttributeList
& rAttribs
) override
266 switch( aElementToken
)
268 case DGM_TOKEN( pt
):
271 mrPoints
.push_back( dgm::Point() );
272 return new PtContext( *this, rAttribs
, mrPoints
.back() );
281 dgm::Points
& mrPoints
;
284 // CT_BackgroundFormatting
285 class BackgroundFormattingContext
286 : public ContextHandler2
289 BackgroundFormattingContext( ContextHandler2Helper
& rParent
, DiagramDataPtr
& pModel
)
290 : ContextHandler2( rParent
)
291 , mpDataModel( pModel
)
293 OSL_ENSURE( pModel
, "the data model MUST NOT be NULL" );
296 virtual ContextHandlerRef
297 onCreateContext( sal_Int32 aElementToken
,
298 const AttributeList
& rAttribs
) override
300 switch( aElementToken
)
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
):
309 return FillPropertiesContext::createFillContext(
310 *this, aElementToken
, rAttribs
, *mpDataModel
->getFillProperties() );
311 case A_TOKEN( effectDag
):
312 case A_TOKEN( effectLst
):
314 // EG_EffectProperties
322 DiagramDataPtr mpDataModel
;
325 DataModelContext::DataModelContext( ContextHandler2Helper
& rParent
,
326 const DiagramDataPtr
& pDataModel
)
327 : ContextHandler2( rParent
)
328 , mpDataModel( pDataModel
)
330 OSL_ENSURE( pDataModel
, "Data Model must not be NULL" );
333 DataModelContext::~DataModelContext()
340 DataModelContext::onCreateContext( ::sal_Int32 aElement
,
341 const AttributeList
& rAttribs
)
345 case DGM_TOKEN( cxnLst
):
347 return new CxnListContext( *this, mpDataModel
->getConnections() );
348 case DGM_TOKEN( ptLst
):
350 return new PtListContext( *this, mpDataModel
->getPoints() );
351 case DGM_TOKEN( bg
):
352 // CT_BackgroundFormatting
353 return new BackgroundFormattingContext( *this, mpDataModel
);
354 case DGM_TOKEN( whole
):
355 // CT_WholeE2oFormatting
358 case DGM_TOKEN( extLst
):
361 case DSP_TOKEN( dataModelExt
):
362 mpDataModel
->getExtDrawings().push_back( rAttribs
.getString( XML_relId
).get() );
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */