Get the style color and number just once
[LibreOffice.git] / include / oox / vml / vmlshape.hxx
blob6348b539f689184c139a1d874e001f7e03ac3d02
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/vml/vmlformatting.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
33 namespace com::sun::star {
34 namespace awt { struct Rectangle; }
35 namespace drawing { class XShape; }
36 namespace drawing { class XShapes; }
37 namespace graphic { class XGraphic; }
40 namespace oox::vml {
42 class Drawing;
43 struct ShapeParentAnchor;
44 class ShapeContainer;
45 class TextBox;
47 const sal_Int32 VML_CLIENTDATA_UNCHECKED = 0;
48 const sal_Int32 VML_CLIENTDATA_CHECKED = 1;
49 const sal_Int32 VML_CLIENTDATA_MIXED = 2;
51 const sal_Int32 VML_CLIENTDATA_TEXT = 0;
52 const sal_Int32 VML_CLIENTDATA_INTEGER = 1;
53 const sal_Int32 VML_CLIENTDATA_NUMBER = 2;
54 const sal_Int32 VML_CLIENTDATA_REFERENCE = 3;
55 const sal_Int32 VML_CLIENTDATA_FORMULA = 4;
58 /** The shape model structure contains all properties shared by all types of shapes. */
59 struct ShapeTypeModel
61 OUString maShapeId; ///< Unique identifier of the shape.
62 OUString maLegacyId; ///< Plaintext identifier of the shape.
63 OUString maShapeName; ///< Name of the shape, if present.
64 std::optional< sal_Int32 > moShapeType; ///< Builtin shape type identifier.
66 std::optional< Int32Pair > moCoordPos; ///< Top-left position of coordinate system for children scaling.
67 std::optional< Int32Pair > moCoordSize; ///< Size of coordinate system for children scaling.
68 OUString maPosition; ///< Position type of the shape.
69 OUString maZIndex; ///< ZIndex of the shape
70 OUString maLeft; ///< X position of the shape bounding box (number with unit).
71 OUString maTop; ///< Y position of the shape bounding box (number with unit).
72 OUString maWidth; ///< Width of the shape bounding box (number with unit).
73 OUString maHeight; ///< Height of the shape bounding box (number with unit).
74 OUString maMarginLeft; ///< X position of the shape bounding box to shape anchor (number with unit).
75 OUString maMarginTop; ///< Y position of the shape bounding box to shape anchor (number with unit).
76 OUString maPositionHorizontalRelative; ///< The X position is relative to this.
77 OUString maPositionVerticalRelative; ///< The Y position is relative to this.
78 OUString maPositionHorizontal; ///< The X position orientation (default: absolute).
79 OUString maPositionVertical; ///< The Y position orientation.
80 OUString maWidthPercent; ///< The width in percents of the WidthRelative
81 OUString maHeightPercent; ///< The height in percents of the HeightRelative
82 OUString maWidthRelative; ///< To what the width is relative
83 OUString maHeightRelative; ///< To what the height is relative
84 OUString maRotation; ///< Rotation of the shape, in degrees.
85 OUString maFlip; ///< Flip type of the shape (can be "x" or "y").
86 bool mbAutoHeight; ///< If true, the height value is a minimum value (mostly used for textboxes)
87 bool mbVisible; ///< Visible or Hidden
88 OUString maWrapStyle; ///< Wrapping mode for text.
89 OUString maArcsize; ///< round rectangles arc size
90 OUString maEditAs; ///< Edit As type (e.g. "canvas" etc)
91 OUString maAdjustments; ///< Shape adjustment values
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 std::optional< OUString > moGraphicPath; ///< Path to a graphic for this shape.
99 std::optional< OUString > moGraphicTitle; ///< Title of the graphic.
100 std::optional< OUString > moWrapAnchorX; ///< The base object from which our horizontal positioning should be calculated.
101 std::optional< OUString > moWrapAnchorY; ///< The base object from which our vertical positioning should be calculated.
102 std::optional< OUString > moWrapType; ///< How to wrap the text around the object
103 std::optional< 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 std::optional<OUString> moCropBottom; ///< Specifies the how much to crop the image from the bottom up as a fraction of picture size.
110 std::optional<OUString> moCropLeft; ///< Specifies how much to crop the image from the left in as a fraction of picture size.
111 std::optional<OUString> moCropRight; ///< Specifies how much to crop the image from the right in as a fraction of picture size.
112 std::optional<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 /// An adjustment for the intensity of all colors, i.e. contrast, on a 0..0x10000 scale.
116 sal_Int32 mnGain = 0x10000;
118 /// The image brightness, on a 0..0x10000 scale.
119 sal_Int16 mnBlacklevel = 0;
121 explicit ShapeTypeModel();
123 void assignUsed( const ShapeTypeModel& rSource );
127 /** A shape template contains all formatting properties of shapes and can serve
128 as templates for several shapes in a drawing. */
129 class SAL_DLLPUBLIC_RTTI ShapeType
131 public:
132 explicit ShapeType( Drawing& rDrawing );
133 virtual ~ShapeType();
135 /** Returns read/write access to the shape template model structure. */
136 ShapeTypeModel& getTypeModel() { return maTypeModel; }
137 /** Returns read access to the shape template model structure. */
138 const ShapeTypeModel& getTypeModel() const { return maTypeModel; }
140 /** Returns the shape identifier (which is unique through the containing drawing). */
141 const OUString& getShapeId() const { return maTypeModel.maShapeId; }
142 /** Returns the application defined shape type. */
143 sal_Int32 getShapeType() const;
144 /** Returns the fragment path to the embedded graphic used by this shape. */
145 OUString getGraphicPath() const;
147 const Drawing& getDrawing() const { return mrDrawing; }
148 void setTextBox(bool bSet) {mbTextBox = bSet;}
149 bool isTextBox() const {return mbTextBox;}
151 protected:
152 /** Returns the coordinate system of this shape. */
153 css::awt::Rectangle getCoordSystem() const;
154 /** Returns the absolute shape rectangle according to the passed anchor. */
155 css::awt::Rectangle getRectangle( const ShapeParentAnchor* pParentAnchor ) const;
156 /** Returns the absolute shape rectangle. */
157 virtual css::awt::Rectangle getAbsRectangle() const;
158 /** Returns the rectangle relative to the parent coordinate system. */
159 virtual css::awt::Rectangle getRelRectangle() const;
161 protected:
162 Drawing& mrDrawing; ///< The VML drawing page that contains this shape.
163 ShapeTypeModel maTypeModel; ///< The model structure containing shape type data.
164 bool mbTextBox; //will be set if the shape contains a text box
168 /** Excel specific shape client data (such as cell anchor). */
169 struct ClientData
171 OUString maAnchor; ///< Cell anchor as comma-separated string.
172 OUString maFmlaMacro; ///< Link to macro associated to the control.
173 OUString maFmlaPict; ///< Target cell range of picture links.
174 OUString maFmlaLink; ///< Link to value cell associated to the control.
175 OUString maFmlaRange; ///< Link to cell range used as data source for the control.
176 OUString maFmlaGroup; ///< Link to value cell associated to a group of option buttons.
177 sal_Int32 mnObjType; ///< Type of the shape.
178 sal_Int32 mnTextHAlign; ///< Horizontal text alignment.
179 sal_Int32 mnTextVAlign; ///< Vertical text alignment.
180 sal_Int32 mnCol; ///< Column index for spreadsheet cell note.
181 sal_Int32 mnRow; ///< Row index for spreadsheet cell note.
182 sal_Int32 mnChecked; ///< State for checkboxes and option buttons.
183 sal_Int32 mnDropStyle; ///< Drop down box style (read-only or editable).
184 sal_Int32 mnDropLines; ///< Number of lines in drop down box.
185 sal_Int32 mnVal; ///< Current value of spin buttons and scroll bars.
186 sal_Int32 mnMin; ///< Minimum value of spin buttons and scroll bars.
187 sal_Int32 mnMax; ///< Maximum value of spin buttons and scroll bars.
188 sal_Int32 mnInc; ///< Small increment of spin buttons and scroll bars.
189 sal_Int32 mnPage; ///< Large increment of spin buttons and scroll bars.
190 sal_Int32 mnSelType; ///< Listbox selection type.
191 sal_Int32 mnVTEdit; ///< Data type of the textbox.
192 bool mbPrintObject; ///< True = print the object.
193 bool mbVisible; ///< True = cell note is visible.
194 bool mbDde; ///< True = object is linked through DDE.
195 bool mbNo3D; ///< True = flat style, false = 3D style.
196 bool mbNo3D2; ///< True = flat style, false = 3D style (listboxes and dropdowns).
197 bool mbMultiLine; ///< True = textbox allows line breaks.
198 bool mbVScroll; ///< True = textbox has a vertical scrollbar.
199 bool mbSecretEdit; ///< True = textbox is a password edit field.
201 explicit ClientData();
205 struct ShapeModel
207 typedef ::std::vector< css::awt::Point > PointVector;
209 OUString maType; ///< Shape template with default properties.
210 PointVector maPoints; ///< Points for the polyline shape.
211 std::unique_ptr<TextBox> mxTextBox; ///< Text contents and properties.
212 std::unique_ptr<ClientData> mxClientData; ///< Excel specific client data.
213 OUString maLegacyDiagramPath;///< Legacy Diagram Fragment Path
214 OUString maFrom; ///< Start point for line shape.
215 OUString maTo; ///< End point for line shape.
216 OUString maControl1; ///< Bezier control point 1
217 OUString maControl2; ///< Bezier control point 2
218 OUString maVmlPath; ///< VML path for this shape
219 bool mbIsSignatureLine; ///< Shape is a signature line
220 OUString maSignatureId; ///< ID of the signature
221 OUString maSignatureLineSuggestedSignerName;
222 OUString maSignatureLineSuggestedSignerTitle;
223 OUString maSignatureLineSuggestedSignerEmail;
224 OUString maSignatureLineSigningInstructions;
225 bool mbSignatureLineShowSignDate;
226 bool mbSignatureLineCanAddComment;
227 bool mbInGroup;
228 OUString maHyperlink; ///< The hyperlink assigned to the shape
230 explicit ShapeModel();
231 ~ShapeModel();
233 /** Creates and returns a new shape textbox structure. */
234 TextBox& createTextBox(ShapeTypeModel& rModel);
235 /** Creates and returns a new shape client data structure. */
236 ClientData& createClientData();
240 /** A shape object that is part of a drawing. May inherit properties from a
241 shape template. */
242 class OOX_DLLPUBLIC ShapeBase : public ShapeType
244 public:
245 /** Returns read/write access to the shape model structure. */
246 ShapeModel& getShapeModel() { return maShapeModel; }
247 /** Returns read access to the shape model structure. */
248 const ShapeModel& getShapeModel() const { return maShapeModel; }
250 /** Returns read access to the shape textbox. */
251 const TextBox* getTextBox() const { return maShapeModel.mxTextBox.get(); }
252 /** Returns read access to the shape client data structure. */
253 const ClientData* getClientData() const { return maShapeModel.mxClientData.get(); }
255 /** Final processing after import of the drawing fragment. */
256 virtual void finalizeFragmentImport();
258 /** Returns the real shape name if existing, or a generated shape name. */
259 OUString getShapeName() const;
261 /** Returns the shape template with the passed identifier from the child shapes. */
262 virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const;
263 /** Returns the shape with the passed identifier from the child shapes. */
264 virtual const ShapeBase* getChildById( const OUString& rShapeId ) const;
266 /** Creates the corresponding XShape and inserts it into the passed container. */
267 css::uno::Reference< css::drawing::XShape >
268 convertAndInsert(
269 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
270 const ShapeParentAnchor* pParentAnchor = nullptr ) const;
272 /** Returns bounds of Shape */
273 css::awt::Rectangle getShapeRectangle() const;
275 /** Collects common shape properties such as formatting attributes. */
276 oox::drawingml::ShapePropertyMap makeShapePropertyMap() const;
278 void setContainer(ShapeContainer* pContainer);
279 ShapeContainer* getContainer() const;
281 protected:
282 explicit ShapeBase( Drawing& rDrawing );
284 /** Derived classes create the corresponding XShape and insert it into the passed container. */
285 virtual css::uno::Reference< css::drawing::XShape >
286 implConvertAndInsert(
287 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
288 const css::awt::Rectangle& rShapeRect ) const = 0;
290 /** Always called after implConvertAndInsert for the same task.*/
291 virtual css::uno::Reference<css::drawing::XShape> finalImplConvertAndInsert(
292 const css::uno::Reference<css::drawing::XShape>& rxShape) const
294 return rxShape;
297 /** Calculates the final shape rectangle according to the passed anchor,
298 if present, otherwise according to the own anchor settings. */
299 css::awt::Rectangle calcShapeRectangle(
300 const ShapeParentAnchor* pParentAnchor ) const;
302 /** Converts common shape properties such as formatting attributes. */
303 void convertShapeProperties(
304 const css::uno::Reference< css::drawing::XShape >& rxShape ) const;
306 protected:
307 ShapeModel maShapeModel; ///< The model structure containing shape data.
308 ShapeContainer* mpContainer = nullptr;
312 /** A simple shape object based on a specific UNO shape service. */
313 class SimpleShape : public ShapeBase
315 public:
316 explicit SimpleShape( Drawing& rDrawing, OUString aService );
318 void setService( const OUString& aService ) { maService = aService; }
320 protected:
321 /** Creates the corresponding XShape and inserts it into the passed container. */
322 virtual css::uno::Reference< css::drawing::XShape >
323 implConvertAndInsert(
324 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
325 const css::awt::Rectangle& rShapeRect ) const override;
326 virtual css::uno::Reference<css::drawing::XShape> finalImplConvertAndInsert(
327 const css::uno::Reference<css::drawing::XShape>& rxShape) const override;
328 /** Used by both RectangleShape and ComplexShape. */
329 css::uno::Reference<css::drawing::XShape>createEmbeddedPictureObject(
330 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
331 const css::awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const;
333 css::uno::Reference<css::drawing::XShape>createPictureObject(
334 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
335 const css::awt::Rectangle& rShapeRect,
336 css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) const;
338 private:
339 OUString maService; ///< Name of the UNO shape service.
343 /** A rectangular shape object. */
344 class RectangleShape final : public SimpleShape
346 public:
347 explicit RectangleShape( Drawing& rDrawing );
348 private:
349 /** Creates the corresponding XShape and inserts it into the passed container. */
350 virtual css::uno::Reference<css::drawing::XShape>
351 implConvertAndInsert(
352 const css::uno::Reference<css::drawing::XShapes>& rxShapes,
353 const css::awt::Rectangle& rShapeRect) const override;
357 /** An oval shape object. */
358 class EllipseShape final : public SimpleShape
360 public:
361 explicit EllipseShape( Drawing& rDrawing );
365 /** A polygon shape object. */
366 class PolyLineShape final : public SimpleShape
368 public:
369 explicit PolyLineShape( Drawing& rDrawing );
371 private:
372 /** Creates the corresponding XShape and inserts it into the passed container. */
373 virtual css::uno::Reference< css::drawing::XShape >
374 implConvertAndInsert(
375 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
376 const css::awt::Rectangle& rShapeRect ) const override;
379 /** A Line shape object. */
380 class LineShape final : public SimpleShape
382 public:
383 explicit LineShape( Drawing& rDrawing );
384 virtual css::uno::Reference< css::drawing::XShape >
385 implConvertAndInsert(
386 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
387 const css::awt::Rectangle& rShapeRect ) const override;
390 private:
391 /** Returns the absolute shape rectangle. */
392 virtual css::awt::Rectangle getAbsRectangle() const override;
393 /** Returns the rectangle relative to the parent coordinate system. */
394 virtual css::awt::Rectangle getRelRectangle() const override;
397 /** Bezier shape object that supports to, from, control1 and control2
398 attribute or path attribute specification */
399 class BezierShape final : public SimpleShape
401 public:
402 explicit BezierShape( Drawing& rDrawing );
404 private:
405 /** Creates the corresponding XShape and inserts it into the passed container. */
406 virtual css::uno::Reference< css::drawing::XShape >
407 implConvertAndInsert(
408 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
409 const css::awt::Rectangle& rShapeRect ) const override;
413 /** A shape object with custom geometry. */
414 class CustomShape : public SimpleShape
416 public:
417 explicit CustomShape( Drawing& rDrawing );
419 protected:
420 /** Creates the corresponding XShape and inserts it into the passed container. */
421 virtual css::uno::Reference< css::drawing::XShape >
422 implConvertAndInsert(
423 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
424 const css::awt::Rectangle& rShapeRect ) const override;
428 /** A complex shape object. This can be a picture shape, a custom shape, an OLE
429 object, or an ActiveX form control. */
430 class ComplexShape final : public CustomShape
432 public:
433 explicit ComplexShape( Drawing& rDrawing );
435 private:
436 /** Creates the corresponding XShape and inserts it into the passed container. */
437 virtual css::uno::Reference< css::drawing::XShape >
438 implConvertAndInsert(
439 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
440 const css::awt::Rectangle& rShapeRect ) const override;
444 /** A group shape that extends the basic shape by a container of child shapes. */
445 class GroupShape final : public ShapeBase
447 public:
448 explicit GroupShape( Drawing& rDrawing );
449 virtual ~GroupShape() override;
451 /** Returns read/write access to the container of child shapes and templates. */
452 ShapeContainer& getChildren() { return *mxChildren; }
453 /** Returns read access to the container of child shapes and templates. */
454 const ShapeContainer& getChildren() const { return *mxChildren; }
456 /** Final processing after import of the drawing fragment. */
457 virtual void finalizeFragmentImport() override;
459 /** Returns the shape template with the passed identifier from the child shapes. */
460 virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const override;
461 /** Returns the shape with the passed identifier from the child shapes. */
462 virtual const ShapeBase* getChildById( const OUString& rShapeId ) const override;
464 private:
465 /** Creates the corresponding XShape and inserts it into the passed container. */
466 virtual css::uno::Reference< css::drawing::XShape >
467 implConvertAndInsert(
468 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
469 const css::awt::Rectangle& rShapeRect ) const override;
471 private:
472 std::unique_ptr<ShapeContainer> mxChildren; ///< Shapes and templates that are part of this group.
476 } // namespace oox::vml
478 #endif
480 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */