1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"CommandBarControl" script:
language=
"StarBasic">REM =======================================================================================================================
4 REM === The Access2Base library is a part of the LibreOffice project. ===
5 REM === Full documentation is available on http://www.access2base.com ===
6 REM =======================================================================================================================
13 REM -----------------------------------------------------------------------------------------------------------------------
14 REM --- CLASS ROOT FIELDS ---
15 REM -----------------------------------------------------------------------------------------------------------------------
17 Private _Type As String
' Must be COMMANDBARCONTROL
18 Private _InternalIndex As Integer
' Index in toolbar including separators
19 Private _Index As Integer
' Index in collection, starting at
1 !!
20 Private _ControlType As Integer
' 1 of the msoControl* constants
21 Private _ParentCommandBarName As String
22 Private _ParentCommandBar As Object
' com.sun.star.ui.XUIElement
23 Private _ParentBuiltin As Boolean
24 Private _Element As Variant
25 Private _BeginGroup As Boolean
27 REM -----------------------------------------------------------------------------------------------------------------------
28 REM --- CONSTRUCTORS / DESTRUCTORS ---
29 REM -----------------------------------------------------------------------------------------------------------------------
30 Private Sub Class_Initialize()
31 _Type = OBJCOMMANDBARCONTROL
33 _ParentCommandBarName =
""
34 Set _ParentCommandBar = Nothing
35 _ParentBuiltin = False
38 End Sub
' Constructor
40 REM -----------------------------------------------------------------------------------------------------------------------
41 Private Sub Class_Terminate()
42 On Local Error Resume Next
43 Call Class_Initialize()
44 End Sub
' Destructor
46 REM -----------------------------------------------------------------------------------------------------------------------
48 Call Class_Terminate()
49 End Sub
' Explicit destructor
51 REM -----------------------------------------------------------------------------------------------------------------------
52 REM --- CLASS GET/LET/SET PROPERTIES ---
53 REM -----------------------------------------------------------------------------------------------------------------------
55 REM -----------------------------------------------------------------------------------------------------------------------
56 Property Get BeginGroup() As Boolean
57 BeginGroup = _PropertyGet(
"BeginGroup
")
58 End Property
' BeginGroup (get)
60 REM -----------------------------------------------------------------------------------------------------------------------
61 Property Get BuiltIn() As Boolean
62 BuiltIn = _PropertyGet(
"BuiltIn
")
63 End Property
' BuiltIn (get)
65 REM -----------------------------------------------------------------------------------------------------------------------
66 Property Get Caption() As Variant
67 Caption = _PropertyGet(
"Caption
")
68 End Property
' Caption (get)
70 Property Let Caption(ByVal pvValue As Variant)
71 Call _PropertySet(
"Caption
", pvValue)
72 End Property
' Caption (set)
74 REM -----------------------------------------------------------------------------------------------------------------------
75 Property Get Index() As Integer
76 Index = _PropertyGet(
"Index
")
77 End Property
' Index (get)
79 REM -----------------------------------------------------------------------------------------------------------------------
80 Property Get ObjectType() As String
81 ObjectType = _PropertyGet(
"ObjectType
")
82 End Property
' ObjectType (get)
84 REM -----------------------------------------------------------------------------------------------------------------------
85 Property Get OnAction() As Variant
86 OnAction = _PropertyGet(
"OnAction
")
87 End Property
' OnAction (get)
89 Property Let OnAction(ByVal pvValue As Variant)
90 Call _PropertySet(
"OnAction
", pvValue)
91 End Property
' OnAction (set)
93 REM -----------------------------------------------------------------------------------------------------------------------
94 Property Get Parent() As Object
95 Parent = _PropertyGet(
"Parent
")
96 End Property
' Parent (get)
98 REM -----------------------------------------------------------------------------------------------------------------------
99 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
101 ' a Collection object if pvIndex absent
102 ' a Property object otherwise
104 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
105 vPropertiesList = _PropertiesList()
106 sObject = Utils._PCase(_Type)
107 If IsMissing(pvIndex) Then
108 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList)
110 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList, pvIndex)
111 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
115 Set Properties = vProperty
117 End Function
' Properties
119 REM -----------------------------------------------------------------------------------------------------------------------
120 Property Get TooltipText() As Variant
121 TooltipText = _PropertyGet(
"TooltipText
")
122 End Property
' TooltipText (get)
124 Property Let TooltipText(ByVal pvValue As Variant)
125 Call _PropertySet(
"TooltipText
", pvValue)
126 End Property
' TooltipText (set)
128 REM -----------------------------------------------------------------------------------------------------------------------
129 Public Function pType() As Integer
130 pType = _PropertyGet(
"Type
")
131 End Function
' Type (get)
133 REM -----------------------------------------------------------------------------------------------------------------------
134 Property Get Visible() As Variant
135 Visible = _PropertyGet(
"Visible
")
136 End Property
' Visible (get)
138 Property Let Visible(ByVal pvValue As Variant)
139 Call _PropertySet(
"Visible
", pvValue)
140 End Property
' Visible (set)
142 REM -----------------------------------------------------------------------------------------------------------------------
143 REM --- CLASS METHODS ---
144 REM -----------------------------------------------------------------------------------------------------------------------
146 REM -----------------------------------------------------------------------------------------------------------------------
147 Public Function Execute()
148 ' Execute the command stored in a toolbar button
150 If _ErrorHandler() Then On Local Error Goto Error_Function
151 Const cstThisSub =
"CommandBarControl.Execute
"
152 Utils._SetCalledSub(cstThisSub)
154 Dim sExecute As String
157 sExecute = _GetPropertyValue(_Element,
"CommandURL
",
"")
160 Case sExecute =
"" : Execute = False
161 Case _IsLeft(sExecute,
".uno:
")
162 Execute = DoCmd.RunCommand(sExecute)
163 Case _IsLeft(sExecute,
"vnd.sun.star.script:
")
164 Execute = Utils._RunScript(sExecute, Array(Nothing))
169 Utils._ResetCalledSub(cstThisSub)
172 TraceError(TRACEABORT, Err, cstThisSub, Erl)
175 End Function
' Execute V1.3
.0
177 REM -----------------------------------------------------------------------------------------------------------------------
178 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
179 ' Return property value of psProperty property name
181 Utils._SetCalledSub(
"CommandBarControl.getProperty
")
182 If IsMissing(pvProperty) Then Call _TraceArguments()
183 getProperty = _PropertyGet(pvProperty)
184 Utils._ResetCalledSub(
"CommandBar.getProperty
")
186 End Function
' getProperty
188 REM -----------------------------------------------------------------------------------------------------------------------
189 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
190 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
192 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
195 End Function
' hasProperty
197 REM -----------------------------------------------------------------------------------------------------------------------
198 REM --- PRIVATE FUNCTIONS ---
199 REM -----------------------------------------------------------------------------------------------------------------------
201 REM -----------------------------------------------------------------------------------------------------------------------
202 Private Function _PropertiesList() As Variant
203 _PropertiesList = Array(
"BeginGroup
",
"BuiltIn
",
"Caption
",
"Index
" _
204 ,
"ObjectType
",
"OnAction
",
"Parent
" _
205 ,
"TooltipText
",
"Type
",
"Visible
" _
207 End Function
' _PropertiesList
209 REM -----------------------------------------------------------------------------------------------------------------------
210 Private Function _PropertyGet(ByVal psProperty As String) As Variant
211 ' Return property value of the psProperty property name
213 If _ErrorHandler() Then On Local Error Goto Error_Function
214 Dim cstThisSub As String
215 cstThisSub =
"CommandBarControl.get
" & psProperty
216 Utils._SetCalledSub(cstThisSub)
219 Dim oLayout As Object, iElementIndex As Integer
221 Const cstUnoPrefix =
".uno:
"
223 Select Case UCase(psProperty)
224 Case UCase(
"BeginGroup
")
225 _PropertyGet = _BeginGroup
226 Case UCase(
"BuiltIn
")
227 sValue = _GetPropertyValue(_Element,
"CommandURL
",
"")
228 _PropertyGet = ( _IsLeft(sValue, cstUnoPrefix) )
229 Case UCase(
"Caption
")
230 _PropertyGet = _GetPropertyValue(_Element,
"Label
",
"")
231 Case UCase(
"Index
")
232 _PropertyGet = _Index
233 Case UCase(
"ObjectType
")
235 Case UCase(
"OnAction
")
236 _PropertyGet = _GetPropertyValue(_Element,
"CommandURL
",
"")
237 Case UCase(
"Parent
")
238 Set _PropertyGet = Application.CommandBars(_ParentCommandBarName)
239 Case UCase(
"TooltipText
")
240 sValue = _GetPropertyValue(_Element,
"Tooltip
",
"")
241 If sValue
<> "" Then _PropertyGet = sValue Else _PropertyGet = _GetPropertyValue(_Element,
"Label
",
"")
242 Case UCase(
"Type
")
243 _PropertyGet = msoControlButton
244 Case UCase(
"Visible
")
245 _PropertyGet = _GetPropertyValue(_Element,
"IsVisible
",
"")
251 Utils._ResetCalledSub(cstThisSub)
254 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
255 _PropertyGet = Nothing
258 TraceError(TRACEABORT, Err, Utils._CalledSub(), Erl)
259 _PropertyGet = Nothing
261 End Function
' _PropertyGet
263 REM -----------------------------------------------------------------------------------------------------------------------
264 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
265 ' Return True if property setting OK
267 If _ErrorHandler() Then On Local Error Goto Error_Function
268 Dim cstThisSub As String
269 cstThisSub =
"CommandBarControl.set
" & psProperty
270 Utils._SetCalledSub(cstThisSub)
272 Dim iArgNr As Integer
273 Dim oSettings As Object, sValue As String
276 Select Case UCase(_A2B_.CalledSub)
277 Case UCase(
"setProperty
") : iArgNr =
3
278 Case UCase(
"CommandBar.setProperty
") : iArgNr =
2
279 Case UCase(cstThisSub) : iArgNr =
1
282 If Not hasProperty(psProperty) Then Goto Trace_Error
283 If _ParentBuiltin Then Goto Trace_Error
' Modifications of individual controls forbidden for builtin toolbars (design choice)
285 Const cstUnoPrefix =
".uno:
"
286 Const cstScript =
"vnd.sun.star.script:
"
288 Set oSettings = _ParentCommandBar.getSettings(True)
289 Select Case UCase(psProperty)
290 Case UCase(
"OnAction
")
291 If Not Utils._CheckArgument(pvValue, iArgNr, _AddNumeric(vbString), , False) Then Goto Trace_Error_Value
292 Select Case VarType(pvValue)
294 If _IsLeft(pvValue, cstUnoPrefix) Then
296 ElseIf _IsLeft(pvValue, cstScript) Then
299 sValue = DoCmd.RunCommand(pvValue, True)
301 Case Else
' Numeric
302 sValue = DoCmd.RunCommand(pvValue, True)
304 _SetPropertyValue(_Element,
"CommandURL
", sValue)
305 Case UCase(
"TooltipText
")
306 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
307 _SetPropertyValue(_Element,
"Tooltip
", pvValue)
308 Case UCase(
"Visible
")
309 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
310 _SetPropertyValue(_Element,
"IsVisible
", pvValue)
314 oSettings.replaceByIndex(_InternalIndex, _Element)
315 _ParentCommandBar.setSettings(oSettings)
318 Utils._ResetCalledSub(cstThisSub)
321 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
325 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
329 TraceError(TRACEABORT, Err, cstThisSub, Erl)
332 End Function
' _PropertySet