Bump version to 6.4-15
[LibreOffice.git] / include / oox / vml / vmlshape.hxx
blob2b3677df106dfcfc48223a604e46e285f847e001
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <memory>
24 #include <vector>
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; }
38 namespace graphic { class XGraphic; }
39 } } }
41 namespace oox {
42 namespace vml {
44 class Drawing;
45 struct ShapeParentAnchor;
46 class ShapeContainer;
47 class TextBox;
49 const sal_Int32 VML_CLIENTDATA_UNCHECKED = 0;
50 const sal_Int32 VML_CLIENTDATA_CHECKED = 1;
51 const sal_Int32 VML_CLIENTDATA_MIXED = 2;
53 const sal_Int32 VML_CLIENTDATA_TEXT = 0;
54 const sal_Int32 VML_CLIENTDATA_INTEGER = 1;
55 const sal_Int32 VML_CLIENTDATA_NUMBER = 2;
56 const sal_Int32 VML_CLIENTDATA_REFERENCE = 3;
57 const sal_Int32 VML_CLIENTDATA_FORMULA = 4;
60 /** The shape model structure contains all properties shared by all types of shapes. */
61 struct OOX_DLLPUBLIC ShapeTypeModel
63 OUString maShapeId; ///< Unique identifier of the shape.
64 OUString maLegacyId; ///< Plaintext identifier of the shape.
65 OUString maShapeName; ///< Name of the shape, if present.
66 OptValue< sal_Int32 > moShapeType; ///< Builtin shape type identifier.
68 OptValue< Int32Pair > moCoordPos; ///< Top-left position of coordinate system for children scaling.
69 OptValue< Int32Pair > moCoordSize; ///< Size of coordinate system for children scaling.
70 OUString maPosition; ///< Position type of the shape.
71 OUString maZIndex; ///< ZIndex of the shape
72 OUString maLeft; ///< X position of the shape bounding box (number with unit).
73 OUString maTop; ///< Y position of the shape bounding box (number with unit).
74 OUString maWidth; ///< Width of the shape bounding box (number with unit).
75 OUString maHeight; ///< Height of the shape bounding box (number with unit).
76 OUString maMarginLeft; ///< X position of the shape bounding box to shape anchor (number with unit).
77 OUString maMarginTop; ///< Y position of the shape bounding box to shape anchor (number with unit).
78 OUString maPositionHorizontalRelative; ///< The X position is relative to this.
79 OUString maPositionVerticalRelative; ///< The Y position is relative to this.
80 OUString maPositionHorizontal; ///< The X position orientation (default: absolute).
81 OUString maPositionVertical; ///< The Y position orientation.
82 OUString maWidthPercent; ///< The width in percents of the WidthRelative
83 OUString maHeightPercent; ///< The height in percents of the HeightRelative
84 OUString maWidthRelative; ///< To what the width is relative
85 OUString maHeightRelative; ///< To what the height is relative
86 OUString maRotation; ///< Rotation of the shape, in degrees.
87 OUString maFlip; ///< Flip type of the shape (can be "x" or "y").
88 bool mbAutoHeight; ///< If true, the height value is a minimum value (mostly used for textboxes)
89 bool mbVisible; ///< Visible or Hidden
90 OUString maWrapStyle; ///< Wrapping mode for text.
91 OUString maArcsize; ///< round rectangles arc size
92 OUString maEditAs; ///< Edit As type (e.g. "canvas" etc)
93 OUString maAdjustments; ///< Shape adjustment values
95 StrokeModel maStrokeModel; ///< Border line formatting.
96 FillModel maFillModel; ///< Shape fill formatting.
97 ShadowModel maShadowModel; ///< Shape shadow formatting.
98 TextpathModel maTextpathModel; ///< Shape textpath formatting.
100 OptValue< OUString > moGraphicPath; ///< Path to a graphic for this shape.
101 OptValue< OUString > moGraphicTitle; ///< Title of the graphic.
102 OptValue< OUString > moWrapAnchorX; ///< The base object from which our horizontal positioning should be calculated.
103 OptValue< OUString > moWrapAnchorY; ///< The base object from which our vertical positioning should be calculated.
104 OptValue< OUString > moWrapType; ///< How to wrap the text around the object
105 OptValue< OUString > moWrapSide; ///< On which side to wrap the text around the object
106 OUString maVTextAnchor; ///< How the text inside the shape is anchored vertically.
107 OUString maWrapDistanceLeft; ///< Distance from the left side of the shape to the text that wraps around it.
108 OUString maWrapDistanceRight; ///< Distance from the right side of the shape to the text that wraps around it.
109 OUString maWrapDistanceTop; ///< Distance from the top of the shape to the text that wraps around it.
110 OUString maWrapDistanceBottom; ///< Distance from the bottom of the shape to the text that wraps around it.
111 OptValue<OUString> moCropBottom; ///< Specifies the how much to crop the image from the bottom up as a fraction of picture size.
112 OptValue<OUString> moCropLeft; ///< Specifies how much to crop the image from the left in as a fraction of picture size.
113 OptValue<OUString> moCropRight; ///< Specifies how much to crop the image from the right in as a fraction of picture size.
114 OptValue<OUString> moCropTop; ///< Specifies how much to crop the image from the top down as a fraction of picture size.
115 OUString maLayoutFlowAlt; ///< Specifies the alternate layout flow for text in textboxes.
117 explicit ShapeTypeModel();
119 void assignUsed( const ShapeTypeModel& rSource );
123 /** A shape template contains all formatting properties of shapes and can serve
124 as templates for several shapes in a drawing. */
125 class SAL_DLLPUBLIC_RTTI ShapeType
127 public:
128 explicit ShapeType( Drawing& rDrawing );
129 virtual ~ShapeType();
131 /** Returns read/write access to the shape template model structure. */
132 ShapeTypeModel& getTypeModel() { return maTypeModel; }
133 /** Returns read access to the shape template model structure. */
134 const ShapeTypeModel& getTypeModel() const { return maTypeModel; }
136 /** Returns the shape identifier (which is unique through the containing drawing). */
137 const OUString& getShapeId() const { return maTypeModel.maShapeId; }
138 /** Returns the application defined shape type. */
139 sal_Int32 getShapeType() const;
140 /** Returns the fragment path to the embedded graphic used by this shape. */
141 OUString getGraphicPath() const;
143 const Drawing& getDrawing() const { return mrDrawing; }
145 protected:
146 /** Returns the coordinate system of this shape. */
147 css::awt::Rectangle getCoordSystem() const;
148 /** Returns the absolute shape rectangle according to the passed anchor. */
149 css::awt::Rectangle getRectangle( const ShapeParentAnchor* pParentAnchor ) const;
150 /** Returns the absolute shape rectangle. */
151 virtual css::awt::Rectangle getAbsRectangle() const;
152 /** Returns the rectangle relative to the parent coordinate system. */
153 virtual css::awt::Rectangle getRelRectangle() const;
155 protected:
156 Drawing& mrDrawing; ///< The VML drawing page that contains this shape.
157 ShapeTypeModel maTypeModel; ///< The model structure containing shape type data.
161 /** Excel specific shape client data (such as cell anchor). */
162 struct ClientData
164 OUString maAnchor; ///< Cell anchor as comma-separated string.
165 OUString maFmlaMacro; ///< Link to macro associated to the control.
166 OUString maFmlaPict; ///< Target cell range of picture links.
167 OUString maFmlaLink; ///< Link to value cell associated to the control.
168 OUString maFmlaRange; ///< Link to cell range used as data source for the control.
169 OUString maFmlaGroup; ///< Link to value cell associated to a group of option buttons.
170 sal_Int32 mnObjType; ///< Type of the shape.
171 sal_Int32 mnTextHAlign; ///< Horizontal text alignment.
172 sal_Int32 mnTextVAlign; ///< Vertical text alignment.
173 sal_Int32 mnCol; ///< Column index for spreadsheet cell note.
174 sal_Int32 mnRow; ///< Row index for spreadsheet cell note.
175 sal_Int32 mnChecked; ///< State for checkboxes and option buttons.
176 sal_Int32 mnDropStyle; ///< Drop down box style (read-only or editable).
177 sal_Int32 mnDropLines; ///< Number of lines in drop down box.
178 sal_Int32 mnVal; ///< Current value of spin buttons and scroll bars.
179 sal_Int32 mnMin; ///< Minimum value of spin buttons and scroll bars.
180 sal_Int32 mnMax; ///< Maximum value of spin buttons and scroll bars.
181 sal_Int32 mnInc; ///< Small increment of spin buttons and scroll bars.
182 sal_Int32 mnPage; ///< Large increment of spin buttons and scroll bars.
183 sal_Int32 mnSelType; ///< Listbox selection type.
184 sal_Int32 mnVTEdit; ///< Data type of the textbox.
185 bool mbPrintObject; ///< True = print the object.
186 bool mbVisible; ///< True = cell note is visible.
187 bool mbDde; ///< True = object is linked through DDE.
188 bool mbNo3D; ///< True = flat style, false = 3D style.
189 bool mbNo3D2; ///< True = flat style, false = 3D style (listboxes and dropdowns).
190 bool mbMultiLine; ///< True = textbox allows line breaks.
191 bool mbVScroll; ///< True = textbox has a vertical scrollbar.
192 bool mbSecretEdit; ///< True = textbox is a password edit field.
194 explicit ClientData();
198 struct ShapeModel
200 typedef ::std::vector< css::awt::Point > PointVector;
202 OUString maType; ///< Shape template with default properties.
203 PointVector maPoints; ///< Points for the polyline shape.
204 std::unique_ptr<TextBox> mxTextBox; ///< Text contents and properties.
205 std::unique_ptr<ClientData> mxClientData; ///< Excel specific client data.
206 OUString maLegacyDiagramPath;///< Legacy Diagram Fragment Path
207 OUString maFrom; ///< Start point for line shape.
208 OUString maTo; ///< End point for line shape.
209 OUString maControl1; ///< Bezier control point 1
210 OUString maControl2; ///< Bezier control point 2
211 OUString maVmlPath; ///< VML path for this shape
212 bool mbIsSignatureLine; ///< Shape is a signature line
213 OUString maSignatureId; ///< ID of the signature
214 OUString maSignatureLineSuggestedSignerName;
215 OUString maSignatureLineSuggestedSignerTitle;
216 OUString maSignatureLineSuggestedSignerEmail;
217 OUString maSignatureLineSigningInstructions;
218 bool mbSignatureLineShowSignDate;
219 bool mbSignatureLineCanAddComment;
221 explicit ShapeModel();
222 ~ShapeModel();
224 /** Creates and returns a new shape textbox structure. */
225 TextBox& createTextBox(ShapeTypeModel& rModel);
226 /** Creates and returns a new shape client data structure. */
227 ClientData& createClientData();
231 /** A shape object that is part of a drawing. May inherit properties from a
232 shape template. */
233 class OOX_DLLPUBLIC ShapeBase : public ShapeType
235 public:
236 /** Returns read/write access to the shape model structure. */
237 ShapeModel& getShapeModel() { return maShapeModel; }
238 /** Returns read access to the shape model structure. */
239 const ShapeModel& getShapeModel() const { return maShapeModel; }
241 /** Returns read access to the shape textbox. */
242 const TextBox* getTextBox() const { return maShapeModel.mxTextBox.get(); }
243 /** Returns read access to the shape client data structure. */
244 const ClientData* getClientData() const { return maShapeModel.mxClientData.get(); }
246 /** Final processing after import of the drawing fragment. */
247 virtual void finalizeFragmentImport();
249 /** Returns the real shape name if existing, or a generated shape name. */
250 OUString getShapeName() const;
252 /** Returns the shape template with the passed identifier from the child shapes. */
253 virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const;
254 /** Returns the shape with the passed identifier from the child shapes. */
255 virtual const ShapeBase* getChildById( const OUString& rShapeId ) const;
257 /** Creates the corresponding XShape and inserts it into the passed container. */
258 css::uno::Reference< css::drawing::XShape >
259 convertAndInsert(
260 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
261 const ShapeParentAnchor* pParentAnchor = nullptr ) const;
263 /** Converts position and formatting into the passed existing XShape. */
264 void convertFormatting(
265 const css::uno::Reference< css::drawing::XShape >& rxShape ) const;
267 void setContainer(ShapeContainer* pContainer);
268 ShapeContainer* getContainer() const;
270 protected:
271 explicit ShapeBase( Drawing& rDrawing );
273 /** Derived classes create the corresponding XShape and insert it into the passed container. */
274 virtual css::uno::Reference< css::drawing::XShape >
275 implConvertAndInsert(
276 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
277 const css::awt::Rectangle& rShapeRect ) const = 0;
279 /** Calculates the final shape rectangle according to the passed anchor,
280 if present, otherwise according to the own anchor settings. */
281 css::awt::Rectangle calcShapeRectangle(
282 const ShapeParentAnchor* pParentAnchor ) const;
284 /** Converts common shape properties such as formatting attributes. */
285 void convertShapeProperties(
286 const css::uno::Reference< css::drawing::XShape >& rxShape ) const;
288 protected:
289 ShapeModel maShapeModel; ///< The model structure containing shape data.
290 ShapeContainer* mpContainer = nullptr;
294 /** A simple shape object based on a specific UNO shape service. */
295 class SimpleShape : public ShapeBase
297 public:
298 explicit SimpleShape( Drawing& rDrawing, const OUString& rService );
300 void setService( const OUString& aService ) { maService = aService; }
302 protected:
303 /** Creates the corresponding XShape and inserts it into the passed container. */
304 virtual css::uno::Reference< css::drawing::XShape >
305 implConvertAndInsert(
306 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
307 const css::awt::Rectangle& rShapeRect ) const override;
308 /** Used by both RectangleShape and ComplexShape. */
309 css::uno::Reference<css::drawing::XShape>createEmbeddedPictureObject(
310 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
311 const css::awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const;
313 css::uno::Reference<css::drawing::XShape>createPictureObject(
314 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
315 const css::awt::Rectangle& rShapeRect,
316 css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) const;
318 private:
319 OUString maService; ///< Name of the UNO shape service.
323 /** A rectangular shape object. */
324 class RectangleShape final : public SimpleShape
326 public:
327 explicit RectangleShape( Drawing& rDrawing );
328 private:
329 /** Creates the corresponding XShape and inserts it into the passed container. */
330 virtual css::uno::Reference<css::drawing::XShape>
331 implConvertAndInsert(
332 const css::uno::Reference<css::drawing::XShapes>& rxShapes,
333 const css::awt::Rectangle& rShapeRect) const override;
337 /** An oval shape object. */
338 class EllipseShape final : public SimpleShape
340 public:
341 explicit EllipseShape( Drawing& rDrawing );
345 /** A polygon shape object. */
346 class PolyLineShape final : public SimpleShape
348 public:
349 explicit PolyLineShape( Drawing& rDrawing );
351 private:
352 /** Creates the corresponding XShape and inserts it into the passed container. */
353 virtual css::uno::Reference< css::drawing::XShape >
354 implConvertAndInsert(
355 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
356 const css::awt::Rectangle& rShapeRect ) const override;
359 /** A Line shape object. */
360 class LineShape final : public SimpleShape
362 public:
363 explicit LineShape( Drawing& rDrawing );
365 private:
366 /** Returns the absolute shape rectangle. */
367 virtual css::awt::Rectangle getAbsRectangle() const override;
368 /** Returns the rectangle relative to the parent coordinate system. */
369 virtual css::awt::Rectangle getRelRectangle() const override;
372 /** Bezier shape object that supports to, from, control1 and control2
373 attribute or path attribute specification */
374 class BezierShape final : public SimpleShape
376 public:
377 explicit BezierShape( Drawing& rDrawing );
379 private:
380 /** Creates the corresponding XShape and inserts it into the passed container. */
381 virtual css::uno::Reference< css::drawing::XShape >
382 implConvertAndInsert(
383 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
384 const css::awt::Rectangle& rShapeRect ) const override;
388 /** A shape object with custom geometry. */
389 class CustomShape : public SimpleShape
391 public:
392 explicit CustomShape( Drawing& rDrawing );
394 protected:
395 /** Creates the corresponding XShape and inserts it into the passed container. */
396 virtual css::uno::Reference< css::drawing::XShape >
397 implConvertAndInsert(
398 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
399 const css::awt::Rectangle& rShapeRect ) const override;
403 /** A complex shape object. This can be a picture shape, a custom shape, an OLE
404 object, or an ActiveX form control. */
405 class ComplexShape final : public CustomShape
407 public:
408 explicit ComplexShape( Drawing& rDrawing );
410 private:
411 /** Creates the corresponding XShape and inserts it into the passed container. */
412 virtual css::uno::Reference< css::drawing::XShape >
413 implConvertAndInsert(
414 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
415 const css::awt::Rectangle& rShapeRect ) const override;
419 /** A group shape that extends the basic shape by a container of child shapes. */
420 class GroupShape final : public ShapeBase
422 public:
423 explicit GroupShape( Drawing& rDrawing );
424 virtual ~GroupShape() override;
426 /** Returns read/write access to the container of child shapes and templates. */
427 ShapeContainer& getChildren() { return *mxChildren; }
428 /** Returns read access to the container of child shapes and templates. */
429 const ShapeContainer& getChildren() const { return *mxChildren; }
431 /** Final processing after import of the drawing fragment. */
432 virtual void finalizeFragmentImport() override;
434 /** Returns the shape template with the passed identifier from the child shapes. */
435 virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const override;
436 /** Returns the shape with the passed identifier from the child shapes. */
437 virtual const ShapeBase* getChildById( const OUString& rShapeId ) const override;
439 private:
440 /** Creates the corresponding XShape and inserts it into the passed container. */
441 virtual css::uno::Reference< css::drawing::XShape >
442 implConvertAndInsert(
443 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
444 const css::awt::Rectangle& rShapeRect ) const override;
446 private:
447 std::unique_ptr<ShapeContainer> mxChildren; ///< Shapes and templates that are part of this group.
451 } // namespace vml
452 } // namespace oox
454 #endif
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */