/src/libreoffice/include/oox/vml/vmldrawing.hxx
Line | Count | Source |
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_VMLDRAWING_HXX |
21 | | #define INCLUDED_OOX_VML_VMLDRAWING_HXX |
22 | | |
23 | | #include <map> |
24 | | #include <memory> |
25 | | #include <vector> |
26 | | |
27 | | #include <com/sun/star/uno/Reference.hxx> |
28 | | #include <oox/dllapi.h> |
29 | | #include <oox/ole/oleobjecthelper.hxx> |
30 | | #include <rtl/ustring.hxx> |
31 | | #include <sal/types.h> |
32 | | |
33 | | namespace com::sun::star { |
34 | | namespace awt { struct Rectangle; } |
35 | | namespace drawing { class XDrawPage; } |
36 | | namespace drawing { class XShape; } |
37 | | namespace drawing { class XShapes; } |
38 | | } |
39 | | |
40 | | namespace oox { |
41 | | namespace core { class XmlFilterBase; } |
42 | | namespace ole { class EmbeddedControl; } |
43 | | namespace ole { class EmbeddedForm; } |
44 | | namespace vml { class ShapeContainer; } |
45 | | } |
46 | | |
47 | | namespace oox::vml { |
48 | | |
49 | | class ShapeBase; |
50 | | |
51 | | |
52 | | /** Enumerates different types of VML drawings. */ |
53 | | enum DrawingType |
54 | | { |
55 | | VMLDRAWING_WORD, ///< Word: One shape per drawing. |
56 | | VMLDRAWING_EXCEL, ///< Excel: OLE objects are part of VML. |
57 | | VMLDRAWING_POWERPOINT ///< PowerPoint: OLE objects are part of DrawingML. |
58 | | }; |
59 | | |
60 | | |
61 | | /** Contains information about an OLE object embedded in a draw page. */ |
62 | | struct OOX_DLLPUBLIC OleObjectInfo : public ::oox::ole::OleObjectInfo |
63 | | { |
64 | | OUString maShapeId; ///< Shape identifier for shape lookup. |
65 | | OUString maName; ///< Programmatical name of the OLE object. |
66 | | bool mbAutoLoad; |
67 | | const bool mbDmlShape; ///< True = DrawingML shape (PowerPoint), false = VML shape (Excel/Word). |
68 | | |
69 | | explicit OleObjectInfo( bool bDmlShape = false ); |
70 | | |
71 | | /** Sets the string representation of the passed numeric shape identifier. */ |
72 | | void setShapeId( sal_Int32 nShapeId ); |
73 | | }; |
74 | | |
75 | | // =========================================/=================================== |
76 | | |
77 | | /** Contains information about a form control embedded in a draw page. */ |
78 | | struct OOX_DLLPUBLIC ControlInfo |
79 | | { |
80 | | OUString maShapeId; ///< Shape identifier for shape lookup. |
81 | | OUString maFragmentPath; ///< Path to the fragment describing the form control properties. |
82 | | OUString maName; ///< Programmatical name of the form control. |
83 | | bool mbTextContentShape; ///< Whether this control shape will be imported to Writer or not (has AnchorType property or not). |
84 | | |
85 | | explicit ControlInfo(); |
86 | | |
87 | | /** Sets the string representation of the passed numeric shape identifier. */ |
88 | | void setShapeId( sal_Int32 nShapeId ); |
89 | | }; |
90 | | |
91 | | |
92 | | /** Represents the collection of VML shapes for a complete draw page. */ |
93 | | class OOX_DLLPUBLIC Drawing |
94 | | { |
95 | | public: |
96 | | explicit Drawing( |
97 | | ::oox::core::XmlFilterBase& rFilter, |
98 | | const css::uno::Reference< css::drawing::XDrawPage >& rxDrawPage, |
99 | | DrawingType eType ); |
100 | | |
101 | | virtual ~Drawing(); |
102 | | |
103 | | /** Returns the filter object that imports/exports this VML drawing. */ |
104 | 40.3k | ::oox::core::XmlFilterBase& getFilter() const { return mrFilter; } |
105 | | /** Returns the application type containing the drawing. */ |
106 | 7.84k | DrawingType getType() const { return meType; } |
107 | | /** Returns read/write access to the container of shapes and templates. */ |
108 | 14.9k | ShapeContainer& getShapes() { return *mxShapes; } |
109 | | /** Returns read access to the container of shapes and templates. */ |
110 | 8.67k | const ShapeContainer& getShapes() const { return *mxShapes; } |
111 | | /** Returns the form object used to process ActiveX form controls. */ |
112 | | ::oox::ole::EmbeddedForm& getControlForm() const; |
113 | | |
114 | | /** Registers a block of shape identifiers reserved by this drawing. Block |
115 | | size is 1024, shape identifiers are one-based (block 1 => 1025-2048). */ |
116 | | void registerBlockId( sal_Int32 nBlockId ); |
117 | | /** Registers the passed embedded OLE object. The related shape will then |
118 | | load the OLE object data from the specified fragment. */ |
119 | | void registerOleObject( const OleObjectInfo& rOleObject ); |
120 | | /** Registers the passed embedded form control. The related shape will then |
121 | | load the control properties from the specified fragment. */ |
122 | | void registerControl( const ControlInfo& rControl ); |
123 | | |
124 | | /** Final processing after import of the fragment. */ |
125 | | void finalizeFragmentImport(); |
126 | | |
127 | | /** Creates and inserts all UNO shapes into the draw page. The virtual |
128 | | function notifyXShapeInserted() will be called for each new shape. */ |
129 | | void convertAndInsert() const; |
130 | | |
131 | | /** Returns the local shape index from the passed global shape identifier. */ |
132 | | sal_Int32 getLocalShapeIndex( std::u16string_view rShapeId ) const; |
133 | | /** Returns the registered info structure for an OLE object, if extant. */ |
134 | | const OleObjectInfo* getOleObjectInfo( const OUString& rShapeId ) const; |
135 | | /** Returns the registered info structure for a form control, if extant. */ |
136 | | const ControlInfo* getControlInfo( const OUString& rShapeId ) const; |
137 | | |
138 | | /** Creates a new UNO shape object, inserts it into the passed UNO shape |
139 | | container, and sets the shape position and size. */ |
140 | | css::uno::Reference< css::drawing::XShape > |
141 | | createAndInsertXShape( |
142 | | const OUString& rService, |
143 | | const css::uno::Reference< css::drawing::XShapes >& rxShapes, |
144 | | const css::awt::Rectangle& rShapeRect ) const; |
145 | | |
146 | | /** Creates a new UNO shape object for a form control, inserts the control |
147 | | model into the form, and the shape into the passed UNO shape container. */ |
148 | | css::uno::Reference< css::drawing::XShape > |
149 | | createAndInsertXControlShape( |
150 | | const ::oox::ole::EmbeddedControl& rControl, |
151 | | const css::uno::Reference< css::drawing::XShapes >& rxShapes, |
152 | | const css::awt::Rectangle& rShapeRect, |
153 | | sal_Int32& rnCtrlIndex ) const; |
154 | | |
155 | | /** Derived classes may disable conversion of specific shapes. */ |
156 | | virtual bool isShapeSupported( const ShapeBase& rShape ) const; |
157 | | |
158 | | /** Derived classes may return additional base names for automatic shape |
159 | | name creation. */ |
160 | | virtual OUString getShapeBaseName( const ShapeBase& rShape ) const; |
161 | | |
162 | | /** Derived classes may calculate the shape rectangle from a non-standard |
163 | | anchor information string. */ |
164 | | virtual bool convertClientAnchor( |
165 | | css::awt::Rectangle& orShapeRect, |
166 | | const OUString& rShapeAnchor ) const; |
167 | | |
168 | | /** Derived classes create a UNO shape according to the passed shape model. |
169 | | Called for shape models that specify being under host control. */ |
170 | | virtual css::uno::Reference< css::drawing::XShape > |
171 | | createAndInsertClientXShape( |
172 | | const ShapeBase& rShape, |
173 | | const css::uno::Reference< css::drawing::XShapes >& rxShapes, |
174 | | const css::awt::Rectangle& rShapeRect ) const; |
175 | | |
176 | | /** Derived classes may want to know that a UNO shape has been inserted. |
177 | | Will be called from the convertAndInsert() implementation. |
178 | | @param bGroupChild True = inserted into a group shape, |
179 | | false = inserted directly into this drawing. */ |
180 | | virtual void notifyXShapeInserted( |
181 | | const css::uno::Reference< css::drawing::XShape >& rxShape, |
182 | | const css::awt::Rectangle& rShapeRect, |
183 | | const ShapeBase& rShape, bool bGroupChild ); |
184 | | |
185 | | private: |
186 | | typedef ::std::vector< sal_Int32 > BlockIdVector; |
187 | | typedef ::std::map< OUString, OleObjectInfo > OleObjectInfoMap; |
188 | | typedef ::std::map< OUString, ControlInfo > ControlInfoMap; |
189 | | |
190 | | ::oox::core::XmlFilterBase& mrFilter; ///< Filter object that imports/exports the VML drawing. |
191 | | css::uno::Reference< css::drawing::XDrawPage > |
192 | | mxDrawPage; ///< UNO draw page used to insert the shapes. |
193 | | mutable std::unique_ptr<::oox::ole::EmbeddedForm> mxCtrlForm; ///< The control form used to process embedded controls. |
194 | | mutable BlockIdVector maBlockIds; ///< Block identifiers used by this drawing. |
195 | | std::unique_ptr<ShapeContainer> mxShapes; ///< All shapes and shape templates. |
196 | | OleObjectInfoMap maOleObjects; ///< Info about all embedded OLE objects, mapped by shape id. |
197 | | ControlInfoMap maControls; ///< Info about all embedded form controls, mapped by control name. |
198 | | const DrawingType meType; ///< Application type containing the drawing. |
199 | | }; |
200 | | |
201 | | |
202 | | } // namespace oox::vml |
203 | | |
204 | | #endif |
205 | | |
206 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |