Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / oox / vml / vmlshape.hxx
blobd46c23282324b89c7f8fb4e13e636e23d2519ac1
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::sun::star {
35 namespace awt { struct Rectangle; }
36 namespace drawing { class XShape; }
37 namespace drawing { class XShapes; }
38 namespace graphic { class XGraphic; }
41 namespace oox::vml {
43 class Drawing;
44 struct ShapeParentAnchor;
45 class ShapeContainer;
46 class TextBox;
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 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 std::optional< sal_Int32 > moShapeType; ///< Builtin shape type identifier.
67 std::optional< Int32Pair > moCoordPos; ///< Top-left position of coordinate system for children scaling.
68 std::optional< 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)
92 OUString maAdjustments; ///< Shape adjustment values
94 StrokeModel maStrokeModel; ///< Border line formatting.
95 FillModel maFillModel; ///< Shape fill formatting.
96 ShadowModel maShadowModel; ///< Shape shadow formatting.
97 TextpathModel maTextpathModel; ///< Shape textpath formatting.
99 std::optional< OUString > moGraphicPath; ///< Path to a graphic for this shape.
100 std::optional< OUString > moGraphicTitle; ///< Title of the graphic.
101 std::optional< OUString > moWrapAnchorX; ///< The base object from which our horizontal positioning should be calculated.
102 std::optional< OUString > moWrapAnchorY; ///< The base object from which our vertical positioning should be calculated.
103 std::optional< OUString > moWrapType; ///< How to wrap the text around the object
104 std::optional< OUString > moWrapSide; ///< On which side to wrap the text around the object
105 OUString maVTextAnchor; ///< How the text inside the shape is anchored vertically.
106 OUString maWrapDistanceLeft; ///< Distance from the left side of the shape to the text that wraps around it.
107 OUString maWrapDistanceRight; ///< Distance from the right side of the shape to the text that wraps around it.
108 OUString maWrapDistanceTop; ///< Distance from the top of the shape to the text that wraps around it.
109 OUString maWrapDistanceBottom; ///< Distance from the bottom of the shape to the text that wraps around it.
110 std::optional<OUString> moCropBottom; ///< Specifies the how much to crop the image from the bottom up as a fraction of picture size.
111 std::optional<OUString> moCropLeft; ///< Specifies how much to crop the image from the left in as a fraction of picture size.
112 std::optional<OUString> moCropRight; ///< Specifies how much to crop the image from the right in as a fraction of picture size.
113 std::optional<OUString> moCropTop; ///< Specifies how much to crop the image from the top down as a fraction of picture size.
114 OUString maLayoutFlowAlt; ///< Specifies the alternate layout flow for text in textboxes.
116 /// An adjustment for the intensity of all colors, i.e. contrast, on a 0..0x10000 scale.
117 sal_Int32 mnGain = 0x10000;
119 /// The image brightness, on a 0..0x10000 scale.
120 sal_Int16 mnBlacklevel = 0;
122 explicit ShapeTypeModel();
124 void assignUsed( const ShapeTypeModel& rSource );
128 /** A shape template contains all formatting properties of shapes and can serve
129 as templates for several shapes in a drawing. */
130 class SAL_DLLPUBLIC_RTTI ShapeType
132 public:
133 explicit ShapeType( Drawing& rDrawing );
134 virtual ~ShapeType();
136 /** Returns read/write access to the shape template model structure. */
137 ShapeTypeModel& getTypeModel() { return maTypeModel; }
138 /** Returns read access to the shape template model structure. */
139 const ShapeTypeModel& getTypeModel() const { return maTypeModel; }
141 /** Returns the shape identifier (which is unique through the containing drawing). */
142 const OUString& getShapeId() const { return maTypeModel.maShapeId; }
143 /** Returns the application defined shape type. */
144 sal_Int32 getShapeType() const;
145 /** Returns the fragment path to the embedded graphic used by this shape. */
146 OUString getGraphicPath() const;
148 const Drawing& getDrawing() const { return mrDrawing; }
150 protected:
151 /** Returns the coordinate system of this shape. */
152 css::awt::Rectangle getCoordSystem() const;
153 /** Returns the absolute shape rectangle according to the passed anchor. */
154 css::awt::Rectangle getRectangle( const ShapeParentAnchor* pParentAnchor ) const;
155 /** Returns the absolute shape rectangle. */
156 virtual css::awt::Rectangle getAbsRectangle() const;
157 /** Returns the rectangle relative to the parent coordinate system. */
158 virtual css::awt::Rectangle getRelRectangle() const;
160 protected:
161 Drawing& mrDrawing; ///< The VML drawing page that contains this shape.
162 ShapeTypeModel maTypeModel; ///< The model structure containing shape type data.
166 /** Excel specific shape client data (such as cell anchor). */
167 struct ClientData
169 OUString maAnchor; ///< Cell anchor as comma-separated string.
170 OUString maFmlaMacro; ///< Link to macro associated to the control.
171 OUString maFmlaPict; ///< Target cell range of picture links.
172 OUString maFmlaLink; ///< Link to value cell associated to the control.
173 OUString maFmlaRange; ///< Link to cell range used as data source for the control.
174 OUString maFmlaGroup; ///< Link to value cell associated to a group of option buttons.
175 sal_Int32 mnObjType; ///< Type of the shape.
176 sal_Int32 mnTextHAlign; ///< Horizontal text alignment.
177 sal_Int32 mnTextVAlign; ///< Vertical text alignment.
178 sal_Int32 mnCol; ///< Column index for spreadsheet cell note.
179 sal_Int32 mnRow; ///< Row index for spreadsheet cell note.
180 sal_Int32 mnChecked; ///< State for checkboxes and option buttons.
181 sal_Int32 mnDropStyle; ///< Drop down box style (read-only or editable).
182 sal_Int32 mnDropLines; ///< Number of lines in drop down box.
183 sal_Int32 mnVal; ///< Current value of spin buttons and scroll bars.
184 sal_Int32 mnMin; ///< Minimum value of spin buttons and scroll bars.
185 sal_Int32 mnMax; ///< Maximum value of spin buttons and scroll bars.
186 sal_Int32 mnInc; ///< Small increment of spin buttons and scroll bars.
187 sal_Int32 mnPage; ///< Large increment of spin buttons and scroll bars.
188 sal_Int32 mnSelType; ///< Listbox selection type.
189 sal_Int32 mnVTEdit; ///< Data type of the textbox.
190 bool mbPrintObject; ///< True = print the object.
191 bool mbVisible; ///< True = cell note is visible.
192 bool mbDde; ///< True = object is linked through DDE.
193 bool mbNo3D; ///< True = flat style, false = 3D style.
194 bool mbNo3D2; ///< True = flat style, false = 3D style (listboxes and dropdowns).
195 bool mbMultiLine; ///< True = textbox allows line breaks.
196 bool mbVScroll; ///< True = textbox has a vertical scrollbar.
197 bool mbSecretEdit; ///< True = textbox is a password edit field.
199 explicit ClientData();
203 struct ShapeModel
205 typedef ::std::vector< css::awt::Point > PointVector;
207 OUString maType; ///< Shape template with default properties.
208 PointVector maPoints; ///< Points for the polyline shape.
209 std::unique_ptr<TextBox> mxTextBox; ///< Text contents and properties.
210 std::unique_ptr<ClientData> mxClientData; ///< Excel specific client data.
211 OUString maLegacyDiagramPath;///< Legacy Diagram Fragment Path
212 OUString maFrom; ///< Start point for line shape.
213 OUString maTo; ///< End point for line shape.
214 OUString maControl1; ///< Bezier control point 1
215 OUString maControl2; ///< Bezier control point 2
216 OUString maVmlPath; ///< VML path for this shape
217 bool mbIsSignatureLine; ///< Shape is a signature line
218 OUString maSignatureId; ///< ID of the signature
219 OUString maSignatureLineSuggestedSignerName;
220 OUString maSignatureLineSuggestedSignerTitle;
221 OUString maSignatureLineSuggestedSignerEmail;
222 OUString maSignatureLineSigningInstructions;
223 bool mbSignatureLineShowSignDate;
224 bool mbSignatureLineCanAddComment;
225 bool mbInGroup;
226 OUString maHyperlink; ///< The hyperlink assigned to the shape
228 explicit ShapeModel();
229 ~ShapeModel();
231 /** Creates and returns a new shape textbox structure. */
232 TextBox& createTextBox(ShapeTypeModel& rModel);
233 /** Creates and returns a new shape client data structure. */
234 ClientData& createClientData();
238 /** A shape object that is part of a drawing. May inherit properties from a
239 shape template. */
240 class OOX_DLLPUBLIC ShapeBase : public ShapeType
242 public:
243 /** Returns read/write access to the shape model structure. */
244 ShapeModel& getShapeModel() { return maShapeModel; }
245 /** Returns read access to the shape model structure. */
246 const ShapeModel& getShapeModel() const { return maShapeModel; }
248 /** Returns read access to the shape textbox. */
249 const TextBox* getTextBox() const { return maShapeModel.mxTextBox.get(); }
250 /** Returns read access to the shape client data structure. */
251 const ClientData* getClientData() const { return maShapeModel.mxClientData.get(); }
253 /** Final processing after import of the drawing fragment. */
254 virtual void finalizeFragmentImport();
256 /** Returns the real shape name if existing, or a generated shape name. */
257 OUString getShapeName() const;
259 /** Returns the shape template with the passed identifier from the child shapes. */
260 virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const;
261 /** Returns the shape with the passed identifier from the child shapes. */
262 virtual const ShapeBase* getChildById( const OUString& rShapeId ) const;
264 /** Creates the corresponding XShape and inserts it into the passed container. */
265 css::uno::Reference< css::drawing::XShape >
266 convertAndInsert(
267 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
268 const ShapeParentAnchor* pParentAnchor = nullptr ) const;
270 /** Converts position and formatting into the passed existing XShape. */
271 void convertFormatting(
272 const css::uno::Reference< css::drawing::XShape >& rxShape ) const;
274 void setContainer(ShapeContainer* pContainer);
275 ShapeContainer* getContainer() const;
277 protected:
278 explicit ShapeBase( Drawing& rDrawing );
280 /** Derived classes create the corresponding XShape and insert it into the passed container. */
281 virtual css::uno::Reference< css::drawing::XShape >
282 implConvertAndInsert(
283 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
284 const css::awt::Rectangle& rShapeRect ) const = 0;
286 /** Always called after implConvertAndInsert for the same task.*/
287 virtual css::uno::Reference<css::drawing::XShape> finalImplConvertAndInsert(
288 const css::uno::Reference<css::drawing::XShape>& rxShape) const
290 return rxShape;
293 /** Calculates the final shape rectangle according to the passed anchor,
294 if present, otherwise according to the own anchor settings. */
295 css::awt::Rectangle calcShapeRectangle(
296 const ShapeParentAnchor* pParentAnchor ) const;
298 /** Converts common shape properties such as formatting attributes. */
299 void convertShapeProperties(
300 const css::uno::Reference< css::drawing::XShape >& rxShape ) const;
302 protected:
303 ShapeModel maShapeModel; ///< The model structure containing shape data.
304 ShapeContainer* mpContainer = nullptr;
308 /** A simple shape object based on a specific UNO shape service. */
309 class SimpleShape : public ShapeBase
311 public:
312 explicit SimpleShape( Drawing& rDrawing, OUString aService );
314 void setService( const OUString& aService ) { maService = aService; }
316 protected:
317 /** Creates the corresponding XShape and inserts it into the passed container. */
318 virtual css::uno::Reference< css::drawing::XShape >
319 implConvertAndInsert(
320 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
321 const css::awt::Rectangle& rShapeRect ) const override;
322 virtual css::uno::Reference<css::drawing::XShape> finalImplConvertAndInsert(
323 const css::uno::Reference<css::drawing::XShape>& rxShape) const override;
324 /** Used by both RectangleShape and ComplexShape. */
325 css::uno::Reference<css::drawing::XShape>createEmbeddedPictureObject(
326 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
327 const css::awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const;
329 css::uno::Reference<css::drawing::XShape>createPictureObject(
330 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
331 const css::awt::Rectangle& rShapeRect,
332 css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) const;
334 private:
335 OUString maService; ///< Name of the UNO shape service.
339 /** A rectangular shape object. */
340 class RectangleShape final : public SimpleShape
342 public:
343 explicit RectangleShape( Drawing& rDrawing );
344 private:
345 /** Creates the corresponding XShape and inserts it into the passed container. */
346 virtual css::uno::Reference<css::drawing::XShape>
347 implConvertAndInsert(
348 const css::uno::Reference<css::drawing::XShapes>& rxShapes,
349 const css::awt::Rectangle& rShapeRect) const override;
353 /** An oval shape object. */
354 class EllipseShape final : public SimpleShape
356 public:
357 explicit EllipseShape( Drawing& rDrawing );
361 /** A polygon shape object. */
362 class PolyLineShape final : public SimpleShape
364 public:
365 explicit PolyLineShape( Drawing& rDrawing );
367 private:
368 /** Creates the corresponding XShape and inserts it into the passed container. */
369 virtual css::uno::Reference< css::drawing::XShape >
370 implConvertAndInsert(
371 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
372 const css::awt::Rectangle& rShapeRect ) const override;
375 /** A Line shape object. */
376 class LineShape final : public SimpleShape
378 public:
379 explicit LineShape( Drawing& rDrawing );
380 virtual css::uno::Reference< css::drawing::XShape >
381 implConvertAndInsert(
382 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
383 const css::awt::Rectangle& rShapeRect ) const override;
386 private:
387 /** Returns the absolute shape rectangle. */
388 virtual css::awt::Rectangle getAbsRectangle() const override;
389 /** Returns the rectangle relative to the parent coordinate system. */
390 virtual css::awt::Rectangle getRelRectangle() const override;
393 /** Bezier shape object that supports to, from, control1 and control2
394 attribute or path attribute specification */
395 class BezierShape final : public SimpleShape
397 public:
398 explicit BezierShape( Drawing& rDrawing );
400 private:
401 /** Creates the corresponding XShape and inserts it into the passed container. */
402 virtual css::uno::Reference< css::drawing::XShape >
403 implConvertAndInsert(
404 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
405 const css::awt::Rectangle& rShapeRect ) const override;
409 /** A shape object with custom geometry. */
410 class CustomShape : public SimpleShape
412 public:
413 explicit CustomShape( Drawing& rDrawing );
415 protected:
416 /** Creates the corresponding XShape and inserts it into the passed container. */
417 virtual css::uno::Reference< css::drawing::XShape >
418 implConvertAndInsert(
419 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
420 const css::awt::Rectangle& rShapeRect ) const override;
424 /** A complex shape object. This can be a picture shape, a custom shape, an OLE
425 object, or an ActiveX form control. */
426 class ComplexShape final : public CustomShape
428 public:
429 explicit ComplexShape( Drawing& rDrawing );
431 private:
432 /** Creates the corresponding XShape and inserts it into the passed container. */
433 virtual css::uno::Reference< css::drawing::XShape >
434 implConvertAndInsert(
435 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
436 const css::awt::Rectangle& rShapeRect ) const override;
440 /** A group shape that extends the basic shape by a container of child shapes. */
441 class GroupShape final : public ShapeBase
443 public:
444 explicit GroupShape( Drawing& rDrawing );
445 virtual ~GroupShape() override;
447 /** Returns read/write access to the container of child shapes and templates. */
448 ShapeContainer& getChildren() { return *mxChildren; }
449 /** Returns read access to the container of child shapes and templates. */
450 const ShapeContainer& getChildren() const { return *mxChildren; }
452 /** Final processing after import of the drawing fragment. */
453 virtual void finalizeFragmentImport() override;
455 /** Returns the shape template with the passed identifier from the child shapes. */
456 virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const override;
457 /** Returns the shape with the passed identifier from the child shapes. */
458 virtual const ShapeBase* getChildById( const OUString& rShapeId ) const override;
460 private:
461 /** Creates the corresponding XShape and inserts it into the passed container. */
462 virtual css::uno::Reference< css::drawing::XShape >
463 implConvertAndInsert(
464 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
465 const css::awt::Rectangle& rShapeRect ) const override;
467 private:
468 std::unique_ptr<ShapeContainer> mxChildren; ///< Shapes and templates that are part of this group.
472 } // namespace oox::vml
474 #endif
476 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */