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