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 <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>
31 
32 #include <basegfx/vector/b3dvector.hxx>
33 #include <vector>
34 #include <memory>
35 
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; }
41 
42 class SvXMLImport;
43 class SvXMLTokenMap;
44 class SvXMLStylesContext;
45 class XMLSdPropHdlFactory;
46 class SvXMLImportPropertyMapper;
47 class XMLTableImport;
48 
49 // dr3d:3dlight context
50 
51 class SdXML3DLightContext final : public SvXMLImportContext
52 {
53     // local parameters which need to be read
54     sal_Int32                   maDiffuseColor;
55     ::basegfx::B3DVector        maDirection;
56     bool                        mbEnabled;
57     bool                        mbSpecular;
58 
59 public:
60     SdXML3DLightContext(
61         SvXMLImport& rImport,
62         const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList);
63     virtual ~SdXML3DLightContext() override;
64 
GetDiffuseColor() const65     sal_Int32 GetDiffuseColor() const { return maDiffuseColor; }
GetDirection() const66     const ::basegfx::B3DVector& GetDirection() const { return maDirection; }
GetEnabled() const67     bool GetEnabled() const { return mbEnabled; }
68 };
69 
70 
71 class SdXML3DSceneAttributesHelper
72 {
73 protected:
74     SvXMLImport& mrImport;
75 
76     // list for local light contexts
77     ::std::vector< rtl::Reference< SdXML3DLightContext > >
78                                 maList;
79 
80     // local parameters which need to be read
81     css::drawing::HomogenMatrix mxHomMat;
82     bool                        mbSetTransform;
83 
84     css::drawing::ProjectionMode mxPrjMode;
85     sal_Int32                   mnDistance;
86     sal_Int32                   mnFocalLength;
87     sal_Int32                   mnShadowSlant;
88     css::drawing::ShadeMode     mxShadeMode;
89     sal_Int32                   maAmbientColor;
90     bool                        mbLightingMode;
91 
92     ::basegfx::B3DVector        maVRP;
93     ::basegfx::B3DVector        maVPN;
94     ::basegfx::B3DVector        maVUP;
95     bool                        mbVRPUsed;
96 
97 public:
98     SdXML3DSceneAttributesHelper( SvXMLImport& rImporter );
99 
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);
102 
103     /** this should be called for each scene attribute */
104     void processSceneAttribute( const sax_fastparser::FastAttributeList::FastAttributeIter & aIter );
105 
106     /** this sets the scene attributes at this propertyset */
107     void setSceneAttributes( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
108 };
109 
110 
111 class SvXMLShapeContext : public SvXMLImportContext
112 {
113 protected:
114     css::uno::Reference< css::drawing::XShape >   mxShape;
115     bool                                          mbTemporaryShape;
116     OUString                                      msHyperlink;
117 
118 public:
SvXMLShapeContext(SvXMLImport & rImp,bool bTemporaryShape)119     SvXMLShapeContext( SvXMLImport& rImp, bool bTemporaryShape ) : SvXMLImportContext( rImp ), mbTemporaryShape(bTemporaryShape) {}
120 
121 
getShape() const122     const css::uno::Reference< css::drawing::XShape >& getShape() const { return mxShape; }
123 
124     void setHyperlink( const OUString& rHyperlink );
125 };
126 
127 
128 struct XMLShapeImportHelperImpl;
129 struct XMLShapeImportPageContextImpl;
130 struct SdXMLEventContextData;
131 
132 class XMLOFF_DLLPUBLIC XMLShapeImportHelper : public salhelper::SimpleReferenceObject
133 {
134     std::unique_ptr<XMLShapeImportHelperImpl> mpImpl;
135 
136     std::shared_ptr<XMLShapeImportPageContextImpl> mpPageContext;
137 
138     // PropertySetMappers and factory
139     rtl::Reference<XMLSdPropHdlFactory>       mpSdPropHdlFactory;
140     rtl::Reference<SvXMLImportPropertyMapper> mpPropertySetMapper;
141     rtl::Reference<SvXMLImportPropertyMapper> mpPresPagePropsMapper;
142 
143     // contexts for Style and AutoStyle import
144     rtl::Reference<SvXMLStylesContext> mxStylesContext;
145     rtl::Reference<SvXMLStylesContext> mxAutoStylesContext;
146 
147     rtl::Reference< XMLTableImport > mxShapeTableImport;
148 
149 protected:
150     SvXMLImport& mrImporter;
151 
152 public:
153     XMLShapeImportHelper( SvXMLImport& rImporter,
154         const css::uno::Reference< css::frame::XModel>& rModel,
155     SvXMLImportPropertyMapper *pExtMapper=nullptr );
156 
157     virtual ~XMLShapeImportHelper() override;
158 
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);
164 
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 );
173 
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);
178 
179     // Styles and AutoStyles contexts
GetStylesContext() const180     SvXMLStylesContext* GetStylesContext() const { return mxStylesContext.get(); }
181     void SetStylesContext(SvXMLStylesContext* pNew);
GetAutoStylesContext() const182     SvXMLStylesContext* GetAutoStylesContext() const { return mxAutoStylesContext.get(); }
183     void SetAutoStylesContext(SvXMLStylesContext* pNew);
184 
185     // get factories and mappers
GetPropertySetMapper() const186     SvXMLImportPropertyMapper* GetPropertySetMapper() const { return mpPropertySetMapper.get(); }
GetPresPagePropsMapper() const187     SvXMLImportPropertyMapper* GetPresPagePropsMapper() const { return mpPresPagePropsMapper.get(); }
188 
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);
195 
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);
203 
204     // tdf#127791 help function for group shape events
205     void addShapeEvents(SdXMLEventContextData& rData);
206 
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();
211 
212     void shapeWithZIndexAdded( css::uno::Reference< css::drawing::XShape > const & rShape,
213                                sal_Int32 nZIndex );
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);
217 
218     void addShapeConnection( css::uno::Reference< css::drawing::XShape > const & rConnectorShape,
219                              bool bStart,
220                              const OUString& rDestShapeId,
221                              sal_Int32 nDestGlueId );
222 
223     /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
224         the new glue point 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 );
227 
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 );
230 
231     /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
232         inserting the new glue point 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 );
234 
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 );
238 
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 );
242 
243     void restoreConnections();
244 
245     /** creates a property mapper for external chaining */
246     static SvXMLImportPropertyMapper* CreateShapePropMapper(
247         const css::uno::Reference< css::frame::XModel>& rModel, SvXMLImport& rImport );
248 
249     /** defines if the import should increment the progress bar or not */
250     void enableHandleProgressBar();
251     bool IsHandleProgressBarEnabled() const;
252 
253     /** queries the capability of the current model to create presentation shapes */
254     bool IsPresentationShapesSupported() const;
255 
GetSdPropHdlFactory() const256     XMLSdPropHdlFactory* GetSdPropHdlFactory() const { return mpSdPropHdlFactory.get(); }
257 
258     const rtl::Reference< XMLTableImport >&     GetShapeTableImport();
259 };
260 
261 #endif // INCLUDED_XMLOFF_SHAPEIMPORT_HXX
262 
263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
264