Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _XMLOFF_SHAPEIMPORT_HXX_
30 : : #define _XMLOFF_SHAPEIMPORT_HXX_
31 : :
32 : : #include "sal/config.h"
33 : : #include "xmloff/dllapi.h"
34 : : #include <com/sun/star/beans/XPropertySet.hpp>
35 : : #include <com/sun/star/frame/XModel.hpp>
36 : : #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 : : #include <com/sun/star/drawing/XShapes.hpp>
38 : : #include <com/sun/star/drawing/HomogenMatrix.hpp>
39 : : #include <com/sun/star/drawing/ProjectionMode.hpp>
40 : : #include <com/sun/star/drawing/ShadeMode.hpp>
41 : : #include <xmloff/uniref.hxx>
42 : : #include <xmloff/xmlictxt.hxx>
43 : :
44 : : #include "xmloff/table/XMLTableImport.hxx"
45 : : #include <basegfx/vector/b3dvector.hxx>
46 : : #include <vector>
47 : :
48 : : class SvXMLImport;
49 : : class SvXMLImportContext;
50 : : class SvXMLTokenMap;
51 : : class SvXMLStylesContext;
52 : : class XMLSdPropHdlFactory;
53 : : class XMLPropertySetMapper;
54 : : class SvXMLImportPropertyMapper;
55 : :
56 : : //////////////////////////////////////////////////////////////////////////////
57 : :
58 : : enum SdXMLGroupShapeElemTokenMap
59 : : {
60 : : XML_TOK_GROUP_GROUP,
61 : : XML_TOK_GROUP_RECT,
62 : : XML_TOK_GROUP_LINE,
63 : : XML_TOK_GROUP_CIRCLE,
64 : : XML_TOK_GROUP_ELLIPSE,
65 : : XML_TOK_GROUP_POLYGON,
66 : : XML_TOK_GROUP_POLYLINE,
67 : : XML_TOK_GROUP_PATH,
68 : :
69 : : XML_TOK_GROUP_CONTROL,
70 : : XML_TOK_GROUP_CONNECTOR,
71 : : XML_TOK_GROUP_MEASURE,
72 : : XML_TOK_GROUP_PAGE,
73 : : XML_TOK_GROUP_CAPTION,
74 : :
75 : : XML_TOK_GROUP_CHART,
76 : : XML_TOK_GROUP_3DSCENE,
77 : :
78 : : XML_TOK_GROUP_FRAME,
79 : :
80 : : XML_TOK_GROUP_CUSTOM_SHAPE,
81 : :
82 : : XML_TOK_GROUP_ANNOTATION,
83 : :
84 : : XML_TOK_GROUP_A,
85 : :
86 : : XML_TOK_GROUP_LAST
87 : : };
88 : :
89 : : enum SdXMLFrameShapeElemTokenMap
90 : : {
91 : : XML_TOK_FRAME_TEXT_BOX,
92 : : XML_TOK_FRAME_IMAGE,
93 : : XML_TOK_FRAME_OBJECT,
94 : : XML_TOK_FRAME_OBJECT_OLE,
95 : : XML_TOK_FRAME_PLUGIN,
96 : : XML_TOK_FRAME_FRAME,
97 : : XML_TOK_FRAME_FLOATING_FRAME,
98 : : XML_TOK_FRAME_APPLET,
99 : : XML_TOK_FRAME_TABLE,
100 : :
101 : : XML_TOK_FRAME_LAST
102 : : };
103 : :
104 : : enum SdXML3DSceneShapeElemTokenMap
105 : : {
106 : : XML_TOK_3DSCENE_3DSCENE,
107 : : XML_TOK_3DSCENE_3DCUBE,
108 : : XML_TOK_3DSCENE_3DSPHERE,
109 : : XML_TOK_3DSCENE_3DLATHE,
110 : : XML_TOK_3DSCENE_3DEXTRUDE,
111 : :
112 : : XML_TOK_3DSCENE_LAST
113 : : };
114 : :
115 : : enum SdXMLShapeAttrTokenMap
116 : : {
117 : : XML_TOK_SHAPE_NAME,
118 : : XML_TOK_SHAPE_DRAWSTYLE_NAME_GRAPHICS,
119 : : XML_TOK_SHAPE_PRESENTATION_CLASS,
120 : : XML_TOK_SHAPE_DRAWSTYLE_NAME_PRESENTATION,
121 : : XML_TOK_SHAPE_TRANSFORM,
122 : : XML_TOK_SHAPE_IS_PLACEHOLDER,
123 : : XML_TOK_SHAPE_IS_USER_TRANSFORMED
124 : : };
125 : :
126 : : enum SdXML3DObjectAttrTokenMap
127 : : {
128 : : XML_TOK_3DOBJECT_DRAWSTYLE_NAME,
129 : : XML_TOK_3DOBJECT_TRANSFORM
130 : : };
131 : :
132 : : enum SdXML3DPolygonBasedAttrTokenMap
133 : : {
134 : : XML_TOK_3DPOLYGONBASED_VIEWBOX,
135 : : XML_TOK_3DPOLYGONBASED_D
136 : : };
137 : :
138 : : enum SdXML3DCubeObjectAttrTokenMap
139 : : {
140 : : XML_TOK_3DCUBEOBJ_MINEDGE,
141 : : XML_TOK_3DCUBEOBJ_MAXEDGE
142 : : };
143 : :
144 : : enum SdXML3DSphereObjectAttrTokenMap
145 : : {
146 : : XML_TOK_3DSPHEREOBJ_CENTER,
147 : : XML_TOK_3DSPHEREOBJ_SIZE
148 : : };
149 : :
150 : : enum SdXMLPolygonShapeAttrTokenMap
151 : : {
152 : : XML_TOK_POLYGONSHAPE_VIEWBOX,
153 : : XML_TOK_POLYGONSHAPE_POINTS
154 : : };
155 : :
156 : : enum SdXMLPathShapeAttrTokenMap
157 : : {
158 : : XML_TOK_PATHSHAPE_VIEWBOX,
159 : : XML_TOK_PATHSHAPE_D
160 : : };
161 : :
162 : : enum SdXML3DSceneShapeAttrTokenMap
163 : : {
164 : : XML_TOK_3DSCENESHAPE_TRANSFORM,
165 : : XML_TOK_3DSCENESHAPE_VRP,
166 : : XML_TOK_3DSCENESHAPE_VPN,
167 : : XML_TOK_3DSCENESHAPE_VUP,
168 : : XML_TOK_3DSCENESHAPE_PROJECTION,
169 : : XML_TOK_3DSCENESHAPE_DISTANCE,
170 : : XML_TOK_3DSCENESHAPE_FOCAL_LENGTH,
171 : : XML_TOK_3DSCENESHAPE_SHADOW_SLANT,
172 : : XML_TOK_3DSCENESHAPE_SHADE_MODE,
173 : : XML_TOK_3DSCENESHAPE_AMBIENT_COLOR,
174 : : XML_TOK_3DSCENESHAPE_LIGHTING_MODE
175 : : };
176 : :
177 : : enum SdXML3DLightAttrTokenMap
178 : : {
179 : : XML_TOK_3DLIGHT_DIFFUSE_COLOR,
180 : : XML_TOK_3DLIGHT_DIRECTION,
181 : : XML_TOK_3DLIGHT_ENABLED,
182 : : XML_TOK_3DLIGHT_SPECULAR
183 : : };
184 : :
185 : : //////////////////////////////////////////////////////////////////////////////
186 : : // dr3d:3dlight context
187 : :
188 : : class SdXML3DLightContext: public SvXMLImportContext
189 : : {
190 : : // local parameters which need to be read
191 : : sal_Int32 maDiffuseColor;
192 : : ::basegfx::B3DVector maDirection;
193 : : bool mbEnabled;
194 : : bool mbSpecular;
195 : :
196 : : public:
197 : : SdXML3DLightContext(
198 : : SvXMLImport& rImport,
199 : : sal_uInt16 nPrfx,
200 : : const rtl::OUString& rLName,
201 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
202 : : virtual ~SdXML3DLightContext();
203 : :
204 : 0 : sal_Int32 GetDiffuseColor() { return maDiffuseColor; }
205 : 0 : const ::basegfx::B3DVector& GetDirection() { return maDirection; }
206 : 0 : sal_Bool GetEnabled() { return mbEnabled; }
207 : : sal_Bool GetSpecular() { return mbSpecular; }
208 : : };
209 : :
210 : : //////////////////////////////////////////////////////////////////////////////
211 : :
212 : : typedef ::std::vector< SdXML3DLightContext* > Imp3DLightList;
213 : :
214 : : class SdXML3DSceneAttributesHelper
215 : : {
216 : : protected:
217 : : SvXMLImport& mrImport;
218 : :
219 : : // list for local light contexts
220 : : Imp3DLightList maList;
221 : :
222 : : // local parameters which need to be read
223 : : com::sun::star::drawing::HomogenMatrix mxHomMat;
224 : : sal_Bool mbSetTransform;
225 : :
226 : : com::sun::star::drawing::ProjectionMode mxPrjMode;
227 : : sal_Int32 mnDistance;
228 : : sal_Int32 mnFocalLength;
229 : : sal_Int32 mnShadowSlant;
230 : : com::sun::star::drawing::ShadeMode mxShadeMode;
231 : : sal_Int32 maAmbientColor;
232 : : bool mbLightingMode;
233 : :
234 : : ::basegfx::B3DVector maVRP;
235 : : ::basegfx::B3DVector maVPN;
236 : : ::basegfx::B3DVector maVUP;
237 : : sal_Bool mbVRPUsed;
238 : : sal_Bool mbVPNUsed;
239 : : sal_Bool mbVUPUsed;
240 : :
241 : : public:
242 : : SdXML3DSceneAttributesHelper( SvXMLImport& rImporter );
243 : : ~SdXML3DSceneAttributesHelper();
244 : :
245 : : /** creates a 3d ligth context and adds it to the internal list for later processing */
246 : : SvXMLImportContext * create3DLightContext( sal_uInt16 nPrfx, const rtl::OUString& rLName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
247 : :
248 : : /** this should be called for each scene attribute */
249 : : void processSceneAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue );
250 : :
251 : : /** this sets the scene attributes at this propertyset */
252 : : void setSceneAttributes( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet );
253 : : };
254 : :
255 : : //////////////////////////////////////////////////////////////////////////////
256 : :
257 [ - + ]: 662 : class SvXMLShapeContext : public SvXMLImportContext
258 : : {
259 : : protected:
260 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxShape;
261 : : sal_Bool mbTemporaryShape;
262 : : rtl::OUString msHyperlink;
263 : :
264 : : public:
265 : 647 : SvXMLShapeContext( SvXMLImport& rImp, sal_uInt16 nPrfx,
266 : 647 : const ::rtl::OUString& rLName, sal_Bool bTemporaryShape ) : SvXMLImportContext( rImp, nPrfx, rLName ), mbTemporaryShape(bTemporaryShape) {}
267 : :
268 : : TYPEINFO();
269 : :
270 : 27 : const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& getShape() const { return mxShape; }
271 : :
272 : : void setHyperlink( const ::rtl::OUString& rHyperlink );
273 : : };
274 : :
275 : : //////////////////////////////////////////////////////////////////////////////
276 : :
277 : : class ShapeSortContext;
278 : : struct XMLShapeImportHelperImpl;
279 : : struct XMLShapeImportPageContextImpl;
280 : :
281 : : class XMLOFF_DLLPUBLIC XMLShapeImportHelper : public UniRefBase
282 : : {
283 : : XMLShapeImportHelperImpl* mpImpl;
284 : :
285 : : XMLShapeImportPageContextImpl* mpPageContext;
286 : :
287 : : com::sun::star::uno::Reference< com::sun::star::frame::XModel > mxModel;
288 : :
289 : : // PropertySetMappers and factory
290 : : XMLSdPropHdlFactory* mpSdPropHdlFactory;
291 : : SvXMLImportPropertyMapper* mpPropertySetMapper;
292 : : SvXMLImportPropertyMapper* mpPresPagePropsMapper;
293 : :
294 : : // contexts for Style and AutoStyle import
295 : : SvXMLStylesContext* mpStylesContext;
296 : : SvXMLStylesContext* mpAutoStylesContext;
297 : :
298 : : // contexts for xShape contents TokenMaps
299 : : SvXMLTokenMap* mpGroupShapeElemTokenMap;
300 : : SvXMLTokenMap* mpFrameShapeElemTokenMap;
301 : : SvXMLTokenMap* mp3DSceneShapeElemTokenMap;
302 : : SvXMLTokenMap* mp3DObjectAttrTokenMap;
303 : : SvXMLTokenMap* mp3DPolygonBasedAttrTokenMap;
304 : : SvXMLTokenMap* mp3DCubeObjectAttrTokenMap;
305 : : SvXMLTokenMap* mp3DSphereObjectAttrTokenMap;
306 : : SvXMLTokenMap* mp3DSceneShapeAttrTokenMap;
307 : : SvXMLTokenMap* mp3DLightAttrTokenMap;
308 : : SvXMLTokenMap* mpPathShapeAttrTokenMap;
309 : : SvXMLTokenMap* mpPolygonShapeAttrTokenMap;
310 : :
311 : : const ::rtl::OUString msStartShape;
312 : : const ::rtl::OUString msEndShape;
313 : : const ::rtl::OUString msStartGluePointIndex;
314 : : const ::rtl::OUString msEndGluePointIndex;
315 : :
316 : : rtl::Reference< XMLTableImport > mxShapeTableImport;
317 : :
318 : : protected:
319 : : SvXMLImport& mrImporter;
320 : :
321 : : public:
322 : : XMLShapeImportHelper( SvXMLImport& rImporter,
323 : : const com::sun::star::uno::Reference< com::sun::star::frame::XModel>& rModel,
324 : : SvXMLImportPropertyMapper *pExtMapper=0 );
325 : :
326 : : ~XMLShapeImportHelper();
327 : :
328 : : SvXMLShapeContext* CreateGroupChildContext(
329 : : SvXMLImport& rImport, sal_uInt16 nPrefix, const rtl::OUString& rLocalName,
330 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
331 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
332 : : sal_Bool bTemporaryShape = sal_False);
333 : :
334 : : SvXMLShapeContext* CreateFrameChildContext(
335 : : SvXMLImport& rImport, sal_uInt16 nPrefix, const rtl::OUString& rLocalName,
336 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
337 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
338 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xFrameAttrList);
339 : : SvXMLImportContext* CreateFrameChildContext(
340 : : SvXMLImportContext *pThisContext, sal_uInt16 nPrefix, const rtl::OUString& rLocalName,
341 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
342 : :
343 : : SvXMLShapeContext* Create3DSceneChildContext(
344 : : SvXMLImport& rImport, sal_uInt16 nPrefix, const rtl::OUString& rLocalName,
345 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
346 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes);
347 : :
348 : : const SvXMLTokenMap& GetGroupShapeElemTokenMap();
349 : : const SvXMLTokenMap& GetFrameShapeElemTokenMap();
350 : : const SvXMLTokenMap& Get3DSceneShapeElemTokenMap();
351 : : const SvXMLTokenMap& Get3DObjectAttrTokenMap();
352 : : const SvXMLTokenMap& Get3DPolygonBasedAttrTokenMap();
353 : : const SvXMLTokenMap& Get3DCubeObjectAttrTokenMap();
354 : : const SvXMLTokenMap& Get3DSphereObjectAttrTokenMap();
355 : : const SvXMLTokenMap& Get3DLightAttrTokenMap();
356 : :
357 : : // Styles and AutoStyles contexts
358 : 331 : SvXMLStylesContext* GetStylesContext() const { return mpStylesContext; }
359 : : void SetStylesContext(SvXMLStylesContext* pNew);
360 : 1807 : SvXMLStylesContext* GetAutoStylesContext() const { return mpAutoStylesContext; }
361 : : void SetAutoStylesContext(SvXMLStylesContext* pNew);
362 : :
363 : : // get factories and mappers
364 : 123 : SvXMLImportPropertyMapper* GetPropertySetMapper() const { return mpPropertySetMapper; }
365 : 22 : SvXMLImportPropertyMapper* GetPresPagePropsMapper() const { return mpPresPagePropsMapper; }
366 : :
367 : : // this function is called whenever the implementation classes like to add this new
368 : : // shape to the given XShapes.
369 : : virtual void addShape(
370 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape,
371 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
372 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes);
373 : :
374 : : // this function is called whenever the implementation classes have finished importing
375 : : // a shape to the given XShapes. The shape is already inserted into its XShapes and
376 : : // all properties and styles are set.
377 : : virtual void finishShape(
378 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape,
379 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
380 : : com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes);
381 : :
382 : : // helper functions for z-order sorting
383 : : void pushGroupForSorting( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes );
384 : : void popGroupAndSort();
385 : :
386 : : void shapeWithZIndexAdded( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape,
387 : : sal_Int32 nZIndex );
388 : :
389 : : void addShapeConnection( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rConnectorShape,
390 : : sal_Bool bStart,
391 : : const rtl::OUString& rDestShapeId,
392 : : sal_Int32 nDestGlueId );
393 : :
394 : : /** adds a mapping for a glue point identifier from an xml file to the identifier created after inserting
395 : : the new glue point into the core. The saved mappings can be retrieved by getGluePointId() */
396 : : void addGluePointMapping( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape,
397 : : sal_Int32 nSourceId, sal_Int32 nDestinnationId );
398 : :
399 : : /** moves all current DestinationId's for rXShape by n */
400 : : void moveGluePointMapping( const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, const sal_Int32 n );
401 : :
402 : : /** retrieves a mapping for a glue point identifier from the current xml file to the identifier created after
403 : : inserting the new glue point into the core. The mapping must be initialized first with addGluePointMapping() */
404 : : sal_Int32 getGluePointId( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape, sal_Int32 nSourceId );
405 : :
406 : : /** this method must be calling before the first shape is imported for the given page.
407 : : Calls to this method can be nested */
408 : : void startPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes );
409 : :
410 : : /** this method must be calling after the last shape is imported for the given page
411 : : Calls to this method can be nested */
412 : : void endPage( com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes );
413 : :
414 : : void restoreConnections();
415 : :
416 : : /** creates a property mapper for external chaining */
417 : : static SvXMLImportPropertyMapper* CreateShapePropMapper(
418 : : const com::sun::star::uno::Reference< com::sun::star::frame::XModel>& rModel, SvXMLImport& rImport );
419 : :
420 : : // #88546#
421 : : /** defines if the import should increment the progress bar or not */
422 : : void enableHandleProgressBar( sal_Bool bEnable = sal_True );
423 : : sal_Bool IsHandleProgressBarEnabled() const;
424 : :
425 : : /** queries the capability of the current model to create presentation shapes */
426 : : sal_Bool IsPresentationShapesSupported();
427 : :
428 : 0 : XMLSdPropHdlFactory* GetSdPropHdlFactory() const { return mpSdPropHdlFactory; }
429 : :
430 : : const rtl::Reference< XMLTableImport >& GetShapeTableImport();
431 : : };
432 : :
433 : : #endif // _XMLOFF_SHAPEIMPORT_HXX_
434 : :
435 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|