fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / drawingml / diagram / datamodelcontext.cxx
blob2526be2f7e7dcdf69b14c52f211c95d336b5b228
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 {
32 // CT_CxnList
33 class CxnListContext
34 : public ContextHandler
36 public:
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 );
70 // skip CT_extLst
71 return xRet;
73 default:
74 break;
76 if( !xRet.is() )
77 xRet.set( this );
78 return xRet;
80 private:
81 dgm::Connections& mrConnection;
85 // CT_presLayoutVars
86 class PresLayoutVarsContext
87 : public ContextHandler
89 public:
90 PresLayoutVarsContext( ContextHandler& rParent,
91 dgm::Point & rPoint ) :
92 ContextHandler( rParent ),
93 mrPoint( rPoint )
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 )
106 // TODO
107 case DGM_TOKEN( animLvl ):
108 case DGM_TOKEN( animOne ):
109 break;
110 case DGM_TOKEN( bulletEnabled ):
111 mrPoint.mbBulletEnabled = aAttribs.getBool( XML_val, false );
112 break;
113 case DGM_TOKEN( chMax ):
114 mrPoint.mnMaxChildren = aAttribs.getInteger( XML_val, -1 );
115 break;
116 case DGM_TOKEN( chPref ):
117 mrPoint.mnPreferredChildren = aAttribs.getInteger( XML_val, -1 );
118 break;
119 case DGM_TOKEN( dir ):
120 mrPoint.mnDirection = aAttribs.getToken( XML_val, XML_norm );
121 break;
122 case DGM_TOKEN( hierBranch ):
123 mrPoint.mnHierarchyBranch = aAttribs.getToken( XML_val, XML_std );
124 break;
125 case DGM_TOKEN( orgChart ):
126 mrPoint.mbOrgChartEnabled = aAttribs.getBool( XML_val, false );
127 break;
128 case DGM_TOKEN( resizeHandles ):
129 mrPoint.mnResizeHandles = aAttribs.getToken( XML_val, XML_rel );
130 break;
131 default:
132 break;
134 if( !xRet.is() )
135 xRet.set( this );
136 return xRet;
139 private:
140 dgm::Point& mrPoint;
144 // CT_prSet
145 class PropertiesContext
146 : public ContextHandler
148 public:
149 PropertiesContext( ContextHandler& rParent,
150 dgm::Point & rPoint,
151 const Reference< XFastAttributeList >& xAttribs ) :
152 ContextHandler( rParent ),
153 mrPoint( rPoint )
155 OUString aEmptyStr;
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 ) );
202 break;
204 case DGM_TOKEN( style ):
206 // TODO
207 // skip CT_shapeStyle
208 return xRet;
210 default:
211 break;
213 if( !xRet.is() )
214 xRet.set( this );
215 return xRet;
218 private:
219 dgm::Point& mrPoint;
223 // CL_Pt
224 class PtContext
225 : public ContextHandler
227 public:
228 PtContext( ContextHandler& rParent,
229 const Reference< XFastAttributeList >& xAttribs,
230 dgm::Point & rPoint):
231 ContextHandler( rParent ),
232 mrPoint( rPoint )
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 ):
256 return xRet;
257 case DGM_TOKEN( prSet ):
258 OSL_TRACE( "diagram property set for point");
259 xRet = new PropertiesContext( *this, mrPoint, xAttribs );
260 break;
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) );
266 break;
267 case DGM_TOKEN( t ):
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 );
275 break;
277 default:
278 break;
280 if( !xRet.is() )
281 xRet.set( this );
282 return xRet;
285 private:
286 dgm::Point& mrPoint;
291 // CT_PtList
292 class PtListContext
293 : public ContextHandler
295 public:
296 PtListContext( ContextHandler& rParent, dgm::Points& rPoints) :
297 ContextHandler( rParent ),
298 mrPoints( rPoints )
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 ):
311 // CT_Pt
312 mrPoints.push_back( dgm::Point() );
313 xRet.set( new PtContext( *this, xAttribs, mrPoints.back() ) );
314 break;
316 default:
317 break;
319 if( !xRet.is() )
320 xRet.set( this );
321 return xRet;
324 private:
325 dgm::Points& mrPoints;
328 // CT_BackgroundFormatting
329 class BackgroundFormattingContext
330 : public ContextHandler
332 public:
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 ):
355 // EG_FillProperties
356 xRet.set( FillPropertiesContext::createFillContext(
357 *this, aElementToken, xAttribs, *mpDataModel->getFillProperties() ) );
358 break;
359 case A_TOKEN( effectDag ):
360 case A_TOKEN( effectLst ):
361 // TODO
362 // EG_EffectProperties
363 break;
364 default:
365 break;
367 if( !xRet.is() )
368 xRet.set( this );
369 return xRet;
371 private:
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()
388 // some debug
389 mpDataModel->dump();
392 Reference< XFastContextHandler > SAL_CALL
393 DataModelContext::createFastChildContext( ::sal_Int32 aElement,
394 const Reference< XFastAttributeList >& xAttribs )
395 throw ( SAXException, RuntimeException)
397 Reference< XFastContextHandler > xRet;
399 switch( aElement )
401 case DGM_TOKEN( cxnLst ):
402 // CT_CxnList
403 xRet.set( new CxnListContext( *this, mpDataModel->getConnections() ) );
404 break;
405 case DGM_TOKEN( ptLst ):
406 // CT_PtList
407 xRet.set( new PtListContext( *this, mpDataModel->getPoints() ) );
408 break;
409 case DGM_TOKEN( bg ):
410 // CT_BackgroundFormatting
411 xRet.set( new BackgroundFormattingContext( *this, mpDataModel ) );
412 break;
413 case DGM_TOKEN( whole ):
414 // CT_WholeE2oFormatting
415 // TODO
416 return xRet;
417 case DGM_TOKEN( extLst ):
418 case A_TOKEN( ext ):
419 break;
420 case DSP_TOKEN( dataModelExt ):
421 mpDataModel->getExtDrawings().push_back( xAttribs->getOptionalValue( XML_relId ) );
422 break;
423 default:
424 break;
427 if( !xRet.is() )
428 xRet.set( this );
430 return xRet;
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */