1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "oox/drawingml/diagram/datamodelcontext.hxx"
25 #include "oox/helper/attributelist.hxx"
26 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
27 #include "oox/drawingml/shapepropertiescontext.hxx"
28 #include "oox/drawingml/textbodycontext.hxx"
29
30 using namespace ::oox::core;
31 using namespace ::com::sun::star::xml::sax;
32 using namespace ::com::sun::star::uno;
33 using ::rtl::OUString;
34
35 namespace oox { namespace drawingml {
36
37 // CL_Cxn
38 class CxnContext
39 : public ContextHandler
40 {
41 public:
CxnContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttribs,const dgm::ConnectionPtr & pConnection)42 CxnContext( ContextHandler& rParent,
43 const Reference< XFastAttributeList >& xAttribs,
44 const dgm::ConnectionPtr & pConnection )
45 : ContextHandler( rParent )
46 , mpConnection( pConnection )
47 {
48 sal_Int32 nType = xAttribs->getOptionalValueToken( XML_type, XML_parOf );
49 pConnection->mnType = nType;
50 pConnection->msModelId = xAttribs->getOptionalValue( XML_modelId );
51 pConnection->msSourceId = xAttribs->getOptionalValue( XML_srcId );
52 pConnection->msDestId = xAttribs->getOptionalValue( XML_destId );
53 pConnection->msPresId = xAttribs->getOptionalValue( XML_presId );
54 pConnection->msSibTransId = xAttribs->getOptionalValue( XML_sibTransId );
55 AttributeList attribs( xAttribs );
56 pConnection->mnSourceOrder = attribs.getInteger( XML_srcOrd, 0 );
57 pConnection->mnDestOrder = attribs.getInteger( XML_destOrd, 0 );
58 }
59
60 virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> &)61 createFastChildContext( sal_Int32 aElementToken,
62 const Reference< XFastAttributeList >& /*xAttribs*/ )
63 {
64 Reference< XFastContextHandler > xRet;
65
66 switch( aElementToken )
67 {
68 case DGM_TOKEN( extLst ):
69 return xRet;
70 default:
71 break;
72 }
73 if( !xRet.is() )
74 xRet.set( this );
75 return xRet;
76 }
77 private:
78 dgm::ConnectionPtr mpConnection;
79 };
80
81
82 // CT_CxnList
83 class CxnListContext
84 : public ContextHandler
85 {
86 public:
CxnListContext(ContextHandler & rParent,dgm::Connections & aConnections)87 CxnListContext( ContextHandler& rParent, dgm::Connections & aConnections )
88 : ContextHandler( rParent )
89 , maConnections( aConnections )
90 {
91 }
92 virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)93 createFastChildContext( sal_Int32 aElementToken,
94 const Reference< XFastAttributeList >& xAttribs )
95 {
96 Reference< XFastContextHandler > xRet;
97
98 switch( aElementToken )
99 {
100 case DGM_TOKEN( cxn ):
101 {
102 dgm::ConnectionPtr pConnection( new dgm::Connection() );
103 maConnections.push_back( pConnection );
104 xRet.set( new CxnContext( *this, xAttribs, pConnection ) );
105 break;
106 }
107 default:
108 break;
109 }
110 if( !xRet.is() )
111 xRet.set( this );
112 return xRet;
113 }
114
115 private:
116 dgm::Connections & maConnections;
117 };
118
119
120
121 // CL_Pt
122 class PtContext
123 : public ContextHandler
124 {
125 public:
PtContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttribs,const dgm::PointPtr & pPoint)126 PtContext( ContextHandler& rParent,
127 const Reference< XFastAttributeList >& xAttribs,
128 const dgm::PointPtr & pPoint)
129 : ContextHandler( rParent )
130 , mpPoint( pPoint )
131 {
132 mpPoint->setModelId( xAttribs->getOptionalValue( XML_modelId ) );
133 //
134 // the default type is XML_node
135 sal_Int32 nType = xAttribs->getOptionalValueToken( XML_type, XML_node );
136 mpPoint->setType( nType );
137
138 // ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer
139 if( ( nType == XML_parTrans ) || ( nType == XML_sibTrans ) )
140 {
141 mpPoint->setCnxId( xAttribs->getOptionalValue( XML_cxnId ) );
142 }
143 }
144
145
146 virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> &)147 createFastChildContext( sal_Int32 aElementToken,
148 const Reference< XFastAttributeList >& /*xAttribs*/ )
149 {
150 Reference< XFastContextHandler > xRet;
151
152 switch( aElementToken )
153 {
154 case DGM_TOKEN( extLst ):
155 return xRet;
156 case DGM_TOKEN( prSet ):
157 // TODO
158 // CT_ElemPropSet
159 break;
160 case DGM_TOKEN( spPr ):
161 OSL_TRACE( "shape props for point");
162 xRet = new ShapePropertiesContext( *this, *mpPoint->getShape() );
163 break;
164 case DGM_TOKEN( t ):
165 {
166 OSL_TRACE( "shape text body for point");
167 TextBodyPtr xTextBody( new TextBody );
168 mpPoint->getShape()->setTextBody( xTextBody );
169 xRet = new TextBodyContext( *this, *xTextBody );
170 break;
171 }
172 default:
173 break;
174 }
175 if( !xRet.is() )
176 xRet.set( this );
177 return xRet;
178 }
179
180 private:
181 dgm::PointPtr mpPoint;
182 };
183
184
185
186 // CT_PtList
187 class PtListContext
188 : public ContextHandler
189 {
190 public:
PtListContext(ContextHandler & rParent,dgm::Points & aPoints)191 PtListContext( ContextHandler& rParent, dgm::Points & aPoints)
192 : ContextHandler( rParent )
193 , maPoints( aPoints )
194 {
195 }
196 virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)197 createFastChildContext( sal_Int32 aElementToken,
198 const Reference< XFastAttributeList >& xAttribs )
199 {
200 Reference< XFastContextHandler > xRet;
201
202 switch( aElementToken )
203 {
204 case DGM_TOKEN( pt ):
205 {
206 // CT_Pt
207 dgm::PointPtr pPoint( new dgm::Point() );
208 maPoints.push_back( pPoint );
209 xRet.set( new PtContext( *this, xAttribs, pPoint ) );
210 break;
211 }
212 default:
213 break;
214 }
215 if( !xRet.is() )
216 xRet.set( this );
217 return xRet;
218 }
219
220 private:
221 dgm::Points & maPoints;
222 };
223
224 // CT_BackgroundFormatting
225 class BackgroundFormattingContext
226 : public ContextHandler
227 {
228 public:
BackgroundFormattingContext(ContextHandler & rParent,DiagramDataPtr & pModel)229 BackgroundFormattingContext( ContextHandler& rParent, DiagramDataPtr & pModel )
230 : ContextHandler( rParent )
231 , mpDataModel( pModel )
232 {
233 OSL_ENSURE( pModel, "the data model MUST NOT be NULL" );
234 }
235
236 virtual Reference< XFastContextHandler > SAL_CALL
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)237 createFastChildContext( sal_Int32 aElementToken,
238 const Reference< XFastAttributeList >& xAttribs )
239 {
240 Reference< XFastContextHandler > xRet;
241
242 switch( aElementToken )
243 {
244 case A_TOKEN( blipFill ):
245 case A_TOKEN( gradFill ):
246 case A_TOKEN( grpFill ):
247 case A_TOKEN( noFill ):
248 case A_TOKEN( pattFill ):
249 case A_TOKEN( solidFill ):
250 // EG_FillProperties
251 xRet.set( FillPropertiesContext::createFillContext(
252 *this, aElementToken, xAttribs, *mpDataModel->getFillProperties() ) );
253 break;
254 case A_TOKEN( effectDag ):
255 case A_TOKEN( effectLst ):
256 // TODO
257 // EG_EffectProperties
258 break;
259 default:
260 break;
261 }
262 if( !xRet.is() )
263 xRet.set( this );
264 return xRet;
265 }
266 private:
267 DiagramDataPtr mpDataModel;
268 };
269
270
271
DataModelContext(ContextHandler & rParent,const DiagramDataPtr & pDataModel)272 DataModelContext::DataModelContext( ContextHandler& rParent,
273 const DiagramDataPtr & pDataModel )
274 : ContextHandler( rParent )
275 , mpDataModel( pDataModel )
276 {
277 OSL_ENSURE( pDataModel, "Data Model must not be NULL" );
278 }
279
280
~DataModelContext()281 DataModelContext::~DataModelContext()
282 {
283 // some debug
284 mpDataModel->dump();
285 }
286
287
288 Reference< XFastContextHandler > SAL_CALL
createFastChildContext(::sal_Int32 aElement,const Reference<XFastAttributeList> &)289 DataModelContext::createFastChildContext( ::sal_Int32 aElement,
290 const Reference< XFastAttributeList >& /*xAttribs*/ )
291 {
292 Reference< XFastContextHandler > xRet;
293
294 switch( aElement )
295 {
296 case DGM_TOKEN( cxnLst ):
297 // CT_CxnList
298 xRet.set( new CxnListContext( *this, mpDataModel->getConnections() ) );
299 break;
300 case DGM_TOKEN( ptLst ):
301 // CT_PtList
302 xRet.set( new PtListContext( *this, mpDataModel->getPoints() ) );
303 break;
304 case DGM_TOKEN( bg ):
305 // CT_BackgroundFormatting
306 xRet.set( new BackgroundFormattingContext( *this, mpDataModel ) );
307 break;
308 case DGM_TOKEN( whole ):
309 // CT_WholeE2oFormatting
310 // TODO
311 return xRet;
312 case DGM_TOKEN( extLst ):
313 return xRet;
314 default:
315 break;
316 }
317
318 if( !xRet.is() )
319 xRet.set( this );
320
321 return xRet;
322 }
323
324 } }
325