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