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