1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_OOX_VML_VMLSHAPE_HXX
21 #define INCLUDED_OOX_VML_VMLSHAPE_HXX
25 #include <com/sun/star/awt/Point.hpp>
26 #include <oox/vml/vmlformatting.hxx>
27 #include <oox/vml/vmltextbox.hxx>
28 #include <oox/dllapi.h>
30 namespace com
{ namespace sun
{ namespace star
{
31 namespace awt
{ struct Rectangle
; }
32 namespace drawing
{ class XShape
; }
33 namespace drawing
{ class XShapes
; }
40 struct ShapeParentAnchor
;
45 const sal_Int32 VML_CLIENTDATA_UNCHECKED
= 0;
46 const sal_Int32 VML_CLIENTDATA_CHECKED
= 1;
47 const sal_Int32 VML_CLIENTDATA_MIXED
= 2;
49 const sal_Int32 VML_CLIENTDATA_TEXT
= 0;
50 const sal_Int32 VML_CLIENTDATA_INTEGER
= 1;
51 const sal_Int32 VML_CLIENTDATA_NUMBER
= 2;
52 const sal_Int32 VML_CLIENTDATA_REFERENCE
= 3;
53 const sal_Int32 VML_CLIENTDATA_FORMULA
= 4;
57 /** The shape model structure contains all properties shared by all types of shapes. */
58 struct OOX_DLLPUBLIC ShapeTypeModel
60 OUString maShapeId
; ///< Unique identifier of the shape.
61 OUString maLegacyId
; ///< Plaintext identifier of the shape.
62 OUString maShapeName
; ///< Name of the shape, if present.
63 OptValue
< sal_Int32
> moShapeType
; ///< Builtin shape type identifier.
65 OptValue
< Int32Pair
> moCoordPos
; ///< Top-left position of coordinate system for children scaling.
66 OptValue
< Int32Pair
> moCoordSize
; ///< Size of coordinate system for children scaling.
67 OUString maPosition
; ///< Position type of the shape.
68 OUString maZIndex
; ///< ZIndex of the shape
69 OUString maLeft
; ///< X position of the shape bounding box (number with unit).
70 OUString maTop
; ///< Y position of the shape bounding box (number with unit).
71 OUString maWidth
; ///< Width of the shape bounding box (number with unit).
72 OUString maHeight
; ///< Height of the shape bounding box (number with unit).
73 OUString maMarginLeft
; ///< X position of the shape bounding box to shape anchor (number with unit).
74 OUString maMarginTop
; ///< Y position of the shape bounding box to shape anchor (number with unit).
75 OUString maPositionHorizontalRelative
; ///< The X position is relative to this.
76 OUString maPositionVerticalRelative
; ///< The Y position is relative to this.
77 OUString maPositionHorizontal
; ///< The X position orientation (default: absolute).
78 OUString maPositionVertical
; ///< The Y position orientation.
79 OUString maWidthPercent
; ///< The width in percents of the WidthRelative
80 OUString maHeightPercent
; ///< The height in percents of the HeightRelative
81 OUString maWidthRelative
; ///< To what the width is relative
82 OUString maHeightRelative
; ///< To what the height is relative
83 OUString maRotation
; ///< Rotation of the shape, in degrees.
84 OUString maFlip
; ///< Flip type of the shape (can be "x" or "y").
85 bool mbAutoHeight
; ///< If true, the height value is a minimum value (mostly used for textboxes)
86 bool mbVisible
; ///< Visible or Hidden
87 OUString maWrapStyle
; ///< Wrapping mode for text.
88 OUString maArcsize
; ///< round rectangles arc size
89 OUString maEditAs
; ///< Edit As type (e.g. "canvas" etc)
91 StrokeModel maStrokeModel
; ///< Border line formatting.
92 FillModel maFillModel
; ///< Shape fill formatting.
93 ShadowModel maShadowModel
; ///< Shape shadow formatting.
94 TextpathModel maTextpathModel
; ///< Shape textpath formatting.
96 OptValue
< OUString
> moGraphicPath
; ///< Path to a graphic for this shape.
97 OptValue
< OUString
> moGraphicTitle
; ///< Title of the graphic.
98 OptValue
< OUString
> moWrapAnchorX
; ///< The base object from which our horizontal positioning should be calculated.
99 OptValue
< OUString
> moWrapAnchorY
; ///< The base object from which our vertical positioning should be calculated.
100 OptValue
< ::rtl::OUString
> moWrapType
; ///< How to wrap the text around the object
101 OptValue
< ::rtl::OUString
> moWrapSide
; ///< On which side to wrap the text around the object
102 OUString maVTextAnchor
; ///< How the text inside the shape is anchored vertically.
103 OUString maWrapDistanceLeft
; ///< Distance from the left side of the shape to the text that wraps around it.
104 OUString maWrapDistanceRight
; ///< Distance from the right side of the shape to the text that wraps around it.
105 OUString maWrapDistanceTop
; ///< Distance from the top of the shape to the text that wraps around it.
106 OUString maWrapDistanceBottom
; ///< Distance from the bottom of the shape to the text that wraps around it.
107 OUString maLayoutFlowAlt
; ///< Specifies the alternate layout flow for text in textboxes.
109 explicit ShapeTypeModel();
111 void assignUsed( const ShapeTypeModel
& rSource
);
116 /** A shape template contains all formatting properties of shapes and can serve
117 as templates for several shapes in a drawing. */
121 explicit ShapeType( Drawing
& rDrawing
);
122 virtual ~ShapeType();
124 /** Returns read/write access to the shape template model structure. */
125 ShapeTypeModel
& getTypeModel() { return maTypeModel
; }
126 /** Returns read access to the shape template model structure. */
127 const ShapeTypeModel
& getTypeModel() const { return maTypeModel
; }
129 /** Returns the shape identifier (which is unique through the containing drawing). */
130 const OUString
& getShapeId() const { return maTypeModel
.maShapeId
; }
131 /** Returns the application defined shape type. */
132 sal_Int32
getShapeType() const;
133 /** Returns the fragment path to the embedded graphic used by this shape. */
134 OUString
getGraphicPath() const;
136 const Drawing
& getDrawing() const { return mrDrawing
; }
139 /** Returns the coordinate system of this shape. */
140 ::com::sun::star::awt::Rectangle
getCoordSystem() const;
141 /** Returns the absolute shape rectangle according to the passed anchor. */
142 ::com::sun::star::awt::Rectangle
getRectangle( const ShapeParentAnchor
* pParentAnchor
) const;
143 /** Returns the absolute shape rectangle. */
144 virtual ::com::sun::star::awt::Rectangle
getAbsRectangle() const;
145 /** Returns the rectangle relative to the parent coordinate system. */
146 virtual ::com::sun::star::awt::Rectangle
getRelRectangle() const;
149 Drawing
& mrDrawing
; ///< The VML drawing page that contains this shape.
150 ShapeTypeModel maTypeModel
; ///< The model structure containing shape type data.
155 /** Excel specific shape client data (such as cell anchor). */
158 OUString maAnchor
; ///< Cell anchor as comma-separated string.
159 OUString maFmlaMacro
; ///< Link to macro associated to the control.
160 OUString maFmlaPict
; ///< Target cell range of picture links.
161 OUString maFmlaLink
; ///< Link to value cell associated to the control.
162 OUString maFmlaRange
; ///< Link to cell range used as data source for the control.
163 OUString maFmlaGroup
; ///< Link to value cell associated to a group of option buttons.
164 sal_Int32 mnObjType
; ///< Type of the shape.
165 sal_Int32 mnTextHAlign
; ///< Horizontal text alignment.
166 sal_Int32 mnTextVAlign
; ///< Vertical text alignment.
167 sal_Int32 mnCol
; ///< Column index for spreadsheet cell note.
168 sal_Int32 mnRow
; ///< Row index for spreadsheet cell note.
169 sal_Int32 mnChecked
; ///< State for checkboxes and option buttons.
170 sal_Int32 mnDropStyle
; ///< Drop down box style (read-only or editable).
171 sal_Int32 mnDropLines
; ///< Number of lines in drop down box.
172 sal_Int32 mnVal
; ///< Current value of spin buttons and scroll bars.
173 sal_Int32 mnMin
; ///< Minimum value of spin buttons and scroll bars.
174 sal_Int32 mnMax
; ///< Maximum value of spin buttons and scroll bars.
175 sal_Int32 mnInc
; ///< Small increment of spin buttons and scroll bars.
176 sal_Int32 mnPage
; ///< Large increment of spin buttons and scroll bars.
177 sal_Int32 mnSelType
; ///< Listbox selection type.
178 sal_Int32 mnVTEdit
; ///< Data type of the textbox.
179 bool mbPrintObject
; ///< True = print the object.
180 bool mbVisible
; ///< True = cell note is visible.
181 bool mbDde
; ///< True = object is linked through DDE.
182 bool mbNo3D
; ///< True = flat style, false = 3D style.
183 bool mbNo3D2
; ///< True = flat style, false = 3D style (listboxes and dropdowns).
184 bool mbMultiLine
; ///< True = textbox allows line breaks.
185 bool mbVScroll
; ///< True = textbox has a vertical scrollbar.
186 bool mbSecretEdit
; ///< True = textbox is a password edit field.
188 explicit ClientData();
195 typedef ::std::vector
< ::com::sun::star::awt::Point
> PointVector
;
196 typedef ::std::unique_ptr
< TextBox
> TextBoxPtr
;
197 typedef ::std::unique_ptr
< ClientData
> ClientDataPtr
;
199 OUString maType
; ///< Shape template with default properties.
200 PointVector maPoints
; ///< Points for the polyline shape.
201 TextBoxPtr mxTextBox
; ///< Text contents and properties.
202 ClientDataPtr mxClientData
; ///< Excel specific client data.
203 OUString maLegacyDiagramPath
;///< Legacy Diagram Fragment Path
204 OUString maFrom
; ///< Start point for line shape.
205 OUString maTo
; ///< End point for line shape.
206 OUString maControl1
; ///< Bezier control point 1
207 OUString maControl2
; ///< Bezier control point 2
208 OUString maVmlPath
; ///< VML path for this shape
209 OUString maEditAs
; ///< VML EditAs for shape
211 explicit ShapeModel();
214 /** Creates and returns a new shape textbox structure. */
215 TextBox
& createTextBox(ShapeTypeModel
& rModel
);
216 /** Creates and returns a new shape client data structure. */
217 ClientData
& createClientData();
222 /** A shape object that is part of a drawing. May inherit properties from a
224 class OOX_DLLPUBLIC ShapeBase
: public ShapeType
227 /** Returns read/write access to the shape model structure. */
228 ShapeModel
& getShapeModel() { return maShapeModel
; }
229 /** Returns read access to the shape model structure. */
230 const ShapeModel
& getShapeModel() const { return maShapeModel
; }
232 /** Returns read access to the shape textbox. */
233 const TextBox
* getTextBox() const { return maShapeModel
.mxTextBox
.get(); }
234 /** Returns read access to the shape client data structure. */
235 const ClientData
* getClientData() const { return maShapeModel
.mxClientData
.get(); }
237 /** Final processing after import of the drawing fragment. */
238 virtual void finalizeFragmentImport();
240 /** Returns the real shape name if existing, or a generated shape name. */
241 OUString
getShapeName() const;
243 /** Returns the shape template with the passed identifier from the child shapes. */
244 virtual const ShapeType
* getChildTypeById( const OUString
& rShapeId
) const;
245 /** Returns the shape with the passed identifier from the child shapes. */
246 virtual const ShapeBase
* getChildById( const OUString
& rShapeId
) const;
248 /** Creates the corresponding XShape and inserts it into the passed container. */
249 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
251 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& rxShapes
,
252 const ShapeParentAnchor
* pParentAnchor
= 0 ) const;
254 /** Converts position and formatting into the passed existing XShape. */
255 void convertFormatting(
256 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>& rxShape
,
257 const ShapeParentAnchor
* pParentAnchor
= 0 ) const;
260 explicit ShapeBase( Drawing
& rDrawing
);
262 /** Derived classes create the corresponding XShape and insert it into the passed container. */
263 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
264 implConvertAndInsert(
265 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& rxShapes
,
266 const ::com::sun::star::awt::Rectangle
& rShapeRect
) const = 0;
268 /** Calculates the final shape rectangle according to the passed anchor,
269 if present, otherwise according to the own anchor settings. */
270 ::com::sun::star::awt::Rectangle
calcShapeRectangle(
271 const ShapeParentAnchor
* pParentAnchor
) const;
273 /** Converts common shape properties such as formatting attributes. */
274 void convertShapeProperties(
275 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>& rxShape
) const;
278 ShapeModel maShapeModel
; ///< The model structure containing shape data.
283 /** A simple shape object based on a specific UNO shape service. */
284 class SimpleShape
: public ShapeBase
287 explicit SimpleShape( Drawing
& rDrawing
, const OUString
& rService
);
289 void setService( const OUString
& aService
) { maService
= aService
; }
292 /** Creates the corresponding XShape and inserts it into the passed container. */
293 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
294 implConvertAndInsert(
295 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& rxShapes
,
296 const ::com::sun::star::awt::Rectangle
& rShapeRect
) const SAL_OVERRIDE
;
297 /** Used by both RectangleShape and ComplexShape. */
298 com::sun::star::uno::Reference
<com::sun::star::drawing::XShape
>createPictureObject(
299 const com::sun::star::uno::Reference
< com::sun::star::drawing::XShapes
>& rxShapes
,
300 const com::sun::star::awt::Rectangle
& rShapeRect
, OUString
& rGraphicPath
) const;
303 OUString maService
; ///< Name of the UNO shape service.
308 /** A rectangular shape object. */
309 class RectangleShape
: public SimpleShape
312 explicit RectangleShape( Drawing
& rDrawing
);
314 /** Creates the corresponding XShape and inserts it into the passed container. */
315 virtual com::sun::star::uno::Reference
<com::sun::star::drawing::XShape
>
316 implConvertAndInsert(
317 const com::sun::star::uno::Reference
<com::sun::star::drawing::XShapes
>& rxShapes
,
318 const com::sun::star::awt::Rectangle
& rShapeRect
) const SAL_OVERRIDE
;
323 /** An oval shape object. */
324 class EllipseShape
: public SimpleShape
327 explicit EllipseShape( Drawing
& rDrawing
);
332 /** A polygon shape object. */
333 class PolyLineShape
: public SimpleShape
336 explicit PolyLineShape( Drawing
& rDrawing
);
339 /** Creates the corresponding XShape and inserts it into the passed container. */
340 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
341 implConvertAndInsert(
342 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& rxShapes
,
343 const ::com::sun::star::awt::Rectangle
& rShapeRect
) const SAL_OVERRIDE
;
346 /** A Line shape object. */
347 class LineShape
: public SimpleShape
350 explicit LineShape( Drawing
& rDrawing
);
353 /** Returns the absolute shape rectangle. */
354 virtual ::com::sun::star::awt::Rectangle
getAbsRectangle() const SAL_OVERRIDE
;
355 /** Returns the rectangle relative to the parent coordinate system. */
356 virtual ::com::sun::star::awt::Rectangle
getRelRectangle() const SAL_OVERRIDE
;
359 /** Bezier shape object that supports to, from, control1 and control2
360 attribute or path attribute specification */
361 class BezierShape
: public SimpleShape
364 explicit BezierShape( Drawing
& rDrawing
);
367 /** Creates the corresponding XShape and inserts it into the passed container. */
368 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
369 implConvertAndInsert(
370 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& rxShapes
,
371 const ::com::sun::star::awt::Rectangle
& rShapeRect
) const SAL_OVERRIDE
;
376 /** A shape object with custom geometry. */
377 class CustomShape
: public SimpleShape
380 explicit CustomShape( Drawing
& rDrawing
);
383 /** Creates the corresponding XShape and inserts it into the passed container. */
384 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
385 implConvertAndInsert(
386 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& rxShapes
,
387 const ::com::sun::star::awt::Rectangle
& rShapeRect
) const SAL_OVERRIDE
;
392 /** A complex shape object. This can be a picture shape, a custom shape, an OLE
393 object, or an ActiveX form control. */
394 class ComplexShape
: public CustomShape
397 explicit ComplexShape( Drawing
& rDrawing
);
400 /** Creates the corresponding XShape and inserts it into the passed container. */
401 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
402 implConvertAndInsert(
403 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& rxShapes
,
404 const ::com::sun::star::awt::Rectangle
& rShapeRect
) const SAL_OVERRIDE
;
409 /** A group shape that extends the basic shape by a container of child shapes. */
410 class GroupShape
: public ShapeBase
413 explicit GroupShape( Drawing
& rDrawing
);
414 virtual ~GroupShape();
416 /** Returns read/write access to the container of child shapes and templates. */
417 ShapeContainer
& getChildren() { return *mxChildren
; }
418 /** Returns read access to the container of child shapes and templates. */
419 const ShapeContainer
& getChildren() const { return *mxChildren
; }
421 /** Final processing after import of the drawing fragment. */
422 virtual void finalizeFragmentImport() SAL_OVERRIDE
;
424 /** Returns the shape template with the passed identifier from the child shapes. */
425 virtual const ShapeType
* getChildTypeById( const OUString
& rShapeId
) const SAL_OVERRIDE
;
426 /** Returns the shape with the passed identifier from the child shapes. */
427 virtual const ShapeBase
* getChildById( const OUString
& rShapeId
) const SAL_OVERRIDE
;
430 /** Creates the corresponding XShape and inserts it into the passed container. */
431 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
432 implConvertAndInsert(
433 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& rxShapes
,
434 const ::com::sun::star::awt::Rectangle
& rShapeRect
) const SAL_OVERRIDE
;
437 typedef ::std::unique_ptr
< ShapeContainer
> ShapeContainerPtr
;
438 ShapeContainerPtr mxChildren
; ///< Shapes and templates that are part of this group.
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */