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