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/fillpropertiesgroupcontext.hxx"
23 #include "drawingml/shapepropertiescontext.hxx"
24 #include "drawingml/textbodycontext.hxx"
25 #include <osl/diagnose.h>
27 using namespace ::oox::core
;
28 using namespace ::com::sun::star::xml::sax
;
29 using namespace ::com::sun::star::uno
;
31 namespace oox
{ namespace drawingml
{
35 : public ContextHandler2
38 CxnListContext( ContextHandler2Helper
& rParent
,
39 dgm::Connections
& aConnections
)
40 : ContextHandler2( rParent
)
41 , mrConnection( aConnections
)
45 virtual ContextHandlerRef
46 onCreateContext( sal_Int32 aElementToken
,
47 const AttributeList
& rAttribs
) SAL_OVERRIDE
49 switch( aElementToken
)
51 case DGM_TOKEN( cxn
):
53 mrConnection
.push_back( dgm::Connection() );
54 dgm::Connection
& rConnection
=mrConnection
.back();
56 const sal_Int32 nType
= rAttribs
.getToken( XML_type
, XML_parOf
);
57 rConnection
.mnType
= nType
;
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
& rParent
,
86 dgm::Point
& rPoint
) :
87 ContextHandler2( rParent
),
91 virtual ContextHandlerRef
92 onCreateContext( sal_Int32 aElementToken
,
93 const AttributeList
& rAttribs
) SAL_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
.mnHierarchyBranch
= rAttribs
.getToken( XML_val
, XML_std
);
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
& rParent
,
140 const AttributeList
& rAttribs
) :
141 ContextHandler2( rParent
),
146 mrPoint
.msColorTransformCategoryId
= rAttribs
.getString( XML_csCatId
, aEmptyStr
);
147 mrPoint
.msColorTransformTypeId
= rAttribs
.getString( XML_csTypeId
, aEmptyStr
);
148 mrPoint
.msLayoutCategoryId
= rAttribs
.getString( XML_loCatId
, aEmptyStr
);
149 mrPoint
.msLayoutTypeId
= rAttribs
.getString( XML_loTypeId
, aEmptyStr
);
150 mrPoint
.msPlaceholderText
= rAttribs
.getString( XML_phldrT
, aEmptyStr
);
151 mrPoint
.msPresentationAssociationId
= rAttribs
.getString( XML_presAssocID
, aEmptyStr
);
152 mrPoint
.msPresentationLayoutName
= rAttribs
.getString( XML_presName
, aEmptyStr
);
153 mrPoint
.msPresentationLayoutStyleLabel
= rAttribs
.getString( XML_presStyleLbl
, aEmptyStr
);
154 mrPoint
.msQuickStyleCategoryId
= rAttribs
.getString( XML_qsCatId
, aEmptyStr
);
155 mrPoint
.msQuickStyleTypeId
= rAttribs
.getString( XML_qsTypeId
, aEmptyStr
);
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
& ) SAL_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
) SAL_OVERRIDE
225 switch( aElementToken
)
227 case DGM_TOKEN( extLst
):
229 case DGM_TOKEN( prSet
):
230 OSL_TRACE( "diagram property set for point");
231 return new PropertiesContext( *this, mrPoint
, rAttribs
);
232 case DGM_TOKEN( spPr
):
233 OSL_TRACE( "shape props for point");
234 if( !mrPoint
.mpShape
)
235 mrPoint
.mpShape
.reset( new Shape() );
236 return new ShapePropertiesContext( *this, *(mrPoint
.mpShape
) );
239 OSL_TRACE( "shape text body for point");
240 TextBodyPtr
xTextBody( new TextBody
);
241 if( !mrPoint
.mpShape
)
242 mrPoint
.mpShape
.reset( new Shape() );
243 mrPoint
.mpShape
->setTextBody( xTextBody
);
244 return new TextBodyContext( *this, *xTextBody
);
258 : public ContextHandler2
261 PtListContext( ContextHandler2Helper
& rParent
, dgm::Points
& rPoints
) :
262 ContextHandler2( rParent
),
265 virtual ContextHandlerRef
266 onCreateContext( sal_Int32 aElementToken
,
267 const AttributeList
& rAttribs
) SAL_OVERRIDE
269 switch( aElementToken
)
271 case DGM_TOKEN( pt
):
274 mrPoints
.push_back( dgm::Point() );
275 return new PtContext( *this, rAttribs
, mrPoints
.back() );
284 dgm::Points
& mrPoints
;
287 // CT_BackgroundFormatting
288 class BackgroundFormattingContext
289 : public ContextHandler2
292 BackgroundFormattingContext( ContextHandler2Helper
& rParent
, DiagramDataPtr
& pModel
)
293 : ContextHandler2( rParent
)
294 , mpDataModel( pModel
)
296 OSL_ENSURE( pModel
, "the data model MUST NOT be NULL" );
299 virtual ContextHandlerRef
300 onCreateContext( sal_Int32 aElementToken
,
301 const AttributeList
& rAttribs
) SAL_OVERRIDE
303 switch( aElementToken
)
305 case A_TOKEN( blipFill
):
306 case A_TOKEN( gradFill
):
307 case A_TOKEN( grpFill
):
308 case A_TOKEN( noFill
):
309 case A_TOKEN( pattFill
):
310 case A_TOKEN( solidFill
):
312 return FillPropertiesContext::createFillContext(
313 *this, aElementToken
, rAttribs
, *mpDataModel
->getFillProperties() );
314 case A_TOKEN( effectDag
):
315 case A_TOKEN( effectLst
):
317 // EG_EffectProperties
325 DiagramDataPtr mpDataModel
;
328 DataModelContext::DataModelContext( ContextHandler2Helper
& rParent
,
329 const DiagramDataPtr
& pDataModel
)
330 : ContextHandler2( rParent
)
331 , mpDataModel( pDataModel
)
333 OSL_ENSURE( pDataModel
, "Data Model must not be NULL" );
336 DataModelContext::~DataModelContext()
343 DataModelContext::onCreateContext( ::sal_Int32 aElement
,
344 const AttributeList
& rAttribs
)
348 case DGM_TOKEN( cxnLst
):
350 return new CxnListContext( *this, mpDataModel
->getConnections() );
351 case DGM_TOKEN( ptLst
):
353 return new PtListContext( *this, mpDataModel
->getPoints() );
354 case DGM_TOKEN( bg
):
355 // CT_BackgroundFormatting
356 return new BackgroundFormattingContext( *this, mpDataModel
);
357 case DGM_TOKEN( whole
):
358 // CT_WholeE2oFormatting
361 case DGM_TOKEN( extLst
):
364 case DSP_TOKEN( dataModelExt
):
365 mpDataModel
->getExtDrawings().push_back( rAttribs
.getString( XML_relId
).get() );
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */