Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/debug.hxx>
31 : :
32 : : #include <com/sun/star/text/PositionLayoutDir.hpp>
33 : : #include <com/sun/star/chart/XChartDocument.hpp>
34 : :
35 : : #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
36 : :
37 : : #include <list>
38 : :
39 : : #include <xmloff/shapeimport.hxx>
40 : : #include <xmloff/xmltkmap.hxx>
41 : : #include "xmloff/xmlnmspe.hxx"
42 : : #include <xmloff/xmltoken.hxx>
43 : : #include "ximpstyl.hxx"
44 : : #include "ximpshap.hxx"
45 : : #include "sdpropls.hxx"
46 : : #include <xmloff/xmlprmap.hxx>
47 : : #include "ximp3dscene.hxx"
48 : : #include "ximp3dobject.hxx"
49 : : #include "ximpgrp.hxx"
50 : : #include "ximplink.hxx"
51 : :
52 : : #include <map>
53 : : #include <vector>
54 : :
55 : : using ::rtl::OUString;
56 : : using ::rtl::OUStringBuffer;
57 : :
58 : : using namespace ::std;
59 : : using namespace ::com::sun::star;
60 : : using namespace ::xmloff::token;
61 : :
62 : : //////////////////////////////////////////////////////////////////////////////
63 : :
64 : : struct ltint32
65 : : {
66 : 1692 : bool operator()(const sal_Int32 p, sal_Int32 q) const
67 : : {
68 : 1692 : return p < q;
69 : : }
70 : : };
71 : :
72 : : typedef std::map<sal_Int32,com::sun::star::uno::Reference< com::sun::star::drawing::XShape >,ltint32> IdShapeMap;
73 : :
74 : 0 : struct ConnectionHint
75 : : {
76 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxConnector;
77 : : sal_Bool bStart;
78 : : OUString aDestShapeId;
79 : : sal_Int32 nDestGlueId;
80 : : };
81 : :
82 : : struct XShapeCompareHelper
83 : : {
84 : 2397 : bool operator()(com::sun::star::uno::Reference < com::sun::star::drawing::XShape > x1,
85 : : com::sun::star::uno::Reference < com::sun::star::drawing::XShape > x2 ) const
86 : : {
87 : 2397 : return x1.get() < x2.get();
88 : : }
89 : : };
90 : :
91 : : /** this map store all glue point id mappings for shapes that had user defined glue points. This
92 : : is needed because on insertion the glue points will get a new and unique id */
93 : : typedef std::map<sal_Int32,sal_Int32,ltint32> GluePointIdMap;
94 : : typedef std::map< com::sun::star::uno::Reference < com::sun::star::drawing::XShape >, GluePointIdMap, XShapeCompareHelper > ShapeGluePointsMap;
95 : :
96 : : /** this struct is created for each startPage() call and stores information that is needed during
97 : : import of shapes for one page. Since pages could be nested ( notes pages inside impress ) there
98 : : is a pointer so one can build up a stack of this structs */
99 : 376 : struct XMLShapeImportPageContextImpl
100 : : {
101 : : ShapeGluePointsMap maShapeGluePointsMap;
102 : :
103 : : uno::Reference < drawing::XShapes > mxShapes;
104 : :
105 : : struct XMLShapeImportPageContextImpl* mpNext;
106 : : };
107 : :
108 : : /** this class is to enable adding members to the XMLShapeImportHelper without getting incompatible */
109 [ + - ]: 776 : struct XMLShapeImportHelperImpl
110 : : {
111 : : // context for sorting shapes
112 : : ShapeSortContext* mpSortContext;
113 : :
114 : : IdShapeMap maShapeIds;
115 : :
116 : : std::vector<ConnectionHint> maConnections;
117 : :
118 : : // #88546# possibility to swich progress bar handling on/off
119 : : sal_Bool mbHandleProgressBar;
120 : :
121 : : // stores the capability of the current model to create presentation shapes
122 : : sal_Bool mbIsPresentationShapesSupported;
123 : : };
124 : :
125 : : //////////////////////////////////////////////////////////////////////////////
126 : :
127 : 388 : XMLShapeImportHelper::XMLShapeImportHelper(
128 : : SvXMLImport& rImporter,
129 : : const uno::Reference< frame::XModel>& rModel,
130 : : SvXMLImportPropertyMapper *pExtMapper )
131 : : : mpPageContext(NULL),
132 : : mxModel(rModel),
133 : :
134 : : mpPropertySetMapper(0L),
135 : : mpPresPagePropsMapper(0L),
136 : : mpStylesContext(0L),
137 : : mpAutoStylesContext(0L),
138 : : mpGroupShapeElemTokenMap(0L),
139 : : mpFrameShapeElemTokenMap(0L),
140 : : mp3DSceneShapeElemTokenMap(0L),
141 : : mp3DObjectAttrTokenMap(0L),
142 : : mp3DPolygonBasedAttrTokenMap(0L),
143 : : mp3DCubeObjectAttrTokenMap(0L),
144 : : mp3DSphereObjectAttrTokenMap(0L),
145 : : mp3DSceneShapeAttrTokenMap(0L),
146 : : mp3DLightAttrTokenMap(0L),
147 : : mpPathShapeAttrTokenMap(0L),
148 : : mpPolygonShapeAttrTokenMap(0L),
149 : : msStartShape(RTL_CONSTASCII_USTRINGPARAM("StartShape")),
150 : : msEndShape(RTL_CONSTASCII_USTRINGPARAM("EndShape")),
151 : : msStartGluePointIndex(RTL_CONSTASCII_USTRINGPARAM("StartGluePointIndex")),
152 : : msEndGluePointIndex(RTL_CONSTASCII_USTRINGPARAM("EndGluePointIndex")),
153 : :
154 [ + - ][ + - ]: 388 : mrImporter( rImporter )
[ + - ][ + - ]
155 : : {
156 [ + - ][ + - ]: 388 : mpImpl = new XMLShapeImportHelperImpl();
157 : 388 : mpImpl->mpSortContext = 0;
158 : :
159 : : // #88546# init to sal_False
160 : 388 : mpImpl->mbHandleProgressBar = sal_False;
161 : :
162 [ + - ][ + - ]: 388 : mpSdPropHdlFactory = new XMLSdPropHdlFactory( rModel, rImporter );
163 : :
164 : : // set lock to avoid deletion
165 [ + - ]: 388 : mpSdPropHdlFactory->acquire();
166 : :
167 : : // construct PropertySetMapper
168 [ + - ][ + - ]: 388 : UniReference < XMLPropertySetMapper > xMapper = new XMLShapePropertySetMapper(mpSdPropHdlFactory);
[ + - ][ + - ]
[ + - ]
169 [ + - ][ + - ]: 388 : mpPropertySetMapper = new SvXMLImportPropertyMapper( xMapper, rImporter );
170 : : // set lock to avoid deletion
171 [ + - ]: 388 : mpPropertySetMapper->acquire();
172 : :
173 [ + + ]: 388 : if( pExtMapper )
174 : : {
175 [ + - ]: 126 : UniReference < SvXMLImportPropertyMapper > xExtMapper( pExtMapper );
176 [ + - ][ + - ]: 126 : mpPropertySetMapper->ChainImportMapper( xExtMapper );
177 : : }
178 : :
179 : : // chain text attributes
180 [ + - ][ + - ]: 388 : mpPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(rImporter));
[ + - ][ + - ]
181 [ + - ][ + - ]: 388 : mpPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaDefaultExtPropMapper(rImporter));
[ + - ][ + - ]
182 : :
183 : : // construct PresPagePropsMapper
184 [ + - ][ + - ]: 388 : xMapper = new XMLPropertySetMapper((XMLPropertyMapEntry*)aXMLSDPresPageProps, mpSdPropHdlFactory);
[ + - ][ + - ]
[ + - ]
185 [ + - ][ + - ]: 388 : mpPresPagePropsMapper = new SvXMLImportPropertyMapper( xMapper, rImporter );
186 [ + - ]: 388 : if(mpPresPagePropsMapper)
187 : : {
188 : : // set lock to avoid deletion
189 [ + - ]: 388 : mpPresPagePropsMapper->acquire();
190 : : }
191 : :
192 [ + - ]: 388 : uno::Reference< lang::XServiceInfo > xInfo( rImporter.GetModel(), uno::UNO_QUERY );
193 [ + - ]: 388 : const OUString aSName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument") );
194 [ + - ][ + - ]: 388 : mpImpl->mbIsPresentationShapesSupported = xInfo.is() && xInfo->supportsService( aSName );
[ + - ][ + + ]
[ + - ]
195 : 388 : }
196 : :
197 : : //////////////////////////////////////////////////////////////////////////////
198 : :
199 [ + - ]: 388 : XMLShapeImportHelper::~XMLShapeImportHelper()
200 : : {
201 : : DBG_ASSERT( mpImpl->maConnections.empty(), "XMLShapeImportHelper::restoreConnections() was not called!" );
202 : :
203 : : // cleanup factory, decrease refcount. Should lead to destruction.
204 [ + - ]: 388 : if(mpSdPropHdlFactory)
205 : : {
206 [ + - ]: 388 : mpSdPropHdlFactory->release();
207 : 388 : mpSdPropHdlFactory = 0L;
208 : : }
209 : :
210 : : // cleanup mapper, decrease refcount. Should lead to destruction.
211 [ + - ]: 388 : if(mpPropertySetMapper)
212 : : {
213 [ + - ]: 388 : mpPropertySetMapper->release();
214 : 388 : mpPropertySetMapper = 0L;
215 : : }
216 : :
217 : : // cleanup presPage mapper, decrease refcount. Should lead to destruction.
218 [ + - ]: 388 : if(mpPresPagePropsMapper)
219 : : {
220 [ + - ]: 388 : mpPresPagePropsMapper->release();
221 : 388 : mpPresPagePropsMapper = 0L;
222 : : }
223 : :
224 [ + + ][ + - ]: 388 : if(mpGroupShapeElemTokenMap) delete mpGroupShapeElemTokenMap;
[ + - ]
225 [ + + ][ + - ]: 388 : if(mpFrameShapeElemTokenMap) delete mpFrameShapeElemTokenMap;
[ + - ]
226 : :
227 [ - + ][ # # ]: 388 : if(mpPolygonShapeAttrTokenMap) delete mpPolygonShapeAttrTokenMap;
[ # # ]
228 [ - + ][ # # ]: 388 : if(mpPathShapeAttrTokenMap) delete mpPathShapeAttrTokenMap;
[ # # ]
229 [ - + ][ # # ]: 388 : if(mp3DSceneShapeElemTokenMap) delete mp3DSceneShapeElemTokenMap;
[ # # ]
230 [ - + ][ # # ]: 388 : if(mp3DObjectAttrTokenMap) delete mp3DObjectAttrTokenMap;
[ # # ]
231 [ - + ][ # # ]: 388 : if(mp3DPolygonBasedAttrTokenMap) delete mp3DPolygonBasedAttrTokenMap;
[ # # ]
232 [ - + ][ # # ]: 388 : if(mp3DCubeObjectAttrTokenMap) delete mp3DCubeObjectAttrTokenMap;
[ # # ]
233 [ - + ][ # # ]: 388 : if(mp3DSphereObjectAttrTokenMap) delete mp3DSphereObjectAttrTokenMap;
[ # # ]
234 [ - + ][ # # ]: 388 : if(mp3DSceneShapeAttrTokenMap) delete mp3DSceneShapeAttrTokenMap;
[ # # ]
235 [ - + ][ # # ]: 388 : if(mp3DLightAttrTokenMap) delete mp3DLightAttrTokenMap;
[ # # ]
236 : :
237 : : // Styles or AutoStyles context?
238 [ + + ]: 388 : if(mpStylesContext)
239 : : {
240 [ + - ]: 11 : mpStylesContext->Clear();
241 [ + - ]: 11 : mpStylesContext->ReleaseRef();
242 : : }
243 : :
244 [ + + ]: 388 : if(mpAutoStylesContext)
245 : : {
246 [ + - ]: 354 : mpAutoStylesContext->Clear();
247 [ + - ]: 354 : mpAutoStylesContext->ReleaseRef();
248 : : }
249 : :
250 [ + - ]: 388 : delete mpImpl;
251 [ - + ]: 464 : }
252 : :
253 : : //////////////////////////////////////////////////////////////////////////////
254 : :
255 : :
256 : :
257 : 521 : const SvXMLTokenMap& XMLShapeImportHelper::GetGroupShapeElemTokenMap()
258 : : {
259 [ + + ]: 521 : if(!mpGroupShapeElemTokenMap)
260 : : {
261 : : static SvXMLTokenMapEntry aGroupShapeElemTokenMap[] =
262 : : {
263 : : { XML_NAMESPACE_DRAW, XML_G, XML_TOK_GROUP_GROUP },
264 : : { XML_NAMESPACE_DRAW, XML_RECT, XML_TOK_GROUP_RECT },
265 : : { XML_NAMESPACE_DRAW, XML_LINE, XML_TOK_GROUP_LINE },
266 : : { XML_NAMESPACE_DRAW, XML_CIRCLE, XML_TOK_GROUP_CIRCLE },
267 : : { XML_NAMESPACE_DRAW, XML_ELLIPSE, XML_TOK_GROUP_ELLIPSE },
268 : : { XML_NAMESPACE_DRAW, XML_POLYGON, XML_TOK_GROUP_POLYGON },
269 : : { XML_NAMESPACE_DRAW, XML_POLYLINE, XML_TOK_GROUP_POLYLINE },
270 : : { XML_NAMESPACE_DRAW, XML_PATH, XML_TOK_GROUP_PATH },
271 : :
272 : : { XML_NAMESPACE_DRAW, XML_CONTROL, XML_TOK_GROUP_CONTROL },
273 : : { XML_NAMESPACE_DRAW, XML_CONNECTOR, XML_TOK_GROUP_CONNECTOR },
274 : : { XML_NAMESPACE_DRAW, XML_MEASURE, XML_TOK_GROUP_MEASURE },
275 : : { XML_NAMESPACE_DRAW, XML_PAGE_THUMBNAIL, XML_TOK_GROUP_PAGE },
276 : : { XML_NAMESPACE_DRAW, XML_CAPTION, XML_TOK_GROUP_CAPTION },
277 : :
278 : : { XML_NAMESPACE_CHART, XML_CHART, XML_TOK_GROUP_CHART },
279 : : { XML_NAMESPACE_DR3D, XML_SCENE, XML_TOK_GROUP_3DSCENE },
280 : :
281 : : { XML_NAMESPACE_DRAW, XML_FRAME, XML_TOK_GROUP_FRAME },
282 : : { XML_NAMESPACE_DRAW, XML_CUSTOM_SHAPE, XML_TOK_GROUP_CUSTOM_SHAPE },
283 : :
284 : : { XML_NAMESPACE_DRAW, XML_CUSTOM_SHAPE, XML_TOK_GROUP_CUSTOM_SHAPE },
285 : : { XML_NAMESPACE_OFFICE, XML_ANNOTATION, XML_TOK_GROUP_ANNOTATION },
286 : : { XML_NAMESPACE_DRAW, XML_A, XML_TOK_GROUP_A },
287 : :
288 : : XML_TOKEN_MAP_END
289 : : };
290 : :
291 [ + - ]: 45 : mpGroupShapeElemTokenMap = new SvXMLTokenMap(aGroupShapeElemTokenMap);
292 : : } // if(!mpGroupShapeElemTokenMap)
293 : :
294 : 521 : return *mpGroupShapeElemTokenMap;
295 : : }
296 : :
297 : 126 : const SvXMLTokenMap& XMLShapeImportHelper::GetFrameShapeElemTokenMap()
298 : : {
299 [ + + ]: 126 : if(!mpFrameShapeElemTokenMap)
300 : : {
301 : : static SvXMLTokenMapEntry aFrameShapeElemTokenMap[] =
302 : : {
303 : : { XML_NAMESPACE_DRAW, XML_TEXT_BOX, XML_TOK_FRAME_TEXT_BOX },
304 : : { XML_NAMESPACE_DRAW, XML_IMAGE, XML_TOK_FRAME_IMAGE },
305 : : { XML_NAMESPACE_DRAW, XML_OBJECT, XML_TOK_FRAME_OBJECT },
306 : : { XML_NAMESPACE_DRAW, XML_OBJECT_OLE, XML_TOK_FRAME_OBJECT_OLE },
307 : : { XML_NAMESPACE_DRAW, XML_PLUGIN, XML_TOK_FRAME_PLUGIN },
308 : : { XML_NAMESPACE_DRAW, XML_FLOATING_FRAME, XML_TOK_FRAME_FLOATING_FRAME},
309 : : { XML_NAMESPACE_DRAW, XML_APPLET, XML_TOK_FRAME_APPLET },
310 : : { XML_NAMESPACE_TABLE, XML_TABLE, XML_TOK_FRAME_TABLE },
311 : : XML_TOKEN_MAP_END
312 : : };
313 : :
314 [ + - ]: 19 : mpFrameShapeElemTokenMap = new SvXMLTokenMap(aFrameShapeElemTokenMap);
315 : : } // if(!mpFrameShapeElemTokenMap)
316 : :
317 : 126 : return *mpFrameShapeElemTokenMap;
318 : : }
319 : :
320 : : //////////////////////////////////////////////////////////////////////////////
321 : :
322 : :
323 : 0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DSceneShapeElemTokenMap()
324 : : {
325 [ # # ]: 0 : if(!mp3DSceneShapeElemTokenMap)
326 : : {
327 : : static SvXMLTokenMapEntry a3DSceneShapeElemTokenMap[] =
328 : : {
329 : : { XML_NAMESPACE_DR3D, XML_SCENE, XML_TOK_3DSCENE_3DSCENE },
330 : : { XML_NAMESPACE_DR3D, XML_CUBE, XML_TOK_3DSCENE_3DCUBE },
331 : : { XML_NAMESPACE_DR3D, XML_SPHERE, XML_TOK_3DSCENE_3DSPHERE },
332 : : { XML_NAMESPACE_DR3D, XML_ROTATE, XML_TOK_3DSCENE_3DLATHE },
333 : : { XML_NAMESPACE_DR3D, XML_EXTRUDE, XML_TOK_3DSCENE_3DEXTRUDE },
334 : : XML_TOKEN_MAP_END
335 : : };
336 : :
337 [ # # ]: 0 : mp3DSceneShapeElemTokenMap = new SvXMLTokenMap(a3DSceneShapeElemTokenMap);
338 : : } // if(!mp3DSceneShapeElemTokenMap)
339 : :
340 : 0 : return *mp3DSceneShapeElemTokenMap;
341 : : }
342 : :
343 : : //////////////////////////////////////////////////////////////////////////////
344 : :
345 : :
346 : 0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DObjectAttrTokenMap()
347 : : {
348 [ # # ]: 0 : if(!mp3DObjectAttrTokenMap)
349 : : {
350 : : static SvXMLTokenMapEntry a3DObjectAttrTokenMap[] =
351 : : {
352 : : { XML_NAMESPACE_DRAW, XML_STYLE_NAME, XML_TOK_3DOBJECT_DRAWSTYLE_NAME },
353 : : { XML_NAMESPACE_DR3D, XML_TRANSFORM, XML_TOK_3DOBJECT_TRANSFORM },
354 : : XML_TOKEN_MAP_END
355 : : };
356 : :
357 [ # # ]: 0 : mp3DObjectAttrTokenMap = new SvXMLTokenMap(a3DObjectAttrTokenMap);
358 : : } // if(!mp3DObjectAttrTokenMap)
359 : :
360 : 0 : return *mp3DObjectAttrTokenMap;
361 : : }
362 : :
363 : : //////////////////////////////////////////////////////////////////////////////
364 : :
365 : :
366 : 0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DPolygonBasedAttrTokenMap()
367 : : {
368 [ # # ]: 0 : if(!mp3DPolygonBasedAttrTokenMap)
369 : : {
370 : : static SvXMLTokenMapEntry a3DPolygonBasedAttrTokenMap[] =
371 : : {
372 : : { XML_NAMESPACE_SVG, XML_VIEWBOX, XML_TOK_3DPOLYGONBASED_VIEWBOX },
373 : : { XML_NAMESPACE_SVG, XML_D, XML_TOK_3DPOLYGONBASED_D },
374 : : XML_TOKEN_MAP_END
375 : : };
376 : :
377 [ # # ]: 0 : mp3DPolygonBasedAttrTokenMap = new SvXMLTokenMap(a3DPolygonBasedAttrTokenMap);
378 : : } // if(!mp3DPolygonBasedAttrTokenMap)
379 : :
380 : 0 : return *mp3DPolygonBasedAttrTokenMap;
381 : : }
382 : :
383 : : //////////////////////////////////////////////////////////////////////////////
384 : :
385 : :
386 : 0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DCubeObjectAttrTokenMap()
387 : : {
388 [ # # ]: 0 : if(!mp3DCubeObjectAttrTokenMap)
389 : : {
390 : : static SvXMLTokenMapEntry a3DCubeObjectAttrTokenMap[] =
391 : : {
392 : : { XML_NAMESPACE_DR3D, XML_MIN_EDGE, XML_TOK_3DCUBEOBJ_MINEDGE },
393 : : { XML_NAMESPACE_DR3D, XML_MAX_EDGE, XML_TOK_3DCUBEOBJ_MAXEDGE },
394 : : XML_TOKEN_MAP_END
395 : : };
396 : :
397 [ # # ]: 0 : mp3DCubeObjectAttrTokenMap = new SvXMLTokenMap(a3DCubeObjectAttrTokenMap);
398 : : } // if(!mp3DCubeObjectAttrTokenMap)
399 : :
400 : 0 : return *mp3DCubeObjectAttrTokenMap;
401 : : }
402 : :
403 : : //////////////////////////////////////////////////////////////////////////////
404 : :
405 : :
406 : 0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DSphereObjectAttrTokenMap()
407 : : {
408 [ # # ]: 0 : if(!mp3DSphereObjectAttrTokenMap)
409 : : {
410 : : static SvXMLTokenMapEntry a3DSphereObjectAttrTokenMap[] =
411 : : {
412 : : { XML_NAMESPACE_DR3D, XML_CENTER, XML_TOK_3DSPHEREOBJ_CENTER },
413 : : { XML_NAMESPACE_DR3D, XML_SIZE, XML_TOK_3DSPHEREOBJ_SIZE },
414 : : XML_TOKEN_MAP_END
415 : : };
416 : :
417 [ # # ]: 0 : mp3DSphereObjectAttrTokenMap = new SvXMLTokenMap(a3DSphereObjectAttrTokenMap);
418 : : } // if(!mp3DSphereObjectAttrTokenMap)
419 : :
420 : 0 : return *mp3DSphereObjectAttrTokenMap;
421 : : }
422 : :
423 : : //////////////////////////////////////////////////////////////////////////////
424 : :
425 : 0 : const SvXMLTokenMap& XMLShapeImportHelper::Get3DLightAttrTokenMap()
426 : : {
427 [ # # ]: 0 : if(!mp3DLightAttrTokenMap)
428 : : {
429 : : static SvXMLTokenMapEntry a3DLightAttrTokenMap[] =
430 : : {
431 : : { XML_NAMESPACE_DR3D, XML_DIFFUSE_COLOR, XML_TOK_3DLIGHT_DIFFUSE_COLOR },
432 : : { XML_NAMESPACE_DR3D, XML_DIRECTION, XML_TOK_3DLIGHT_DIRECTION },
433 : : { XML_NAMESPACE_DR3D, XML_ENABLED, XML_TOK_3DLIGHT_ENABLED },
434 : : { XML_NAMESPACE_DR3D, XML_SPECULAR, XML_TOK_3DLIGHT_SPECULAR },
435 : : XML_TOKEN_MAP_END
436 : : };
437 : :
438 [ # # ]: 0 : mp3DLightAttrTokenMap = new SvXMLTokenMap(a3DLightAttrTokenMap);
439 : : } // if(!mp3DLightAttrTokenMap)
440 : :
441 : 0 : return *mp3DLightAttrTokenMap;
442 : : }
443 : :
444 : : //////////////////////////////////////////////////////////////////////////////
445 : :
446 : :
447 : 0 : SvXMLShapeContext* XMLShapeImportHelper::Create3DSceneChildContext(
448 : : SvXMLImport& rImport,
449 : : sal_uInt16 p_nPrefix,
450 : : const OUString& rLocalName,
451 : : const uno::Reference< xml::sax::XAttributeList>& xAttrList,
452 : : uno::Reference< drawing::XShapes >& rShapes)
453 : : {
454 : 0 : SdXMLShapeContext *pContext = 0L;
455 : :
456 [ # # ]: 0 : if(rShapes.is())
457 : : {
458 : 0 : const SvXMLTokenMap& rTokenMap = Get3DSceneShapeElemTokenMap();
459 [ # # # # : 0 : switch(rTokenMap.Get(p_nPrefix, rLocalName))
# # ]
460 : : {
461 : : case XML_TOK_3DSCENE_3DSCENE:
462 : : {
463 : : // dr3d:3dscene inside dr3d:3dscene context
464 [ # # ]: 0 : pContext = new SdXML3DSceneShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
465 : 0 : break;
466 : : }
467 : : case XML_TOK_3DSCENE_3DCUBE:
468 : : {
469 : : // dr3d:3dcube inside dr3d:3dscene context
470 [ # # ]: 0 : pContext = new SdXML3DCubeObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
471 : 0 : break;
472 : : }
473 : : case XML_TOK_3DSCENE_3DSPHERE:
474 : : {
475 : : // dr3d:3dsphere inside dr3d:3dscene context
476 [ # # ]: 0 : pContext = new SdXML3DSphereObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
477 : 0 : break;
478 : : }
479 : : case XML_TOK_3DSCENE_3DLATHE:
480 : : {
481 : : // dr3d:3dlathe inside dr3d:3dscene context
482 [ # # ]: 0 : pContext = new SdXML3DLatheObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
483 : 0 : break;
484 : : }
485 : : case XML_TOK_3DSCENE_3DEXTRUDE:
486 : : {
487 : : // dr3d:3dextrude inside dr3d:3dscene context
488 [ # # ]: 0 : pContext = new SdXML3DExtrudeObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False);
489 : 0 : break;
490 : : }
491 : : }
492 : : }
493 : :
494 : : // now parse the attribute list and call the child context for each unknown attribute
495 [ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
496 [ # # ]: 0 : for(sal_Int16 a(0); a < nAttrCount; a++)
497 : : {
498 [ # # ][ # # ]: 0 : const OUString& rAttrName = xAttrList->getNameByIndex(a);
499 : 0 : OUString aLocalName;
500 [ # # ]: 0 : sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
501 [ # # ][ # # ]: 0 : const OUString aValue( xAttrList->getValueByIndex(a) );
502 : :
503 [ # # ]: 0 : pContext->processAttribute( nPrefix, aLocalName, aValue );
504 : 0 : }
505 : :
506 : 0 : return pContext;
507 : : }
508 : :
509 : : //////////////////////////////////////////////////////////////////////////////
510 : :
511 : 11 : void XMLShapeImportHelper::SetStylesContext(SvXMLStylesContext* pNew)
512 : : {
513 : 11 : mpStylesContext = pNew;
514 : 11 : mpStylesContext->AddRef();
515 : 11 : }
516 : :
517 : : //////////////////////////////////////////////////////////////////////////////
518 : :
519 : 354 : void XMLShapeImportHelper::SetAutoStylesContext(SvXMLStylesContext* pNew)
520 : : {
521 : 354 : mpAutoStylesContext = pNew;
522 : 354 : mpAutoStylesContext->AddRef();
523 : 354 : }
524 : :
525 : : //////////////////////////////////////////////////////////////////////////////
526 : :
527 : 521 : SvXMLShapeContext* XMLShapeImportHelper::CreateGroupChildContext(
528 : : SvXMLImport& rImport,
529 : : sal_uInt16 p_nPrefix,
530 : : const OUString& rLocalName,
531 : : const uno::Reference< xml::sax::XAttributeList>& xAttrList,
532 : : uno::Reference< drawing::XShapes >& rShapes,
533 : : sal_Bool bTemporaryShape)
534 : : {
535 : 521 : SdXMLShapeContext *pContext = 0L;
536 : :
537 : 521 : const SvXMLTokenMap& rTokenMap = GetGroupShapeElemTokenMap();
538 [ + - ]: 521 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
539 : :
540 [ + - + + : 521 : switch(rTokenMap.Get(p_nPrefix, rLocalName))
+ + + + +
- - + + -
+ - + ]
541 : : {
542 : : case XML_TOK_GROUP_GROUP:
543 : : {
544 : : // draw:g inside group context (RECURSIVE)
545 [ + - ]: 6 : pContext = new SdXMLGroupShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape);
546 : 6 : break;
547 : : }
548 : : case XML_TOK_GROUP_3DSCENE:
549 : : {
550 : : // dr3d:3dscene inside group context
551 [ # # ]: 0 : pContext = new SdXML3DSceneShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape);
552 : 0 : break;
553 : : }
554 : : case XML_TOK_GROUP_RECT:
555 : : {
556 : : // draw:rect inside group context
557 [ + - ]: 12 : pContext = new SdXMLRectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
558 : 12 : break;
559 : : }
560 : : case XML_TOK_GROUP_LINE:
561 : : {
562 : : // draw:line inside group context
563 [ + - ]: 14 : pContext = new SdXMLLineShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
564 : 14 : break;
565 : : }
566 : : case XML_TOK_GROUP_CIRCLE:
567 : : case XML_TOK_GROUP_ELLIPSE:
568 : : {
569 : : // draw:circle or draw:ellipse inside group context
570 [ + - ]: 16 : pContext = new SdXMLEllipseShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
571 : 16 : break;
572 : : }
573 : : case XML_TOK_GROUP_POLYGON:
574 : : case XML_TOK_GROUP_POLYLINE:
575 : : {
576 : : // draw:polygon or draw:polyline inside group context
577 : : pContext = new SdXMLPolygonShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes,
578 [ + + ][ + - ]: 12 : rTokenMap.Get(p_nPrefix, rLocalName) == XML_TOK_GROUP_POLYGON ? sal_True : sal_False, bTemporaryShape );
579 : 12 : break;
580 : : }
581 : : case XML_TOK_GROUP_PATH:
582 : : {
583 : : // draw:path inside group context
584 [ + - ]: 12 : pContext = new SdXMLPathShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape);
585 : 12 : break;
586 : : }
587 : : case XML_TOK_GROUP_FRAME:
588 : : {
589 : : // text:text-box inside group context
590 [ + - ]: 126 : pContext = new SdXMLFrameShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
591 : 126 : break;
592 : : }
593 : : case XML_TOK_GROUP_CONTROL:
594 : : {
595 : : // draw:control inside group context
596 [ + - ]: 37 : pContext = new SdXMLControlShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
597 : 37 : break;
598 : : }
599 : : case XML_TOK_GROUP_CONNECTOR:
600 : : {
601 : : // draw:connector inside group context
602 [ # # ]: 0 : pContext = new SdXMLConnectorShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
603 : 0 : break;
604 : : }
605 : : case XML_TOK_GROUP_MEASURE:
606 : : {
607 : : // draw:measure inside group context
608 [ # # ]: 0 : pContext = new SdXMLMeasureShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
609 : 0 : break;
610 : : }
611 : : case XML_TOK_GROUP_PAGE:
612 : : {
613 : : // draw:page inside group context
614 [ + - ]: 77 : pContext = new SdXMLPageShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
615 : 77 : break;
616 : : }
617 : : case XML_TOK_GROUP_CAPTION:
618 : : case XML_TOK_GROUP_ANNOTATION:
619 : : {
620 : : // draw:caption inside group context
621 [ + - ]: 8 : pContext = new SdXMLCaptionShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
622 : 8 : break;
623 : : }
624 : : case XML_TOK_GROUP_CHART:
625 : : {
626 : : // chart:chart inside group context
627 [ # # ]: 0 : pContext = new SdXMLChartShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, bTemporaryShape );
628 : 0 : break;
629 : : }
630 : : case XML_TOK_GROUP_CUSTOM_SHAPE:
631 : : {
632 : : // draw:customshape
633 [ + - ]: 186 : pContext = new SdXMLCustomShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
634 : 186 : break;
635 : : }
636 : : case XML_TOK_GROUP_A:
637 : : {
638 [ # # ]: 0 : return new SdXMLShapeLinkContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes );
639 : : }
640 : : // add other shapes here...
641 : : default:
642 [ + - ]: 15 : return new SvXMLShapeContext( rImport, p_nPrefix, rLocalName, bTemporaryShape );
643 : : }
644 : :
645 : : // now parse the attribute list and call the child context for each unknown attribute
646 [ + + ]: 4297 : for(sal_Int16 a(0); a < nAttrCount; a++)
647 : : {
648 [ + - ][ + - ]: 3791 : const OUString& rAttrName = xAttrList->getNameByIndex(a);
649 : 3791 : OUString aLocalName;
650 [ + - ]: 3791 : sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
651 [ + - ][ + - ]: 3791 : const OUString aValue( xAttrList->getValueByIndex(a) );
652 : :
653 [ + - ]: 3791 : pContext->processAttribute( nPrefix, aLocalName, aValue );
654 : 3791 : }
655 : :
656 : 521 : return pContext;
657 : : }
658 : :
659 : : // This method is called from SdXMLFrameContext to create children of drawe:frame
660 : 126 : SvXMLShapeContext* XMLShapeImportHelper::CreateFrameChildContext(
661 : : SvXMLImport& rImport,
662 : : sal_uInt16 p_nPrefix,
663 : : const OUString& rLocalName,
664 : : const uno::Reference< xml::sax::XAttributeList>& rAttrList,
665 : : uno::Reference< drawing::XShapes >& rShapes,
666 : : const uno::Reference< xml::sax::XAttributeList>& rFrameAttrList)
667 : : {
668 : 126 : SdXMLShapeContext *pContext = 0L;
669 : :
670 [ + - ]: 126 : const SvXMLTokenMap& rTokenMap = GetFrameShapeElemTokenMap();
671 : :
672 [ + - ]: 126 : SvXMLAttributeList *pAttrList = new SvXMLAttributeList( rAttrList );
673 [ + - ]: 126 : if( rFrameAttrList.is() )
674 [ + - ]: 126 : pAttrList->AppendAttributeList( rFrameAttrList );
675 [ + - ][ + - ]: 126 : uno::Reference < xml::sax::XAttributeList > xAttrList = pAttrList;
676 : :
677 : :
678 [ + - ][ + + : 126 : switch(rTokenMap.Get(p_nPrefix, rLocalName))
- + - - -
- ]
679 : : {
680 : : case XML_TOK_FRAME_TEXT_BOX:
681 : : {
682 : : // text:text-box inside group context
683 [ + - ][ + - ]: 112 : pContext = new SdXMLTextBoxShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
684 : 112 : break;
685 : : }
686 : : case XML_TOK_FRAME_IMAGE:
687 : : {
688 : : // office:image inside group context
689 [ + - ][ + - ]: 8 : pContext = new SdXMLGraphicObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
690 : 8 : break;
691 : : }
692 : : case XML_TOK_FRAME_OBJECT:
693 : : case XML_TOK_FRAME_OBJECT_OLE:
694 : : {
695 : : // draw:object or draw:object_ole
696 [ # # ][ # # ]: 0 : pContext = new SdXMLObjectShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
697 : 0 : break;
698 : : }
699 : : case XML_TOK_FRAME_TABLE:
700 : : {
701 : : // draw:object or draw:object_ole
702 [ + - ]: 6 : if( rImport.IsTableShapeSupported() )
703 [ + - ][ + - ]: 6 : pContext = new SdXMLTableShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes );
704 : 6 : break;
705 : :
706 : : }
707 : : case XML_TOK_FRAME_PLUGIN:
708 : : {
709 : : // draw:plugin
710 [ # # ][ # # ]: 0 : pContext = new SdXMLPluginShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
711 : 0 : break;
712 : : }
713 : : case XML_TOK_FRAME_FLOATING_FRAME:
714 : : {
715 : : // draw:floating-frame
716 [ # # ][ # # ]: 0 : pContext = new SdXMLFloatingFrameShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
717 : 0 : break;
718 : : }
719 : : case XML_TOK_FRAME_APPLET:
720 : : {
721 : : // draw:applet
722 [ # # ][ # # ]: 0 : pContext = new SdXMLAppletShapeContext( rImport, p_nPrefix, rLocalName, xAttrList, rShapes, sal_False );
723 : 0 : break;
724 : : }
725 : : // add other shapes here...
726 : : default:
727 : 0 : break;
728 : : }
729 : :
730 [ + - ]: 126 : if( pContext )
731 : : {
732 : : // now parse the attribute list and call the child context for each unknown attribute
733 [ + - ][ + - ]: 126 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
734 [ + + ]: 1199 : for(sal_Int16 a(0); a < nAttrCount; a++)
735 : : {
736 [ + - ][ + - ]: 1073 : const OUString& rAttrName = xAttrList->getNameByIndex(a);
737 : 1073 : OUString aLocalName;
738 [ + - ]: 1073 : sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
739 [ + - ][ + - ]: 1073 : const OUString aValue( xAttrList->getValueByIndex(a) );
740 : :
741 [ + - ]: 1073 : pContext->processAttribute( nPrefix, aLocalName, aValue );
742 : 1073 : }
743 : : }
744 : :
745 : 126 : return pContext;
746 : : }
747 : :
748 : 0 : SvXMLImportContext *XMLShapeImportHelper::CreateFrameChildContext(
749 : : SvXMLImportContext *pThisContext,
750 : : sal_uInt16 nPrefix,
751 : : const OUString& rLocalName,
752 : : const uno::Reference< xml::sax::XAttributeList>& xAttrList )
753 : : {
754 : 0 : SvXMLImportContext * pContext = NULL;
755 : :
756 [ # # ][ # # ]: 0 : SdXMLFrameShapeContext *pFrameContext = PTR_CAST( SdXMLFrameShapeContext, pThisContext );
757 [ # # ]: 0 : if( pFrameContext )
758 : 0 : pContext = pFrameContext->CreateChildContext( nPrefix, rLocalName, xAttrList );
759 : :
760 : 0 : return pContext;
761 : : }
762 : :
763 : :
764 : : /** this function is called whenever the implementation classes like to add this new
765 : : shape to the given XShapes.
766 : : */
767 : 486 : void XMLShapeImportHelper::addShape( uno::Reference< drawing::XShape >& rShape,
768 : : const uno::Reference< xml::sax::XAttributeList >&,
769 : : uno::Reference< drawing::XShapes >& rShapes)
770 : : {
771 [ + - ][ + - ]: 486 : if( rShape.is() && rShapes.is() )
[ + - ]
772 : : {
773 : : // add new shape to parent
774 : 486 : rShapes->add( rShape );
775 : : }
776 : 486 : }
777 : :
778 : : /** this function is called whenever the implementation classes have finished importing
779 : : a shape to the given XShapes. The shape is already inserted into its XShapes and
780 : : all properties and styles are set.
781 : : */
782 : 506 : void XMLShapeImportHelper::finishShape(
783 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape,
784 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >&,
785 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >&)
786 : : {
787 : : /* Set property <PositionLayoutDir>
788 : : to <PositionInHoriL2R>, if it exists and the import states that
789 : : the shape positioning attributes are in horizontal left-to-right
790 : : layout. This is the case for the OpenOffice.org file format.
791 : : This setting is done for Writer documents, because the property
792 : : only exists at service com::sun::star::text::Shape - the Writer
793 : : UNO service for shapes.
794 : : The value indicates that the positioning attributes are given
795 : : in horizontal left-to-right layout. The property is evaluated
796 : : during the first positioning of the shape in order to convert
797 : : the shape position given in the OpenOffice.org file format to
798 : : the one for the OASIS Open Office file format. (#i28749#, #i36248#)
799 : : */
800 [ + - ]: 506 : uno::Reference< beans::XPropertySet > xPropSet(rShape, uno::UNO_QUERY);
801 [ + - ]: 506 : if ( xPropSet.is() )
802 : : {
803 [ + - ][ + + ]: 1018 : if ( mrImporter.IsShapePositionInHoriL2R() &&
[ + - ][ + + ]
804 [ + - ][ + - ]: 512 : xPropSet->getPropertySetInfo()->hasPropertyByName(
[ + - ][ + + ]
[ # # ]
805 [ + - ][ + - ]: 512 : OUString(RTL_CONSTASCII_USTRINGPARAM("PositionLayoutDir"))) )
[ + + ][ # # ]
806 : : {
807 : 6 : uno::Any aPosLayoutDir;
808 [ + - ]: 6 : aPosLayoutDir <<= text::PositionLayoutDir::PositionInHoriL2R;
809 [ + - ]: 6 : xPropSet->setPropertyValue(
810 : : OUString(RTL_CONSTASCII_USTRINGPARAM("PositionLayoutDir")),
811 [ + - ][ + - ]: 6 : aPosLayoutDir );
812 : : }
813 : 506 : }
814 : 506 : }
815 : :
816 : : // helper functions for z-order sorting
817 : : struct ZOrderHint
818 : : {
819 : : sal_Int32 nIs;
820 : : sal_Int32 nShould;
821 : :
822 : 135 : int operator<(const ZOrderHint& rComp) const { return nShould < rComp.nShould; }
823 : : };
824 : :
825 : 229 : class ShapeSortContext
826 : : {
827 : : public:
828 : : uno::Reference< drawing::XShapes > mxShapes;
829 : : list<ZOrderHint> maZOrderList;
830 : : list<ZOrderHint> maUnsortedList;
831 : :
832 : : sal_Int32 mnCurrentZ;
833 : : ShapeSortContext* mpParentContext;
834 : : const OUString msZOrder;
835 : :
836 : : ShapeSortContext( uno::Reference< drawing::XShapes >& rShapes, ShapeSortContext* pParentContext = NULL );
837 : :
838 : : void moveShape( sal_Int32 nSourcePos, sal_Int32 nDestPos );
839 : : };
840 : :
841 : 229 : ShapeSortContext::ShapeSortContext( uno::Reference< drawing::XShapes >& rShapes, ShapeSortContext* pParentContext )
842 : : : mxShapes( rShapes ), mnCurrentZ( 0 ), mpParentContext( pParentContext ),
843 [ + - ][ + - ]: 229 : msZOrder(RTL_CONSTASCII_USTRINGPARAM("ZOrder"))
[ + - ]
844 : : {
845 : 229 : }
846 : :
847 : 12 : void ShapeSortContext::moveShape( sal_Int32 nSourcePos, sal_Int32 nDestPos )
848 : : {
849 [ + - ][ + - ]: 12 : uno::Any aAny( mxShapes->getByIndex( nSourcePos ) );
850 : 12 : uno::Reference< beans::XPropertySet > xPropSet;
851 [ + - ]: 12 : aAny >>= xPropSet;
852 : :
853 [ + - ][ + - ]: 12 : if( xPropSet.is() && xPropSet->getPropertySetInfo()->hasPropertyByName( msZOrder ) )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
[ + - # # ]
854 : : {
855 [ + - ]: 12 : aAny <<= nDestPos;
856 [ + - ][ + - ]: 12 : xPropSet->setPropertyValue( msZOrder, aAny );
857 : :
858 : 12 : list<ZOrderHint>::iterator aIter = maZOrderList.begin();
859 : 12 : list<ZOrderHint>::iterator aEnd = maZOrderList.end();
860 : :
861 [ + + ]: 93 : while( aIter != aEnd )
862 : : {
863 [ + + ]: 81 : if( (*aIter).nIs < nSourcePos )
864 : : {
865 : : DBG_ASSERT( (*aIter).nIs >= nDestPos, "Shape sorting failed" );
866 : 12 : (*aIter).nIs++;
867 : : }
868 : 81 : ++aIter;
869 : : }
870 : :
871 : 12 : aIter = maUnsortedList.begin();
872 : 12 : aEnd = maUnsortedList.end();
873 : :
874 [ - + ]: 12 : while( aIter != aEnd )
875 : : {
876 [ # # ]: 0 : if( (*aIter).nIs < nSourcePos )
877 : : {
878 : : DBG_ASSERT( (*aIter).nIs >= nDestPos, "shape sorting failed" );
879 : 0 : (*aIter).nIs++;
880 : : }
881 : 0 : ++aIter;
882 : : }
883 : 12 : }
884 : 12 : }
885 : :
886 : 229 : void XMLShapeImportHelper::pushGroupForSorting( uno::Reference< drawing::XShapes >& rShapes )
887 : : {
888 [ + - ]: 229 : mpImpl->mpSortContext = new ShapeSortContext( rShapes, mpImpl->mpSortContext );
889 : 229 : }
890 : :
891 : 229 : void XMLShapeImportHelper::popGroupAndSort()
892 : : {
893 : : DBG_ASSERT( mpImpl->mpSortContext, "No context to sort!" );
894 [ - + ]: 229 : if( mpImpl->mpSortContext == NULL )
895 [ # # ]: 229 : return;
896 : :
897 : : try
898 : : {
899 : 229 : list<ZOrderHint>& rZList = mpImpl->mpSortContext->maZOrderList;
900 : 229 : list<ZOrderHint>& rUnsortedList = mpImpl->mpSortContext->maUnsortedList;
901 : :
902 : : // sort shapes
903 [ + + ]: 229 : if( !rZList.empty() )
904 : : {
905 : : // only do something if we have shapes to sort
906 : :
907 : : // check if there are more shapes than inserted with ::shapeWithZIndexAdded()
908 : : // This can happen if there where already shapes on the page before import
909 : : // Since the writer may delete some of this shapes during import, we need
910 : : // to do this here and not in our c'tor anymore
911 : :
912 : : // check if we have more shapes than we know of
913 [ + - ][ + - ]: 21 : sal_Int32 nCount = mpImpl->mpSortContext->mxShapes->getCount();
914 : :
915 : 21 : nCount -= rZList.size();
916 : 21 : nCount -= rUnsortedList.size();
917 : :
918 : :
919 [ - + ]: 21 : if( nCount > 0 )
920 : : {
921 : : // first update offsets of added shapes
922 : 0 : list<ZOrderHint>::iterator aIter( rZList.begin() );
923 [ # # ]: 0 : while( aIter != rZList.end() )
924 : 0 : (*aIter++).nIs += nCount;
925 : :
926 : 0 : aIter = rUnsortedList.begin();
927 [ # # ]: 0 : while( aIter != rUnsortedList.end() )
928 : 0 : (*aIter++).nIs += nCount;
929 : :
930 : : // second add the already existing shapes in the unsorted list
931 : : ZOrderHint aNewHint;
932 : :
933 [ # # ]: 0 : do
934 : : {
935 : 0 : nCount--;
936 : :
937 : 0 : aNewHint.nIs = nCount;
938 : 0 : aNewHint.nShould = -1;
939 : :
940 [ # # ]: 0 : rUnsortedList.insert(rUnsortedList.begin(), aNewHint);
941 : : }
942 : : while( nCount );
943 : : }
944 : :
945 : : // sort z ordered shapes
946 [ + - ]: 21 : rZList.sort();
947 : :
948 : : // this is the current index, all shapes before that
949 : : // index are finished
950 : 21 : sal_Int32 nIndex = 0;
951 [ + + ]: 106 : while( !rZList.empty() )
952 : : {
953 : 85 : list<ZOrderHint>::iterator aIter( rZList.begin() );
954 : :
955 [ - + ][ # # ]: 85 : while( nIndex < (*aIter).nShould && !rUnsortedList.empty() )
[ - + ]
956 : : {
957 : 0 : ZOrderHint aGapHint( *rUnsortedList.begin() );
958 [ # # ]: 0 : rUnsortedList.pop_front();
959 : :
960 [ # # ]: 0 : mpImpl->mpSortContext->moveShape( aGapHint.nIs, nIndex++ );
961 : : }
962 : :
963 [ + + ]: 85 : if( (*aIter).nIs != nIndex )
964 [ + - ]: 12 : mpImpl->mpSortContext->moveShape( (*aIter).nIs, nIndex );
965 : :
966 [ + - ]: 85 : rZList.pop_front();
967 : 85 : nIndex++;
968 : : }
969 : : }
970 : : }
971 : 0 : catch( uno::Exception& )
972 : : {
973 : : OSL_FAIL("exception while sorting shapes, sorting failed!");
974 : : }
975 : :
976 : : // put parent on top and delete current context, were done
977 : 229 : ShapeSortContext* pContext = mpImpl->mpSortContext;
978 : 229 : mpImpl->mpSortContext = pContext->mpParentContext;
979 [ + - ]: 229 : delete pContext;
980 : : }
981 : :
982 : 511 : void XMLShapeImportHelper::shapeWithZIndexAdded( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >&, sal_Int32 nZIndex )
983 : : {
984 [ + - ]: 511 : if( mpImpl->mpSortContext)
985 : : {
986 : : ZOrderHint aNewHint;
987 : 511 : aNewHint.nIs = mpImpl->mpSortContext->mnCurrentZ++;
988 : 511 : aNewHint.nShould = nZIndex;
989 : :
990 [ + + ]: 511 : if( nZIndex == -1 )
991 : : {
992 : : // don't care, so add to unsorted list
993 [ + - ]: 426 : mpImpl->mpSortContext->maUnsortedList.push_back(aNewHint);
994 : : }
995 : : else
996 : : {
997 : : // insert into sort list
998 [ + - ]: 511 : mpImpl->mpSortContext->maZOrderList.push_back(aNewHint);
999 : : }
1000 : : }
1001 : 511 : }
1002 : :
1003 : 0 : void XMLShapeImportHelper::addShapeConnection( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rConnectorShape,
1004 : : sal_Bool bStart,
1005 : : const rtl::OUString& rDestShapeId,
1006 : : sal_Int32 nDestGlueId )
1007 : : {
1008 [ # # ]: 0 : ConnectionHint aHint;
1009 [ # # ]: 0 : aHint.mxConnector = rConnectorShape;
1010 : 0 : aHint.bStart = bStart;
1011 : 0 : aHint.aDestShapeId = rDestShapeId;
1012 : 0 : aHint.nDestGlueId = nDestGlueId;
1013 : :
1014 [ # # ][ # # ]: 0 : mpImpl->maConnections.push_back( aHint );
1015 : 0 : }
1016 : :
1017 : 188 : void XMLShapeImportHelper::restoreConnections()
1018 : : {
1019 [ - + ]: 188 : if( !mpImpl->maConnections.empty() )
1020 : : {
1021 : 0 : uno::Any aAny;
1022 : :
1023 : 0 : const vector<ConnectionHint>::size_type nCount = mpImpl->maConnections.size();
1024 [ # # ]: 0 : for( vector<ConnectionHint>::size_type i = 0; i < nCount; i++ )
1025 : : {
1026 : 0 : ConnectionHint& rHint = mpImpl->maConnections[i];
1027 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xConnector( rHint.mxConnector, uno::UNO_QUERY );
1028 [ # # ]: 0 : if( xConnector.is() )
1029 : : {
1030 : : // #86637# remember line deltas
1031 : 0 : uno::Any aLine1Delta;
1032 : 0 : uno::Any aLine2Delta;
1033 : 0 : uno::Any aLine3Delta;
1034 [ # # ]: 0 : OUString aStr1(RTL_CONSTASCII_USTRINGPARAM("EdgeLine1Delta"));
1035 [ # # ]: 0 : OUString aStr2(RTL_CONSTASCII_USTRINGPARAM("EdgeLine2Delta"));
1036 [ # # ]: 0 : OUString aStr3(RTL_CONSTASCII_USTRINGPARAM("EdgeLine3Delta"));
1037 [ # # ][ # # ]: 0 : aLine1Delta = xConnector->getPropertyValue(aStr1);
1038 [ # # ][ # # ]: 0 : aLine2Delta = xConnector->getPropertyValue(aStr2);
1039 [ # # ][ # # ]: 0 : aLine3Delta = xConnector->getPropertyValue(aStr3);
1040 : :
1041 : : // #86637# simply setting these values WILL force the connector to do
1042 : : // an new layout promptly. So the line delta values have to be rescued
1043 : : // and restored around connector changes.
1044 : : uno::Reference< drawing::XShape > xShape(
1045 [ # # ][ # # ]: 0 : mrImporter.getInterfaceToIdentifierMapper().getReference( rHint.aDestShapeId ), uno::UNO_QUERY );
[ # # ]
1046 [ # # ]: 0 : if( xShape.is() )
1047 : : {
1048 [ # # ]: 0 : aAny <<= xShape;
1049 [ # # ][ # # ]: 0 : xConnector->setPropertyValue( rHint.bStart ? msStartShape : msEndShape, aAny );
[ # # ]
1050 : :
1051 [ # # ][ # # ]: 0 : sal_Int32 nGlueId = rHint.nDestGlueId < 4 ? rHint.nDestGlueId : getGluePointId( xShape, rHint.nDestGlueId );
1052 [ # # ]: 0 : aAny <<= nGlueId;
1053 [ # # ][ # # ]: 0 : xConnector->setPropertyValue( rHint.bStart ? msStartGluePointIndex : msEndGluePointIndex, aAny );
[ # # ]
1054 : : }
1055 : :
1056 : : // #86637# restore line deltas
1057 [ # # ][ # # ]: 0 : xConnector->setPropertyValue(aStr1, aLine1Delta );
1058 [ # # ][ # # ]: 0 : xConnector->setPropertyValue(aStr2, aLine2Delta );
1059 [ # # ][ # # ]: 0 : xConnector->setPropertyValue(aStr3, aLine3Delta );
1060 : : }
1061 : 0 : }
1062 : 0 : mpImpl->maConnections.clear();
1063 : : }
1064 : 188 : }
1065 : :
1066 : 6 : SvXMLImportPropertyMapper* XMLShapeImportHelper::CreateShapePropMapper( const uno::Reference< frame::XModel>& rModel, SvXMLImport& rImport )
1067 : : {
1068 [ + - ][ + - ]: 6 : UniReference< XMLPropertyHandlerFactory > xFactory = new XMLSdPropHdlFactory( rModel, rImport );
[ + - ]
1069 [ + - ][ + - ]: 6 : UniReference < XMLPropertySetMapper > xMapper = new XMLShapePropertySetMapper( xFactory );
[ + - ]
1070 [ + - ][ + - ]: 6 : SvXMLImportPropertyMapper* pResult = new SvXMLImportPropertyMapper( xMapper, rImport );
1071 : :
1072 : : // chain text attributes
1073 [ + - ][ + - ]: 6 : pResult->ChainImportMapper( XMLTextImportHelper::CreateParaExtPropMapper( rImport ) );
[ + - ][ + - ]
1074 [ + - ][ + - ]: 6 : return pResult;
1075 : : }
1076 : :
1077 : : /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
1078 : : the new glue point into the core. The saved mappings can be retrieved by getGluePointId() */
1079 : 507 : void XMLShapeImportHelper::addGluePointMapping( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape,
1080 : : sal_Int32 nSourceId, sal_Int32 nDestinnationId )
1081 : : {
1082 [ + - ]: 507 : if( mpPageContext )
1083 : 507 : mpPageContext->maShapeGluePointsMap[xShape][nSourceId] = nDestinnationId;
1084 : 507 : }
1085 : :
1086 : : /** moves all current DestinationId's by n */
1087 : 99 : void XMLShapeImportHelper::moveGluePointMapping( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, const sal_Int32 n )
1088 : : {
1089 [ + - ]: 99 : if( mpPageContext )
1090 : : {
1091 [ + - ]: 99 : ShapeGluePointsMap::iterator aShapeIter( mpPageContext->maShapeGluePointsMap.find( xShape ) );
1092 [ - + ]: 99 : if( aShapeIter != mpPageContext->maShapeGluePointsMap.end() )
1093 : : {
1094 : 0 : GluePointIdMap::iterator aShapeIdIter = (*aShapeIter).second.begin();
1095 : 0 : GluePointIdMap::iterator aShapeIdEnd = (*aShapeIter).second.end();
1096 [ # # ][ # # ]: 99 : while ( aShapeIdIter != aShapeIdEnd )
1097 : : {
1098 [ # # ][ # # ]: 0 : if ( (*aShapeIdIter).second != -1 )
1099 [ # # ]: 0 : (*aShapeIdIter).second += n;
1100 [ # # ]: 0 : ++aShapeIdIter;
1101 : : }
1102 : : }
1103 : : }
1104 : 99 : }
1105 : :
1106 : : /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
1107 : : inserting the new glue point into the core. The mapping must be initialized first with addGluePointMapping() */
1108 : 0 : sal_Int32 XMLShapeImportHelper::getGluePointId( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, sal_Int32 nSourceId )
1109 : : {
1110 [ # # ]: 0 : if( mpPageContext )
1111 : : {
1112 [ # # ]: 0 : ShapeGluePointsMap::iterator aShapeIter( mpPageContext->maShapeGluePointsMap.find( xShape ) );
1113 [ # # ]: 0 : if( aShapeIter != mpPageContext->maShapeGluePointsMap.end() )
1114 : : {
1115 [ # # ]: 0 : GluePointIdMap::iterator aIdIter = (*aShapeIter).second.find(nSourceId);
1116 [ # # ][ # # ]: 0 : if( aIdIter != (*aShapeIter).second.end() )
1117 [ # # ]: 0 : return (*aIdIter).second;
1118 : : }
1119 : : }
1120 : :
1121 : 0 : return -1;
1122 : : }
1123 : :
1124 : : /** this method must be calling before the first shape is imported for the given page */
1125 : 188 : void XMLShapeImportHelper::startPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes )
1126 : : {
1127 : 188 : XMLShapeImportPageContextImpl* pOldContext = mpPageContext;
1128 [ + - ]: 188 : mpPageContext = new XMLShapeImportPageContextImpl();
1129 : 188 : mpPageContext->mpNext = pOldContext;
1130 : 188 : mpPageContext->mxShapes = rShapes;
1131 : 188 : }
1132 : :
1133 : : /** this method must be calling after the last shape is imported for the given page */
1134 : 188 : void XMLShapeImportHelper::endPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >&
1135 : : #ifdef DBG_UTIL
1136 : : rShapes
1137 : : #endif
1138 : : )
1139 : : {
1140 : : DBG_ASSERT( mpPageContext && (mpPageContext->mxShapes == rShapes), "wrong call to endPage(), no startPage called or wrong page" );
1141 [ - + ]: 188 : if( NULL == mpPageContext )
1142 : 188 : return;
1143 : :
1144 : 188 : restoreConnections();
1145 : :
1146 : 188 : XMLShapeImportPageContextImpl* pNextContext = mpPageContext->mpNext;
1147 [ + - ]: 188 : delete mpPageContext;
1148 : 188 : mpPageContext = pNextContext;
1149 : : }
1150 : :
1151 : : // #88546#
1152 : : /** defines if the import should increment the progress bar or not */
1153 : 56 : void XMLShapeImportHelper::enableHandleProgressBar( sal_Bool bEnable )
1154 : : {
1155 : 56 : mpImpl->mbHandleProgressBar = bEnable;
1156 : 56 : }
1157 : :
1158 : 506 : sal_Bool XMLShapeImportHelper::IsHandleProgressBarEnabled() const
1159 : : {
1160 : 506 : return mpImpl->mbHandleProgressBar;
1161 : : }
1162 : :
1163 : : /** queries the capability of the current model to create presentation shapes */
1164 : 262 : sal_Bool XMLShapeImportHelper::IsPresentationShapesSupported()
1165 : : {
1166 : 262 : return mpImpl->mbIsPresentationShapesSupported;
1167 : : }
1168 : :
1169 : 215 : const rtl::Reference< XMLTableImport >& XMLShapeImportHelper::GetShapeTableImport()
1170 : : {
1171 [ + + ]: 215 : if( !mxShapeTableImport.is() )
1172 : : {
1173 [ + - ][ + - ]: 14 : rtl::Reference< XMLPropertyHandlerFactory > xFactory( new XMLSdPropHdlFactory( mrImporter.GetModel(), mrImporter ) );
[ + - ]
1174 [ + - ][ + - ]: 14 : rtl::Reference< XMLPropertySetMapper > xPropertySetMapper( new XMLShapePropertySetMapper( xFactory.get() ) );
[ + - ][ + - ]
[ + - ]
1175 [ + - ][ + - ]: 14 : mxShapeTableImport = new XMLTableImport( mrImporter, xPropertySetMapper, xFactory );
[ + - ][ + - ]
[ + - ]
1176 : : }
1177 : :
1178 : 215 : return mxShapeTableImport;
1179 : : }
1180 : :
1181 : 0 : void SvXMLShapeContext::setHyperlink( const OUString& rHyperlink )
1182 : : {
1183 : 0 : msHyperlink = rHyperlink;
1184 : 0 : }
1185 : :
1186 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|