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>
41 class SvXMLImportContext
;
43 class SvXMLStylesContext
;
44 class XMLSdPropHdlFactory
;
45 class XMLPropertySetMapper
;
46 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 css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
);
193 virtual ~SdXML3DLightContext() override
;
195 sal_Int32
GetDiffuseColor() { return maDiffuseColor
; }
196 const ::basegfx::B3DVector
& GetDirection() { return maDirection
; }
197 bool GetEnabled() { return mbEnabled
; }
201 class SdXML3DSceneAttributesHelper
204 SvXMLImport
& mrImport
;
206 // list for local light contexts
207 ::std::vector
< rtl::Reference
< SdXML3DLightContext
> >
210 // local parameters which need to be read
211 css::drawing::HomogenMatrix mxHomMat
;
214 css::drawing::ProjectionMode mxPrjMode
;
215 sal_Int32 mnDistance
;
216 sal_Int32 mnFocalLength
;
217 sal_Int32 mnShadowSlant
;
218 css::drawing::ShadeMode mxShadeMode
;
219 sal_Int32 maAmbientColor
;
222 ::basegfx::B3DVector maVRP
;
223 ::basegfx::B3DVector maVPN
;
224 ::basegfx::B3DVector maVUP
;
230 SdXML3DSceneAttributesHelper( SvXMLImport
& rImporter
);
232 /** creates a 3d light context and adds it to the internal list for later processing */
233 SvXMLImportContext
* create3DLightContext( sal_uInt16 nPrfx
, const OUString
& rLName
, const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
);
235 /** this should be called for each scene attribute */
236 void processSceneAttribute( sal_uInt16 nPrefix
, const OUString
& rLocalName
, const OUString
& rValue
);
238 /** this sets the scene attributes at this propertyset */
239 void setSceneAttributes( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
243 class SvXMLShapeContext
: public SvXMLImportContext
246 css::uno::Reference
< css::drawing::XShape
> mxShape
;
247 bool mbTemporaryShape
;
248 OUString msHyperlink
;
251 SvXMLShapeContext( SvXMLImport
& rImp
, sal_uInt16 nPrfx
,
252 const OUString
& rLName
, bool bTemporaryShape
) : SvXMLImportContext( rImp
, nPrfx
, rLName
), mbTemporaryShape(bTemporaryShape
) {}
255 const css::uno::Reference
< css::drawing::XShape
>& getShape() const { return mxShape
; }
257 void setHyperlink( const OUString
& rHyperlink
);
261 class ShapeSortContext
;
262 struct XMLShapeImportHelperImpl
;
263 struct XMLShapeImportPageContextImpl
;
265 class XMLOFF_DLLPUBLIC XMLShapeImportHelper
: public salhelper::SimpleReferenceObject
267 std::unique_ptr
<XMLShapeImportHelperImpl
> mpImpl
;
269 std::shared_ptr
<XMLShapeImportPageContextImpl
> mpPageContext
;
271 // PropertySetMappers and factory
272 rtl::Reference
<XMLSdPropHdlFactory
> mpSdPropHdlFactory
;
273 rtl::Reference
<SvXMLImportPropertyMapper
> mpPropertySetMapper
;
274 rtl::Reference
<SvXMLImportPropertyMapper
> mpPresPagePropsMapper
;
276 // contexts for Style and AutoStyle import
277 rtl::Reference
<SvXMLStylesContext
> mxStylesContext
;
278 rtl::Reference
<SvXMLStylesContext
> mxAutoStylesContext
;
280 // contexts for xShape contents TokenMaps
281 std::unique_ptr
<SvXMLTokenMap
> mpGroupShapeElemTokenMap
;
282 std::unique_ptr
<SvXMLTokenMap
> mpFrameShapeElemTokenMap
;
283 std::unique_ptr
<SvXMLTokenMap
> mp3DSceneShapeElemTokenMap
;
284 std::unique_ptr
<SvXMLTokenMap
> mp3DObjectAttrTokenMap
;
285 std::unique_ptr
<SvXMLTokenMap
> mp3DPolygonBasedAttrTokenMap
;
286 std::unique_ptr
<SvXMLTokenMap
> mp3DCubeObjectAttrTokenMap
;
287 std::unique_ptr
<SvXMLTokenMap
> mp3DSphereObjectAttrTokenMap
;
288 std::unique_ptr
<SvXMLTokenMap
> mp3DLightAttrTokenMap
;
290 const OUString msStartShape
;
291 const OUString msEndShape
;
292 const OUString msStartGluePointIndex
;
293 const OUString msEndGluePointIndex
;
295 rtl::Reference
< XMLTableImport
> mxShapeTableImport
;
298 SvXMLImport
& mrImporter
;
301 XMLShapeImportHelper( SvXMLImport
& rImporter
,
302 const css::uno::Reference
< css::frame::XModel
>& rModel
,
303 SvXMLImportPropertyMapper
*pExtMapper
=nullptr );
305 virtual ~XMLShapeImportHelper() override
;
307 SvXMLShapeContext
* CreateGroupChildContext(
308 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
309 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
310 css::uno::Reference
< css::drawing::XShapes
>& rShapes
,
311 bool bTemporaryShape
= false);
313 SvXMLShapeContext
* CreateFrameChildContext(
314 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
315 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
316 css::uno::Reference
< css::drawing::XShapes
>& rShapes
,
317 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xFrameAttrList
);
318 static SvXMLImportContext
* CreateFrameChildContext(
319 SvXMLImportContext
*pThisContext
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
320 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
);
322 SvXMLShapeContext
* Create3DSceneChildContext(
323 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
324 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
325 css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
327 const SvXMLTokenMap
& GetGroupShapeElemTokenMap();
328 const SvXMLTokenMap
& GetFrameShapeElemTokenMap();
329 const SvXMLTokenMap
& Get3DSceneShapeElemTokenMap();
330 const SvXMLTokenMap
& Get3DObjectAttrTokenMap();
331 const SvXMLTokenMap
& Get3DPolygonBasedAttrTokenMap();
332 const SvXMLTokenMap
& Get3DCubeObjectAttrTokenMap();
333 const SvXMLTokenMap
& Get3DSphereObjectAttrTokenMap();
334 const SvXMLTokenMap
& Get3DLightAttrTokenMap();
336 // Styles and AutoStyles contexts
337 SvXMLStylesContext
* GetStylesContext() const { return mxStylesContext
.get(); }
338 void SetStylesContext(SvXMLStylesContext
* pNew
);
339 SvXMLStylesContext
* GetAutoStylesContext() const { return mxAutoStylesContext
.get(); }
340 void SetAutoStylesContext(SvXMLStylesContext
* pNew
);
342 // get factories and mappers
343 SvXMLImportPropertyMapper
* GetPropertySetMapper() const { return mpPropertySetMapper
.get(); }
344 SvXMLImportPropertyMapper
* GetPresPagePropsMapper() const { return mpPresPagePropsMapper
.get(); }
346 // this function is called whenever the implementation classes like to add this new
347 // shape to the given XShapes.
348 virtual void addShape(
349 css::uno::Reference
< css::drawing::XShape
>& rShape
,
350 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
351 css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
353 // this function is called whenever the implementation classes have finished importing
354 // a shape to the given XShapes. The shape is already inserted into its XShapes and
355 // all properties and styles are set.
356 virtual void finishShape(
357 css::uno::Reference
< css::drawing::XShape
>& rShape
,
358 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
359 css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
361 // helper functions for z-order sorting
362 void pushGroupForSorting( css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
363 void popGroupAndSort();
365 void shapeWithZIndexAdded( css::uno::Reference
< css::drawing::XShape
>& rShape
,
367 /// Updates the z-order of other shapes to be consistent again, needed due
368 /// to the removal of rShape.
369 void shapeRemoved(const css::uno::Reference
<css::drawing::XShape
>& rShape
);
371 void addShapeConnection( css::uno::Reference
< css::drawing::XShape
>& rConnectorShape
,
373 const OUString
& rDestShapeId
,
374 sal_Int32 nDestGlueId
);
376 /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
377 the new glue point into the core. The saved mappings can be retrieved by getGluePointId() */
378 void addGluePointMapping( css::uno::Reference
< css::drawing::XShape
>& xShape
,
379 sal_Int32 nSourceId
, sal_Int32 nDestinnationId
);
381 /** find mapping for given DestinationID. This allows to extract the original draw:id imported with a draw:glue-point */
382 sal_Int32
findGluePointMapping(
383 const css::uno::Reference
< css::drawing::XShape
>& xShape
,
384 sal_Int32 nDestinnationId
) const;
386 /** moves all current DestinationId's for rXShape by n */
387 void moveGluePointMapping( const css::uno::Reference
< css::drawing::XShape
>& xShape
, const sal_Int32 n
);
389 /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
390 inserting the new glue point into the core. The mapping must be initialized first with addGluePointMapping() */
391 sal_Int32
getGluePointId( const css::uno::Reference
< css::drawing::XShape
>& xShape
, sal_Int32 nSourceId
);
393 /** this method must be calling before the first shape is imported for the given page.
394 Calls to this method can be nested */
395 void startPage( css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
397 /** this method must be calling after the last shape is imported for the given page
398 Calls to this method can be nested */
399 void endPage( css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
401 void restoreConnections();
403 /** creates a property mapper for external chaining */
404 static SvXMLImportPropertyMapper
* CreateShapePropMapper(
405 const css::uno::Reference
< css::frame::XModel
>& rModel
, SvXMLImport
& rImport
);
407 /** defines if the import should increment the progress bar or not */
408 void enableHandleProgressBar();
409 bool IsHandleProgressBarEnabled() const;
411 /** queries the capability of the current model to create presentation shapes */
412 bool IsPresentationShapesSupported();
414 XMLSdPropHdlFactory
* GetSdPropHdlFactory() const { return mpSdPropHdlFactory
.get(); }
416 const rtl::Reference
< XMLTableImport
>& GetShapeTableImport();
419 #endif // INCLUDED_XMLOFF_SHAPEIMPORT_HXX
421 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */