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 OOX_VML_VMLDRAWING_HXX 29 #define OOX_VML_VMLDRAWING_HXX 30 31 #include <map> 32 #include <memory> 33 #include <vector> 34 #include "oox/ole/oleobjecthelper.hxx" 35 36 namespace com { namespace sun { namespace star { 37 namespace awt { struct Rectangle; } 38 namespace awt { class XControlModel; } 39 namespace drawing { class XDrawPage; } 40 namespace drawing { class XShape; } 41 namespace drawing { class XShapes; } 42 } } } 43 44 namespace oox { 45 namespace core { class XmlFilterBase; } 46 namespace ole { class EmbeddedControl; } 47 namespace ole { class EmbeddedForm; } 48 } 49 50 namespace oox { 51 namespace vml { 52 53 class ShapeBase; 54 class ShapeContainer; 55 struct ClientData; 56 57 // ============================================================================ 58 59 /** Enumerates different types of VML drawings. */ 60 enum DrawingType 61 { 62 VMLDRAWING_WORD, /// Word: One shape per drawing. 63 VMLDRAWING_EXCEL, /// Excel: OLE objects are part of VML. 64 VMLDRAWING_POWERPOINT /// PowerPoint: OLE objects are part of DrawingML. 65 }; 66 67 // ============================================================================ 68 69 /** Contains information about an OLE object embedded in a draw page. */ 70 struct OleObjectInfo : public ::oox::ole::OleObjectInfo 71 { 72 ::rtl::OUString maShapeId; /// Shape identifier for shape lookup. 73 ::rtl::OUString maName; /// Programmatical name of the OLE object. 74 bool mbAutoLoad; 75 const bool mbDmlShape; /// True = DrawingML shape (PowerPoint), false = VML shape (Excel/Word). 76 77 explicit OleObjectInfo( bool bDmlShape = false ); 78 79 /** Sets the string representation of the passed numeric shape identifier. */ 80 void setShapeId( sal_Int32 nShapeId ); 81 }; 82 83 // ============================================================================ 84 85 /** Contains information about a form control embedded in a draw page. */ 86 struct ControlInfo 87 { 88 ::rtl::OUString maShapeId; /// Shape identifier for shape lookup. 89 ::rtl::OUString maFragmentPath; /// Path to the fragment describing the form control properties. 90 ::rtl::OUString maName; /// Programmatical name of the form control. 91 92 explicit ControlInfo(); 93 94 /** Sets the string representation of the passed numeric shape identifier. */ 95 void setShapeId( sal_Int32 nShapeId ); 96 }; 97 98 // ============================================================================ 99 100 /** Represents the collection of VML shapes for a complete draw page. */ 101 class Drawing 102 { 103 public: 104 explicit Drawing( 105 ::oox::core::XmlFilterBase& rFilter, 106 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxDrawPage, 107 DrawingType eType ); 108 109 virtual ~Drawing(); 110 111 /** Returns the filter object that imports/exports this VML drawing. */ 112 inline ::oox::core::XmlFilterBase& getFilter() const { return mrFilter; } 113 /** Returns the application type containing the drawing. */ 114 inline DrawingType getType() const { return meType; } 115 /** Returns read/write access to the container of shapes and templates. */ 116 inline ShapeContainer& getShapes() { return *mxShapes; } 117 /** Returns read access to the container of shapes and templates. */ 118 inline const ShapeContainer& getShapes() const { return *mxShapes; } 119 /** Returns the form object used to process ActiveX form controls. */ 120 ::oox::ole::EmbeddedForm& getControlForm() const; 121 122 /** Registers a block of shape identifiers reserved by this drawing. Block 123 size is 1024, shape identifiers are one-based (block 1 => 1025-2048). */ 124 void registerBlockId( sal_Int32 nBlockId ); 125 /** Registers the passed embedded OLE object. The related shape will then 126 load the OLE object data from the specified fragment. */ 127 void registerOleObject( const OleObjectInfo& rOleObject ); 128 /** Registers the passed embedded form control. The related shape will then 129 load the control properties from the specified fragment. */ 130 void registerControl( const ControlInfo& rControl ); 131 132 /** Final processing after import of the fragment. */ 133 void finalizeFragmentImport(); 134 135 /** Creates and inserts all UNO shapes into the draw page. The virtual 136 function notifyXShapeInserted() will be called for each new shape. */ 137 void convertAndInsert() const; 138 139 /** Returns the local shape index from the passed global shape identifier. */ 140 sal_Int32 getLocalShapeIndex( const ::rtl::OUString& rShapeId ) const; 141 /** Returns the registered info structure for an OLE object, if extant. */ 142 const OleObjectInfo* getOleObjectInfo( const ::rtl::OUString& rShapeId ) const; 143 /** Returns the registered info structure for a form control, if extant. */ 144 const ControlInfo* getControlInfo( const ::rtl::OUString& rShapeId ) const; 145 146 /** Creates a new UNO shape object, inserts it into the passed UNO shape 147 container, and sets the shape position and size. */ 148 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > 149 createAndInsertXShape( 150 const ::rtl::OUString& rService, 151 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, 152 const ::com::sun::star::awt::Rectangle& rShapeRect ) const; 153 154 /** Creates a new UNO shape object for a form control, inserts the control 155 model into the form, and the shape into the passed UNO shape container. */ 156 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > 157 createAndInsertXControlShape( 158 const ::oox::ole::EmbeddedControl& rControl, 159 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, 160 const ::com::sun::star::awt::Rectangle& rShapeRect, 161 sal_Int32& rnCtrlIndex ) const; 162 163 /** Derived classes may disable conversion of specific shapes. */ 164 virtual bool isShapeSupported( const ShapeBase& rShape ) const; 165 166 /** Derived classes may return additional base names for automatic shape 167 name creation. */ 168 virtual ::rtl::OUString getShapeBaseName( const ShapeBase& rShape ) const; 169 170 /** Derived classes may calculate the shape rectangle from a non-standard 171 anchor information string. */ 172 virtual bool convertClientAnchor( 173 ::com::sun::star::awt::Rectangle& orShapeRect, 174 const ::rtl::OUString& rShapeAnchor ) const; 175 176 /** Derived classes create a UNO shape according to the passed shape model. 177 Called for shape models that specify being under host control. */ 178 virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > 179 createAndInsertClientXShape( 180 const ShapeBase& rShape, 181 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, 182 const ::com::sun::star::awt::Rectangle& rShapeRect ) const; 183 184 /** Derived classes may want to know that a UNO shape has been inserted. 185 Will be called from the convertAndInsert() implementation. 186 @param bGroupChild True = inserted into a group shape, 187 false = inserted directly into this drawing. */ 188 virtual void notifyXShapeInserted( 189 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape, 190 const ::com::sun::star::awt::Rectangle& rShapeRect, 191 const ShapeBase& rShape, bool bGroupChild ); 192 193 private: 194 typedef ::std::vector< sal_Int32 > BlockIdVector; 195 typedef ::std::auto_ptr< ::oox::ole::EmbeddedForm > EmbeddedFormPtr; 196 typedef ::std::auto_ptr< ShapeContainer > ShapeContainerPtr; 197 typedef ::std::map< ::rtl::OUString, OleObjectInfo > OleObjectInfoMap; 198 typedef ::std::map< ::rtl::OUString, ControlInfo > ControlInfoMap; 199 200 ::oox::core::XmlFilterBase& mrFilter; /// Filter object that imports/exports the VML drawing. 201 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > 202 mxDrawPage; /// UNO draw page used to insert the shapes. 203 mutable EmbeddedFormPtr mxCtrlForm; /// The control form used to process embedded controls. 204 mutable BlockIdVector maBlockIds; /// Block identifiers used by this drawing. 205 ShapeContainerPtr mxShapes; /// All shapes and shape templates. 206 OleObjectInfoMap maOleObjects; /// Info about all embedded OLE objects, mapped by shape id. 207 ControlInfoMap maControls; /// Info about all embedded form controls, mapped by control name. 208 const DrawingType meType; /// Application type containing the drawing. 209 }; 210 211 // ============================================================================ 212 213 } // namespace vml 214 } // namespace oox 215 216 #endif 217