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