xref: /aoo4110/main/oox/inc/oox/vml/vmlshape.hxx (revision b1cdbd2c)
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_VMLSHAPE_HXX
25 #define OOX_VML_VMLSHAPE_HXX
26 
27 #include <memory>
28 #include <vector>
29 #include <com/sun/star/awt/Point.hpp>
30 #include "oox/vml/vmlformatting.hxx"
31 
32 namespace com { namespace sun { namespace star {
33     namespace awt { struct Rectangle; }
34     namespace drawing { class XShape; }
35     namespace drawing { class XShapes; }
36 } } }
37 
38 namespace oox {
39 namespace vml {
40 
41 class Drawing;
42 struct ShapeParentAnchor;
43 class ShapeContainer;
44 class TextBox;
45 
46 // ============================================================================
47 
48 const sal_Int32 VML_CLIENTDATA_UNCHECKED        = 0;
49 const sal_Int32 VML_CLIENTDATA_CHECKED          = 1;
50 const sal_Int32 VML_CLIENTDATA_MIXED            = 2;
51 
52 const sal_Int32 VML_CLIENTDATA_TEXT             = 0;
53 const sal_Int32 VML_CLIENTDATA_INTEGER          = 1;
54 const sal_Int32 VML_CLIENTDATA_NUMBER           = 2;
55 const sal_Int32 VML_CLIENTDATA_REFERENCE        = 3;
56 const sal_Int32 VML_CLIENTDATA_FORMULA          = 4;
57 
58 // ============================================================================
59 
60 /** The shape model structure contains all properties shared by all types of shapes. */
61 struct ShapeTypeModel
62 {
63     ::rtl::OUString     maShapeId;              /// Unique identifier of the shape.
64     ::rtl::OUString     maShapeName;            /// Name of the shape, if present.
65     OptValue< sal_Int32 > moShapeType;          /// Builtin shape type identifier.
66 
67     OptValue< Int32Pair > moCoordPos;           /// Top-left position of coordinate system for children scaling.
68     OptValue< Int32Pair > moCoordSize;          /// Size of coordinate system for children scaling.
69     ::rtl::OUString     maPosition;             /// Position type of the shape.
70     ::rtl::OUString     maLeft;                 /// X position of the shape bounding box (number with unit).
71     ::rtl::OUString     maTop;                  /// Y position of the shape bounding box (number with unit).
72     ::rtl::OUString     maWidth;                /// Width of the shape bounding box (number with unit).
73     ::rtl::OUString     maHeight;               /// Height of the shape bounding box (number with unit).
74     ::rtl::OUString     maMarginLeft;           /// X position of the shape bounding box to shape anchor (number with unit).
75     ::rtl::OUString     maMarginTop;            /// Y position of the shape bounding box to shape anchor (number with unit).
76 
77     StrokeModel         maStrokeModel;          /// Border line formatting.
78     FillModel           maFillModel;            /// Shape fill formatting.
79 
80     OptValue< ::rtl::OUString > moGraphicPath;  /// Path to a graphic for this shape.
81     OptValue< ::rtl::OUString > moGraphicTitle; /// Title of the graphic.
82 
83     explicit            ShapeTypeModel();
84 
85     void                assignUsed( const ShapeTypeModel& rSource );
86 };
87 
88 // ----------------------------------------------------------------------------
89 
90 /** A shape template contains all formatting properties of shapes and can serve
91     as templates for several shapes in a drawing. */
92 class ShapeType
93 {
94 public:
95     explicit            ShapeType( Drawing& rDrawing );
96     virtual             ~ShapeType();
97 
98     /** Returns read/write access to the shape template model structure. */
getTypeModel()99     inline ShapeTypeModel& getTypeModel() { return maTypeModel; }
100     /** Returns read access to the shape template model structure. */
getTypeModel() const101     inline const ShapeTypeModel& getTypeModel() const { return maTypeModel; }
102 
103     /** Returns the shape identifier (which is unique through the containing drawing). */
getShapeId() const104     inline const ::rtl::OUString& getShapeId() const { return maTypeModel.maShapeId; }
105     /** Returns the application defined shape type. */
106     sal_Int32           getShapeType() const;
107     /** Returns the fragment path to the embedded graphic used by this shape. */
108     ::rtl::OUString     getGraphicPath() const;
109 
110 protected:
111     /** Returns the coordinate system of this shape. */
112     ::com::sun::star::awt::Rectangle getCoordSystem() const;
113     /** Returns the absolute shape rectangle according to the passed anchor. */
114     ::com::sun::star::awt::Rectangle getRectangle( const ShapeParentAnchor* pParentAnchor ) const;
115 
116 private:
117     /** Returns the absolute shape rectangle. */
118     ::com::sun::star::awt::Rectangle getAbsRectangle() const;
119     /** Returns the rectangle relative to the parent coordinate system. */
120     ::com::sun::star::awt::Rectangle getRelRectangle() const;
121 
122 protected:
123     Drawing&            mrDrawing;          /// The VML drawing page that contains this shape.
124     ShapeTypeModel      maTypeModel;        /// The model structure containing shape type data.
125 };
126 
127 // ============================================================================
128 
129 /** Excel specific shape client data (such as cell anchor). */
130 struct ClientData
131 {
132     ::rtl::OUString     maAnchor;           /// Cell anchor as comma-separated string.
133     ::rtl::OUString     maFmlaMacro;        /// Link to macro associated to the control.
134     ::rtl::OUString     maFmlaPict;         /// Target cell range of picture links.
135     ::rtl::OUString     maFmlaLink;         /// Link to value cell associated to the control.
136     ::rtl::OUString     maFmlaRange;        /// Link to cell range used as data source for the control.
137     ::rtl::OUString     maFmlaGroup;        /// Link to value cell associated to a group of option buttons.
138     sal_Int32           mnObjType;          /// Type of the shape.
139     sal_Int32           mnTextHAlign;       /// Horizontal text alignment.
140     sal_Int32           mnTextVAlign;       /// Vertical text alignment.
141     sal_Int32           mnCol;              /// Column index for spreadsheet cell note.
142     sal_Int32           mnRow;              /// Row index for spreadsheet cell note.
143     sal_Int32           mnChecked;          /// State for checkboxes and option buttons.
144     sal_Int32           mnDropStyle;        /// Drop down box style (read-only or editable).
145     sal_Int32           mnDropLines;        /// Number of lines in drop down box.
146     sal_Int32           mnVal;              /// Current value of spin buttons and scroll bars.
147     sal_Int32           mnMin;              /// Minimum value of spin buttons and scroll bars.
148     sal_Int32           mnMax;              /// Maximum value of spin buttons and scroll bars.
149     sal_Int32           mnInc;              /// Small increment of spin buttons and scroll bars.
150     sal_Int32           mnPage;             /// Large increment of spin buttons and scroll bars.
151     sal_Int32           mnSelType;          /// Listbox selection type.
152     sal_Int32           mnVTEdit;           /// Data type of the textbox.
153     bool                mbPrintObject;      /// True = print the object.
154     bool                mbVisible;          /// True = cell note is visible.
155     bool                mbDde;              /// True = object is linked through DDE.
156     bool                mbNo3D;             /// True = flat style, false = 3D style.
157     bool                mbNo3D2;            /// True = flat style, false = 3D style (listboxes and dropdowns).
158     bool                mbMultiLine;        /// True = textbox allows line breaks.
159     bool                mbVScroll;          /// True = textbox has a vertical scrollbar.
160     bool                mbSecretEdit;       /// True = textbox is a password edit field.
161 
162     explicit            ClientData();
163 };
164 
165 // ----------------------------------------------------------------------------
166 
167 struct ShapeModel
168 {
169     typedef ::std::vector< ::com::sun::star::awt::Point >   PointVector;
170     typedef ::std::auto_ptr< TextBox >                      TextBoxPtr;
171     typedef ::std::auto_ptr< ClientData >                   ClientDataPtr;
172 
173     ::rtl::OUString     maType;             /// Shape template with default properties.
174     PointVector         maPoints;           /// Points for the polyline shape.
175     TextBoxPtr          mxTextBox;          /// Text contents and properties.
176     ClientDataPtr       mxClientData;       /// Excel specific client data.
177 
178     explicit            ShapeModel();
179                         ~ShapeModel();
180 
181     /** Creates and returns a new shape textbox structure. */
182     TextBox&            createTextBox();
183     /** Creates and returns a new shape client data structure. */
184     ClientData&         createClientData();
185 };
186 
187 // ----------------------------------------------------------------------------
188 
189 /** A shape object that is part of a drawing. May inherit properties from a
190     shape template. */
191 class ShapeBase : public ShapeType
192 {
193 public:
194     /** Returns read/write access to the shape model structure. */
getShapeModel()195     inline ShapeModel&  getShapeModel() { return maShapeModel; }
196     /** Returns read access to the shape model structure. */
getShapeModel() const197     inline const ShapeModel& getShapeModel() const { return maShapeModel; }
198 
199     /** Returns read access to the shape textbox. */
getTextBox() const200     inline const TextBox* getTextBox() const { return maShapeModel.mxTextBox.get(); }
201     /** Returns read access to the shape client data structure. */
getClientData() const202     inline const ClientData* getClientData() const { return maShapeModel.mxClientData.get(); }
203 
204     /** Final processing after import of the drawing fragment. */
205     virtual void        finalizeFragmentImport();
206 
207     /** Returns the real shape name if existing, or a generated shape name. */
208     ::rtl::OUString     getShapeName() const;
209 
210     /** Returns the shape template with the passed identifier from the child shapes. */
211     virtual const ShapeType* getChildTypeById( const ::rtl::OUString& rShapeId ) const;
212     /** Returns the shape with the passed identifier from the child shapes. */
213     virtual const ShapeBase* getChildById( const ::rtl::OUString& rShapeId ) const;
214 
215     /** Creates the corresponding XShape and inserts it into the passed container. */
216     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
217                         convertAndInsert(
218                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
219                             const ShapeParentAnchor* pParentAnchor = 0 ) const;
220 
221     /** Converts position and formatting into the passed existing XShape. */
222     void                convertFormatting(
223                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape,
224                             const ShapeParentAnchor* pParentAnchor = 0 ) const;
225 
226 protected:
227     explicit            ShapeBase( Drawing& rDrawing );
228 
229     /** Derived classes create the corresponding XShape and insert it into the passed container. */
230     virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
231                         implConvertAndInsert(
232                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
233                             const ::com::sun::star::awt::Rectangle& rShapeRect ) const = 0;
234 
235     /** Calculates the final shape rectangle according to the passed anchor,
236         if present, otherwise according to the own anchor settings. */
237     ::com::sun::star::awt::Rectangle calcShapeRectangle(
238                             const ShapeParentAnchor* pParentAnchor ) const;
239 
240     /** Converts common shape properties such as formatting attributes. */
241     void                convertShapeProperties(
242                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape ) const;
243 
244 protected:
245     ShapeModel          maShapeModel;       /// The model structure containing shape data.
246 };
247 
248 // ============================================================================
249 
250 /** A simple shape object based on a specific UNO shape service. */
251 class SimpleShape : public ShapeBase
252 {
253 public:
254     explicit            SimpleShape( Drawing& rDrawing, const ::rtl::OUString& rService );
255 
256 protected:
257     /** Creates the corresponding XShape and inserts it into the passed container. */
258     virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
259                         implConvertAndInsert(
260                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
261                             const ::com::sun::star::awt::Rectangle& rShapeRect ) const;
262 
263 private:
264     ::rtl::OUString     maService;          /// Name of the UNO shape service.
265 };
266 
267 // ============================================================================
268 
269 /** A rectangular shape object. */
270 class RectangleShape : public SimpleShape
271 {
272 public:
273     explicit            RectangleShape( Drawing& rDrawing );
274 };
275 
276 // ============================================================================
277 
278 /** An oval shape object. */
279 class EllipseShape : public SimpleShape
280 {
281 public:
282     explicit            EllipseShape( Drawing& rDrawing );
283 };
284 
285 // ============================================================================
286 
287 /** A polygon shape object. */
288 class PolyLineShape : public SimpleShape
289 {
290 public:
291     explicit            PolyLineShape( Drawing& rDrawing );
292 
293 protected:
294     /** Creates the corresponding XShape and inserts it into the passed container. */
295     virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
296                         implConvertAndInsert(
297                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
298                             const ::com::sun::star::awt::Rectangle& rShapeRect ) const;
299 };
300 
301 // ============================================================================
302 
303 /** A shape object with custom geometry. */
304 class CustomShape : public SimpleShape
305 {
306 public:
307     explicit            CustomShape( Drawing& rDrawing );
308 
309 protected:
310     /** Creates the corresponding XShape and inserts it into the passed container. */
311     virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
312                         implConvertAndInsert(
313                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
314                             const ::com::sun::star::awt::Rectangle& rShapeRect ) const;
315 };
316 
317 // ============================================================================
318 
319 /** A complex shape object. This can be a picture shape, a custom shape, an OLE
320     object, or an ActiveX form control. */
321 class ComplexShape : public CustomShape
322 {
323 public:
324     explicit            ComplexShape( Drawing& rDrawing );
325 
326 protected:
327     /** Creates the corresponding XShape and inserts it into the passed container. */
328     virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
329                         implConvertAndInsert(
330                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
331                             const ::com::sun::star::awt::Rectangle& rShapeRect ) const;
332 };
333 
334 // ============================================================================
335 
336 /** A group shape that extends the basic shape by a container of child shapes. */
337 class GroupShape : public ShapeBase
338 {
339 public:
340     explicit            GroupShape( Drawing& rDrawing );
341     virtual             ~GroupShape();
342 
343     /** Returns read/write access to the container of child shapes and templates. */
getChildren()344     inline ShapeContainer& getChildren() { return *mxChildren; }
345     /** Returns read access to the container of child shapes and templates. */
getChildren() const346     inline const ShapeContainer& getChildren() const { return *mxChildren; }
347 
348     /** Final processing after import of the drawing fragment. */
349     virtual void        finalizeFragmentImport();
350 
351     /** Returns the shape template with the passed identifier from the child shapes. */
352     virtual const ShapeType* getChildTypeById( const ::rtl::OUString& rShapeId ) const;
353     /** Returns the shape with the passed identifier from the child shapes. */
354     virtual const ShapeBase* getChildById( const ::rtl::OUString& rShapeId ) const;
355 
356 protected:
357     /** Creates the corresponding XShape and inserts it into the passed container. */
358     virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
359                         implConvertAndInsert(
360                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
361                             const ::com::sun::star::awt::Rectangle& rShapeRect ) const;
362 
363 private:
364     typedef ::std::auto_ptr< ShapeContainer > ShapeContainerPtr;
365     ShapeContainerPtr   mxChildren;         /// Shapes and templates that are part of this group.
366 };
367 
368 // ============================================================================
369 
370 } // namespace vml
371 } // namespace oox
372 
373 #endif
374