xref: /trunk/main/oox/inc/oox/ole/vbacontrol.hxx (revision e3508121)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_OLE_VBACONTROL_HXX
25 #define OOX_OLE_VBACONTROL_HXX
26 
27 #include "oox/ole/axcontrol.hxx"
28 
29 namespace com { namespace sun { namespace star {
30     namespace container { class XNameContainer; }
31     namespace uno { class XComponentContext; }
32 } } }
33 
34 namespace oox { class StorageBase; }
35 
36 namespace oox {
37 namespace ole {
38 
39 // ============================================================================
40 
41 /** Common properties for all controls that are part of a VBA user form or of
42     another container control in a VBA user form. */
43 class VbaSiteModel
44 {
45 public:
46     explicit            VbaSiteModel();
47     virtual             ~VbaSiteModel();
48 
49     /** Allows to set single properties specified by XML token identifier. */
50     void                importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
51     /** Imports the site model data from the passed input stream. */
52     bool                importBinaryModel( BinaryInputStream& rInStrm );
53     /** Moves the control relative to its current position by the passed distance. */
54     void                moveRelative( const AxPairData& rDistance );
55 
56     /** Returns the programmatical name of the control. */
getName() const57     inline const ::rtl::OUString& getName() const { return maName; }
58     /** Returns the position of the control in its parent. */
getPosition() const59     inline const AxPairData& getPosition() const { return maPos; }
60     /** Returns the unique identifier of this control. */
getId() const61     inline sal_Int32    getId() const { return mnId; }
62     /** Returns true, if the control is visible. */
63     bool                isVisible() const;
64     /** Returns true, if this control is a container control. */
65     bool                isContainer() const;
66     /** Returns the length of the stream data for stream based controls. */
67     sal_uInt32          getStreamLength() const;
68     /** Returns the name of the substorage for the container control data. */
69     ::rtl::OUString     getSubStorageName() const;
70     /** Returns the tab index of the control. */
getTabIndex() const71     inline sal_Int16    getTabIndex() const { return mnTabIndex; }
72 
73     /** Tries to create the control model according to the site model. */
74     ControlModelRef     createControlModel( const AxClassTable& rClassTable ) const;
75     /** Converts all form site properties. */
76     void                convertProperties(
77                             PropertyMap& rPropMap,
78                             const ControlConverter& rConv,
79                             ApiControlType eCtrlType,
80                             sal_Int32 nCtrlIndex ) const;
81 
82     /** Binds the passed control model to the data sources. The implementation
83         will check which source types are supported. */
84     void                bindToSources(
85                             const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxCtrlModel,
86                             const ControlConverter& rConv ) const;
87 
88 protected:
89     ::rtl::OUString     maName;             /// Name of the control.
90     ::rtl::OUString     maTag;              /// User defined tag.
91     ::rtl::OUString     maToolTip;          /// Tool tip for the control.
92     ::rtl::OUString     maControlSource;    /// Linked cell for the control value in a spreadsheet.
93     ::rtl::OUString     maRowSource;        /// Source data for the control in a spreadsheet.
94     AxPairData          maPos;              /// Position in parent container.
95     sal_Int32           mnId;               /// Control identifier.
96     sal_Int32           mnHelpContextId;    /// Help context identifier.
97     sal_uInt32          mnFlags;            /// Various flags.
98     sal_uInt32          mnStreamLen;        /// Size of control stream data.
99     sal_Int16           mnTabIndex;         /// Tab order index.
100     sal_uInt16          mnClassIdOrCache;   /// Class name identifier or GUID cache index.
101     sal_uInt16          mnGroupId;          /// Group identifier for grouped controls.
102 };
103 
104 typedef ::boost::shared_ptr< VbaSiteModel > VbaSiteModelRef;
105 
106 // ============================================================================
107 
108 /** A control that is embedded in a VBA user form or in another container
109     control in a VBA user form.
110 
111     The control may be a 'simple' control with its data stored in the 'o'
112     stream, or it may be a container control with its data stored in an own
113     substorage.
114  */
115 class VbaFormControl
116 {
117 public:
118     explicit            VbaFormControl();
119     virtual             ~VbaFormControl();
120 
121     /** Imports the model from the passed stream or storage, depending on the
122         control's type. Imports all embedded controls, if this is a container. */
123     void                importModelOrStorage(
124                             BinaryInputStream& rInStrm,
125                             StorageBase& rStrg,
126                             const AxClassTable& rClassTable );
127 
128     /** Returns the programmatical name of the control. */
129     ::rtl::OUString     getControlName() const;
130     /** Returns the unique identifier of this control. */
131     sal_Int32           getControlId() const;
132 
133     /** Creates the UNO control model, inserts it into the passed container,
134         and converts all control properties. */
135     void                createAndConvert(
136                             sal_Int32 nCtrlIndex,
137                             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxParentNC,
138                             const ControlConverter& rConv ) const;
139 
140 protected:
141     /** Creates and imports the control model containing properties of the control. */
142     void                importControlModel( BinaryInputStream& rInStrm, const AxClassTable& rClassTable );
143     /** Creates and imports the control model, and imports all embedded
144         controls from the passed substorage. */
145     void                importStorage( StorageBase& rStrg, const AxClassTable& rClassTable );
146 
147     /** Converts all control properties, and inserts and converts embedded controls. */
148     bool                convertProperties(
149                             const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxCtrlModel,
150                             const ControlConverter& rConv,
151                             sal_Int32 nCtrlIndex ) const;
152 
153 private:
154     typedef RefVector< VbaFormControl >         VbaFormControlVector;
155     typedef VbaFormControlVector::value_type    VbaFormControlRef;
156 
157     /** Creates the control model according to the current site model. */
158     void                createControlModel( const AxClassTable& rClassTable );
159     /** Imports the site model data containing common properties of the control. */
160     bool                importSiteModel( BinaryInputStream& rInStrm );
161 
162     /** Imports the site models of all embedded controls from the 'f' stream. */
163     bool                importEmbeddedSiteModels( BinaryInputStream& rInStrm );
164     /*  Final processing of all embedded controls after import. */
165     void                finalizeEmbeddedControls();
166 
167     /** Moves the control relative to its current position by the passed distance. */
168     void                moveRelative( const AxPairData& rDistance );
169     /** Moves all embedded controls from their relative position in this
170         control to an absolute position in the parent of this control. */
171     void                moveEmbeddedToAbsoluteParent();
172 
173     /** Functor for comparing controls by their tab index. */
174     static bool         compareByTabIndex( const VbaFormControlRef& rxLeft, const VbaFormControlRef& rxRight );
175 
176 protected:
177     VbaSiteModelRef     mxSiteModel;        /// Common control properties.
178     ControlModelRef     mxCtrlModel;        /// Specific control properties.
179 
180 private:
181     VbaFormControlVector maControls;        /// All embedded form controls.
182     AxClassTable         maClassTable;      /// Class identifiers for exotic embedded controls.
183 };
184 
185 // ============================================================================
186 
187 class VbaUserForm : public VbaFormControl
188 {
189 public:
190     explicit            VbaUserForm(
191                             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
192                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxDocModel,
193                             const GraphicHelper& rGraphicHelper,
194                             bool bDefaultColorBgr = true );
195 
196     /** Imports the form and its embedded controls, and inserts the form with
197         all its controls into the passed dialog library. */
198     void                importForm(
199                             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxDialogLib,
200                             StorageBase& rVbaFormStrg,
201                             const ::rtl::OUString& rModuleName,
202                             rtl_TextEncoding eTextEnc );
203 
204 private:
205     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
206     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > mxDocModel;
207     ControlConverter    maConverter;
208 };
209 
210 // ============================================================================
211 
212 } // namespace ole
213 } // namespace oox
214 
215 #endif
216