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 "oox/drawingml/fillpropertiesgroupcontext.hxx"
23 #include "oox/drawingml/shapepropertiescontext.hxx"
24 #include "oox/drawingml/textbodycontext.hxx"
26 using namespace ::oox::core
;
27 using namespace ::com::sun::star::xml::sax
;
28 using namespace ::com::sun::star::uno
;
30 namespace oox
{ namespace drawingml
{
34 : public ContextHandler
37 CxnListContext( ContextHandler
& rParent
,
38 dgm::Connections
& aConnections
)
39 : ContextHandler( rParent
)
40 , mrConnection( aConnections
)
44 virtual Reference
< XFastContextHandler
> SAL_CALL
45 createFastChildContext( sal_Int32 aElementToken
,
46 const Reference
< XFastAttributeList
>& xAttribs
)
47 throw (SAXException
, RuntimeException
)
49 Reference
< XFastContextHandler
> xRet
;
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
= xAttribs
->getOptionalValueToken( XML_type
, XML_parOf
);
59 rConnection
.mnType
= nType
;
60 rConnection
.msModelId
= xAttribs
->getOptionalValue( XML_modelId
);
61 rConnection
.msSourceId
= xAttribs
->getOptionalValue( XML_srcId
);
62 rConnection
.msDestId
= xAttribs
->getOptionalValue( XML_destId
);
63 rConnection
.msPresId
= xAttribs
->getOptionalValue( XML_presId
);
64 rConnection
.msSibTransId
= xAttribs
->getOptionalValue( XML_sibTransId
);
65 rConnection
.msParTransId
= xAttribs
->getOptionalValue( XML_parTransId
);
66 const AttributeList
attribs( xAttribs
);
67 rConnection
.mnSourceOrder
= attribs
.getInteger( XML_srcOrd
, 0 );
68 rConnection
.mnDestOrder
= attribs
.getInteger( XML_destOrd
, 0 );
81 dgm::Connections
& mrConnection
;
86 class PresLayoutVarsContext
87 : public ContextHandler
90 PresLayoutVarsContext( ContextHandler
& rParent
,
91 dgm::Point
& rPoint
) :
92 ContextHandler( rParent
),
96 virtual Reference
< XFastContextHandler
> SAL_CALL
97 createFastChildContext( sal_Int32 aElementToken
,
98 const Reference
< XFastAttributeList
>& xAttribs
)
99 throw (SAXException
, RuntimeException
)
101 Reference
< XFastContextHandler
> xRet
;
102 AttributeList
aAttribs( xAttribs
);
104 switch( aElementToken
)
107 case DGM_TOKEN( animLvl
):
108 case DGM_TOKEN( animOne
):
110 case DGM_TOKEN( bulletEnabled
):
111 mrPoint
.mbBulletEnabled
= aAttribs
.getBool( XML_val
, false );
113 case DGM_TOKEN( chMax
):
114 mrPoint
.mnMaxChildren
= aAttribs
.getInteger( XML_val
, -1 );
116 case DGM_TOKEN( chPref
):
117 mrPoint
.mnPreferredChildren
= aAttribs
.getInteger( XML_val
, -1 );
119 case DGM_TOKEN( dir
):
120 mrPoint
.mnDirection
= aAttribs
.getToken( XML_val
, XML_norm
);
122 case DGM_TOKEN( hierBranch
):
123 mrPoint
.mnHierarchyBranch
= aAttribs
.getToken( XML_val
, XML_std
);
125 case DGM_TOKEN( orgChart
):
126 mrPoint
.mbOrgChartEnabled
= aAttribs
.getBool( XML_val
, false );
128 case DGM_TOKEN( resizeHandles
):
129 mrPoint
.mnResizeHandles
= aAttribs
.getToken( XML_val
, XML_rel
);
145 class PropertiesContext
146 : public ContextHandler
149 PropertiesContext( ContextHandler
& rParent
,
151 const Reference
< XFastAttributeList
>& xAttribs
) :
152 ContextHandler( rParent
),
156 AttributeList
aAttribs( xAttribs
);
158 mrPoint
.msColorTransformCategoryId
= aAttribs
.getString( XML_csCatId
, aEmptyStr
);
159 mrPoint
.msColorTransformTypeId
= aAttribs
.getString( XML_csTypeId
, aEmptyStr
);
160 mrPoint
.msLayoutCategoryId
= aAttribs
.getString( XML_loCatId
, aEmptyStr
);
161 mrPoint
.msLayoutTypeId
= aAttribs
.getString( XML_loTypeId
, aEmptyStr
);
162 mrPoint
.msPlaceholderText
= aAttribs
.getString( XML_phldrT
, aEmptyStr
);
163 mrPoint
.msPresentationAssociationId
= aAttribs
.getString( XML_presAssocID
, aEmptyStr
);
164 mrPoint
.msPresentationLayoutName
= aAttribs
.getString( XML_presName
, aEmptyStr
);
165 mrPoint
.msPresentationLayoutStyleLabel
= aAttribs
.getString( XML_presStyleLbl
, aEmptyStr
);
166 mrPoint
.msQuickStyleCategoryId
= aAttribs
.getString( XML_qsCatId
, aEmptyStr
);
167 mrPoint
.msQuickStyleTypeId
= aAttribs
.getString( XML_qsTypeId
, aEmptyStr
);
169 mrPoint
.mnCustomAngle
= aAttribs
.getInteger( XML_custAng
, -1 );
170 mrPoint
.mnPercentageNeighbourWidth
= aAttribs
.getInteger( XML_custLinFactNeighborX
, -1 );
171 mrPoint
.mnPercentageNeighbourHeight
= aAttribs
.getInteger( XML_custLinFactNeighborY
, -1 );
172 mrPoint
.mnPercentageOwnWidth
= aAttribs
.getInteger( XML_custLinFactX
, -1 );
173 mrPoint
.mnPercentageOwnHeight
= aAttribs
.getInteger( XML_custLinFactY
, -1 );
174 mrPoint
.mnIncludeAngleScale
= aAttribs
.getInteger( XML_custRadScaleInc
, -1 );
175 mrPoint
.mnRadiusScale
= aAttribs
.getInteger( XML_custRadScaleRad
, -1 );
176 mrPoint
.mnWidthScale
= aAttribs
.getInteger( XML_custScaleX
, -1 );
177 mrPoint
.mnHeightScale
= aAttribs
.getInteger( XML_custScaleY
, -1 );
178 mrPoint
.mnWidthOverride
= aAttribs
.getInteger( XML_custSzX
, -1 );
179 mrPoint
.mnHeightOverride
= aAttribs
.getInteger( XML_custSzY
, -1 );
180 mrPoint
.mnLayoutStyleCount
= aAttribs
.getInteger( XML_presStyleCnt
, -1 );
181 mrPoint
.mnLayoutStyleIndex
= aAttribs
.getInteger( XML_presStyleIdx
, -1 );
183 mrPoint
.mbCoherent3DOffset
= aAttribs
.getBool( XML_coherent3DOff
, false );
184 mrPoint
.mbCustomHorizontalFlip
= aAttribs
.getBool( XML_custFlipHor
, false );
185 mrPoint
.mbCustomVerticalFlip
= aAttribs
.getBool( XML_custFlipVert
, false );
186 mrPoint
.mbCustomText
= aAttribs
.getBool( XML_custT
, false );
187 mrPoint
.mbIsPlaceholder
= aAttribs
.getBool( XML_phldr
, false );
190 virtual Reference
< XFastContextHandler
> SAL_CALL
191 createFastChildContext( sal_Int32 aElementToken
,
192 const Reference
< XFastAttributeList
>& )
193 throw (SAXException
, RuntimeException
)
195 Reference
< XFastContextHandler
> xRet
;
197 switch( aElementToken
)
199 case DGM_TOKEN( presLayoutVars
):
201 xRet
.set( new PresLayoutVarsContext( *this, mrPoint
) );
204 case DGM_TOKEN( style
):
207 // skip CT_shapeStyle
225 : public ContextHandler
228 PtContext( ContextHandler
& rParent
,
229 const Reference
< XFastAttributeList
>& xAttribs
,
230 dgm::Point
& rPoint
):
231 ContextHandler( rParent
),
234 mrPoint
.msModelId
= xAttribs
->getOptionalValue( XML_modelId
);
236 // the default type is XML_node
237 const sal_Int32 nType
= xAttribs
->getOptionalValueToken( XML_type
, XML_node
);
238 mrPoint
.mnType
= nType
;
240 // ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer
241 if( ( nType
== XML_parTrans
) || ( nType
== XML_sibTrans
) )
242 mrPoint
.msCnxId
= xAttribs
->getOptionalValue( XML_cxnId
);
246 virtual Reference
< XFastContextHandler
> SAL_CALL
247 createFastChildContext( sal_Int32 aElementToken
,
248 const Reference
< XFastAttributeList
>& xAttribs
)
249 throw (SAXException
, RuntimeException
)
251 Reference
< XFastContextHandler
> xRet
;
253 switch( aElementToken
)
255 case DGM_TOKEN( extLst
):
257 case DGM_TOKEN( prSet
):
258 OSL_TRACE( "diagram property set for point");
259 xRet
= new PropertiesContext( *this, mrPoint
, xAttribs
);
261 case DGM_TOKEN( spPr
):
262 OSL_TRACE( "shape props for point");
263 if( !mrPoint
.mpShape
)
264 mrPoint
.mpShape
.reset( new Shape() );
265 xRet
= new ShapePropertiesContext( *this, *(mrPoint
.mpShape
) );
269 OSL_TRACE( "shape text body for point");
270 TextBodyPtr
xTextBody( new TextBody
);
271 if( !mrPoint
.mpShape
)
272 mrPoint
.mpShape
.reset( new Shape() );
273 mrPoint
.mpShape
->setTextBody( xTextBody
);
274 xRet
= new TextBodyContext( *this, *xTextBody
);
293 : public ContextHandler
296 PtListContext( ContextHandler
& rParent
, dgm::Points
& rPoints
) :
297 ContextHandler( rParent
),
300 virtual Reference
< XFastContextHandler
> SAL_CALL
301 createFastChildContext( sal_Int32 aElementToken
,
302 const Reference
< XFastAttributeList
>& xAttribs
)
303 throw (SAXException
, RuntimeException
)
305 Reference
< XFastContextHandler
> xRet
;
307 switch( aElementToken
)
309 case DGM_TOKEN( pt
):
312 mrPoints
.push_back( dgm::Point() );
313 xRet
.set( new PtContext( *this, xAttribs
, mrPoints
.back() ) );
325 dgm::Points
& mrPoints
;
328 // CT_BackgroundFormatting
329 class BackgroundFormattingContext
330 : public ContextHandler
333 BackgroundFormattingContext( ContextHandler
& rParent
, DiagramDataPtr
& pModel
)
334 : ContextHandler( rParent
)
335 , mpDataModel( pModel
)
337 OSL_ENSURE( pModel
, "the data model MUST NOT be NULL" );
340 virtual Reference
< XFastContextHandler
> SAL_CALL
341 createFastChildContext( sal_Int32 aElementToken
,
342 const Reference
< XFastAttributeList
>& xAttribs
)
343 throw (SAXException
, RuntimeException
)
345 Reference
< XFastContextHandler
> xRet
;
347 switch( aElementToken
)
349 case A_TOKEN( blipFill
):
350 case A_TOKEN( gradFill
):
351 case A_TOKEN( grpFill
):
352 case A_TOKEN( noFill
):
353 case A_TOKEN( pattFill
):
354 case A_TOKEN( solidFill
):
356 xRet
.set( FillPropertiesContext::createFillContext(
357 *this, aElementToken
, xAttribs
, *mpDataModel
->getFillProperties() ) );
359 case A_TOKEN( effectDag
):
360 case A_TOKEN( effectLst
):
362 // EG_EffectProperties
372 DiagramDataPtr mpDataModel
;
377 DataModelContext::DataModelContext( ContextHandler
& rParent
,
378 const DiagramDataPtr
& pDataModel
)
379 : ContextHandler( rParent
)
380 , mpDataModel( pDataModel
)
382 OSL_ENSURE( pDataModel
, "Data Model must not be NULL" );
386 DataModelContext::~DataModelContext()
392 Reference
< XFastContextHandler
> SAL_CALL
393 DataModelContext::createFastChildContext( ::sal_Int32 aElement
,
394 const Reference
< XFastAttributeList
>& xAttribs
)
395 throw ( SAXException
, RuntimeException
)
397 Reference
< XFastContextHandler
> xRet
;
401 case DGM_TOKEN( cxnLst
):
403 xRet
.set( new CxnListContext( *this, mpDataModel
->getConnections() ) );
405 case DGM_TOKEN( ptLst
):
407 xRet
.set( new PtListContext( *this, mpDataModel
->getPoints() ) );
409 case DGM_TOKEN( bg
):
410 // CT_BackgroundFormatting
411 xRet
.set( new BackgroundFormattingContext( *this, mpDataModel
) );
413 case DGM_TOKEN( whole
):
414 // CT_WholeE2oFormatting
417 case DGM_TOKEN( extLst
):
420 case DSP_TOKEN( dataModelExt
):
421 mpDataModel
->getExtDrawings().push_back( xAttribs
->getOptionalValue( XML_relId
) );
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */