bump product version to 4.1.6.2
[LibreOffice.git] / include / oox / ole / vbacontrol.hxx
blobe31ee4312f29433bfc2e117b7c4f33cf4484aa2d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef OOX_OLE_VBACONTROL_HXX
21 #define OOX_OLE_VBACONTROL_HXX
23 #include "oox/ole/axcontrol.hxx"
24 #include <com/sun/star/frame/XModel.hpp>
26 namespace com { namespace sun { namespace star {
27 namespace container { class XNameContainer; }
28 namespace uno { class XComponentContext; }
29 } } }
31 namespace oox { class StorageBase; }
33 namespace oox {
34 namespace ole {
36 // ============================================================================
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
42 public:
43 explicit VbaSiteModel();
44 virtual ~VbaSiteModel();
46 /** Allows to set single properties specified by XML token identifier. */
47 void importProperty( sal_Int32 nPropId, const 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 );
53 /** Returns the programmatical name of the control. */
54 inline const OUString& getName() const { return maName; }
55 /** Returns the position of the control in its parent. */
56 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 OUString getSubStorageName() const;
65 /** Returns the tab index of the control. */
66 inline sal_Int16 getTabIndex() const { return mnTabIndex; }
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 inline ::rtl::OUString getControlSource() { return maControlSource; }
77 inline ::rtl::OUString getRowSource() { return maRowSource; }
78 protected:
79 OUString maName; ///< Name of the control.
80 OUString maTag; ///< User defined tag.
81 OUString maToolTip; ///< Tool tip for the control.
82 OUString maControlSource; ///< Linked cell for the control value in a spreadsheet.
83 OUString maRowSource; ///< Source data for the control in a spreadsheet.
85 AxPairData maPos; ///< Position in parent container.
86 sal_Int32 mnId; ///< Control identifier.
87 sal_Int32 mnHelpContextId; ///< Help context identifier.
88 sal_uInt32 mnFlags; ///< Various flags.
89 sal_uInt32 mnStreamLen; ///< Size of control stream data.
90 sal_Int16 mnTabIndex; ///< Tab order index.
91 sal_uInt16 mnClassIdOrCache; ///< Class name identifier or GUID cache index.
92 sal_uInt16 mnGroupId; ///< Group identifier for grouped controls.
95 typedef ::boost::shared_ptr< VbaSiteModel > VbaSiteModelRef;
97 // ============================================================================
99 /** A control that is embedded in a VBA user form or in another container
100 control in a VBA user form.
102 The control may be a 'simple' control with its data stored in the 'o'
103 stream, or it may be a container control with its data stored in an own
104 substorage.
106 class VbaFormControl
108 public:
109 explicit VbaFormControl();
110 virtual ~VbaFormControl();
112 /** Imports the model from the passed stream or storage, depending on the
113 control's type. Imports all embedded controls, if this is a container. */
114 void importModelOrStorage(
115 BinaryInputStream& rInStrm,
116 StorageBase& rStrg,
117 const AxClassTable& rClassTable );
119 /** Returns the programmatical name of the control. */
120 OUString getControlName() const;
122 /** Creates the UNO control model, inserts it into the passed container,
123 and converts all control properties. */
124 void createAndConvert(
125 sal_Int32 nCtrlIndex,
126 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxParentNC,
127 const ControlConverter& rConv ) const;
129 protected:
130 /** Creates and imports the control model containing properties of the control. */
131 void importControlModel( BinaryInputStream& rInStrm, const AxClassTable& rClassTable );
132 /** Creates and imports the control model, and imports all embedded
133 controls from the passed substorage. */
134 void importStorage( StorageBase& rStrg, const AxClassTable& rClassTable );
136 /** Converts all control properties, and inserts and converts embedded controls. */
137 bool convertProperties(
138 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxCtrlModel,
139 const ControlConverter& rConv,
140 sal_Int32 nCtrlIndex ) const;
142 private:
143 typedef RefVector< VbaFormControl > VbaFormControlVector;
144 typedef VbaFormControlVector::value_type VbaFormControlRef;
146 /** Creates the control model according to the current site model. */
147 void createControlModel( const AxClassTable& rClassTable );
148 /** Imports the site model data containing common properties of the control. */
149 bool importSiteModel( BinaryInputStream& rInStrm );
151 /** Imports the site models of all embedded controls from the 'f' stream. */
152 bool importEmbeddedSiteModels( BinaryInputStream& rInStrm );
153 /* Final processing of all embedded controls after import. */
154 void finalizeEmbeddedControls();
156 /** Moves the control relative to its current position by the passed distance. */
157 void moveRelative( const AxPairData& rDistance );
158 /** Moves all embedded controls from their relative position in this
159 control to an absolute position in the parent of this control. */
160 void moveEmbeddedToAbsoluteParent();
162 /** Functor for comparing controls by their tab index. */
163 static bool compareByTabIndex( const VbaFormControlRef& rxLeft, const VbaFormControlRef& rxRight );
165 protected:
166 VbaSiteModelRef mxSiteModel; ///< Common control properties.
167 ControlModelRef mxCtrlModel; ///< Specific control properties.
169 private:
170 VbaFormControlVector maControls; ///< All embedded form controls.
171 AxClassTable maClassTable; ///< Class identifiers for exotic embedded controls.
174 // ============================================================================
176 class VbaUserForm : public VbaFormControl
178 public:
179 explicit VbaUserForm(
180 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
181 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxDocModel,
182 const GraphicHelper& rGraphicHelper,
183 bool bDefaultColorBgr = true );
185 /** Imports the form and its embedded controls, and inserts the form with
186 all its controls into the passed dialog library. */
187 void importForm(
188 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxDialogLib,
189 StorageBase& rVbaFormStrg,
190 const OUString& rModuleName,
191 rtl_TextEncoding eTextEnc );
193 private:
194 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
195 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > mxDocModel;
196 ControlConverter maConverter;
199 // ============================================================================
201 } // namespace ole
202 } // namespace oox
204 #endif
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */