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