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
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
; }
31 namespace oox
{ class StorageBase
; }
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. */
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 const OUString
& getName() const { return maName
; }
55 /** Returns the position of the control in its parent. */
56 const AxPairData
& getPosition() const { return maPos
; }
57 /** Returns the unique identifier of this control. */
58 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 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 ::rtl::OUString
getControlSource() { return maControlSource
; }
77 ::rtl::OUString
getRowSource() { return maRowSource
; }
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 std::shared_ptr
< VbaSiteModel
> VbaSiteModelRef
;
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
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
,
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;
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;
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
);
166 VbaSiteModelRef mxSiteModel
; ///< Common control properties.
167 ControlModelRef mxCtrlModel
; ///< Specific control properties.
170 VbaFormControlVector maControls
; ///< All embedded form controls.
171 AxClassTable maClassTable
; ///< Class identifiers for exotic embedded controls.
176 class VbaUserForm
: public VbaFormControl
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. */
188 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>& rxDialogLib
,
189 StorageBase
& rVbaFormStrg
,
190 const OUString
& rModuleName
,
191 rtl_TextEncoding eTextEnc
);
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
;
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */