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/drawing/HomogenMatrix.hpp>
26 #include <com/sun/star/drawing/ProjectionMode.hpp>
27 #include <com/sun/star/drawing/ShadeMode.hpp>
28 #include <salhelper/simplereferenceobject.hxx>
29 #include <xmloff/xmlictxt.hxx>
31 #include <basegfx/vector/b3dvector.hxx>
35 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{ class XPropertySet
; } } } }
36 namespace com
{ namespace sun
{ namespace star
{ namespace drawing
{ class XShape
; } } } }
37 namespace com
{ namespace sun
{ namespace star
{ namespace drawing
{ class XShapes
; } } } }
38 namespace com
{ namespace sun
{ namespace star
{ namespace frame
{ class XModel
; } } } }
39 namespace com
{ namespace sun
{ namespace star
{ namespace xml
{ namespace sax
{ class XAttributeList
; } } } } }
43 class SvXMLStylesContext
;
44 class XMLSdPropHdlFactory
;
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
,
78 enum SdXMLFrameShapeElemTokenMap
80 XML_TOK_FRAME_TEXT_BOX
,
83 XML_TOK_FRAME_OBJECT_OLE
,
85 XML_TOK_FRAME_FLOATING_FRAME
,
90 enum SdXML3DSceneShapeElemTokenMap
92 XML_TOK_3DSCENE_3DSCENE
,
93 XML_TOK_3DSCENE_3DCUBE
,
94 XML_TOK_3DSCENE_3DSPHERE
,
95 XML_TOK_3DSCENE_3DLATHE
,
96 XML_TOK_3DSCENE_3DEXTRUDE
99 enum SdXML3DObjectAttrTokenMap
101 XML_TOK_3DOBJECT_DRAWSTYLE_NAME
,
102 XML_TOK_3DOBJECT_TRANSFORM
105 enum SdXML3DPolygonBasedAttrTokenMap
107 XML_TOK_3DPOLYGONBASED_VIEWBOX
,
108 XML_TOK_3DPOLYGONBASED_D
111 enum SdXML3DCubeObjectAttrTokenMap
113 XML_TOK_3DCUBEOBJ_MINEDGE
,
114 XML_TOK_3DCUBEOBJ_MAXEDGE
117 enum SdXML3DSphereObjectAttrTokenMap
119 XML_TOK_3DSPHEREOBJ_CENTER
,
120 XML_TOK_3DSPHEREOBJ_SIZE
123 enum SdXML3DLightAttrTokenMap
125 XML_TOK_3DLIGHT_DIFFUSE_COLOR
,
126 XML_TOK_3DLIGHT_DIRECTION
,
127 XML_TOK_3DLIGHT_ENABLED
,
128 XML_TOK_3DLIGHT_SPECULAR
132 // dr3d:3dlight context
134 class SdXML3DLightContext
: public SvXMLImportContext
136 // local parameters which need to be read
137 sal_Int32 maDiffuseColor
;
138 ::basegfx::B3DVector maDirection
;
144 SvXMLImport
& rImport
,
146 const OUString
& rLName
,
147 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
);
148 virtual ~SdXML3DLightContext() override
;
150 sal_Int32
GetDiffuseColor() { return maDiffuseColor
; }
151 const ::basegfx::B3DVector
& GetDirection() { return maDirection
; }
152 bool GetEnabled() { return mbEnabled
; }
156 class SdXML3DSceneAttributesHelper
159 SvXMLImport
& mrImport
;
161 // list for local light contexts
162 ::std::vector
< rtl::Reference
< SdXML3DLightContext
> >
165 // local parameters which need to be read
166 css::drawing::HomogenMatrix mxHomMat
;
169 css::drawing::ProjectionMode mxPrjMode
;
170 sal_Int32 mnDistance
;
171 sal_Int32 mnFocalLength
;
172 sal_Int32 mnShadowSlant
;
173 css::drawing::ShadeMode mxShadeMode
;
174 sal_Int32 maAmbientColor
;
177 ::basegfx::B3DVector maVRP
;
178 ::basegfx::B3DVector maVPN
;
179 ::basegfx::B3DVector maVUP
;
185 SdXML3DSceneAttributesHelper( SvXMLImport
& rImporter
);
187 /** creates a 3d light context and adds it to the internal list for later processing */
188 SvXMLImportContext
* create3DLightContext( sal_uInt16 nPrfx
, const OUString
& rLName
, const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
);
190 /** this should be called for each scene attribute */
191 void processSceneAttribute( sal_uInt16 nPrefix
, const OUString
& rLocalName
, const OUString
& rValue
);
193 /** this sets the scene attributes at this propertyset */
194 void setSceneAttributes( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
198 class SvXMLShapeContext
: public SvXMLImportContext
201 css::uno::Reference
< css::drawing::XShape
> mxShape
;
202 bool const mbTemporaryShape
;
203 OUString msHyperlink
;
206 SvXMLShapeContext( SvXMLImport
& rImp
, sal_uInt16 nPrfx
,
207 const OUString
& rLName
, bool bTemporaryShape
) : SvXMLImportContext( rImp
, nPrfx
, rLName
), mbTemporaryShape(bTemporaryShape
) {}
210 const css::uno::Reference
< css::drawing::XShape
>& getShape() const { return mxShape
; }
212 void setHyperlink( const OUString
& rHyperlink
);
216 struct XMLShapeImportHelperImpl
;
217 struct XMLShapeImportPageContextImpl
;
219 class XMLOFF_DLLPUBLIC XMLShapeImportHelper
: public salhelper::SimpleReferenceObject
221 std::unique_ptr
<XMLShapeImportHelperImpl
> mpImpl
;
223 std::shared_ptr
<XMLShapeImportPageContextImpl
> mpPageContext
;
225 // PropertySetMappers and factory
226 rtl::Reference
<XMLSdPropHdlFactory
> mpSdPropHdlFactory
;
227 rtl::Reference
<SvXMLImportPropertyMapper
> mpPropertySetMapper
;
228 rtl::Reference
<SvXMLImportPropertyMapper
> mpPresPagePropsMapper
;
230 // contexts for Style and AutoStyle import
231 rtl::Reference
<SvXMLStylesContext
> mxStylesContext
;
232 rtl::Reference
<SvXMLStylesContext
> mxAutoStylesContext
;
234 // contexts for xShape contents TokenMaps
235 std::unique_ptr
<SvXMLTokenMap
> mpGroupShapeElemTokenMap
;
236 std::unique_ptr
<SvXMLTokenMap
> mpFrameShapeElemTokenMap
;
237 std::unique_ptr
<SvXMLTokenMap
> mp3DSceneShapeElemTokenMap
;
238 std::unique_ptr
<SvXMLTokenMap
> mp3DObjectAttrTokenMap
;
239 std::unique_ptr
<SvXMLTokenMap
> mp3DPolygonBasedAttrTokenMap
;
240 std::unique_ptr
<SvXMLTokenMap
> mp3DCubeObjectAttrTokenMap
;
241 std::unique_ptr
<SvXMLTokenMap
> mp3DSphereObjectAttrTokenMap
;
242 std::unique_ptr
<SvXMLTokenMap
> mp3DLightAttrTokenMap
;
244 rtl::Reference
< XMLTableImport
> mxShapeTableImport
;
247 SvXMLImport
& mrImporter
;
250 XMLShapeImportHelper( SvXMLImport
& rImporter
,
251 const css::uno::Reference
< css::frame::XModel
>& rModel
,
252 SvXMLImportPropertyMapper
*pExtMapper
=nullptr );
254 virtual ~XMLShapeImportHelper() override
;
256 SvXMLShapeContext
* CreateGroupChildContext(
257 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
258 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
259 css::uno::Reference
< css::drawing::XShapes
> const & rShapes
,
260 bool bTemporaryShape
= false);
262 SvXMLShapeContext
* CreateFrameChildContext(
263 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
264 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
265 css::uno::Reference
< css::drawing::XShapes
> const & rShapes
,
266 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xFrameAttrList
);
267 static SvXMLImportContextRef
CreateFrameChildContext(
268 SvXMLImportContext
*pThisContext
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
269 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
);
271 SvXMLShapeContext
* Create3DSceneChildContext(
272 SvXMLImport
& rImport
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
273 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
274 css::uno::Reference
< css::drawing::XShapes
> const & rShapes
);
276 const SvXMLTokenMap
& GetGroupShapeElemTokenMap();
277 const SvXMLTokenMap
& GetFrameShapeElemTokenMap();
278 const SvXMLTokenMap
& Get3DSceneShapeElemTokenMap();
279 const SvXMLTokenMap
& Get3DObjectAttrTokenMap();
280 const SvXMLTokenMap
& Get3DPolygonBasedAttrTokenMap();
281 const SvXMLTokenMap
& Get3DCubeObjectAttrTokenMap();
282 const SvXMLTokenMap
& Get3DSphereObjectAttrTokenMap();
283 const SvXMLTokenMap
& Get3DLightAttrTokenMap();
285 // Styles and AutoStyles contexts
286 SvXMLStylesContext
* GetStylesContext() const { return mxStylesContext
.get(); }
287 void SetStylesContext(SvXMLStylesContext
* pNew
);
288 SvXMLStylesContext
* GetAutoStylesContext() const { return mxAutoStylesContext
.get(); }
289 void SetAutoStylesContext(SvXMLStylesContext
* pNew
);
291 // get factories and mappers
292 SvXMLImportPropertyMapper
* GetPropertySetMapper() const { return mpPropertySetMapper
.get(); }
293 SvXMLImportPropertyMapper
* GetPresPagePropsMapper() const { return mpPresPagePropsMapper
.get(); }
295 // this function is called whenever the implementation classes like to add this new
296 // shape to the given XShapes.
297 virtual void addShape(
298 css::uno::Reference
< css::drawing::XShape
>& rShape
,
299 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
300 css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
302 // this function is called whenever the implementation classes have finished importing
303 // a shape to the given XShapes. The shape is already inserted into its XShapes and
304 // all properties and styles are set.
305 virtual void finishShape(
306 css::uno::Reference
< css::drawing::XShape
>& rShape
,
307 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
308 css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
310 // helper functions for z-order sorting
311 void pushGroupForSorting( css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
312 void popGroupAndSort();
314 void shapeWithZIndexAdded( css::uno::Reference
< css::drawing::XShape
> const & rShape
,
316 /// Updates the z-order of other shapes to be consistent again, needed due
317 /// to the removal of rShape.
318 void shapeRemoved(const css::uno::Reference
<css::drawing::XShape
>& rShape
);
320 void addShapeConnection( css::uno::Reference
< css::drawing::XShape
> const & rConnectorShape
,
322 const OUString
& rDestShapeId
,
323 sal_Int32 nDestGlueId
);
325 /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
326 the new glue point into the core. The saved mappings can be retrieved by getGluePointId() */
327 void addGluePointMapping( css::uno::Reference
< css::drawing::XShape
> const & xShape
,
328 sal_Int32 nSourceId
, sal_Int32 nDestinnationId
);
330 /** moves all current DestinationId's for rXShape by n */
331 void moveGluePointMapping( const css::uno::Reference
< css::drawing::XShape
>& xShape
, const sal_Int32 n
);
333 /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
334 inserting the new glue point into the core. The mapping must be initialized first with addGluePointMapping() */
335 sal_Int32
getGluePointId( const css::uno::Reference
< css::drawing::XShape
>& xShape
, sal_Int32 nSourceId
);
337 /** this method must be calling before the first shape is imported for the given page.
338 Calls to this method can be nested */
339 void startPage( css::uno::Reference
< css::drawing::XShapes
> const & rShapes
);
341 /** this method must be calling after the last shape is imported for the given page
342 Calls to this method can be nested */
343 void endPage( css::uno::Reference
< css::drawing::XShapes
> const & rShapes
);
345 void restoreConnections();
347 /** creates a property mapper for external chaining */
348 static SvXMLImportPropertyMapper
* CreateShapePropMapper(
349 const css::uno::Reference
< css::frame::XModel
>& rModel
, SvXMLImport
& rImport
);
351 /** defines if the import should increment the progress bar or not */
352 void enableHandleProgressBar();
353 bool IsHandleProgressBarEnabled() const;
355 /** queries the capability of the current model to create presentation shapes */
356 bool IsPresentationShapesSupported();
358 XMLSdPropHdlFactory
* GetSdPropHdlFactory() const { return mpSdPropHdlFactory
.get(); }
360 const rtl::Reference
< XMLTableImport
>& GetShapeTableImport();
363 #endif // INCLUDED_XMLOFF_SHAPEIMPORT_HXX
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */