/src/libreoffice/include/xmloff/shapeimport.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_XMLOFF_SHAPEIMPORT_HXX |
21 | | #define INCLUDED_XMLOFF_SHAPEIMPORT_HXX |
22 | | |
23 | | #include <sal/config.h> |
24 | | #include <xmloff/dllapi.h> |
25 | | #include <xmloff/xmlimppr.hxx> |
26 | | #include <com/sun/star/drawing/HomogenMatrix.hpp> |
27 | | #include <salhelper/simplereferenceobject.hxx> |
28 | | #include <xmloff/xmlictxt.hxx> |
29 | | #include <sax/fastattribs.hxx> |
30 | | |
31 | | #include <basegfx/vector/b3dvector.hxx> |
32 | | #include <vector> |
33 | | #include <memory> |
34 | | |
35 | | namespace com::sun::star::beans { class XPropertySet; } |
36 | | namespace com::sun::star::drawing { enum class ProjectionMode; } |
37 | | namespace com::sun::star::drawing { enum class ShadeMode; } |
38 | | namespace com::sun::star::drawing { class XShape; } |
39 | | namespace com::sun::star::drawing { class XShapes; } |
40 | | namespace com::sun::star::frame { class XModel; } |
41 | | |
42 | | class SvXMLImport; |
43 | | class SvXMLStylesContext; |
44 | | class XMLSdPropHdlFactory; |
45 | | class XMLTableImport; |
46 | | |
47 | | // dr3d:3dlight context |
48 | | |
49 | | class SdXML3DLightContext final : public SvXMLImportContext |
50 | | { |
51 | | // local parameters which need to be read |
52 | | sal_Int32 maDiffuseColor; |
53 | | ::basegfx::B3DVector maDirection; |
54 | | bool mbEnabled; |
55 | | bool mbSpecular; |
56 | | |
57 | | public: |
58 | | SdXML3DLightContext( |
59 | | SvXMLImport& rImport, |
60 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList); |
61 | | virtual ~SdXML3DLightContext() override; |
62 | | |
63 | 0 | sal_Int32 GetDiffuseColor() const { return maDiffuseColor; } |
64 | 0 | const ::basegfx::B3DVector& GetDirection() const { return maDirection; } |
65 | 0 | bool GetEnabled() const { return mbEnabled; } |
66 | | }; |
67 | | |
68 | | |
69 | | class SdXML3DSceneAttributesHelper |
70 | | { |
71 | | protected: |
72 | | SvXMLImport& mrImport; |
73 | | |
74 | | // list for local light contexts |
75 | | ::std::vector< rtl::Reference< SdXML3DLightContext > > |
76 | | maList; |
77 | | |
78 | | // local parameters which need to be read |
79 | | css::drawing::HomogenMatrix mxHomMat; |
80 | | bool mbSetTransform; |
81 | | |
82 | | css::drawing::ProjectionMode mxPrjMode; |
83 | | sal_Int32 mnDistance; |
84 | | sal_Int32 mnFocalLength; |
85 | | sal_Int32 mnShadowSlant; |
86 | | css::drawing::ShadeMode mxShadeMode; |
87 | | sal_Int32 maAmbientColor; |
88 | | bool mbLightingMode; |
89 | | |
90 | | ::basegfx::B3DVector maVRP; |
91 | | ::basegfx::B3DVector maVPN; |
92 | | ::basegfx::B3DVector maVUP; |
93 | | bool mbVRPUsed; |
94 | | |
95 | | public: |
96 | | SdXML3DSceneAttributesHelper( SvXMLImport& rImporter ); |
97 | | |
98 | | /** creates a 3d light context and adds it to the internal list for later processing */ |
99 | | SvXMLImportContext * create3DLightContext( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList); |
100 | | |
101 | | /** this should be called for each scene attribute */ |
102 | | void processSceneAttribute( const sax_fastparser::FastAttributeList::FastAttributeIter & aIter ); |
103 | | |
104 | | /** this sets the scene attributes at this propertyset */ |
105 | | void setSceneAttributes( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); |
106 | | }; |
107 | | |
108 | | |
109 | | class SvXMLShapeContext : public SvXMLImportContext |
110 | | { |
111 | | protected: |
112 | | css::uno::Reference< css::drawing::XShape > mxShape; |
113 | | bool mbTemporaryShape; |
114 | | OUString msHyperlink; |
115 | | |
116 | | public: |
117 | 25.0k | SvXMLShapeContext( SvXMLImport& rImp, bool bTemporaryShape ) : SvXMLImportContext( rImp ), mbTemporaryShape(bTemporaryShape) {} |
118 | | |
119 | | |
120 | 5.95k | const css::uno::Reference< css::drawing::XShape >& getShape() const { return mxShape; } |
121 | | |
122 | | void setHyperlink( const OUString& rHyperlink ); |
123 | | }; |
124 | | |
125 | | |
126 | | struct XMLShapeImportHelperImpl; |
127 | | struct XMLShapeImportPageContextImpl; |
128 | | struct SdXMLEventContextData; |
129 | | |
130 | | class XMLOFF_DLLPUBLIC XMLShapeImportHelper : public salhelper::SimpleReferenceObject |
131 | | { |
132 | | std::unique_ptr<XMLShapeImportHelperImpl> mpImpl; |
133 | | |
134 | | std::shared_ptr<XMLShapeImportPageContextImpl> mpPageContext; |
135 | | |
136 | | // PropertySetMappers and factory |
137 | | rtl::Reference<XMLSdPropHdlFactory> mpSdPropHdlFactory; |
138 | | std::unique_ptr<SvXMLImportPropertyMapper> mpPropertySetMapper; |
139 | | std::unique_ptr<SvXMLImportPropertyMapper> mpPresPagePropsMapper; |
140 | | |
141 | | // contexts for Style and AutoStyle import |
142 | | rtl::Reference<SvXMLStylesContext> mxStylesContext; |
143 | | rtl::Reference<SvXMLStylesContext> mxAutoStylesContext; |
144 | | |
145 | | rtl::Reference< XMLTableImport > mxShapeTableImport; |
146 | | |
147 | | protected: |
148 | | SvXMLImport& mrImporter; |
149 | | |
150 | | public: |
151 | | XMLShapeImportHelper( SvXMLImport& rImporter, |
152 | | const css::uno::Reference< css::frame::XModel>& rModel, |
153 | | std::unique_ptr<SvXMLImportPropertyMapper> pExtMapper={} ); |
154 | | |
155 | | virtual ~XMLShapeImportHelper() override; |
156 | | |
157 | | static SvXMLShapeContext* CreateGroupChildContext( |
158 | | SvXMLImport& rImport, sal_Int32 nElement, |
159 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
160 | | css::uno::Reference< css::drawing::XShapes > const & rShapes, |
161 | | bool bTemporaryShape = false); |
162 | | |
163 | | static SvXMLShapeContext* CreateFrameChildContext( |
164 | | SvXMLImport& rImport, sal_Int32 nElement, |
165 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
166 | | css::uno::Reference< css::drawing::XShapes > const & rShapes, |
167 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xFrameAttrList); |
168 | | static css::uno::Reference< css::xml::sax::XFastContextHandler > CreateFrameChildContext( |
169 | | SvXMLImportContext *pThisContext, sal_Int32 nElement, |
170 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ); |
171 | | |
172 | | static SvXMLShapeContext* Create3DSceneChildContext( |
173 | | SvXMLImport& rImport, sal_Int32 nElement, |
174 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
175 | | css::uno::Reference< css::drawing::XShapes > const & rShapes); |
176 | | |
177 | | // Styles and AutoStyles contexts |
178 | 1.31k | SvXMLStylesContext* GetStylesContext() const { return mxStylesContext.get(); } |
179 | | void SetStylesContext(SvXMLStylesContext* pNew); |
180 | 5.14k | SvXMLStylesContext* GetAutoStylesContext() const { return mxAutoStylesContext.get(); } |
181 | | void SetAutoStylesContext(SvXMLStylesContext* pNew); |
182 | | |
183 | | // get factories and mappers |
184 | 26.5k | SvXMLImportPropertyMapper* GetPropertySetMapper() const { return mpPropertySetMapper.get(); } |
185 | 0 | SvXMLImportPropertyMapper* GetPresPagePropsMapper() const { return mpPresPagePropsMapper.get(); } |
186 | | |
187 | | // this function is called whenever the implementation classes like to add this new |
188 | | // shape to the given XShapes. |
189 | | virtual void addShape( |
190 | | css::uno::Reference< css::drawing::XShape >& rShape, |
191 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
192 | | css::uno::Reference< css::drawing::XShapes >& rShapes); |
193 | | |
194 | | // this function is called whenever the implementation classes have finished importing |
195 | | // a shape to the given XShapes. The shape is already inserted into its XShapes and |
196 | | // all properties and styles are set. |
197 | | virtual void finishShape( |
198 | | css::uno::Reference< css::drawing::XShape >& rShape, |
199 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
200 | | css::uno::Reference< css::drawing::XShapes >& rShapes); |
201 | | |
202 | | // tdf#127791 help function for group shape events |
203 | | void addShapeEvents(SdXMLEventContextData& rData); |
204 | | |
205 | | // helper functions processing groups after their component shapes are collected |
206 | | // e.g. for z-order sorting or adding events to the group |
207 | | void pushGroupForPostProcessing( css::uno::Reference< css::drawing::XShapes >& rShapes ); |
208 | | void popGroupAndPostProcess(); |
209 | | |
210 | | void shapeWithZIndexAdded( css::uno::Reference< css::drawing::XShape > const & rShape, |
211 | | sal_Int32 nZIndex ); |
212 | | /// Updates the z-order of other shapes to be consistent again, needed due |
213 | | /// to the removal of rShape. |
214 | | void shapeRemoved(const css::uno::Reference<css::drawing::XShape>& rShape); |
215 | | |
216 | | void addShapeConnection( css::uno::Reference< css::drawing::XShape > const & rConnectorShape, |
217 | | bool bStart, |
218 | | const OUString& rDestShapeId, |
219 | | sal_Int32 nDestGlueId ); |
220 | | |
221 | | /** adds a mapping for a gluepoint identifier from an xml file to the identifier created after inserting |
222 | | the new gluepoint into the core. The saved mappings can be retrieved by getGluePointId() */ |
223 | | void addGluePointMapping( css::uno::Reference< css::drawing::XShape > const & xShape, |
224 | | sal_Int32 nSourceId, sal_Int32 nDestinnationId ); |
225 | | |
226 | | /** moves all current DestinationId's for rXShape by n */ |
227 | | void moveGluePointMapping( const css::uno::Reference< css::drawing::XShape >& xShape, const sal_Int32 n ); |
228 | | |
229 | | /** retrieves a mapping for a gluepoint identifier from the current xml file to the identifier created after |
230 | | inserting the new gluepoint into the core. The mapping must be initialized first with addGluePointMapping() */ |
231 | | sal_Int32 getGluePointId( const css::uno::Reference< css::drawing::XShape >& xShape, sal_Int32 nSourceId ); |
232 | | |
233 | | /** this method must be calling before the first shape is imported for the given page. |
234 | | Calls to this method can be nested */ |
235 | | void startPage( css::uno::Reference< css::drawing::XShapes > const & rShapes ); |
236 | | |
237 | | /** this method must be calling after the last shape is imported for the given page |
238 | | Calls to this method can be nested */ |
239 | | void endPage( css::uno::Reference< css::drawing::XShapes > const & rShapes ); |
240 | | |
241 | | void restoreConnections(); |
242 | | |
243 | | /** creates a property mapper for external chaining */ |
244 | | static std::unique_ptr<SvXMLImportPropertyMapper> CreateShapePropMapper( |
245 | | const css::uno::Reference< css::frame::XModel>& rModel, SvXMLImport& rImport ); |
246 | | |
247 | | /** defines if the import should increment the progress bar or not */ |
248 | | void enableHandleProgressBar(); |
249 | | bool IsHandleProgressBarEnabled() const; |
250 | | |
251 | | /** queries the capability of the current model to create presentation shapes */ |
252 | | bool IsPresentationShapesSupported() const; |
253 | | |
254 | 0 | XMLSdPropHdlFactory* GetSdPropHdlFactory() const { return mpSdPropHdlFactory.get(); } |
255 | | |
256 | | const rtl::Reference< XMLTableImport >& GetShapeTableImport(); |
257 | | }; |
258 | | |
259 | | #endif // INCLUDED_XMLOFF_SHAPEIMPORT_HXX |
260 | | |
261 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |