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
26 #include <com/sun/star/awt/Point.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <oox/dllapi.h>
29 #include <oox/helper/helper.hxx>
30 #include <oox/vml/vmlformatting.hxx>
31 #include <rtl/ustring.hxx>
32 #include <sal/types.h>
34 namespace com
{ namespace sun
{ namespace star
{
35 namespace awt
{ struct Rectangle
; }
36 namespace drawing
{ class XShape
; }
37 namespace drawing
{ class XShapes
; }
44 struct ShapeParentAnchor
;
48 const sal_Int32 VML_CLIENTDATA_UNCHECKED
= 0;
49 const sal_Int32 VML_CLIENTDATA_CHECKED
= 1;
50 const sal_Int32 VML_CLIENTDATA_MIXED
= 2;
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;
59 /** The shape model structure contains all properties shared by all types of shapes. */
60 struct OOX_DLLPUBLIC ShapeTypeModel
62 OUString maShapeId
; ///< Unique identifier of the shape.
63 OUString maLegacyId
; ///< Plaintext identifier of the shape.
64 OUString maShapeName
; ///< Name of the shape, if present.
65 OptValue
< sal_Int32
> moShapeType
; ///< Builtin shape type identifier.
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 OUString maPosition
; ///< Position type of the shape.
70 OUString maZIndex
; ///< ZIndex of the shape
71 OUString maLeft
; ///< X position of the shape bounding box (number with unit).
72 OUString maTop
; ///< Y position of the shape bounding box (number with unit).
73 OUString maWidth
; ///< Width of the shape bounding box (number with unit).
74 OUString maHeight
; ///< Height of the shape bounding box (number with unit).
75 OUString maMarginLeft
; ///< X position of the shape bounding box to shape anchor (number with unit).
76 OUString maMarginTop
; ///< Y position of the shape bounding box to shape anchor (number with unit).
77 OUString maPositionHorizontalRelative
; ///< The X position is relative to this.
78 OUString maPositionVerticalRelative
; ///< The Y position is relative to this.
79 OUString maPositionHorizontal
; ///< The X position orientation (default: absolute).
80 OUString maPositionVertical
; ///< The Y position orientation.
81 OUString maWidthPercent
; ///< The width in percents of the WidthRelative
82 OUString maHeightPercent
; ///< The height in percents of the HeightRelative
83 OUString maWidthRelative
; ///< To what the width is relative
84 OUString maHeightRelative
; ///< To what the height is relative
85 OUString maRotation
; ///< Rotation of the shape, in degrees.
86 OUString maFlip
; ///< Flip type of the shape (can be "x" or "y").
87 bool mbAutoHeight
; ///< If true, the height value is a minimum value (mostly used for textboxes)
88 bool mbVisible
; ///< Visible or Hidden
89 OUString maWrapStyle
; ///< Wrapping mode for text.
90 OUString maArcsize
; ///< round rectangles arc size
91 OUString maEditAs
; ///< Edit As type (e.g. "canvas" etc)
93 StrokeModel maStrokeModel
; ///< Border line formatting.
94 FillModel maFillModel
; ///< Shape fill formatting.
95 ShadowModel maShadowModel
; ///< Shape shadow formatting.
96 TextpathModel maTextpathModel
; ///< Shape textpath formatting.
98 OptValue
< OUString
> moGraphicPath
; ///< Path to a graphic for this shape.
99 OptValue
< OUString
> moGraphicTitle
; ///< Title of the graphic.
100 OptValue
< OUString
> moWrapAnchorX
; ///< The base object from which our horizontal positioning should be calculated.
101 OptValue
< OUString
> moWrapAnchorY
; ///< The base object from which our vertical positioning should be calculated.
102 OptValue
< ::rtl::OUString
> moWrapType
; ///< How to wrap the text around the object
103 OptValue
< ::rtl::OUString
> moWrapSide
; ///< On which side to wrap the text around the object
104 OUString maVTextAnchor
; ///< How the text inside the shape is anchored vertically.
105 OUString maWrapDistanceLeft
; ///< Distance from the left side of the shape to the text that wraps around it.
106 OUString maWrapDistanceRight
; ///< Distance from the right side of the shape to the text that wraps around it.
107 OUString maWrapDistanceTop
; ///< Distance from the top of the shape to the text that wraps around it.
108 OUString maWrapDistanceBottom
; ///< Distance from the bottom of the shape to the text that wraps around it.
109 OptValue
<OUString
> moCropBottom
; ///< Specifies the how much to crop the image from the bottom up as a fraction of picture size.
110 OptValue
<OUString
> moCropLeft
; ///< Specifies how much to crop the image from the left in as a fraction of picture size.
111 OptValue
<OUString
> moCropRight
; ///< Specifies how much to crop the image from the right in as a fraction of picture size.
112 OptValue
<OUString
> moCropTop
; ///< Specifies how much to crop the image from the top down as a fraction of picture size.
113 OUString maLayoutFlowAlt
; ///< Specifies the alternate layout flow for text in textboxes.
115 explicit ShapeTypeModel();
117 void assignUsed( const ShapeTypeModel
& rSource
);
121 /** A shape template contains all formatting properties of shapes and can serve
122 as templates for several shapes in a drawing. */
126 explicit ShapeType( Drawing
& rDrawing
);
127 virtual ~ShapeType();
129 /** Returns read/write access to the shape template model structure. */
130 ShapeTypeModel
& getTypeModel() { return maTypeModel
; }
131 /** Returns read access to the shape template model structure. */
132 const ShapeTypeModel
& getTypeModel() const { return maTypeModel
; }
134 /** Returns the shape identifier (which is unique through the containing drawing). */
135 const OUString
& getShapeId() const { return maTypeModel
.maShapeId
; }
136 /** Returns the application defined shape type. */
137 sal_Int32
getShapeType() const;
138 /** Returns the fragment path to the embedded graphic used by this shape. */
139 OUString
getGraphicPath() const;
141 const Drawing
& getDrawing() const { return mrDrawing
; }
144 /** Returns the coordinate system of this shape. */
145 css::awt::Rectangle
getCoordSystem() const;
146 /** Returns the absolute shape rectangle according to the passed anchor. */
147 css::awt::Rectangle
getRectangle( const ShapeParentAnchor
* pParentAnchor
) const;
148 /** Returns the absolute shape rectangle. */
149 virtual css::awt::Rectangle
getAbsRectangle() const;
150 /** Returns the rectangle relative to the parent coordinate system. */
151 virtual css::awt::Rectangle
getRelRectangle() const;
154 Drawing
& mrDrawing
; ///< The VML drawing page that contains this shape.
155 ShapeTypeModel maTypeModel
; ///< The model structure containing shape type data.
159 /** Excel specific shape client data (such as cell anchor). */
162 OUString maAnchor
; ///< Cell anchor as comma-separated string.
163 OUString maFmlaMacro
; ///< Link to macro associated to the control.
164 OUString maFmlaPict
; ///< Target cell range of picture links.
165 OUString maFmlaLink
; ///< Link to value cell associated to the control.
166 OUString maFmlaRange
; ///< Link to cell range used as data source for the control.
167 OUString maFmlaGroup
; ///< Link to value cell associated to a group of option buttons.
168 sal_Int32 mnObjType
; ///< Type of the shape.
169 sal_Int32 mnTextHAlign
; ///< Horizontal text alignment.
170 sal_Int32 mnTextVAlign
; ///< Vertical text alignment.
171 sal_Int32 mnCol
; ///< Column index for spreadsheet cell note.
172 sal_Int32 mnRow
; ///< Row index for spreadsheet cell note.
173 sal_Int32 mnChecked
; ///< State for checkboxes and option buttons.
174 sal_Int32 mnDropStyle
; ///< Drop down box style (read-only or editable).
175 sal_Int32 mnDropLines
; ///< Number of lines in drop down box.
176 sal_Int32 mnVal
; ///< Current value of spin buttons and scroll bars.
177 sal_Int32 mnMin
; ///< Minimum value of spin buttons and scroll bars.
178 sal_Int32 mnMax
; ///< Maximum value of spin buttons and scroll bars.
179 sal_Int32 mnInc
; ///< Small increment of spin buttons and scroll bars.
180 sal_Int32 mnPage
; ///< Large increment of spin buttons and scroll bars.
181 sal_Int32 mnSelType
; ///< Listbox selection type.
182 sal_Int32 mnVTEdit
; ///< Data type of the textbox.
183 bool mbPrintObject
; ///< True = print the object.
184 bool mbVisible
; ///< True = cell note is visible.
185 bool mbDde
; ///< True = object is linked through DDE.
186 bool mbNo3D
; ///< True = flat style, false = 3D style.
187 bool mbNo3D2
; ///< True = flat style, false = 3D style (listboxes and dropdowns).
188 bool mbMultiLine
; ///< True = textbox allows line breaks.
189 bool mbVScroll
; ///< True = textbox has a vertical scrollbar.
190 bool mbSecretEdit
; ///< True = textbox is a password edit field.
192 explicit ClientData();
198 typedef ::std::vector
< css::awt::Point
> PointVector
;
200 OUString maType
; ///< Shape template with default properties.
201 PointVector maPoints
; ///< Points for the polyline shape.
202 std::unique_ptr
<TextBox
> mxTextBox
; ///< Text contents and properties.
203 std::unique_ptr
<ClientData
> mxClientData
; ///< Excel specific client data.
204 OUString maLegacyDiagramPath
;///< Legacy Diagram Fragment Path
205 OUString maFrom
; ///< Start point for line shape.
206 OUString maTo
; ///< End point for line shape.
207 OUString maControl1
; ///< Bezier control point 1
208 OUString maControl2
; ///< Bezier control point 2
209 OUString maVmlPath
; ///< VML path for this 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();
221 /** A shape object that is part of a drawing. May inherit properties from a
223 class OOX_DLLPUBLIC ShapeBase
: public ShapeType
226 /** Returns read/write access to the shape model structure. */
227 ShapeModel
& getShapeModel() { return maShapeModel
; }
228 /** Returns read access to the shape model structure. */
229 const ShapeModel
& getShapeModel() const { return maShapeModel
; }
231 /** Returns read access to the shape textbox. */
232 const TextBox
* getTextBox() const { return maShapeModel
.mxTextBox
.get(); }
233 /** Returns read access to the shape client data structure. */
234 const ClientData
* getClientData() const { return maShapeModel
.mxClientData
.get(); }
236 /** Final processing after import of the drawing fragment. */
237 virtual void finalizeFragmentImport();
239 /** Returns the real shape name if existing, or a generated shape name. */
240 OUString
getShapeName() const;
242 /** Returns the shape template with the passed identifier from the child shapes. */
243 virtual const ShapeType
* getChildTypeById( const OUString
& rShapeId
) const;
244 /** Returns the shape with the passed identifier from the child shapes. */
245 virtual const ShapeBase
* getChildById( const OUString
& rShapeId
) const;
247 /** Creates the corresponding XShape and inserts it into the passed container. */
248 css::uno::Reference
< css::drawing::XShape
>
250 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
251 const ShapeParentAnchor
* pParentAnchor
= nullptr ) const;
253 /** Converts position and formatting into the passed existing XShape. */
254 void convertFormatting(
255 const css::uno::Reference
< css::drawing::XShape
>& rxShape
) const;
258 explicit ShapeBase( Drawing
& rDrawing
);
260 /** Derived classes create the corresponding XShape and insert it into the passed container. */
261 virtual css::uno::Reference
< css::drawing::XShape
>
262 implConvertAndInsert(
263 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
264 const css::awt::Rectangle
& rShapeRect
) const = 0;
266 /** Calculates the final shape rectangle according to the passed anchor,
267 if present, otherwise according to the own anchor settings. */
268 css::awt::Rectangle
calcShapeRectangle(
269 const ShapeParentAnchor
* pParentAnchor
) const;
271 /** Converts common shape properties such as formatting attributes. */
272 void convertShapeProperties(
273 const css::uno::Reference
< css::drawing::XShape
>& rxShape
) const;
276 ShapeModel maShapeModel
; ///< The model structure containing shape data.
280 /** A simple shape object based on a specific UNO shape service. */
281 class SimpleShape
: public ShapeBase
284 explicit SimpleShape( Drawing
& rDrawing
, const OUString
& rService
);
286 void setService( const OUString
& aService
) { maService
= aService
; }
289 /** Creates the corresponding XShape and inserts it into the passed container. */
290 virtual css::uno::Reference
< css::drawing::XShape
>
291 implConvertAndInsert(
292 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
293 const css::awt::Rectangle
& rShapeRect
) const override
;
294 /** Used by both RectangleShape and ComplexShape. */
295 css::uno::Reference
<css::drawing::XShape
>createPictureObject(
296 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
297 const css::awt::Rectangle
& rShapeRect
, OUString
& rGraphicPath
) const;
300 OUString maService
; ///< Name of the UNO shape service.
304 /** A rectangular shape object. */
305 class RectangleShape
: public SimpleShape
308 explicit RectangleShape( Drawing
& rDrawing
);
310 /** Creates the corresponding XShape and inserts it into the passed container. */
311 virtual css::uno::Reference
<css::drawing::XShape
>
312 implConvertAndInsert(
313 const css::uno::Reference
<css::drawing::XShapes
>& rxShapes
,
314 const css::awt::Rectangle
& rShapeRect
) const override
;
318 /** An oval shape object. */
319 class EllipseShape
: public SimpleShape
322 explicit EllipseShape( Drawing
& rDrawing
);
326 /** A polygon shape object. */
327 class PolyLineShape
: public SimpleShape
330 explicit PolyLineShape( Drawing
& rDrawing
);
333 /** Creates the corresponding XShape and inserts it into the passed container. */
334 virtual css::uno::Reference
< css::drawing::XShape
>
335 implConvertAndInsert(
336 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
337 const css::awt::Rectangle
& rShapeRect
) const override
;
340 /** A Line shape object. */
341 class LineShape
: public SimpleShape
344 explicit LineShape( Drawing
& rDrawing
);
347 /** Returns the absolute shape rectangle. */
348 virtual css::awt::Rectangle
getAbsRectangle() const override
;
349 /** Returns the rectangle relative to the parent coordinate system. */
350 virtual css::awt::Rectangle
getRelRectangle() const override
;
353 /** Bezier shape object that supports to, from, control1 and control2
354 attribute or path attribute specification */
355 class BezierShape
: public SimpleShape
358 explicit BezierShape( Drawing
& rDrawing
);
361 /** Creates the corresponding XShape and inserts it into the passed container. */
362 virtual css::uno::Reference
< css::drawing::XShape
>
363 implConvertAndInsert(
364 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
365 const css::awt::Rectangle
& rShapeRect
) const override
;
369 /** A shape object with custom geometry. */
370 class CustomShape
: public SimpleShape
373 explicit CustomShape( Drawing
& rDrawing
);
376 /** Creates the corresponding XShape and inserts it into the passed container. */
377 virtual css::uno::Reference
< css::drawing::XShape
>
378 implConvertAndInsert(
379 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
380 const css::awt::Rectangle
& rShapeRect
) const override
;
384 /** A complex shape object. This can be a picture shape, a custom shape, an OLE
385 object, or an ActiveX form control. */
386 class ComplexShape
: public CustomShape
389 explicit ComplexShape( Drawing
& rDrawing
);
392 /** Creates the corresponding XShape and inserts it into the passed container. */
393 virtual css::uno::Reference
< css::drawing::XShape
>
394 implConvertAndInsert(
395 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
396 const css::awt::Rectangle
& rShapeRect
) const override
;
400 /** A group shape that extends the basic shape by a container of child shapes. */
401 class GroupShape
: public ShapeBase
404 explicit GroupShape( Drawing
& rDrawing
);
405 virtual ~GroupShape() override
;
407 /** Returns read/write access to the container of child shapes and templates. */
408 ShapeContainer
& getChildren() { return *mxChildren
; }
409 /** Returns read access to the container of child shapes and templates. */
410 const ShapeContainer
& getChildren() const { return *mxChildren
; }
412 /** Final processing after import of the drawing fragment. */
413 virtual void finalizeFragmentImport() override
;
415 /** Returns the shape template with the passed identifier from the child shapes. */
416 virtual const ShapeType
* getChildTypeById( const OUString
& rShapeId
) const override
;
417 /** Returns the shape with the passed identifier from the child shapes. */
418 virtual const ShapeBase
* getChildById( const OUString
& rShapeId
) const override
;
421 /** Creates the corresponding XShape and inserts it into the passed container. */
422 virtual css::uno::Reference
< css::drawing::XShape
>
423 implConvertAndInsert(
424 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
425 const css::awt::Rectangle
& rShapeRect
) const override
;
428 std::unique_ptr
<ShapeContainer
> mxChildren
; ///< Shapes and templates that are part of this group.
437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */