1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shapeimport.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <tools/debug.hxx>
36 #include <com/sun/star/text/PositionLayoutDir.hpp>
37 #include <com/sun/star/chart/XChartDocument.hpp>
39 #include "unointerfacetouniqueidentifiermapper.hxx"
43 #ifndef _XMLOFF_SHAPEIMPORT_HXX
44 #include <xmloff/shapeimport.hxx>
46 #include <xmloff/xmltkmap.hxx>
47 #include "xmlnmspe.hxx"
48 #include <xmloff/xmltoken.hxx>
49 #include "ximpstyl.hxx"
50 #include "ximpshap.hxx"
51 #include "sdpropls.hxx"
52 #include <xmloff/xmlprmap.hxx>
53 #include "ximp3dscene.hxx"
54 #include "ximp3dobject.hxx"
55 #include "ximpgrp.hxx"
56 #include "ximplink.hxx"
61 using ::rtl::OUString
;
62 using ::rtl::OUStringBuffer
;
64 using namespace ::std
;
65 using namespace ::com::sun::star
;
66 using namespace ::xmloff::token
;
68 //////////////////////////////////////////////////////////////////////////////
72 bool operator()(const sal_Int32 p
, sal_Int32 q
) const
78 typedef std::map
<sal_Int32
,com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>,ltint32
> IdShapeMap
;
82 com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
> mxConnector
;
84 OUString aDestShapeId
;
85 sal_Int32 nDestGlueId
;
88 struct XShapeCompareHelper
90 bool operator()(com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
> x1
,
91 com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
> x2
) const
93 return x1
.get() < x2
.get();
97 /** this map store all glue point id mappings for shapes that had user defined glue points. This
98 is needed because on insertion the glue points will get a new and unique id */
99 typedef std::map
<sal_Int32
,sal_Int32
,ltint32
> GluePointIdMap
;
100 typedef std::map
< com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>, GluePointIdMap
, XShapeCompareHelper
> ShapeGluePointsMap
;
102 /** this struct is created for each startPage() call and stores information that is needed during
103 import of shapes for one page. Since pages could be nested ( notes pages inside impress ) there
104 is a pointer so one can build up a stack of this structs */
105 struct XMLShapeImportPageContextImpl
107 ShapeGluePointsMap maShapeGluePointsMap
;
109 uno::Reference
< drawing::XShapes
> mxShapes
;
111 struct XMLShapeImportPageContextImpl
* mpNext
;
114 /** this class is to enable adding members to the XMLShapeImportHelper without getting incompatible */
115 struct XMLShapeImportHelperImpl
117 // context for sorting shapes
118 ShapeSortContext
* mpSortContext
;
120 IdShapeMap maShapeIds
;
122 std::vector
<ConnectionHint
> maConnections
;
124 // #88546# possibility to swich progress bar handling on/off
125 sal_Bool mbHandleProgressBar
;
127 // stores the capability of the current model to create presentation shapes
128 sal_Bool mbIsPresentationShapesSupported
;
131 //////////////////////////////////////////////////////////////////////////////
133 XMLShapeImportHelper::XMLShapeImportHelper(
134 SvXMLImport
& rImporter
,
135 const uno::Reference
< frame::XModel
>& rModel
,
136 SvXMLImportPropertyMapper
*pExtMapper
)
137 : mpPageContext(NULL
),
140 mpPropertySetMapper(0L),
141 mpPresPagePropsMapper(0L),
143 mpAutoStylesContext(0L),
144 mpGroupShapeElemTokenMap(0L),
145 mpFrameShapeElemTokenMap(0L),
146 mp3DSceneShapeElemTokenMap(0L),
147 mp3DObjectAttrTokenMap(0L),
148 mp3DPolygonBasedAttrTokenMap(0L),
149 mp3DCubeObjectAttrTokenMap(0L),
150 mp3DSphereObjectAttrTokenMap(0L),
151 mp3DSceneShapeAttrTokenMap(0L),
152 mp3DLightAttrTokenMap(0L),
153 mpPathShapeAttrTokenMap(0L),
154 mpPolygonShapeAttrTokenMap(0L),
155 msStartShape(RTL_CONSTASCII_USTRINGPARAM("StartShape")),
156 msEndShape(RTL_CONSTASCII_USTRINGPARAM("EndShape")),
157 msStartGluePointIndex(RTL_CONSTASCII_USTRINGPARAM("StartGluePointIndex")),
158 msEndGluePointIndex(RTL_CONSTASCII_USTRINGPARAM("EndGluePointIndex")),
160 mrImporter( rImporter
)
162 mpImpl
= new XMLShapeImportHelperImpl();
163 mpImpl
->mpSortContext
= 0;
165 // #88546# init to FALSE
166 mpImpl
->mbHandleProgressBar
= sal_False
;
168 mpSdPropHdlFactory
= new XMLSdPropHdlFactory( rModel
, rImporter
);
170 // set lock to avoid deletion
171 mpSdPropHdlFactory
->acquire();
173 // construct PropertySetMapper
174 UniReference
< XMLPropertySetMapper
> xMapper
= new XMLShapePropertySetMapper(mpSdPropHdlFactory
);
175 mpPropertySetMapper
= new SvXMLImportPropertyMapper( xMapper
, rImporter
);
176 // set lock to avoid deletion
177 mpPropertySetMapper
->acquire();
181 UniReference
< SvXMLImportPropertyMapper
> xExtMapper( pExtMapper
);
182 mpPropertySetMapper
->ChainImportMapper( xExtMapper
);
185 // chain text attributes
186 mpPropertySetMapper
->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(rImporter
));
187 mpPropertySetMapper
->ChainImportMapper(XMLTextImportHelper::CreateParaDefaultExtPropMapper(rImporter
));
190 // chain form attributes
191 const UniReference< SvXMLImportPropertyMapper> xFormMapper( rImporter.GetFormImport()->getStylePropertyMapper().getBodyPtr() );
192 mpPropertySetMapper->ChainImportMapper(xFormMapper);
195 // construct PresPagePropsMapper
196 xMapper
= new XMLPropertySetMapper((XMLPropertyMapEntry
*)aXMLSDPresPageProps
, mpSdPropHdlFactory
);
197 mpPresPagePropsMapper
= new SvXMLImportPropertyMapper( xMapper
, rImporter
);
198 if(mpPresPagePropsMapper
)
200 // set lock to avoid deletion
201 mpPresPagePropsMapper
->acquire();
204 uno::Reference
< lang::XServiceInfo
> xInfo( rImporter
.GetModel(), uno::UNO_QUERY
);
205 const OUString
aSName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument") );
206 mpImpl
->mbIsPresentationShapesSupported
= xInfo
.is() && xInfo
->supportsService( aSName
);
209 //////////////////////////////////////////////////////////////////////////////
211 XMLShapeImportHelper::~XMLShapeImportHelper()
213 DBG_ASSERT( mpImpl
->maConnections
.empty(), "XMLShapeImportHelper::restoreConnections() was not called!" );
215 // cleanup factory, decrease refcount. Should lead to destruction.
216 if(mpSdPropHdlFactory
)
218 mpSdPropHdlFactory
->release();
219 mpSdPropHdlFactory
= 0L;
222 // cleanup mapper, decrease refcount. Should lead to destruction.
223 if(mpPropertySetMapper
)
225 mpPropertySetMapper
->release();
226 mpPropertySetMapper
= 0L;
229 // cleanup presPage mapper, decrease refcount. Should lead to destruction.
230 if(mpPresPagePropsMapper
)
232 mpPresPagePropsMapper
->release();
233 mpPresPagePropsMapper
= 0L;
236 if(mpGroupShapeElemTokenMap
) delete mpGroupShapeElemTokenMap
;
237 if(mpFrameShapeElemTokenMap
) delete mpFrameShapeElemTokenMap
;
239 if(mpShapeAttrTokenMap) delete mpShapeAttrTokenMap;
240 if(mpRectShapeAttrTokenMap) delete mpRectShapeAttrTokenMap;
241 if(mpLineShapeAttrTokenMap) delete mpLineShapeAttrTokenMap;
242 if(mpEllipseShapeAttrTokenMap) delete mpEllipseShapeAttrTokenMap;
243 if(mpTextBoxShapeAttrTokenMap) delete mpTextBoxShapeAttrTokenMap;
244 if(mpControlShapeAttrTokenMap) delete mpControlShapeAttrTokenMap;
245 if(mpPageShapeAttrTokenMap) delete mpPageShapeAttrTokenMap;
246 if(mpGraphicObjectShapeAttrTokenMap) delete mpGraphicObjectShapeAttrTokenMap;
248 if(mpPolygonShapeAttrTokenMap
) delete mpPolygonShapeAttrTokenMap
;
249 if(mpPathShapeAttrTokenMap
) delete mpPathShapeAttrTokenMap
;
250 if(mp3DSceneShapeElemTokenMap
) delete mp3DSceneShapeElemTokenMap
;
251 if(mp3DObjectAttrTokenMap
) delete mp3DObjectAttrTokenMap
;
252 if(mp3DPolygonBasedAttrTokenMap
) delete mp3DPolygonBasedAttrTokenMap
;
253 if(mp3DCubeObjectAttrTokenMap
) delete mp3DCubeObjectAttrTokenMap
;
254 if(mp3DSphereObjectAttrTokenMap
) delete mp3DSphereObjectAttrTokenMap
;
255 if(mp3DSceneShapeAttrTokenMap
) delete mp3DSceneShapeAttrTokenMap
;
256 if(mp3DLightAttrTokenMap
) delete mp3DLightAttrTokenMap
;
258 // Styles or AutoStyles context?
261 mpStylesContext
->Clear();
262 mpStylesContext
->ReleaseRef();
265 if(mpAutoStylesContext
)
267 mpAutoStylesContext
->Clear();
268 mpAutoStylesContext
->ReleaseRef();
274 //////////////////////////////////////////////////////////////////////////////
278 const SvXMLTokenMap
& XMLShapeImportHelper::GetGroupShapeElemTokenMap()
280 if(!mpGroupShapeElemTokenMap
)
282 static __FAR_DATA SvXMLTokenMapEntry aGroupShapeElemTokenMap
[] =
284 { XML_NAMESPACE_DRAW
, XML_G
, XML_TOK_GROUP_GROUP
},
285 { XML_NAMESPACE_DRAW
, XML_RECT
, XML_TOK_GROUP_RECT
},
286 { XML_NAMESPACE_DRAW
, XML_LINE
, XML_TOK_GROUP_LINE
},
287 { XML_NAMESPACE_DRAW
, XML_CIRCLE
, XML_TOK_GROUP_CIRCLE
},
288 { XML_NAMESPACE_DRAW
, XML_ELLIPSE
, XML_TOK_GROUP_ELLIPSE
},
289 { XML_NAMESPACE_DRAW
, XML_POLYGON
, XML_TOK_GROUP_POLYGON
},
290 { XML_NAMESPACE_DRAW
, XML_POLYLINE
, XML_TOK_GROUP_POLYLINE
},
291 { XML_NAMESPACE_DRAW
, XML_PATH
, XML_TOK_GROUP_PATH
},
293 { XML_NAMESPACE_DRAW
, XML_CONTROL
, XML_TOK_GROUP_CONTROL
},
294 { XML_NAMESPACE_DRAW
, XML_CONNECTOR
, XML_TOK_GROUP_CONNECTOR
},
295 { XML_NAMESPACE_DRAW
, XML_MEASURE
, XML_TOK_GROUP_MEASURE
},
296 { XML_NAMESPACE_DRAW
, XML_PAGE_THUMBNAIL
, XML_TOK_GROUP_PAGE
},
297 { XML_NAMESPACE_DRAW
, XML_CAPTION
, XML_TOK_GROUP_CAPTION
},
299 { XML_NAMESPACE_CHART
, XML_CHART
, XML_TOK_GROUP_CHART
},
300 { XML_NAMESPACE_DR3D
, XML_SCENE
, XML_TOK_GROUP_3DSCENE
},
302 { XML_NAMESPACE_DRAW
, XML_FRAME
, XML_TOK_GROUP_FRAME
},
303 { XML_NAMESPACE_DRAW
, XML_CUSTOM_SHAPE
, XML_TOK_GROUP_CUSTOM_SHAPE
},
305 { XML_NAMESPACE_DRAW
, XML_CUSTOM_SHAPE
, XML_TOK_GROUP_CUSTOM_SHAPE
},
306 { XML_NAMESPACE_OFFICE
, XML_ANNOTATION
, XML_TOK_GROUP_ANNOTATION
},
307 { XML_NAMESPACE_DRAW
, XML_A
, XML_TOK_GROUP_A
},
312 mpGroupShapeElemTokenMap
= new SvXMLTokenMap(aGroupShapeElemTokenMap
);
313 } // if(!mpGroupShapeElemTokenMap)
315 return *mpGroupShapeElemTokenMap
;
318 const SvXMLTokenMap
& XMLShapeImportHelper::GetFrameShapeElemTokenMap()
320 if(!mpFrameShapeElemTokenMap
)
322 static __FAR_DATA SvXMLTokenMapEntry aFrameShapeElemTokenMap
[] =
324 { XML_NAMESPACE_DRAW
, XML_TEXT_BOX
, XML_TOK_FRAME_TEXT_BOX
},
325 { XML_NAMESPACE_DRAW
, XML_IMAGE
, XML_TOK_FRAME_IMAGE
},
326 { XML_NAMESPACE_DRAW
, XML_OBJECT
, XML_TOK_FRAME_OBJECT
},
327 { XML_NAMESPACE_DRAW
, XML_OBJECT_OLE
, XML_TOK_FRAME_OBJECT_OLE
},
328 { XML_NAMESPACE_DRAW
, XML_PLUGIN
, XML_TOK_FRAME_PLUGIN
},
329 { XML_NAMESPACE_DRAW
, XML_FLOATING_FRAME
, XML_TOK_FRAME_FLOATING_FRAME
},
330 { XML_NAMESPACE_DRAW
, XML_APPLET
, XML_TOK_FRAME_APPLET
},
331 { XML_NAMESPACE_TABLE
, XML_TABLE
, XML_TOK_FRAME_TABLE
},
335 mpFrameShapeElemTokenMap
= new SvXMLTokenMap(aFrameShapeElemTokenMap
);
336 } // if(!mpFrameShapeElemTokenMap)
338 return *mpFrameShapeElemTokenMap
;
341 //////////////////////////////////////////////////////////////////////////////
344 const SvXMLTokenMap
& XMLShapeImportHelper::Get3DSceneShapeElemTokenMap()
346 if(!mp3DSceneShapeElemTokenMap
)
348 static __FAR_DATA SvXMLTokenMapEntry a3DSceneShapeElemTokenMap
[] =
350 { XML_NAMESPACE_DR3D
, XML_SCENE
, XML_TOK_3DSCENE_3DSCENE
},
351 { XML_NAMESPACE_DR3D
, XML_CUBE
, XML_TOK_3DSCENE_3DCUBE
},
352 { XML_NAMESPACE_DR3D
, XML_SPHERE
, XML_TOK_3DSCENE_3DSPHERE
},
353 { XML_NAMESPACE_DR3D
, XML_ROTATE
, XML_TOK_3DSCENE_3DLATHE
},
354 { XML_NAMESPACE_DR3D
, XML_EXTRUDE
, XML_TOK_3DSCENE_3DEXTRUDE
},
358 mp3DSceneShapeElemTokenMap
= new SvXMLTokenMap(a3DSceneShapeElemTokenMap
);
359 } // if(!mp3DSceneShapeElemTokenMap)
361 return *mp3DSceneShapeElemTokenMap
;
364 //////////////////////////////////////////////////////////////////////////////
367 const SvXMLTokenMap& XMLShapeImportHelper::GetShapeAttrTokenMap()
369 if(!mpShapeAttrTokenMap)
371 static __FAR_DATA SvXMLTokenMapEntry aShapeAttrTokenMap[] =
373 { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_SHAPE_NAME },
374 { XML_NAMESPACE_DRAW, XML_STYLE_NAME, XML_TOK_SHAPE_DRAWSTYLE_NAME_GRAPHICS },
375 { XML_NAMESPACE_PRESENTATION, XML_CLASS, XML_TOK_SHAPE_PRESENTATION_CLASS },
376 { XML_NAMESPACE_PRESENTATION, XML_STYLE_NAME, XML_TOK_SHAPE_DRAWSTYLE_NAME_PRESENTATION },
377 { XML_NAMESPACE_SVG, XML_TRANSFORM, XML_TOK_SHAPE_TRANSFORM },
378 { XML_NAMESPACE_PRESENTATION, XML_PLACEHOLDER, XML_TOK_SHAPE_IS_PLACEHOLDER },
379 { XML_NAMESPACE_PRESENTATION, XML_USER_TRANSFORMED, XML_TOK_SHAPE_IS_USER_TRANSFORMED },
383 mpShapeAttrTokenMap = new SvXMLTokenMap(aShapeAttrTokenMap);
386 return *mpShapeAttrTokenMap;
389 //////////////////////////////////////////////////////////////////////////////
392 const SvXMLTokenMap
& XMLShapeImportHelper::Get3DObjectAttrTokenMap()
394 if(!mp3DObjectAttrTokenMap
)
396 static __FAR_DATA SvXMLTokenMapEntry a3DObjectAttrTokenMap
[] =
398 { XML_NAMESPACE_DRAW
, XML_STYLE_NAME
, XML_TOK_3DOBJECT_DRAWSTYLE_NAME
},
399 { XML_NAMESPACE_DR3D
, XML_TRANSFORM
, XML_TOK_3DOBJECT_TRANSFORM
},
403 mp3DObjectAttrTokenMap
= new SvXMLTokenMap(a3DObjectAttrTokenMap
);
404 } // if(!mp3DObjectAttrTokenMap)
406 return *mp3DObjectAttrTokenMap
;
409 //////////////////////////////////////////////////////////////////////////////
412 const SvXMLTokenMap
& XMLShapeImportHelper::Get3DPolygonBasedAttrTokenMap()
414 if(!mp3DPolygonBasedAttrTokenMap
)
416 static __FAR_DATA SvXMLTokenMapEntry a3DPolygonBasedAttrTokenMap
[] =
418 { XML_NAMESPACE_SVG
, XML_VIEWBOX
, XML_TOK_3DPOLYGONBASED_VIEWBOX
},
419 { XML_NAMESPACE_SVG
, XML_D
, XML_TOK_3DPOLYGONBASED_D
},
423 mp3DPolygonBasedAttrTokenMap
= new SvXMLTokenMap(a3DPolygonBasedAttrTokenMap
);
424 } // if(!mp3DPolygonBasedAttrTokenMap)
426 return *mp3DPolygonBasedAttrTokenMap
;
429 //////////////////////////////////////////////////////////////////////////////
432 const SvXMLTokenMap
& XMLShapeImportHelper::Get3DCubeObjectAttrTokenMap()
434 if(!mp3DCubeObjectAttrTokenMap
)
436 static __FAR_DATA SvXMLTokenMapEntry a3DCubeObjectAttrTokenMap
[] =
438 { XML_NAMESPACE_DR3D
, XML_MIN_EDGE
, XML_TOK_3DCUBEOBJ_MINEDGE
},
439 { XML_NAMESPACE_DR3D
, XML_MAX_EDGE
, XML_TOK_3DCUBEOBJ_MAXEDGE
},
443 mp3DCubeObjectAttrTokenMap
= new SvXMLTokenMap(a3DCubeObjectAttrTokenMap
);
444 } // if(!mp3DCubeObjectAttrTokenMap)
446 return *mp3DCubeObjectAttrTokenMap
;
449 //////////////////////////////////////////////////////////////////////////////
452 const SvXMLTokenMap
& XMLShapeImportHelper::Get3DSphereObjectAttrTokenMap()
454 if(!mp3DSphereObjectAttrTokenMap
)
456 static __FAR_DATA SvXMLTokenMapEntry a3DSphereObjectAttrTokenMap
[] =
458 { XML_NAMESPACE_DR3D
, XML_CENTER
, XML_TOK_3DSPHEREOBJ_CENTER
},
459 { XML_NAMESPACE_DR3D
, XML_SIZE
, XML_TOK_3DSPHEREOBJ_SIZE
},
463 mp3DSphereObjectAttrTokenMap
= new SvXMLTokenMap(a3DSphereObjectAttrTokenMap
);
464 } // if(!mp3DSphereObjectAttrTokenMap)
466 return *mp3DSphereObjectAttrTokenMap
;
469 //////////////////////////////////////////////////////////////////////////////
472 const SvXMLTokenMap& XMLShapeImportHelper::GetRectShapeAttrTokenMap()
474 if(!mpRectShapeAttrTokenMap)
476 static __FAR_DATA SvXMLTokenMapEntry aRectShapeAttrTokenMap[] =
478 { XML_NAMESPACE_SVG, XML_X, XML_TOK_RECTSHAPE_X },
479 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_RECTSHAPE_Y },
480 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_RECTSHAPE_WIDTH },
481 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_RECTSHAPE_HEIGHT },
482 { XML_NAMESPACE_DRAW, XML_CORNER_RADIUS, XML_TOK_RECTSHAPE_CORNER_RADIUS },
486 mpRectShapeAttrTokenMap = new SvXMLTokenMap(aRectShapeAttrTokenMap);
489 return *mpRectShapeAttrTokenMap;
492 //////////////////////////////////////////////////////////////////////////////
495 const SvXMLTokenMap& XMLShapeImportHelper::GetLineShapeAttrTokenMap()
497 if(!mpLineShapeAttrTokenMap)
499 static __FAR_DATA SvXMLTokenMapEntry aLineShapeAttrTokenMap[] =
501 { XML_NAMESPACE_SVG, XML_X1, XML_TOK_LINESHAPE_X1 },
502 { XML_NAMESPACE_SVG, XML_Y1, XML_TOK_LINESHAPE_Y1 },
503 { XML_NAMESPACE_SVG, XML_X2, XML_TOK_LINESHAPE_X2 },
504 { XML_NAMESPACE_SVG, XML_Y2, XML_TOK_LINESHAPE_Y2 },
508 mpLineShapeAttrTokenMap = new SvXMLTokenMap(aLineShapeAttrTokenMap);
511 return *mpLineShapeAttrTokenMap;
514 //////////////////////////////////////////////////////////////////////////////
517 const SvXMLTokenMap& XMLShapeImportHelper::GetEllipseShapeAttrTokenMap()
519 if(!mpEllipseShapeAttrTokenMap)
521 static __FAR_DATA SvXMLTokenMapEntry aEllipseShapeAttrTokenMap[] =
523 { XML_NAMESPACE_SVG, XML_RX, XML_TOK_ELLIPSESHAPE_RX },
524 { XML_NAMESPACE_SVG, XML_RY, XML_TOK_ELLIPSESHAPE_RY },
525 { XML_NAMESPACE_SVG, XML_CX, XML_TOK_ELLIPSESHAPE_CX },
526 { XML_NAMESPACE_SVG, XML_CY, XML_TOK_ELLIPSESHAPE_CY },
527 { XML_NAMESPACE_SVG, XML_R, XML_TOK_ELLIPSESHAPE_R },
531 mpEllipseShapeAttrTokenMap = new SvXMLTokenMap(aEllipseShapeAttrTokenMap);
534 return *mpEllipseShapeAttrTokenMap;
537 //////////////////////////////////////////////////////////////////////////////
540 const SvXMLTokenMap
& XMLShapeImportHelper::GetPolygonShapeAttrTokenMap()
542 if(!mpPolygonShapeAttrTokenMap
)
544 static __FAR_DATA SvXMLTokenMapEntry aPolygonShapeAttrTokenMap
[] =
546 { XML_NAMESPACE_SVG
, XML_VIEWBOX
, XML_TOK_POLYGONSHAPE_VIEWBOX
},
547 { XML_NAMESPACE_DRAW
, XML_POINTS
, XML_TOK_POLYGONSHAPE_POINTS
},
551 mpPolygonShapeAttrTokenMap
= new SvXMLTokenMap(aPolygonShapeAttrTokenMap
);
552 } // if(!mpPolygonShapeAttrTokenMap)
554 return *mpPolygonShapeAttrTokenMap
;
557 //////////////////////////////////////////////////////////////////////////////
560 const SvXMLTokenMap
& XMLShapeImportHelper::GetPathShapeAttrTokenMap()
562 if(!mpPathShapeAttrTokenMap
)
564 static __FAR_DATA SvXMLTokenMapEntry aPathShapeAttrTokenMap
[] =
566 { XML_NAMESPACE_SVG
, XML_VIEWBOX
, XML_TOK_PATHSHAPE_VIEWBOX
},
567 { XML_NAMESPACE_SVG
, XML_D
, XML_TOK_PATHSHAPE_D
},
571 mpPathShapeAttrTokenMap
= new SvXMLTokenMap(aPathShapeAttrTokenMap
);
572 } // if(!mpPathShapeAttrTokenMap)
574 return *mpPathShapeAttrTokenMap
;
577 //////////////////////////////////////////////////////////////////////////////
580 const SvXMLTokenMap& XMLShapeImportHelper::GetTextBoxShapeAttrTokenMap()
582 if(!mpTextBoxShapeAttrTokenMap)
584 static __FAR_DATA SvXMLTokenMapEntry aTextBoxShapeAttrTokenMap[] =
586 { XML_NAMESPACE_SVG, XML_X, XML_TOK_TEXTBOXSHAPE_X },
587 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_TEXTBOXSHAPE_Y },
588 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_TEXTBOXSHAPE_WIDTH },
589 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_TEXTBOXSHAPE_HEIGHT },
593 mpTextBoxShapeAttrTokenMap = new SvXMLTokenMap(aTextBoxShapeAttrTokenMap);
596 return *mpTextBoxShapeAttrTokenMap;
599 //////////////////////////////////////////////////////////////////////////////
602 const SvXMLTokenMap& XMLShapeImportHelper::GetControlShapeAttrTokenMap()
604 if(!mpControlShapeAttrTokenMap)
606 static __FAR_DATA SvXMLTokenMapEntry aControlShapeAttrTokenMap[] =
608 { XML_NAMESPACE_SVG, XML_X, XML_TOK_CONTROLSHAPE_X },
609 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_CONTROLSHAPE_Y },
610 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_CONTROLSHAPE_WIDTH },
611 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_CONTROLSHAPE_HEIGHT },
615 mpControlShapeAttrTokenMap = new SvXMLTokenMap(aControlShapeAttrTokenMap);
618 return *mpControlShapeAttrTokenMap;
621 //////////////////////////////////////////////////////////////////////////////
624 const SvXMLTokenMap
& XMLShapeImportHelper::Get3DSceneShapeAttrTokenMap()
626 if(!mp3DSceneShapeAttrTokenMap
)
628 static __FAR_DATA SvXMLTokenMapEntry a3DSceneShapeAttrTokenMap
[] =
630 { XML_NAMESPACE_DR3D
, XML_TRANSFORM
, XML_TOK_3DSCENESHAPE_TRANSFORM
},
631 { XML_NAMESPACE_DR3D
, XML_VRP
, XML_TOK_3DSCENESHAPE_VRP
},
632 { XML_NAMESPACE_DR3D
, XML_VPN
, XML_TOK_3DSCENESHAPE_VPN
},
633 { XML_NAMESPACE_DR3D
, XML_VUP
, XML_TOK_3DSCENESHAPE_VUP
},
634 { XML_NAMESPACE_DR3D
, XML_PROJECTION
, XML_TOK_3DSCENESHAPE_PROJECTION
},
635 { XML_NAMESPACE_DR3D
, XML_DISTANCE
, XML_TOK_3DSCENESHAPE_DISTANCE
},
636 { XML_NAMESPACE_DR3D
, XML_FOCAL_LENGTH
, XML_TOK_3DSCENESHAPE_FOCAL_LENGTH
},
637 { XML_NAMESPACE_DR3D
, XML_SHADOW_SLANT
, XML_TOK_3DSCENESHAPE_SHADOW_SLANT
},
638 { XML_NAMESPACE_DR3D
, XML_SHADE_MODE
, XML_TOK_3DSCENESHAPE_SHADE_MODE
},
639 { XML_NAMESPACE_DR3D
, XML_AMBIENT_COLOR
, XML_TOK_3DSCENESHAPE_AMBIENT_COLOR
},
640 { XML_NAMESPACE_DR3D
, XML_LIGHTING_MODE
, XML_TOK_3DSCENESHAPE_LIGHTING_MODE
},
644 mp3DSceneShapeAttrTokenMap
= new SvXMLTokenMap(a3DSceneShapeAttrTokenMap
);
645 } // if(!mp3DSceneShapeAttrTokenMap)
647 return *mp3DSceneShapeAttrTokenMap
;
650 //////////////////////////////////////////////////////////////////////////////
653 const SvXMLTokenMap
& XMLShapeImportHelper::Get3DLightAttrTokenMap()
655 if(!mp3DLightAttrTokenMap
)
657 static __FAR_DATA SvXMLTokenMapEntry a3DLightAttrTokenMap
[] =
659 { XML_NAMESPACE_DR3D
, XML_DIFFUSE_COLOR
, XML_TOK_3DLIGHT_DIFFUSE_COLOR
},
660 { XML_NAMESPACE_DR3D
, XML_DIRECTION
, XML_TOK_3DLIGHT_DIRECTION
},
661 { XML_NAMESPACE_DR3D
, XML_ENABLED
, XML_TOK_3DLIGHT_ENABLED
},
662 { XML_NAMESPACE_DR3D
, XML_SPECULAR
, XML_TOK_3DLIGHT_SPECULAR
},
666 mp3DLightAttrTokenMap
= new SvXMLTokenMap(a3DLightAttrTokenMap
);
667 } // if(!mp3DLightAttrTokenMap)
669 return *mp3DLightAttrTokenMap
;
672 //////////////////////////////////////////////////////////////////////////////
675 const SvXMLTokenMap& XMLShapeImportHelper::GetPageShapeAttrTokenMap()
677 if(!mpPageShapeAttrTokenMap)
679 static __FAR_DATA SvXMLTokenMapEntry aPageShapeAttrTokenMap[] =
681 { XML_NAMESPACE_SVG, XML_X, XML_TOK_PAGESHAPE_X },
682 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_PAGESHAPE_Y },
683 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_PAGESHAPE_WIDTH },
684 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_PAGESHAPE_HEIGHT },
688 mpPageShapeAttrTokenMap = new SvXMLTokenMap(aPageShapeAttrTokenMap);
691 return *mpPageShapeAttrTokenMap;
694 //////////////////////////////////////////////////////////////////////////////
697 const SvXMLTokenMap& XMLShapeImportHelper::GetGraphicObjectShapeAttrTokenMap()
699 if(!mpGraphicObjectShapeAttrTokenMap)
701 static __FAR_DATA SvXMLTokenMapEntry aGraphicObjectShapeAttrTokenMap[] =
703 { XML_NAMESPACE_SVG, XML_X, XML_TOK_GOSHAPE_X },
704 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_GOSHAPE_Y },
705 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_GOSHAPE_WIDTH },
706 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_GOSHAPE_HEIGHT },
707 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_GOSHAPE_URL },
711 mpGraphicObjectShapeAttrTokenMap = new SvXMLTokenMap(aGraphicObjectShapeAttrTokenMap);
714 return *mpGraphicObjectShapeAttrTokenMap;
717 //////////////////////////////////////////////////////////////////////////////
719 SvXMLShapeContext
* XMLShapeImportHelper::Create3DSceneChildContext(
720 SvXMLImport
& rImport
,
722 const OUString
& rLocalName
,
723 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
724 uno::Reference
< drawing::XShapes
>& rShapes
)
726 SdXMLShapeContext
*pContext
= 0L;
730 const SvXMLTokenMap
& rTokenMap
= Get3DSceneShapeElemTokenMap();
731 switch(rTokenMap
.Get(p_nPrefix
, rLocalName
))
733 case XML_TOK_3DSCENE_3DSCENE
:
735 // dr3d:3dscene inside dr3d:3dscene context
736 pContext
= new SdXML3DSceneShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
739 case XML_TOK_3DSCENE_3DCUBE
:
741 // dr3d:3dcube inside dr3d:3dscene context
742 pContext
= new SdXML3DCubeObjectShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
745 case XML_TOK_3DSCENE_3DSPHERE
:
747 // dr3d:3dsphere inside dr3d:3dscene context
748 pContext
= new SdXML3DSphereObjectShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
751 case XML_TOK_3DSCENE_3DLATHE
:
753 // dr3d:3dlathe inside dr3d:3dscene context
754 pContext
= new SdXML3DLatheObjectShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
757 case XML_TOK_3DSCENE_3DEXTRUDE
:
759 // dr3d:3dextrude inside dr3d:3dscene context
760 pContext
= new SdXML3DExtrudeObjectShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
766 // now parse the attribute list and call the child context for each unknown attribute
767 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
768 for(sal_Int16
a(0); a
< nAttrCount
; a
++)
770 const OUString
& rAttrName
= xAttrList
->getNameByIndex(a
);
772 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().GetKeyByAttrName(rAttrName
, &aLocalName
);
773 const OUString
aValue( xAttrList
->getValueByIndex(a
) );
775 pContext
->processAttribute( nPrefix
, aLocalName
, aValue
);
781 //////////////////////////////////////////////////////////////////////////////
783 void XMLShapeImportHelper::SetStylesContext(SvXMLStylesContext
* pNew
)
785 mpStylesContext
= pNew
;
786 mpStylesContext
->AddRef();
789 //////////////////////////////////////////////////////////////////////////////
791 void XMLShapeImportHelper::SetAutoStylesContext(SvXMLStylesContext
* pNew
)
793 mpAutoStylesContext
= pNew
;
794 mpAutoStylesContext
->AddRef();
797 //////////////////////////////////////////////////////////////////////////////
799 SvXMLShapeContext
* XMLShapeImportHelper::CreateGroupChildContext(
800 SvXMLImport
& rImport
,
802 const OUString
& rLocalName
,
803 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
,
804 uno::Reference
< drawing::XShapes
>& rShapes
,
805 sal_Bool bTemporaryShape
)
807 SdXMLShapeContext
*pContext
= 0L;
809 const SvXMLTokenMap
& rTokenMap
= GetGroupShapeElemTokenMap();
810 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
812 switch(rTokenMap
.Get(p_nPrefix
, rLocalName
))
814 case XML_TOK_GROUP_GROUP
:
816 // draw:g inside group context (RECURSIVE)
817 pContext
= new SdXMLGroupShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
820 case XML_TOK_GROUP_3DSCENE
:
822 // dr3d:3dscene inside group context
823 pContext
= new SdXML3DSceneShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
826 case XML_TOK_GROUP_RECT
:
828 // draw:rect inside group context
829 pContext
= new SdXMLRectShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
832 case XML_TOK_GROUP_LINE
:
834 // draw:line inside group context
835 pContext
= new SdXMLLineShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
838 case XML_TOK_GROUP_CIRCLE
:
839 case XML_TOK_GROUP_ELLIPSE
:
841 // draw:circle or draw:ellipse inside group context
842 pContext
= new SdXMLEllipseShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
845 case XML_TOK_GROUP_POLYGON
:
846 case XML_TOK_GROUP_POLYLINE
:
848 // draw:polygon or draw:polyline inside group context
849 pContext
= new SdXMLPolygonShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
,
850 rTokenMap
.Get(p_nPrefix
, rLocalName
) == XML_TOK_GROUP_POLYGON
? TRUE
: FALSE
, bTemporaryShape
);
853 case XML_TOK_GROUP_PATH
:
855 // draw:path inside group context
856 pContext
= new SdXMLPathShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
859 case XML_TOK_GROUP_FRAME
:
861 // text:text-box inside group context
862 pContext
= new SdXMLFrameShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
865 case XML_TOK_GROUP_CONTROL
:
867 // draw:control inside group context
868 pContext
= new SdXMLControlShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
871 case XML_TOK_GROUP_CONNECTOR
:
873 // draw:connector inside group context
874 pContext
= new SdXMLConnectorShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
877 case XML_TOK_GROUP_MEASURE
:
879 // draw:measure inside group context
880 pContext
= new SdXMLMeasureShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
883 case XML_TOK_GROUP_PAGE
:
885 // draw:page inside group context
886 pContext
= new SdXMLPageShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
889 case XML_TOK_GROUP_CAPTION
:
890 case XML_TOK_GROUP_ANNOTATION
:
892 // draw:caption inside group context
893 pContext
= new SdXMLCaptionShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
896 case XML_TOK_GROUP_CHART
:
898 // chart:chart inside group context
899 pContext
= new SdXMLChartShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
);
902 case XML_TOK_GROUP_CUSTOM_SHAPE
:
905 pContext
= new SdXMLCustomShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
908 case XML_TOK_GROUP_A
:
910 return new SdXMLShapeLinkContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
);
912 // add other shapes here...
914 return NULL
; // no shape context...
917 // now parse the attribute list and call the child context for each unknown attribute
918 for(sal_Int16
a(0); a
< nAttrCount
; a
++)
920 const OUString
& rAttrName
= xAttrList
->getNameByIndex(a
);
922 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().GetKeyByAttrName(rAttrName
, &aLocalName
);
923 const OUString
aValue( xAttrList
->getValueByIndex(a
) );
925 pContext
->processAttribute( nPrefix
, aLocalName
, aValue
);
931 // This method is called from SdXMLFrameContext to create children of drawe:frame
932 SvXMLShapeContext
* XMLShapeImportHelper::CreateFrameChildContext(
933 SvXMLImport
& rImport
,
935 const OUString
& rLocalName
,
936 const uno::Reference
< xml::sax::XAttributeList
>& rAttrList
,
937 uno::Reference
< drawing::XShapes
>& rShapes
,
938 const uno::Reference
< xml::sax::XAttributeList
>& rFrameAttrList
)
940 SdXMLShapeContext
*pContext
= 0L;
942 const SvXMLTokenMap
& rTokenMap
= GetFrameShapeElemTokenMap();
944 SvXMLAttributeList
*pAttrList
= new SvXMLAttributeList( rAttrList
);
945 if( rFrameAttrList
.is() )
946 pAttrList
->AppendAttributeList( rFrameAttrList
);
947 uno::Reference
< xml::sax::XAttributeList
> xAttrList
= pAttrList
;
950 switch(rTokenMap
.Get(p_nPrefix
, rLocalName
))
952 case XML_TOK_FRAME_TEXT_BOX
:
954 // text:text-box inside group context
955 pContext
= new SdXMLTextBoxShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
958 case XML_TOK_FRAME_IMAGE
:
960 // office:image inside group context
961 pContext
= new SdXMLGraphicObjectShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
964 case XML_TOK_FRAME_OBJECT
:
965 case XML_TOK_FRAME_OBJECT_OLE
:
967 // draw:object or draw:object_ole
968 pContext
= new SdXMLObjectShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
971 case XML_TOK_FRAME_TABLE
:
973 // draw:object or draw:object_ole
974 if( rImport
.IsTableShapeSupported() )
975 pContext
= new SdXMLTableShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
);
979 case XML_TOK_FRAME_PLUGIN
:
982 pContext
= new SdXMLPluginShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
985 case XML_TOK_FRAME_FLOATING_FRAME
:
987 // draw:floating-frame
988 pContext
= new SdXMLFloatingFrameShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
991 case XML_TOK_FRAME_APPLET
:
994 pContext
= new SdXMLAppletShapeContext( rImport
, p_nPrefix
, rLocalName
, xAttrList
, rShapes
, sal_False
);
997 // add other shapes here...
1004 // now parse the attribute list and call the child context for each unknown attribute
1005 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1006 for(sal_Int16
a(0); a
< nAttrCount
; a
++)
1008 const OUString
& rAttrName
= xAttrList
->getNameByIndex(a
);
1009 OUString aLocalName
;
1010 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().GetKeyByAttrName(rAttrName
, &aLocalName
);
1011 const OUString
aValue( xAttrList
->getValueByIndex(a
) );
1013 pContext
->processAttribute( nPrefix
, aLocalName
, aValue
);
1020 SvXMLImportContext
*XMLShapeImportHelper::CreateFrameChildContext(
1021 SvXMLImportContext
*pThisContext
,
1023 const OUString
& rLocalName
,
1024 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
1026 SvXMLImportContext
* pContext
= NULL
;
1028 SdXMLFrameShapeContext
*pFrameContext
= PTR_CAST( SdXMLFrameShapeContext
, pThisContext
);
1030 pContext
= pFrameContext
->CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
1036 /** this function is called whenever the implementation classes like to add this new
1037 shape to the given XShapes.
1039 void XMLShapeImportHelper::addShape( uno::Reference
< drawing::XShape
>& rShape
,
1040 const uno::Reference
< xml::sax::XAttributeList
>&,
1041 uno::Reference
< drawing::XShapes
>& rShapes
)
1043 if( rShape
.is() && rShapes
.is() )
1045 // add new shape to parent
1046 rShapes
->add( rShape
);
1050 /** this function is called whenever the implementation classes have finished importing
1051 a shape to the given XShapes. The shape is already inserted into its XShapes and
1052 all properties and styles are set.
1054 void XMLShapeImportHelper::finishShape(
1055 com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& rShape
,
1056 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>&,
1057 com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>&)
1059 // --> OD 2004-08-10 #i28749#, #i36248# - set property <PositionLayoutDir>
1060 // to <PositionInHoriL2R>, if it exists and the import states that
1061 // the shape positioning attributes are in horizontal left-to-right
1062 // layout. This is the case for the OpenOffice.org file format.
1063 // This setting is done for Writer documents, because the property
1064 // only exists at service com::sun::star::text::Shape - the Writer
1065 // UNO service for shapes.
1066 // The value indicates that the positioning attributes are given
1067 // in horizontal left-to-right layout. The property is evaluated
1068 // during the first positioning of the shape in order to convert
1069 // the shape position given in the OpenOffice.org file format to
1070 // the one for the OASIS Open Office file format.
1071 uno::Reference
< beans::XPropertySet
> xPropSet(rShape
, uno::UNO_QUERY
);
1072 if ( xPropSet
.is() )
1074 if ( mrImporter
.IsShapePositionInHoriL2R() &&
1075 xPropSet
->getPropertySetInfo()->hasPropertyByName(
1076 OUString(RTL_CONSTASCII_USTRINGPARAM("PositionLayoutDir"))) )
1078 uno::Any aPosLayoutDir
;
1079 aPosLayoutDir
<<= text::PositionLayoutDir::PositionInHoriL2R
;
1080 xPropSet
->setPropertyValue(
1081 OUString(RTL_CONSTASCII_USTRINGPARAM("PositionLayoutDir")),
1088 // helper functions for z-order sorting
1094 int operator<(const ZOrderHint
& rComp
) const { return nShould
< rComp
.nShould
; }
1097 class ShapeSortContext
1100 uno::Reference
< drawing::XShapes
> mxShapes
;
1101 list
<ZOrderHint
> maZOrderList
;
1102 list
<ZOrderHint
> maUnsortedList
;
1104 sal_Int32 mnCurrentZ
;
1105 ShapeSortContext
* mpParentContext
;
1106 const OUString msZOrder
;
1108 ShapeSortContext( uno::Reference
< drawing::XShapes
>& rShapes
, ShapeSortContext
* pParentContext
= NULL
);
1110 void moveShape( sal_Int32 nSourcePos
, sal_Int32 nDestPos
);
1113 ShapeSortContext::ShapeSortContext( uno::Reference
< drawing::XShapes
>& rShapes
, ShapeSortContext
* pParentContext
)
1114 : mxShapes( rShapes
), mnCurrentZ( 0 ), mpParentContext( pParentContext
),
1115 msZOrder(RTL_CONSTASCII_USTRINGPARAM("ZOrder"))
1119 void ShapeSortContext::moveShape( sal_Int32 nSourcePos
, sal_Int32 nDestPos
)
1121 uno::Any
aAny( mxShapes
->getByIndex( nSourcePos
) );
1122 uno::Reference
< beans::XPropertySet
> xPropSet
;
1125 if( xPropSet
.is() && xPropSet
->getPropertySetInfo()->hasPropertyByName( msZOrder
) )
1128 xPropSet
->setPropertyValue( msZOrder
, aAny
);
1130 list
<ZOrderHint
>::iterator aIter
= maZOrderList
.begin();
1131 list
<ZOrderHint
>::iterator aEnd
= maZOrderList
.end();
1133 while( aIter
!= aEnd
)
1135 if( (*aIter
).nIs
< nSourcePos
)
1137 DBG_ASSERT( (*aIter
).nIs
>= nDestPos
, "Shape sorting failed" );
1143 aIter
= maUnsortedList
.begin();
1144 aEnd
= maUnsortedList
.end();
1146 while( aIter
!= aEnd
)
1148 if( (*aIter
).nIs
< nSourcePos
)
1150 DBG_ASSERT( (*aIter
).nIs
>= nDestPos
, "shape sorting failed" );
1158 void XMLShapeImportHelper::pushGroupForSorting( uno::Reference
< drawing::XShapes
>& rShapes
)
1160 mpImpl
->mpSortContext
= new ShapeSortContext( rShapes
, mpImpl
->mpSortContext
);
1163 void XMLShapeImportHelper::popGroupAndSort()
1165 DBG_ASSERT( mpImpl
->mpSortContext
, "No context to sort!" );
1166 if( mpImpl
->mpSortContext
== NULL
)
1171 list
<ZOrderHint
>& rZList
= mpImpl
->mpSortContext
->maZOrderList
;
1172 list
<ZOrderHint
>& rUnsortedList
= mpImpl
->mpSortContext
->maUnsortedList
;
1175 if( !rZList
.empty() )
1177 // only do something if we have shapes to sort
1179 // check if there are more shapes than inserted with ::shapeWithZIndexAdded()
1180 // This can happen if there where already shapes on the page before import
1181 // Since the writer may delete some of this shapes during import, we need
1182 // to do this here and not in our c'tor anymore
1184 // check if we have more shapes than we know of
1185 sal_Int32 nCount
= mpImpl
->mpSortContext
->mxShapes
->getCount();
1187 nCount
-= rZList
.size();
1188 nCount
-= rUnsortedList
.size();
1193 // first update offsets of added shapes
1194 list
<ZOrderHint
>::iterator
aIter( rZList
.begin() );
1195 while( aIter
!= rZList
.end() )
1196 (*aIter
++).nIs
+= nCount
;
1198 aIter
= rUnsortedList
.begin();
1199 while( aIter
!= rUnsortedList
.end() )
1200 (*aIter
++).nIs
+= nCount
;
1202 // second add the already existing shapes in the unsorted list
1203 ZOrderHint aNewHint
;
1209 aNewHint
.nIs
= nCount
;
1210 aNewHint
.nShould
= -1;
1212 rUnsortedList
.insert(rUnsortedList
.begin(), aNewHint
);
1217 // sort z ordered shapes
1220 // this is the current index, all shapes before that
1221 // index are finished
1222 sal_Int32 nIndex
= 0;
1223 while( !rZList
.empty() )
1225 list
<ZOrderHint
>::iterator
aIter( rZList
.begin() );
1227 while( nIndex
< (*aIter
).nShould
&& !rUnsortedList
.empty() )
1229 ZOrderHint
aGapHint( *rUnsortedList
.begin() );
1230 rUnsortedList
.pop_front();
1232 mpImpl
->mpSortContext
->moveShape( aGapHint
.nIs
, nIndex
++ );
1235 if( (*aIter
).nIs
!= nIndex
)
1236 mpImpl
->mpSortContext
->moveShape( (*aIter
).nIs
, nIndex
);
1243 catch( uno::Exception
& )
1245 DBG_ERROR("exception while sorting shapes, sorting failed!");
1248 // put parent on top and delete current context, were done
1249 ShapeSortContext
* pContext
= mpImpl
->mpSortContext
;
1250 mpImpl
->mpSortContext
= pContext
->mpParentContext
;
1254 void XMLShapeImportHelper::shapeWithZIndexAdded( com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>&, sal_Int32 nZIndex
)
1256 if( mpImpl
->mpSortContext
)
1258 ZOrderHint aNewHint
;
1259 aNewHint
.nIs
= mpImpl
->mpSortContext
->mnCurrentZ
++;
1260 aNewHint
.nShould
= nZIndex
;
1264 // don't care, so add to unsorted list
1265 mpImpl
->mpSortContext
->maUnsortedList
.push_back(aNewHint
);
1269 // insert into sort list
1270 mpImpl
->mpSortContext
->maZOrderList
.push_back(aNewHint
);
1275 void XMLShapeImportHelper::addShapeConnection( com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& rConnectorShape
,
1277 const rtl::OUString
& rDestShapeId
,
1278 sal_Int32 nDestGlueId
)
1280 ConnectionHint aHint
;
1281 aHint
.mxConnector
= rConnectorShape
;
1282 aHint
.bStart
= bStart
;
1283 aHint
.aDestShapeId
= rDestShapeId
;
1284 aHint
.nDestGlueId
= nDestGlueId
;
1286 mpImpl
->maConnections
.push_back( aHint
);
1289 void XMLShapeImportHelper::restoreConnections()
1291 if( !mpImpl
->maConnections
.empty() )
1295 const vector
<ConnectionHint
>::size_type nCount
= mpImpl
->maConnections
.size();
1296 for( vector
<ConnectionHint
>::size_type i
= 0; i
< nCount
; i
++ )
1298 ConnectionHint
& rHint
= mpImpl
->maConnections
[i
];
1299 uno::Reference
< beans::XPropertySet
> xConnector( rHint
.mxConnector
, uno::UNO_QUERY
);
1300 if( xConnector
.is() )
1302 // #86637# remember line deltas
1303 uno::Any aLine1Delta
;
1304 uno::Any aLine2Delta
;
1305 uno::Any aLine3Delta
;
1306 OUString
aStr1(RTL_CONSTASCII_USTRINGPARAM("EdgeLine1Delta"));
1307 OUString
aStr2(RTL_CONSTASCII_USTRINGPARAM("EdgeLine2Delta"));
1308 OUString
aStr3(RTL_CONSTASCII_USTRINGPARAM("EdgeLine3Delta"));
1309 aLine1Delta
= xConnector
->getPropertyValue(aStr1
);
1310 aLine2Delta
= xConnector
->getPropertyValue(aStr2
);
1311 aLine3Delta
= xConnector
->getPropertyValue(aStr3
);
1313 // #86637# simply setting these values WILL force the connector to do
1314 // an new layout promptly. So the line delta values have to be rescued
1315 // and restored around connector changes.
1316 uno::Reference
< drawing::XShape
> xShape(
1317 mrImporter
.getInterfaceToIdentifierMapper().getReference( rHint
.aDestShapeId
), uno::UNO_QUERY
);
1321 xConnector
->setPropertyValue( rHint
.bStart
? msStartShape
: msEndShape
, aAny
);
1323 sal_Int32 nGlueId
= rHint
.nDestGlueId
< 4 ? rHint
.nDestGlueId
: getGluePointId( xShape
, rHint
.nDestGlueId
);
1325 xConnector
->setPropertyValue( rHint
.bStart
? msStartGluePointIndex
: msEndGluePointIndex
, aAny
);
1328 // #86637# restore line deltas
1329 xConnector
->setPropertyValue(aStr1
, aLine1Delta
);
1330 xConnector
->setPropertyValue(aStr2
, aLine2Delta
);
1331 xConnector
->setPropertyValue(aStr3
, aLine3Delta
);
1334 mpImpl
->maConnections
.clear();
1338 SvXMLImportPropertyMapper
* XMLShapeImportHelper::CreateShapePropMapper( const uno::Reference
< frame::XModel
>& rModel
, SvXMLImport
& rImport
)
1340 UniReference
< XMLPropertyHandlerFactory
> xFactory
= new XMLSdPropHdlFactory( rModel
, rImport
);
1341 UniReference
< XMLPropertySetMapper
> xMapper
= new XMLShapePropertySetMapper( xFactory
);
1342 SvXMLImportPropertyMapper
* pResult
= new SvXMLImportPropertyMapper( xMapper
, rImport
);
1344 // chain text attributes
1345 pResult
->ChainImportMapper( XMLTextImportHelper::CreateParaExtPropMapper( rImport
) );
1349 /** creates a shape property set mapper that can be used for non shape elements.
1350 Only current feature is that the ShapeUserDefinedAttributes property is not included in this one. */
1351 SvXMLImportPropertyMapper
* XMLShapeImportHelper::CreateExternalShapePropMapper( const uno::Reference
< frame::XModel
>& rModel
, SvXMLImport
& rImport
)
1353 UniReference
< XMLPropertyHandlerFactory
> xFactory
= new XMLSdPropHdlFactory( rModel
, rImport
);
1354 UniReference
< XMLPropertySetMapper
> xMapper
= new XMLShapePropertySetMapper( xFactory
, 1 );
1355 SvXMLImportPropertyMapper
* pResult
= new SvXMLImportPropertyMapper( xMapper
, rImport
);
1357 // chain text attributes
1358 pResult
->ChainImportMapper( XMLTextImportHelper::CreateParaExtPropMapper( rImport
) );
1362 /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
1363 the new glue point into the core. The saved mappings can be retrieved by getGluePointId() */
1364 void XMLShapeImportHelper::addGluePointMapping( com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
,
1365 sal_Int32 nSourceId
, sal_Int32 nDestinnationId
)
1368 mpPageContext
->maShapeGluePointsMap
[xShape
][nSourceId
] = nDestinnationId
;
1371 /** moves all current DestinationId's by n */
1372 void XMLShapeImportHelper::moveGluePointMapping( const com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
, const sal_Int32 n
)
1376 ShapeGluePointsMap::iterator
aShapeIter( mpPageContext
->maShapeGluePointsMap
.find( xShape
) );
1377 if( aShapeIter
!= mpPageContext
->maShapeGluePointsMap
.end() )
1379 GluePointIdMap::iterator aShapeIdIter
= (*aShapeIter
).second
.begin();
1380 GluePointIdMap::iterator aShapeIdEnd
= (*aShapeIter
).second
.end();
1381 while ( aShapeIdIter
!= aShapeIdEnd
)
1383 if ( (*aShapeIdIter
).second
!= -1 )
1384 (*aShapeIdIter
).second
+= n
;
1391 /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
1392 inserting the new glue point into the core. The mapping must be initialized first with addGluePointMapping() */
1393 sal_Int32
XMLShapeImportHelper::getGluePointId( com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
, sal_Int32 nSourceId
)
1397 ShapeGluePointsMap::iterator
aShapeIter( mpPageContext
->maShapeGluePointsMap
.find( xShape
) );
1398 if( aShapeIter
!= mpPageContext
->maShapeGluePointsMap
.end() )
1400 GluePointIdMap::iterator aIdIter
= (*aShapeIter
).second
.find(nSourceId
);
1401 if( aIdIter
!= (*aShapeIter
).second
.end() )
1402 return (*aIdIter
).second
;
1409 /** this method must be calling before the first shape is imported for the given page */
1410 void XMLShapeImportHelper::startPage( com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
)
1412 XMLShapeImportPageContextImpl
* pOldContext
= mpPageContext
;
1413 mpPageContext
= new XMLShapeImportPageContextImpl();
1414 mpPageContext
->mpNext
= pOldContext
;
1415 mpPageContext
->mxShapes
= rShapes
;
1418 /** this method must be calling after the last shape is imported for the given page */
1419 void XMLShapeImportHelper::endPage( com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>&
1425 DBG_ASSERT( mpPageContext
&& (mpPageContext
->mxShapes
== rShapes
), "wrong call to endPage(), no startPage called or wrong page" );
1426 if( NULL
== mpPageContext
)
1429 restoreConnections();
1431 XMLShapeImportPageContextImpl
* pNextContext
= mpPageContext
->mpNext
;
1432 delete mpPageContext
;
1433 mpPageContext
= pNextContext
;
1437 /** defines if the import should increment the progress bar or not */
1438 void XMLShapeImportHelper::enableHandleProgressBar( sal_Bool bEnable
)
1440 mpImpl
->mbHandleProgressBar
= bEnable
;
1443 sal_Bool
XMLShapeImportHelper::IsHandleProgressBarEnabled() const
1445 return mpImpl
->mbHandleProgressBar
;
1448 /** queries the capability of the current model to create presentation shapes */
1449 sal_Bool
XMLShapeImportHelper::IsPresentationShapesSupported()
1451 return mpImpl
->mbIsPresentationShapesSupported
;
1454 const rtl::Reference
< XMLTableImport
>& XMLShapeImportHelper::GetShapeTableImport()
1456 if( !mxShapeTableImport
.is() )
1458 rtl::Reference
< XMLPropertyHandlerFactory
> xFactory( new XMLSdPropHdlFactory( mrImporter
.GetModel(), mrImporter
) );
1459 rtl::Reference
< XMLPropertySetMapper
> xPropertySetMapper( new XMLShapePropertySetMapper( xFactory
.get() ) );
1460 mxShapeTableImport
= new XMLTableImport( mrImporter
, xPropertySetMapper
, xFactory
);
1463 return mxShapeTableImport
;
1466 void SvXMLShapeContext::setHyperlink( const OUString
& rHyperlink
)
1468 msHyperlink
= rHyperlink
;