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_OLE_VBACONTROL_HXX
21 : #define OOX_OLE_VBACONTROL_HXX
22 :
23 : #include "oox/ole/axcontrol.hxx"
24 : #include <com/sun/star/frame/XModel.hpp>
25 :
26 : namespace com { namespace sun { namespace star {
27 : namespace container { class XNameContainer; }
28 : namespace uno { class XComponentContext; }
29 : } } }
30 :
31 : namespace oox { class StorageBase; }
32 :
33 : namespace oox {
34 : namespace ole {
35 :
36 : // ============================================================================
37 :
38 : /** Common properties for all controls that are part of a VBA user form or of
39 : another container control in a VBA user form. */
40 : class VbaSiteModel
41 : {
42 : public:
43 : explicit VbaSiteModel();
44 : virtual ~VbaSiteModel();
45 :
46 : /** Allows to set single properties specified by XML token identifier. */
47 : void importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
48 : /** Imports the site model data from the passed input stream. */
49 : bool importBinaryModel( BinaryInputStream& rInStrm );
50 : /** Moves the control relative to its current position by the passed distance. */
51 : void moveRelative( const AxPairData& rDistance );
52 :
53 : /** Returns the programmatical name of the control. */
54 0 : inline const ::rtl::OUString& getName() const { return maName; }
55 : /** Returns the position of the control in its parent. */
56 0 : inline const AxPairData& getPosition() const { return maPos; }
57 : /** Returns the unique identifier of this control. */
58 : inline sal_Int32 getId() const { return mnId; }
59 : /** Returns true, if this control is a container control. */
60 : bool isContainer() const;
61 : /** Returns the length of the stream data for stream based controls. */
62 : sal_uInt32 getStreamLength() const;
63 : /** Returns the name of the substorage for the container control data. */
64 : ::rtl::OUString getSubStorageName() const;
65 : /** Returns the tab index of the control. */
66 0 : inline sal_Int16 getTabIndex() const { return mnTabIndex; }
67 :
68 : /** Tries to create the control model according to the site model. */
69 : ControlModelRef createControlModel( const AxClassTable& rClassTable ) const;
70 : /** Converts all form site properties. */
71 : void convertProperties(
72 : PropertyMap& rPropMap,
73 : const ControlConverter& rConv,
74 : ApiControlType eCtrlType,
75 : sal_Int32 nCtrlIndex ) const;
76 :
77 : protected:
78 : ::rtl::OUString maName; ///< Name of the control.
79 : ::rtl::OUString maTag; ///< User defined tag.
80 : ::rtl::OUString maToolTip; ///< Tool tip for the control.
81 : ::rtl::OUString maControlSource; ///< Linked cell for the control value in a spreadsheet.
82 : ::rtl::OUString maRowSource; ///< Source data for the control in a spreadsheet.
83 :
84 : AxPairData maPos; ///< Position in parent container.
85 : sal_Int32 mnId; ///< Control identifier.
86 : sal_Int32 mnHelpContextId; ///< Help context identifier.
87 : sal_uInt32 mnFlags; ///< Various flags.
88 : sal_uInt32 mnStreamLen; ///< Size of control stream data.
89 : sal_Int16 mnTabIndex; ///< Tab order index.
90 : sal_uInt16 mnClassIdOrCache; ///< Class name identifier or GUID cache index.
91 : sal_uInt16 mnGroupId; ///< Group identifier for grouped controls.
92 : };
93 :
94 : typedef ::boost::shared_ptr< VbaSiteModel > VbaSiteModelRef;
95 :
96 : // ============================================================================
97 :
98 : /** A control that is embedded in a VBA user form or in another container
99 : control in a VBA user form.
100 :
101 : The control may be a 'simple' control with its data stored in the 'o'
102 : stream, or it may be a container control with its data stored in an own
103 : substorage.
104 : */
105 : class VbaFormControl
106 : {
107 : public:
108 : explicit VbaFormControl();
109 : virtual ~VbaFormControl();
110 :
111 : /** Imports the model from the passed stream or storage, depending on the
112 : control's type. Imports all embedded controls, if this is a container. */
113 : void importModelOrStorage(
114 : BinaryInputStream& rInStrm,
115 : StorageBase& rStrg,
116 : const AxClassTable& rClassTable );
117 :
118 : /** Returns the programmatical name of the control. */
119 : ::rtl::OUString getControlName() const;
120 :
121 : /** Creates the UNO control model, inserts it into the passed container,
122 : and converts all control properties. */
123 : void createAndConvert(
124 : sal_Int32 nCtrlIndex,
125 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxParentNC,
126 : const ControlConverter& rConv ) const;
127 :
128 : protected:
129 : /** Creates and imports the control model containing properties of the control. */
130 : void importControlModel( BinaryInputStream& rInStrm, const AxClassTable& rClassTable );
131 : /** Creates and imports the control model, and imports all embedded
132 : controls from the passed substorage. */
133 : void importStorage( StorageBase& rStrg, const AxClassTable& rClassTable );
134 :
135 : /** Converts all control properties, and inserts and converts embedded controls. */
136 : bool convertProperties(
137 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxCtrlModel,
138 : const ControlConverter& rConv,
139 : sal_Int32 nCtrlIndex ) const;
140 :
141 : private:
142 : typedef RefVector< VbaFormControl > VbaFormControlVector;
143 : typedef VbaFormControlVector::value_type VbaFormControlRef;
144 :
145 : /** Creates the control model according to the current site model. */
146 : void createControlModel( const AxClassTable& rClassTable );
147 : /** Imports the site model data containing common properties of the control. */
148 : bool importSiteModel( BinaryInputStream& rInStrm );
149 :
150 : /** Imports the site models of all embedded controls from the 'f' stream. */
151 : bool importEmbeddedSiteModels( BinaryInputStream& rInStrm );
152 : /* Final processing of all embedded controls after import. */
153 : void finalizeEmbeddedControls();
154 :
155 : /** Moves the control relative to its current position by the passed distance. */
156 : void moveRelative( const AxPairData& rDistance );
157 : /** Moves all embedded controls from their relative position in this
158 : control to an absolute position in the parent of this control. */
159 : void moveEmbeddedToAbsoluteParent();
160 :
161 : /** Functor for comparing controls by their tab index. */
162 : static bool compareByTabIndex( const VbaFormControlRef& rxLeft, const VbaFormControlRef& rxRight );
163 :
164 : protected:
165 : VbaSiteModelRef mxSiteModel; ///< Common control properties.
166 : ControlModelRef mxCtrlModel; ///< Specific control properties.
167 :
168 : private:
169 : VbaFormControlVector maControls; ///< All embedded form controls.
170 : AxClassTable maClassTable; ///< Class identifiers for exotic embedded controls.
171 : };
172 :
173 : // ============================================================================
174 :
175 0 : class VbaUserForm : public VbaFormControl
176 : {
177 : public:
178 : explicit VbaUserForm(
179 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
180 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxDocModel,
181 : const GraphicHelper& rGraphicHelper,
182 : bool bDefaultColorBgr = true );
183 :
184 : /** Imports the form and its embedded controls, and inserts the form with
185 : all its controls into the passed dialog library. */
186 : void importForm(
187 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxDialogLib,
188 : StorageBase& rVbaFormStrg,
189 : const ::rtl::OUString& rModuleName,
190 : rtl_TextEncoding eTextEnc );
191 :
192 : private:
193 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
194 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > mxDocModel;
195 : ControlConverter maConverter;
196 : };
197 :
198 : // ============================================================================
199 :
200 : } // namespace ole
201 : } // namespace oox
202 :
203 : #endif
204 :
205 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|