Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / oox / vml / vmlshape.hxx
blob64259c554caf5d701c2e1c42635c053f1d41cadb
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; }
149 protected:
150 /** Returns the coordinate system of this shape. */
151 css::awt::Rectangle getCoordSystem() const;
152 /** Returns the absolute shape rectangle according to the passed anchor. */
153 css::awt::Rectangle getRectangle( const ShapeParentAnchor* pParentAnchor ) const;
154 /** Returns the absolute shape rectangle. */
155 virtual css::awt::Rectangle getAbsRectangle() const;
156 /** Returns the rectangle relative to the parent coordinate system. */
157 virtual css::awt::Rectangle getRelRectangle() const;
159 protected:
160 Drawing& mrDrawing; ///< The VML drawing page that contains this shape.
161 ShapeTypeModel maTypeModel; ///< The model structure containing shape type data.
165 /** Excel specific shape client data (such as cell anchor). */
166 struct ClientData
168 OUString maAnchor; ///< Cell anchor as comma-separated string.
169 OUString maFmlaMacro; ///< Link to macro associated to the control.
170 OUString maFmlaPict; ///< Target cell range of picture links.
171 OUString maFmlaLink; ///< Link to value cell associated to the control.
172 OUString maFmlaRange; ///< Link to cell range used as data source for the control.
173 OUString maFmlaGroup; ///< Link to value cell associated to a group of option buttons.
174 sal_Int32 mnObjType; ///< Type of the shape.
175 sal_Int32 mnTextHAlign; ///< Horizontal text alignment.
176 sal_Int32 mnTextVAlign; ///< Vertical text alignment.
177 sal_Int32 mnCol; ///< Column index for spreadsheet cell note.
178 sal_Int32 mnRow; ///< Row index for spreadsheet cell note.
179 sal_Int32 mnChecked; ///< State for checkboxes and option buttons.
180 sal_Int32 mnDropStyle; ///< Drop down box style (read-only or editable).
181 sal_Int32 mnDropLines; ///< Number of lines in drop down box.
182 sal_Int32 mnVal; ///< Current value of spin buttons and scroll bars.
183 sal_Int32 mnMin; ///< Minimum value of spin buttons and scroll bars.
184 sal_Int32 mnMax; ///< Maximum value of spin buttons and scroll bars.
185 sal_Int32 mnInc; ///< Small increment of spin buttons and scroll bars.
186 sal_Int32 mnPage; ///< Large increment of spin buttons and scroll bars.
187 sal_Int32 mnSelType; ///< Listbox selection type.
188 sal_Int32 mnVTEdit; ///< Data type of the textbox.
189 bool mbPrintObject; ///< True = print the object.
190 bool mbVisible; ///< True = cell note is visible.
191 bool mbDde; ///< True = object is linked through DDE.
192 bool mbNo3D; ///< True = flat style, false = 3D style.
193 bool mbNo3D2; ///< True = flat style, false = 3D style (listboxes and dropdowns).
194 bool mbMultiLine; ///< True = textbox allows line breaks.
195 bool mbVScroll; ///< True = textbox has a vertical scrollbar.
196 bool mbSecretEdit; ///< True = textbox is a password edit field.
198 explicit ClientData();
202 struct ShapeModel
204 typedef ::std::vector< css::awt::Point > PointVector;
206 OUString maType; ///< Shape template with default properties.
207 PointVector maPoints; ///< Points for the polyline shape.
208 std::unique_ptr<TextBox> mxTextBox; ///< Text contents and properties.
209 std::unique_ptr<ClientData> mxClientData; ///< Excel specific client data.
210 OUString maLegacyDiagramPath;///< Legacy Diagram Fragment Path
211 OUString maFrom; ///< Start point for line shape.
212 OUString maTo; ///< End point for line shape.
213 OUString maControl1; ///< Bezier control point 1
214 OUString maControl2; ///< Bezier control point 2
215 OUString maVmlPath; ///< VML path for this shape
216 bool mbIsSignatureLine; ///< Shape is a signature line
217 OUString maSignatureId; ///< ID of the signature
218 OUString maSignatureLineSuggestedSignerName;
219 OUString maSignatureLineSuggestedSignerTitle;
220 OUString maSignatureLineSuggestedSignerEmail;
221 OUString maSignatureLineSigningInstructions;
222 bool mbSignatureLineShowSignDate;
223 bool mbSignatureLineCanAddComment;
224 bool mbInGroup;
225 OUString maHyperlink; ///< The hyperlink assigned to the shape
227 explicit ShapeModel();
228 ~ShapeModel();
230 /** Creates and returns a new shape textbox structure. */
231 TextBox& createTextBox(ShapeTypeModel& rModel);
232 /** Creates and returns a new shape client data structure. */
233 ClientData& createClientData();
237 /** A shape object that is part of a drawing. May inherit properties from a
238 shape template. */
239 class OOX_DLLPUBLIC ShapeBase : public ShapeType
241 public:
242 /** Returns read/write access to the shape model structure. */
243 ShapeModel& getShapeModel() { return maShapeModel; }
244 /** Returns read access to the shape model structure. */
245 const ShapeModel& getShapeModel() const { return maShapeModel; }
247 /** Returns read access to the shape textbox. */
248 const TextBox* getTextBox() const { return maShapeModel.mxTextBox.get(); }
249 /** Returns read access to the shape client data structure. */
250 const ClientData* getClientData() const { return maShapeModel.mxClientData.get(); }
252 /** Final processing after import of the drawing fragment. */
253 virtual void finalizeFragmentImport();
255 /** Returns the real shape name if existing, or a generated shape name. */
256 OUString getShapeName() const;
258 /** Returns the shape template with the passed identifier from the child shapes. */
259 virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const;
260 /** Returns the shape with the passed identifier from the child shapes. */
261 virtual const ShapeBase* getChildById( const OUString& rShapeId ) const;
263 /** Creates the corresponding XShape and inserts it into the passed container. */
264 css::uno::Reference< css::drawing::XShape >
265 convertAndInsert(
266 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
267 const ShapeParentAnchor* pParentAnchor = nullptr ) const;
269 /** Returns bounds of Shape */
270 css::awt::Rectangle getShapeRectangle() const;
272 /** Collects common shape properties such as formatting attributes. */
273 oox::drawingml::ShapePropertyMap makeShapePropertyMap() const;
275 void setContainer(ShapeContainer* pContainer);
276 ShapeContainer* getContainer() const;
278 protected:
279 explicit ShapeBase( Drawing& rDrawing );
281 /** Derived classes create the corresponding XShape and insert it into the passed container. */
282 virtual css::uno::Reference< css::drawing::XShape >
283 implConvertAndInsert(
284 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
285 const css::awt::Rectangle& rShapeRect ) const = 0;
287 /** Always called after implConvertAndInsert for the same task.*/
288 virtual css::uno::Reference<css::drawing::XShape> finalImplConvertAndInsert(
289 const css::uno::Reference<css::drawing::XShape>& rxShape) const
291 return rxShape;
294 /** Calculates the final shape rectangle according to the passed anchor,
295 if present, otherwise according to the own anchor settings. */
296 css::awt::Rectangle calcShapeRectangle(
297 const ShapeParentAnchor* pParentAnchor ) const;
299 /** Converts common shape properties such as formatting attributes. */
300 void convertShapeProperties(
301 const css::uno::Reference< css::drawing::XShape >& rxShape ) const;
303 protected:
304 ShapeModel maShapeModel; ///< The model structure containing shape data.
305 ShapeContainer* mpContainer = nullptr;
309 /** A simple shape object based on a specific UNO shape service. */
310 class SimpleShape : public ShapeBase
312 public:
313 explicit SimpleShape( Drawing& rDrawing, OUString aService );
315 void setService( const OUString& aService ) { maService = aService; }
317 protected:
318 /** Creates the corresponding XShape and inserts it into the passed container. */
319 virtual css::uno::Reference< css::drawing::XShape >
320 implConvertAndInsert(
321 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
322 const css::awt::Rectangle& rShapeRect ) const override;
323 virtual css::uno::Reference<css::drawing::XShape> finalImplConvertAndInsert(
324 const css::uno::Reference<css::drawing::XShape>& rxShape) const override;
325 /** Used by both RectangleShape and ComplexShape. */
326 css::uno::Reference<css::drawing::XShape>createEmbeddedPictureObject(
327 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
328 const css::awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const;
330 css::uno::Reference<css::drawing::XShape>createPictureObject(
331 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
332 const css::awt::Rectangle& rShapeRect,
333 css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) const;
335 private:
336 OUString maService; ///< Name of the UNO shape service.
340 /** A rectangular shape object. */
341 class RectangleShape final : public SimpleShape
343 public:
344 explicit RectangleShape( Drawing& rDrawing );
345 private:
346 /** Creates the corresponding XShape and inserts it into the passed container. */
347 virtual css::uno::Reference<css::drawing::XShape>
348 implConvertAndInsert(
349 const css::uno::Reference<css::drawing::XShapes>& rxShapes,
350 const css::awt::Rectangle& rShapeRect) const override;
354 /** An oval shape object. */
355 class EllipseShape final : public SimpleShape
357 public:
358 explicit EllipseShape( Drawing& rDrawing );
362 /** A polygon shape object. */
363 class PolyLineShape final : public SimpleShape
365 public:
366 explicit PolyLineShape( Drawing& rDrawing );
368 private:
369 /** Creates the corresponding XShape and inserts it into the passed container. */
370 virtual css::uno::Reference< css::drawing::XShape >
371 implConvertAndInsert(
372 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
373 const css::awt::Rectangle& rShapeRect ) const override;
376 /** A Line shape object. */
377 class LineShape final : public SimpleShape
379 public:
380 explicit LineShape( Drawing& rDrawing );
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;
387 private:
388 /** Returns the absolute shape rectangle. */
389 virtual css::awt::Rectangle getAbsRectangle() const override;
390 /** Returns the rectangle relative to the parent coordinate system. */
391 virtual css::awt::Rectangle getRelRectangle() const override;
394 /** Bezier shape object that supports to, from, control1 and control2
395 attribute or path attribute specification */
396 class BezierShape final : public SimpleShape
398 public:
399 explicit BezierShape( Drawing& rDrawing );
401 private:
402 /** Creates the corresponding XShape and inserts it into the passed container. */
403 virtual css::uno::Reference< css::drawing::XShape >
404 implConvertAndInsert(
405 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
406 const css::awt::Rectangle& rShapeRect ) const override;
410 /** A shape object with custom geometry. */
411 class CustomShape : public SimpleShape
413 public:
414 explicit CustomShape( Drawing& rDrawing );
416 protected:
417 /** Creates the corresponding XShape and inserts it into the passed container. */
418 virtual css::uno::Reference< css::drawing::XShape >
419 implConvertAndInsert(
420 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
421 const css::awt::Rectangle& rShapeRect ) const override;
425 /** A complex shape object. This can be a picture shape, a custom shape, an OLE
426 object, or an ActiveX form control. */
427 class ComplexShape final : public CustomShape
429 public:
430 explicit ComplexShape( Drawing& rDrawing );
432 private:
433 /** Creates the corresponding XShape and inserts it into the passed container. */
434 virtual css::uno::Reference< css::drawing::XShape >
435 implConvertAndInsert(
436 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
437 const css::awt::Rectangle& rShapeRect ) const override;
441 /** A group shape that extends the basic shape by a container of child shapes. */
442 class GroupShape final : public ShapeBase
444 public:
445 explicit GroupShape( Drawing& rDrawing );
446 virtual ~GroupShape() override;
448 /** Returns read/write access to the container of child shapes and templates. */
449 ShapeContainer& getChildren() { return *mxChildren; }
450 /** Returns read access to the container of child shapes and templates. */
451 const ShapeContainer& getChildren() const { return *mxChildren; }
453 /** Final processing after import of the drawing fragment. */
454 virtual void finalizeFragmentImport() override;
456 /** Returns the shape template with the passed identifier from the child shapes. */
457 virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const override;
458 /** Returns the shape with the passed identifier from the child shapes. */
459 virtual const ShapeBase* getChildById( const OUString& rShapeId ) const override;
461 private:
462 /** Creates the corresponding XShape and inserts it into the passed container. */
463 virtual css::uno::Reference< css::drawing::XShape >
464 implConvertAndInsert(
465 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
466 const css::awt::Rectangle& rShapeRect ) const override;
468 private:
469 std::unique_ptr<ShapeContainer> mxChildren; ///< Shapes and templates that are part of this group.
473 } // namespace oox::vml
475 #endif
477 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */