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