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 0 : 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 0 : ShapeTypeModel& getTypeModel() { return maTypeModel; }
125 : /** Returns read access to the shape template model structure. */
126 0 : const ShapeTypeModel& getTypeModel() const { return maTypeModel; }
127 :
128 : /** Returns the shape identifier (which is unique through the containing drawing). */
129 0 : 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 0 : 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 0 : 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 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
196 : typedef ::std::auto_ptr< TextBox > TextBoxPtr;
197 : typedef ::std::auto_ptr< ClientData > ClientDataPtr;
198 : SAL_WNODEPRECATED_DECLARATIONS_POP
199 :
200 : OUString maType; ///< Shape template with default properties.
201 : PointVector maPoints; ///< Points for the polyline shape.
202 : TextBoxPtr mxTextBox; ///< Text contents and properties.
203 : ClientDataPtr mxClientData; ///< Excel specific client data.
204 : OUString maLegacyDiagramPath;///< Legacy Diagram Fragment Path
205 : OUString maFrom; ///< Start point for line shape.
206 : OUString maTo; ///< End point for line shape.
207 : OUString maControl1; ///< Bezier control point 1
208 : OUString maControl2; ///< Bezier control point 2
209 : OUString maVmlPath; ///< VML path for this shape
210 : OUString maEditAs; ///< VML EditAs for shape
211 :
212 : explicit ShapeModel();
213 : ~ShapeModel();
214 :
215 : /** Creates and returns a new shape textbox structure. */
216 : TextBox& createTextBox(ShapeTypeModel& rModel);
217 : /** Creates and returns a new shape client data structure. */
218 : ClientData& createClientData();
219 : };
220 :
221 :
222 :
223 : /** A shape object that is part of a drawing. May inherit properties from a
224 : shape template. */
225 0 : class OOX_DLLPUBLIC ShapeBase : public ShapeType
226 : {
227 : public:
228 : /** Returns read/write access to the shape model structure. */
229 0 : ShapeModel& getShapeModel() { return maShapeModel; }
230 : /** Returns read access to the shape model structure. */
231 : const ShapeModel& getShapeModel() const { return maShapeModel; }
232 :
233 : /** Returns read access to the shape textbox. */
234 0 : const TextBox* getTextBox() const { return maShapeModel.mxTextBox.get(); }
235 : /** Returns read access to the shape client data structure. */
236 0 : const ClientData* getClientData() const { return maShapeModel.mxClientData.get(); }
237 :
238 : /** Final processing after import of the drawing fragment. */
239 : virtual void finalizeFragmentImport();
240 :
241 : /** Returns the real shape name if existing, or a generated shape name. */
242 : OUString getShapeName() const;
243 :
244 : /** Returns the shape template with the passed identifier from the child shapes. */
245 : virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const;
246 : /** Returns the shape with the passed identifier from the child shapes. */
247 : virtual const ShapeBase* getChildById( const OUString& rShapeId ) const;
248 :
249 : /** Creates the corresponding XShape and inserts it into the passed container. */
250 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
251 : convertAndInsert(
252 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
253 : const ShapeParentAnchor* pParentAnchor = 0 ) const;
254 :
255 : /** Converts position and formatting into the passed existing XShape. */
256 : void convertFormatting(
257 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape,
258 : const ShapeParentAnchor* pParentAnchor = 0 ) const;
259 :
260 : protected:
261 : explicit ShapeBase( Drawing& rDrawing );
262 :
263 : /** Derived classes create the corresponding XShape and insert it into the passed container. */
264 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
265 : implConvertAndInsert(
266 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
267 : const ::com::sun::star::awt::Rectangle& rShapeRect ) const = 0;
268 :
269 : /** Calculates the final shape rectangle according to the passed anchor,
270 : if present, otherwise according to the own anchor settings. */
271 : ::com::sun::star::awt::Rectangle calcShapeRectangle(
272 : const ShapeParentAnchor* pParentAnchor ) const;
273 :
274 : /** Converts common shape properties such as formatting attributes. */
275 : void convertShapeProperties(
276 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape ) const;
277 :
278 : protected:
279 : ShapeModel maShapeModel; ///< The model structure containing shape data.
280 : };
281 :
282 :
283 :
284 : /** A simple shape object based on a specific UNO shape service. */
285 0 : class SimpleShape : public ShapeBase
286 : {
287 : public:
288 : explicit SimpleShape( Drawing& rDrawing, const OUString& rService );
289 :
290 0 : void setService( const OUString& aService ) { maService = aService; }
291 :
292 : protected:
293 : /** Creates the corresponding XShape and inserts it into the passed container. */
294 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
295 : implConvertAndInsert(
296 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
297 : const ::com::sun::star::awt::Rectangle& rShapeRect ) const SAL_OVERRIDE;
298 : /** Used by both RectangleShape and ComplexShape. */
299 : com::sun::star::uno::Reference<com::sun::star::drawing::XShape>createPictureObject(
300 : const com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rxShapes,
301 : const com::sun::star::awt::Rectangle& rShapeRect, OUString& rGraphicPath ) const;
302 :
303 : private:
304 : OUString maService; ///< Name of the UNO shape service.
305 : };
306 :
307 :
308 :
309 : /** A rectangular shape object. */
310 0 : class RectangleShape : public SimpleShape
311 : {
312 : public:
313 : explicit RectangleShape( Drawing& rDrawing );
314 : protected:
315 : /** Creates the corresponding XShape and inserts it into the passed container. */
316 : virtual com::sun::star::uno::Reference<com::sun::star::drawing::XShape>
317 : implConvertAndInsert(
318 : const com::sun::star::uno::Reference<com::sun::star::drawing::XShapes>& rxShapes,
319 : const com::sun::star::awt::Rectangle& rShapeRect) const SAL_OVERRIDE;
320 : };
321 :
322 :
323 :
324 : /** An oval shape object. */
325 0 : class EllipseShape : public SimpleShape
326 : {
327 : public:
328 : explicit EllipseShape( Drawing& rDrawing );
329 : };
330 :
331 :
332 :
333 : /** A polygon shape object. */
334 0 : class PolyLineShape : public SimpleShape
335 : {
336 : public:
337 : explicit PolyLineShape( Drawing& rDrawing );
338 :
339 : protected:
340 : /** Creates the corresponding XShape and inserts it into the passed container. */
341 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
342 : implConvertAndInsert(
343 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
344 : const ::com::sun::star::awt::Rectangle& rShapeRect ) const SAL_OVERRIDE;
345 : };
346 :
347 : /** A Line shape object. */
348 0 : class LineShape : public SimpleShape
349 : {
350 : public:
351 : explicit LineShape( Drawing& rDrawing );
352 :
353 : protected:
354 : /** Returns the absolute shape rectangle. */
355 : virtual ::com::sun::star::awt::Rectangle getAbsRectangle() const SAL_OVERRIDE;
356 : /** Returns the rectangle relative to the parent coordinate system. */
357 : virtual ::com::sun::star::awt::Rectangle getRelRectangle() const SAL_OVERRIDE;
358 : };
359 :
360 : /** Bezier shape object that supports to, from, control1 and control2
361 : attribute or path attribute specification */
362 0 : class BezierShape : public SimpleShape
363 : {
364 : public:
365 : explicit BezierShape( Drawing& rDrawing );
366 :
367 : protected:
368 : /** Creates the corresponding XShape and inserts it into the passed container. */
369 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
370 : implConvertAndInsert(
371 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
372 : const ::com::sun::star::awt::Rectangle& rShapeRect ) const SAL_OVERRIDE;
373 : };
374 :
375 :
376 :
377 : /** A shape object with custom geometry. */
378 0 : class CustomShape : public SimpleShape
379 : {
380 : public:
381 : explicit CustomShape( Drawing& rDrawing );
382 :
383 : protected:
384 : /** Creates the corresponding XShape and inserts it into the passed container. */
385 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
386 : implConvertAndInsert(
387 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
388 : const ::com::sun::star::awt::Rectangle& rShapeRect ) const SAL_OVERRIDE;
389 : };
390 :
391 :
392 :
393 : /** A complex shape object. This can be a picture shape, a custom shape, an OLE
394 : object, or an ActiveX form control. */
395 0 : class ComplexShape : public CustomShape
396 : {
397 : public:
398 : explicit ComplexShape( Drawing& rDrawing );
399 :
400 : protected:
401 : /** Creates the corresponding XShape and inserts it into the passed container. */
402 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
403 : implConvertAndInsert(
404 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
405 : const ::com::sun::star::awt::Rectangle& rShapeRect ) const SAL_OVERRIDE;
406 : };
407 :
408 :
409 :
410 : /** A group shape that extends the basic shape by a container of child shapes. */
411 : class GroupShape : public ShapeBase
412 : {
413 : public:
414 : explicit GroupShape( Drawing& rDrawing );
415 : virtual ~GroupShape();
416 :
417 : /** Returns read/write access to the container of child shapes and templates. */
418 0 : ShapeContainer& getChildren() { return *mxChildren; }
419 : /** Returns read access to the container of child shapes and templates. */
420 : const ShapeContainer& getChildren() const { return *mxChildren; }
421 :
422 : /** Final processing after import of the drawing fragment. */
423 : virtual void finalizeFragmentImport() SAL_OVERRIDE;
424 :
425 : /** Returns the shape template with the passed identifier from the child shapes. */
426 : virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const SAL_OVERRIDE;
427 : /** Returns the shape with the passed identifier from the child shapes. */
428 : virtual const ShapeBase* getChildById( const OUString& rShapeId ) const SAL_OVERRIDE;
429 :
430 : protected:
431 : /** Creates the corresponding XShape and inserts it into the passed container. */
432 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
433 : implConvertAndInsert(
434 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
435 : const ::com::sun::star::awt::Rectangle& rShapeRect ) const SAL_OVERRIDE;
436 :
437 : private:
438 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
439 : typedef ::std::auto_ptr< ShapeContainer > ShapeContainerPtr;
440 : SAL_WNODEPRECATED_DECLARATIONS_POP
441 : ShapeContainerPtr mxChildren; ///< Shapes and templates that are part of this group.
442 : };
443 :
444 :
445 :
446 : } // namespace vml
447 : } // namespace oox
448 :
449 : #endif
450 :
451 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|