1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_XMLOFF_SHAPEIMPORT_HXX
21 #define INCLUDED_XMLOFF_SHAPEIMPORT_HXX
23 #include <sal/config.h>
24 #include <xmloff/dllapi.h>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/frame/XModel.hpp>
27 #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 #include <com/sun/star/drawing/XShapes.hpp>
29 #include <com/sun/star/drawing/HomogenMatrix.hpp>
30 #include <com/sun/star/drawing/ProjectionMode.hpp>
31 #include <com/sun/star/drawing/ShadeMode.hpp>
32 #include <salhelper/simplereferenceobject.hxx>
33 #include <xmloff/xmlictxt.hxx>
35 #include <xmloff/table/XMLTableImport.hxx>
36 #include <basegfx/vector/b3dvector.hxx>
40 class SvXMLImportContext
;
42 class SvXMLStylesContext
;
43 class XMLSdPropHdlFactory
;
44 class XMLPropertySetMapper
;
45 class SvXMLImportPropertyMapper
;
49 enum SdXMLGroupShapeElemTokenMap
55 XML_TOK_GROUP_ELLIPSE
,
56 XML_TOK_GROUP_POLYGON
,
57 XML_TOK_GROUP_POLYLINE
,
60 XML_TOK_GROUP_CONTROL
,
61 XML_TOK_GROUP_CONNECTOR
,
62 XML_TOK_GROUP_MEASURE
,
64 XML_TOK_GROUP_CAPTION
,
67 XML_TOK_GROUP_3DSCENE
,
71 XML_TOK_GROUP_CUSTOM_SHAPE
,
73 XML_TOK_GROUP_ANNOTATION
,
80 enum SdXMLFrameShapeElemTokenMap
82 XML_TOK_FRAME_TEXT_BOX
,
85 XML_TOK_FRAME_OBJECT_OLE
,
88 XML_TOK_FRAME_FLOATING_FRAME
,
95 enum SdXML3DSceneShapeElemTokenMap
97 XML_TOK_3DSCENE_3DSCENE
,
98 XML_TOK_3DSCENE_3DCUBE
,
99 XML_TOK_3DSCENE_3DSPHERE
,
100 XML_TOK_3DSCENE_3DLATHE
,
101 XML_TOK_3DSCENE_3DEXTRUDE
,
106 enum SdXMLShapeAttrTokenMap
109 XML_TOK_SHAPE_DRAWSTYLE_NAME_GRAPHICS
,
110 XML_TOK_SHAPE_PRESENTATION_CLASS
,
111 XML_TOK_SHAPE_DRAWSTYLE_NAME_PRESENTATION
,
112 XML_TOK_SHAPE_TRANSFORM
,
113 XML_TOK_SHAPE_IS_PLACEHOLDER
,
114 XML_TOK_SHAPE_IS_USER_TRANSFORMED
117 enum SdXML3DObjectAttrTokenMap
119 XML_TOK_3DOBJECT_DRAWSTYLE_NAME
,
120 XML_TOK_3DOBJECT_TRANSFORM
123 enum SdXML3DPolygonBasedAttrTokenMap
125 XML_TOK_3DPOLYGONBASED_VIEWBOX
,
126 XML_TOK_3DPOLYGONBASED_D
129 enum SdXML3DCubeObjectAttrTokenMap
131 XML_TOK_3DCUBEOBJ_MINEDGE
,
132 XML_TOK_3DCUBEOBJ_MAXEDGE
135 enum SdXML3DSphereObjectAttrTokenMap
137 XML_TOK_3DSPHEREOBJ_CENTER
,
138 XML_TOK_3DSPHEREOBJ_SIZE
141 enum SdXMLPolygonShapeAttrTokenMap
143 XML_TOK_POLYGONSHAPE_VIEWBOX
,
144 XML_TOK_POLYGONSHAPE_POINTS
147 enum SdXMLPathShapeAttrTokenMap
149 XML_TOK_PATHSHAPE_VIEWBOX
,
153 enum SdXML3DSceneShapeAttrTokenMap
155 XML_TOK_3DSCENESHAPE_TRANSFORM
,
156 XML_TOK_3DSCENESHAPE_VRP
,
157 XML_TOK_3DSCENESHAPE_VPN
,
158 XML_TOK_3DSCENESHAPE_VUP
,
159 XML_TOK_3DSCENESHAPE_PROJECTION
,
160 XML_TOK_3DSCENESHAPE_DISTANCE
,
161 XML_TOK_3DSCENESHAPE_FOCAL_LENGTH
,
162 XML_TOK_3DSCENESHAPE_SHADOW_SLANT
,
163 XML_TOK_3DSCENESHAPE_SHADE_MODE
,
164 XML_TOK_3DSCENESHAPE_AMBIENT_COLOR
,
165 XML_TOK_3DSCENESHAPE_LIGHTING_MODE
168 enum SdXML3DLightAttrTokenMap
170 XML_TOK_3DLIGHT_DIFFUSE_COLOR
,
171 XML_TOK_3DLIGHT_DIRECTION
,
172 XML_TOK_3DLIGHT_ENABLED
,
173 XML_TOK_3DLIGHT_SPECULAR
177 // dr3d:3dlight context
179 class SdXML3DLightContext
: public SvXMLImportContext
181 // local parameters which need to be read
182 sal_Int32 maDiffuseColor
;
183 ::basegfx::B3DVector maDirection
;
189 SvXMLImport
& rImport
,
191 const OUString
& rLName
,
192 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
193 virtual ~SdXML3DLightContext();
195 sal_Int32
GetDiffuseColor() { return maDiffuseColor
; }
196 const ::basegfx::B3DVector
& GetDirection() { return maDirection
; }
197 bool GetEnabled() { return mbEnabled
; }
198 bool GetSpecular() { return mbSpecular
; }
203 typedef ::std::vector
< SdXML3DLightContext
* > Imp3DLightList
;
205 class SdXML3DSceneAttributesHelper
208 SvXMLImport
& mrImport
;
210 // list for local light contexts
211 Imp3DLightList maList
;
213 // local parameters which need to be read
214 com::sun::star::drawing::HomogenMatrix mxHomMat
;
217 com::sun::star::drawing::ProjectionMode mxPrjMode
;
218 sal_Int32 mnDistance
;
219 sal_Int32 mnFocalLength
;
220 sal_Int32 mnShadowSlant
;
221 com::sun::star::drawing::ShadeMode mxShadeMode
;
222 sal_Int32 maAmbientColor
;
225 ::basegfx::B3DVector maVRP
;
226 ::basegfx::B3DVector maVPN
;
227 ::basegfx::B3DVector maVUP
;
233 SdXML3DSceneAttributesHelper( SvXMLImport
& rImporter
);
234 ~SdXML3DSceneAttributesHelper();
236 /** creates a 3d ligth context and adds it to the internal list for later processing */
237 SvXMLImportContext
* create3DLightContext( sal_uInt16 nPrfx
, const OUString
& rLName
, const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
239 /** this should be called for each scene attribute */
240 void processSceneAttribute( sal_uInt16 nPrefix
, const OUString
& rLocalName
, const OUString
& rValue
);
242 /** this sets the scene attributes at this propertyset */
243 void setSceneAttributes( const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
>& xPropSet
);
248 class SvXMLShapeContext
: public SvXMLImportContext
251 com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
> mxShape
;
252 bool mbTemporaryShape
;
253 OUString msHyperlink
;
256 SvXMLShapeContext( SvXMLImport
& rImp
, sal_uInt16 nPrfx
,
257 const OUString
& rLName
, bool bTemporaryShape
) : SvXMLImportContext( rImp
, nPrfx
, rLName
), mbTemporaryShape(bTemporaryShape
) {}
261 const com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& getShape() const { return mxShape
; }
263 void setHyperlink( const OUString
& rHyperlink
);
268 class ShapeSortContext
;
269 struct XMLShapeImportHelperImpl
;
270 struct XMLShapeImportPageContextImpl
;
272 class XMLOFF_DLLPUBLIC XMLShapeImportHelper
: public salhelper::SimpleReferenceObject
274 XMLShapeImportHelperImpl
* mpImpl
;
276 XMLShapeImportPageContextImpl
* mpPageContext
;
278 com::sun::star::uno::Reference
< com::sun::star::frame::XModel
> mxModel
;
280 // PropertySetMappers and factory
281 XMLSdPropHdlFactory
* mpSdPropHdlFactory
;
282 SvXMLImportPropertyMapper
* mpPropertySetMapper
;
283 SvXMLImportPropertyMapper
* mpPresPagePropsMapper
;
285 // contexts for Style and AutoStyle import
286 SvXMLStylesContext
* mpStylesContext
;
287 SvXMLStylesContext
* mpAutoStylesContext
;
289 // contexts for xShape contents TokenMaps
290 SvXMLTokenMap
* mpGroupShapeElemTokenMap
;
291 SvXMLTokenMap
* mpFrameShapeElemTokenMap
;
292 SvXMLTokenMap
* mp3DSceneShapeElemTokenMap
;
293 SvXMLTokenMap
* mp3DObjectAttrTokenMap
;
294 SvXMLTokenMap
* mp3DPolygonBasedAttrTokenMap
;
295 SvXMLTokenMap
* mp3DCubeObjectAttrTokenMap
;
296 SvXMLTokenMap
* mp3DSphereObjectAttrTokenMap
;
297 SvXMLTokenMap
* mp3DSceneShapeAttrTokenMap
;
298 SvXMLTokenMap
* mp3DLightAttrTokenMap
;
299 SvXMLTokenMap
* mpPathShapeAttrTokenMap
;
300 SvXMLTokenMap
* mpPolygonShapeAttrTokenMap
;
302 const OUString msStartShape
;
303 const OUString msEndShape
;
304 const OUString msStartGluePointIndex
;
305 const OUString msEndGluePointIndex
;
307 rtl::Reference
< XMLTableImport
> mxShapeTableImport
;
310 SvXMLImport
& mrImporter
;
313 XMLShapeImportHelper( SvXMLImport
& rImporter
,
314 const com::sun::star::uno::Reference
< com::sun::star::frame::XModel
>& rModel
,
315 SvXMLImportPropertyMapper
*pExtMapper
=0 );
317 virtual ~XMLShapeImportHelper();
319 SvXMLShapeContext
* CreateGroupChildContext(
320 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
321 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
322 com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
,
323 bool bTemporaryShape
= false);
325 SvXMLShapeContext
* CreateFrameChildContext(
326 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
327 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
328 com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
,
329 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xFrameAttrList
);
330 static SvXMLImportContext
* CreateFrameChildContext(
331 SvXMLImportContext
*pThisContext
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
332 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
334 SvXMLShapeContext
* Create3DSceneChildContext(
335 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
336 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
337 com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
);
339 const SvXMLTokenMap
& GetGroupShapeElemTokenMap();
340 const SvXMLTokenMap
& GetFrameShapeElemTokenMap();
341 const SvXMLTokenMap
& Get3DSceneShapeElemTokenMap();
342 const SvXMLTokenMap
& Get3DObjectAttrTokenMap();
343 const SvXMLTokenMap
& Get3DPolygonBasedAttrTokenMap();
344 const SvXMLTokenMap
& Get3DCubeObjectAttrTokenMap();
345 const SvXMLTokenMap
& Get3DSphereObjectAttrTokenMap();
346 const SvXMLTokenMap
& Get3DLightAttrTokenMap();
348 // Styles and AutoStyles contexts
349 SvXMLStylesContext
* GetStylesContext() const { return mpStylesContext
; }
350 void SetStylesContext(SvXMLStylesContext
* pNew
);
351 SvXMLStylesContext
* GetAutoStylesContext() const { return mpAutoStylesContext
; }
352 void SetAutoStylesContext(SvXMLStylesContext
* pNew
);
354 // get factories and mappers
355 SvXMLImportPropertyMapper
* GetPropertySetMapper() const { return mpPropertySetMapper
; }
356 SvXMLImportPropertyMapper
* GetPresPagePropsMapper() const { return mpPresPagePropsMapper
; }
358 // this function is called whenever the implementation classes like to add this new
359 // shape to the given XShapes.
360 virtual void addShape(
361 com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& rShape
,
362 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
363 com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
);
365 // this function is called whenever the implementation classes have finished importing
366 // a shape to the given XShapes. The shape is already inserted into its XShapes and
367 // all properties and styles are set.
368 virtual void finishShape(
369 com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& rShape
,
370 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
371 com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
);
373 // helper functions for z-order sorting
374 void pushGroupForSorting( com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
);
375 void popGroupAndSort();
377 void shapeWithZIndexAdded( com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& rShape
,
380 void addShapeConnection( com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& rConnectorShape
,
382 const OUString
& rDestShapeId
,
383 sal_Int32 nDestGlueId
);
385 /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
386 the new glue point into the core. The saved mappings can be retrieved by getGluePointId() */
387 void addGluePointMapping( com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
,
388 sal_Int32 nSourceId
, sal_Int32 nDestinnationId
);
390 /** find mapping for given DestinationID. This allows to extract the original draw:id imported with a draw:glue-point */
391 sal_Int32
findGluePointMapping(
392 const com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
,
393 sal_Int32 nDestinnationId
) const;
395 /** moves all current DestinationId's for rXShape by n */
396 void moveGluePointMapping( const com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
, const sal_Int32 n
);
398 /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
399 inserting the new glue point into the core. The mapping must be initialized first with addGluePointMapping() */
400 sal_Int32
getGluePointId( const com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
, sal_Int32 nSourceId
);
402 /** this method must be calling before the first shape is imported for the given page.
403 Calls to this method can be nested */
404 void startPage( com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
);
406 /** this method must be calling after the last shape is imported for the given page
407 Calls to this method can be nested */
408 void endPage( com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rShapes
);
410 void restoreConnections();
412 /** creates a property mapper for external chaining */
413 static SvXMLImportPropertyMapper
* CreateShapePropMapper(
414 const com::sun::star::uno::Reference
< com::sun::star::frame::XModel
>& rModel
, SvXMLImport
& rImport
);
417 /** defines if the import should increment the progress bar or not */
418 void enableHandleProgressBar( bool bEnable
= true );
419 bool IsHandleProgressBarEnabled() const;
421 /** queries the capability of the current model to create presentation shapes */
422 bool IsPresentationShapesSupported();
424 XMLSdPropHdlFactory
* GetSdPropHdlFactory() const { return mpSdPropHdlFactory
; }
426 const rtl::Reference
< XMLTableImport
>& GetShapeTableImport();
429 #endif // INCLUDED_XMLOFF_SHAPEIMPORT_HXX
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */