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