1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_OOX_OLE_VBACONTROL_HXX
21 #define INCLUDED_OOX_OLE_VBACONTROL_HXX
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <oox/helper/refvector.hxx>
27 #include <oox/ole/axbinaryreader.hxx>
28 #include <oox/ole/axcontrol.hxx>
29 #include <rtl/textenc.h>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
33 namespace com::sun::star
{
34 namespace awt
{ class XControlModel
; }
35 namespace container
{ class XNameContainer
; }
36 namespace frame
{ class XModel
; }
37 namespace uno
{ class XComponentContext
; }
41 class BinaryInputStream
;
50 /** Common properties for all controls that are part of a VBA user form or of
51 another container control in a VBA user form. */
52 class VbaSiteModel final
55 explicit VbaSiteModel();
58 /** Allows to set single properties specified by XML token identifier. */
59 void importProperty( sal_Int32 nPropId
, const OUString
& rValue
);
60 /** Imports the site model data from the passed input stream. */
61 bool importBinaryModel( BinaryInputStream
& rInStrm
);
62 /** Moves the control relative to its current position by the passed distance. */
63 void moveRelative( const AxPairData
& rDistance
);
65 /** Returns the programmatical name of the control. */
66 const OUString
& getName() const { return maName
; }
67 /** Returns the position of the control in its parent. */
68 const AxPairData
& getPosition() const { return maPos
; }
69 /** Returns the unique identifier of this control. */
70 sal_Int32
getId() const { return mnId
; }
71 /** Returns true, if this control is a container control. */
72 bool isContainer() const;
73 /** Returns the length of the stream data for stream based controls. */
74 sal_uInt32
getStreamLength() const;
75 /** Returns the name of the substorage for the container control data. */
76 OUString
getSubStorageName() const;
77 /** Returns the tab index of the control. */
78 sal_Int16
getTabIndex() const { return mnTabIndex
; }
80 /** Tries to create the control model according to the site model. */
81 ControlModelRef
createControlModel( const AxClassTable
& rClassTable
) const;
82 /** Converts all form site properties. */
83 void convertProperties(
84 PropertyMap
& rPropMap
,
85 const ControlConverter
& rConv
,
86 ApiControlType eCtrlType
,
87 sal_Int32 nCtrlIndex
) const;
88 const OUString
& getControlSource() const { return maControlSource
; }
89 const OUString
& getRowSource() const { return maRowSource
; }
91 OUString maName
; ///< Name of the control.
92 OUString maTag
; ///< User defined tag.
93 OUString maToolTip
; ///< Tool tip for the control.
94 OUString maControlSource
; ///< Linked cell for the control value in a spreadsheet.
95 OUString maRowSource
; ///< Source data for the control in a spreadsheet.
97 AxPairData maPos
; ///< Position in parent container.
98 sal_Int32 mnId
; ///< Control identifier.
99 sal_Int32 mnHelpContextId
; ///< Help context identifier.
100 sal_uInt32 mnFlags
; ///< Various flags.
101 sal_uInt32 mnStreamLen
; ///< Size of control stream data.
102 sal_Int16 mnTabIndex
; ///< Tab order index.
103 sal_uInt16 mnClassIdOrCache
; ///< Class name identifier or GUID cache index.
104 sal_uInt16 mnGroupId
; ///< Group identifier for grouped controls.
107 typedef std::shared_ptr
< VbaSiteModel
> VbaSiteModelRef
;
110 /** A control that is embedded in a VBA user form or in another container
111 control in a VBA user form.
113 The control may be a 'simple' control with its data stored in the 'o'
114 stream, or it may be a container control with its data stored in an own
120 explicit VbaFormControl();
121 virtual ~VbaFormControl();
123 /** Imports the model from the passed stream or storage, depending on the
124 control's type. Imports all embedded controls, if this is a container. */
125 void importModelOrStorage(
126 BinaryInputStream
& rInStrm
,
128 const AxClassTable
& rClassTable
);
130 /** Returns the programmatical name of the control. */
131 OUString
getControlName() const;
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 css::uno::Reference
< css::container::XNameContainer
>& rxParentNC
,
138 const ControlConverter
& rConv
) const;
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
);
147 /** Converts all control properties, and inserts and converts embedded controls. */
148 bool convertProperties(
149 const css::uno::Reference
< css::awt::XControlModel
>& rxCtrlModel
,
150 const ControlConverter
& rConv
,
151 sal_Int32 nCtrlIndex
) const;
154 typedef RefVector
< VbaFormControl
> VbaFormControlVector
;
155 typedef VbaFormControlVector::value_type VbaFormControlRef
;
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
);
162 /** Imports the site models of all embedded controls from the 'f' stream. */
163 void importEmbeddedSiteModels( BinaryInputStream
& rInStrm
);
164 /* Final processing of all embedded controls after import. */
165 void finalizeEmbeddedControls();
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();
173 /** Functor for comparing controls by their tab index. */
174 static bool compareByTabIndex( const VbaFormControlRef
& rxLeft
, const VbaFormControlRef
& rxRight
);
177 VbaSiteModelRef mxSiteModel
; ///< Common control properties.
178 ControlModelRef mxCtrlModel
; ///< Specific control properties.
181 VbaFormControlVector maControls
; ///< All embedded form controls.
182 AxClassTable maClassTable
; ///< Class identifiers for exotic embedded controls.
186 class VbaUserForm final
: public VbaFormControl
189 explicit VbaUserForm(
190 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
191 const css::uno::Reference
< css::frame::XModel
>& rxDocModel
,
192 const GraphicHelper
& rGraphicHelper
,
193 bool bDefaultColorBgr
);
195 /** Imports the form and its embedded controls, and inserts the form with
196 all its controls into the passed dialog library. */
198 const css::uno::Reference
< css::container::XNameContainer
>& rxDialogLib
,
199 StorageBase
& rVbaFormStrg
,
200 const OUString
& rModuleName
,
201 rtl_TextEncoding eTextEnc
);
204 css::uno::Reference
< css::uno::XComponentContext
> mxContext
;
205 css::uno::Reference
< css::frame::XModel
> mxDocModel
;
206 ControlConverter maConverter
;
210 } // namespace oox::ole
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */