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
{ namespace sun
{ namespace star
{
34 namespace awt
{ class XControlModel
; }
35 namespace container
{ class XNameContainer
; }
36 namespace frame
{ class XModel
; }
37 namespace uno
{ class XComponentContext
; }
41 class BinaryInputStream
;
51 /** Common properties for all controls that are part of a VBA user form or of
52 another container control in a VBA user form. */
53 class VbaSiteModel final
56 explicit VbaSiteModel();
59 /** Allows to set single properties specified by XML token identifier. */
60 void importProperty( sal_Int32 nPropId
, const OUString
& rValue
);
61 /** Imports the site model data from the passed input stream. */
62 bool importBinaryModel( BinaryInputStream
& rInStrm
);
63 /** Moves the control relative to its current position by the passed distance. */
64 void moveRelative( const AxPairData
& rDistance
);
66 /** Returns the programmatical name of the control. */
67 const OUString
& getName() const { return maName
; }
68 /** Returns the position of the control in its parent. */
69 const AxPairData
& getPosition() const { return maPos
; }
70 /** Returns the unique identifier of this control. */
71 sal_Int32
getId() const { return mnId
; }
72 /** Returns true, if this control is a container control. */
73 bool isContainer() const;
74 /** Returns the length of the stream data for stream based controls. */
75 sal_uInt32
getStreamLength() const;
76 /** Returns the name of the substorage for the container control data. */
77 OUString
getSubStorageName() const;
78 /** Returns the tab index of the control. */
79 sal_Int16
getTabIndex() const { return mnTabIndex
; }
81 /** Tries to create the control model according to the site model. */
82 ControlModelRef
createControlModel( const AxClassTable
& rClassTable
) const;
83 /** Converts all form site properties. */
84 void convertProperties(
85 PropertyMap
& rPropMap
,
86 const ControlConverter
& rConv
,
87 ApiControlType eCtrlType
,
88 sal_Int32 nCtrlIndex
) const;
89 const OUString
& getControlSource() { return maControlSource
; }
90 const OUString
& getRowSource() { return maRowSource
; }
92 OUString maName
; ///< Name of the control.
93 OUString maTag
; ///< User defined tag.
94 OUString maToolTip
; ///< Tool tip for the control.
95 OUString maControlSource
; ///< Linked cell for the control value in a spreadsheet.
96 OUString maRowSource
; ///< Source data for the control in a spreadsheet.
98 AxPairData maPos
; ///< Position in parent container.
99 sal_Int32 mnId
; ///< Control identifier.
100 sal_Int32 mnHelpContextId
; ///< Help context identifier.
101 sal_uInt32 mnFlags
; ///< Various flags.
102 sal_uInt32 mnStreamLen
; ///< Size of control stream data.
103 sal_Int16 mnTabIndex
; ///< Tab order index.
104 sal_uInt16 mnClassIdOrCache
; ///< Class name identifier or GUID cache index.
105 sal_uInt16 mnGroupId
; ///< Group identifier for grouped controls.
108 typedef std::shared_ptr
< VbaSiteModel
> VbaSiteModelRef
;
111 /** A control that is embedded in a VBA user form or in another container
112 control in a VBA user form.
114 The control may be a 'simple' control with its data stored in the 'o'
115 stream, or it may be a container control with its data stored in an own
121 explicit VbaFormControl();
122 virtual ~VbaFormControl();
124 /** Imports the model from the passed stream or storage, depending on the
125 control's type. Imports all embedded controls, if this is a container. */
126 void importModelOrStorage(
127 BinaryInputStream
& rInStrm
,
129 const AxClassTable
& rClassTable
);
131 /** Returns the programmatical name of the control. */
132 OUString
getControlName() const;
134 /** Creates the UNO control model, inserts it into the passed container,
135 and converts all control properties. */
136 void createAndConvert(
137 sal_Int32 nCtrlIndex
,
138 const css::uno::Reference
< css::container::XNameContainer
>& rxParentNC
,
139 const ControlConverter
& rConv
) const;
142 /** Creates and imports the control model containing properties of the control. */
143 void importControlModel( BinaryInputStream
& rInStrm
, const AxClassTable
& rClassTable
);
144 /** Creates and imports the control model, and imports all embedded
145 controls from the passed substorage. */
146 void importStorage( StorageBase
& rStrg
, const AxClassTable
& rClassTable
);
148 /** Converts all control properties, and inserts and converts embedded controls. */
149 bool convertProperties(
150 const css::uno::Reference
< css::awt::XControlModel
>& rxCtrlModel
,
151 const ControlConverter
& rConv
,
152 sal_Int32 nCtrlIndex
) const;
155 typedef RefVector
< VbaFormControl
> VbaFormControlVector
;
156 typedef VbaFormControlVector::value_type VbaFormControlRef
;
158 /** Creates the control model according to the current site model. */
159 void createControlModel( const AxClassTable
& rClassTable
);
160 /** Imports the site model data containing common properties of the control. */
161 bool importSiteModel( BinaryInputStream
& rInStrm
);
163 /** Imports the site models of all embedded controls from the 'f' stream. */
164 void importEmbeddedSiteModels( BinaryInputStream
& rInStrm
);
165 /* Final processing of all embedded controls after import. */
166 void finalizeEmbeddedControls();
168 /** Moves the control relative to its current position by the passed distance. */
169 void moveRelative( const AxPairData
& rDistance
);
170 /** Moves all embedded controls from their relative position in this
171 control to an absolute position in the parent of this control. */
172 void moveEmbeddedToAbsoluteParent();
174 /** Functor for comparing controls by their tab index. */
175 static bool compareByTabIndex( const VbaFormControlRef
& rxLeft
, const VbaFormControlRef
& rxRight
);
178 VbaSiteModelRef mxSiteModel
; ///< Common control properties.
179 ControlModelRef mxCtrlModel
; ///< Specific control properties.
182 VbaFormControlVector maControls
; ///< All embedded form controls.
183 AxClassTable maClassTable
; ///< Class identifiers for exotic embedded controls.
187 class VbaUserForm
: public VbaFormControl
190 explicit VbaUserForm(
191 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
192 const css::uno::Reference
< css::frame::XModel
>& rxDocModel
,
193 const GraphicHelper
& rGraphicHelper
,
194 bool bDefaultColorBgr
);
196 /** Imports the form and its embedded controls, and inserts the form with
197 all its controls into the passed dialog library. */
199 const css::uno::Reference
< css::container::XNameContainer
>& rxDialogLib
,
200 StorageBase
& rVbaFormStrg
,
201 const OUString
& rModuleName
,
202 rtl_TextEncoding eTextEnc
);
205 css::uno::Reference
< css::uno::XComponentContext
> mxContext
;
206 css::uno::Reference
< css::frame::XModel
> mxDocModel
;
207 ControlConverter maConverter
;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */