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>
30 #include <sax/fastattribs.hxx>
32 #include <basegfx/vector/b3dvector.hxx>
36 namespace com::sun::star::beans
{ class XPropertySet
; }
37 namespace com::sun::star::drawing
{ class XShape
; }
38 namespace com::sun::star::drawing
{ class XShapes
; }
39 namespace com::sun::star::frame
{ class XModel
; }
40 namespace com::sun::star::xml::sax
{ class XAttributeList
; }
44 class SvXMLStylesContext
;
45 class XMLSdPropHdlFactory
;
46 class SvXMLImportPropertyMapper
;
49 // dr3d:3dlight context
51 class SdXML3DLightContext final
: public SvXMLImportContext
53 // local parameters which need to be read
54 sal_Int32 maDiffuseColor
;
55 ::basegfx::B3DVector maDirection
;
62 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
);
63 virtual ~SdXML3DLightContext() override
;
65 sal_Int32
GetDiffuseColor() const { return maDiffuseColor
; }
66 const ::basegfx::B3DVector
& GetDirection() const { return maDirection
; }
67 bool GetEnabled() const { return mbEnabled
; }
71 class SdXML3DSceneAttributesHelper
74 SvXMLImport
& mrImport
;
76 // list for local light contexts
77 ::std::vector
< rtl::Reference
< SdXML3DLightContext
> >
80 // local parameters which need to be read
81 css::drawing::HomogenMatrix mxHomMat
;
84 css::drawing::ProjectionMode mxPrjMode
;
86 sal_Int32 mnFocalLength
;
87 sal_Int32 mnShadowSlant
;
88 css::drawing::ShadeMode mxShadeMode
;
89 sal_Int32 maAmbientColor
;
92 ::basegfx::B3DVector maVRP
;
93 ::basegfx::B3DVector maVPN
;
94 ::basegfx::B3DVector maVUP
;
98 SdXML3DSceneAttributesHelper( SvXMLImport
& rImporter
);
100 /** creates a 3d light context and adds it to the internal list for later processing */
101 SvXMLImportContext
* create3DLightContext( const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
);
103 /** this should be called for each scene attribute */
104 void processSceneAttribute( const sax_fastparser::FastAttributeList::FastAttributeIter
& aIter
);
106 /** this sets the scene attributes at this propertyset */
107 void setSceneAttributes( const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
111 class SvXMLShapeContext
: public SvXMLImportContext
114 css::uno::Reference
< css::drawing::XShape
> mxShape
;
115 bool mbTemporaryShape
;
116 OUString msHyperlink
;
119 SvXMLShapeContext( SvXMLImport
& rImp
, bool bTemporaryShape
) : SvXMLImportContext( rImp
), mbTemporaryShape(bTemporaryShape
) {}
122 const css::uno::Reference
< css::drawing::XShape
>& getShape() const { return mxShape
; }
124 void setHyperlink( const OUString
& rHyperlink
);
128 struct XMLShapeImportHelperImpl
;
129 struct XMLShapeImportPageContextImpl
;
130 struct SdXMLEventContextData
;
132 class XMLOFF_DLLPUBLIC XMLShapeImportHelper
: public salhelper::SimpleReferenceObject
134 std::unique_ptr
<XMLShapeImportHelperImpl
> mpImpl
;
136 std::shared_ptr
<XMLShapeImportPageContextImpl
> mpPageContext
;
138 // PropertySetMappers and factory
139 rtl::Reference
<XMLSdPropHdlFactory
> mpSdPropHdlFactory
;
140 rtl::Reference
<SvXMLImportPropertyMapper
> mpPropertySetMapper
;
141 rtl::Reference
<SvXMLImportPropertyMapper
> mpPresPagePropsMapper
;
143 // contexts for Style and AutoStyle import
144 rtl::Reference
<SvXMLStylesContext
> mxStylesContext
;
145 rtl::Reference
<SvXMLStylesContext
> mxAutoStylesContext
;
147 rtl::Reference
< XMLTableImport
> mxShapeTableImport
;
150 SvXMLImport
& mrImporter
;
153 XMLShapeImportHelper( SvXMLImport
& rImporter
,
154 const css::uno::Reference
< css::frame::XModel
>& rModel
,
155 SvXMLImportPropertyMapper
*pExtMapper
=nullptr );
157 virtual ~XMLShapeImportHelper() override
;
159 static SvXMLShapeContext
* CreateGroupChildContext(
160 SvXMLImport
& rImport
, sal_Int32 nElement
,
161 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
162 css::uno::Reference
< css::drawing::XShapes
> const & rShapes
,
163 bool bTemporaryShape
= false);
165 static SvXMLShapeContext
* CreateFrameChildContext(
166 SvXMLImport
& rImport
, sal_Int32 nElement
,
167 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
168 css::uno::Reference
< css::drawing::XShapes
> const & rShapes
,
169 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xFrameAttrList
);
170 static css::uno::Reference
< css::xml::sax::XFastContextHandler
> CreateFrameChildContext(
171 SvXMLImportContext
*pThisContext
, sal_Int32 nElement
,
172 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
);
174 static SvXMLShapeContext
* Create3DSceneChildContext(
175 SvXMLImport
& rImport
, sal_Int32 nElement
,
176 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
177 css::uno::Reference
< css::drawing::XShapes
> const & rShapes
);
179 // Styles and AutoStyles contexts
180 SvXMLStylesContext
* GetStylesContext() const { return mxStylesContext
.get(); }
181 void SetStylesContext(SvXMLStylesContext
* pNew
);
182 SvXMLStylesContext
* GetAutoStylesContext() const { return mxAutoStylesContext
.get(); }
183 void SetAutoStylesContext(SvXMLStylesContext
* pNew
);
185 // get factories and mappers
186 SvXMLImportPropertyMapper
* GetPropertySetMapper() const { return mpPropertySetMapper
.get(); }
187 SvXMLImportPropertyMapper
* GetPresPagePropsMapper() const { return mpPresPagePropsMapper
.get(); }
189 // this function is called whenever the implementation classes like to add this new
190 // shape to the given XShapes.
191 virtual void addShape(
192 css::uno::Reference
< css::drawing::XShape
>& rShape
,
193 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
194 css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
196 // this function is called whenever the implementation classes have finished importing
197 // a shape to the given XShapes. The shape is already inserted into its XShapes and
198 // all properties and styles are set.
199 virtual void finishShape(
200 css::uno::Reference
< css::drawing::XShape
>& rShape
,
201 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
202 css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
204 // tdf#127791 help function for group shape events
205 void addShapeEvents(SdXMLEventContextData
& rData
);
207 // helper functions processing groups after their component shapes are collected
208 // e.g. for z-order sorting or adding events to the group
209 void pushGroupForPostProcessing( css::uno::Reference
< css::drawing::XShapes
>& rShapes
);
210 void popGroupAndPostProcess();
212 void shapeWithZIndexAdded( css::uno::Reference
< css::drawing::XShape
> const & rShape
,
214 /// Updates the z-order of other shapes to be consistent again, needed due
215 /// to the removal of rShape.
216 void shapeRemoved(const css::uno::Reference
<css::drawing::XShape
>& rShape
);
218 void addShapeConnection( css::uno::Reference
< css::drawing::XShape
> const & rConnectorShape
,
220 const OUString
& rDestShapeId
,
221 sal_Int32 nDestGlueId
);
223 /** adds a mapping for a gluepoint identifier from an xml file to the identifier created after inserting
224 the new gluepoint into the core. The saved mappings can be retrieved by getGluePointId() */
225 void addGluePointMapping( css::uno::Reference
< css::drawing::XShape
> const & xShape
,
226 sal_Int32 nSourceId
, sal_Int32 nDestinnationId
);
228 /** moves all current DestinationId's for rXShape by n */
229 void moveGluePointMapping( const css::uno::Reference
< css::drawing::XShape
>& xShape
, const sal_Int32 n
);
231 /** retrieves a mapping for a gluepoint identifier from the current xml file to the identifier created after
232 inserting the new gluepoint into the core. The mapping must be initialized first with addGluePointMapping() */
233 sal_Int32
getGluePointId( const css::uno::Reference
< css::drawing::XShape
>& xShape
, sal_Int32 nSourceId
);
235 /** this method must be calling before the first shape is imported for the given page.
236 Calls to this method can be nested */
237 void startPage( css::uno::Reference
< css::drawing::XShapes
> const & rShapes
);
239 /** this method must be calling after the last shape is imported for the given page
240 Calls to this method can be nested */
241 void endPage( css::uno::Reference
< css::drawing::XShapes
> const & rShapes
);
243 void restoreConnections();
245 /** creates a property mapper for external chaining */
246 static SvXMLImportPropertyMapper
* CreateShapePropMapper(
247 const css::uno::Reference
< css::frame::XModel
>& rModel
, SvXMLImport
& rImport
);
249 /** defines if the import should increment the progress bar or not */
250 void enableHandleProgressBar();
251 bool IsHandleProgressBarEnabled() const;
253 /** queries the capability of the current model to create presentation shapes */
254 bool IsPresentationShapesSupported() const;
256 XMLSdPropHdlFactory
* GetSdPropHdlFactory() const { return mpSdPropHdlFactory
.get(); }
258 const rtl::Reference
< XMLTableImport
>& GetShapeTableImport();
261 #endif // INCLUDED_XMLOFF_SHAPEIMPORT_HXX
263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */