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=
"CommandBar" script:
language=
"StarBasic">
4 REM =======================================================================================================================
5 REM === The Access2Base library is a part of the LibreOffice project. ===
6 REM === Full documentation is available on http://www.access2base.com ===
7 REM =======================================================================================================================
14 REM -----------------------------------------------------------------------------------------------------------------------
15 REM --- CLASS ROOT FIELDS ---
16 REM -----------------------------------------------------------------------------------------------------------------------
18 Private _Type As String
' Must be COMMANDBAR
19 Private _This As Object
' Workaround for absence of This builtin function
20 Private _Parent As Object
21 Private _Name As String
22 Private _ResourceURL As String
23 Private _Window As Object
' com.sun.star.frame.XFrame
24 Private _Module As String
25 Private _Toolbar As Object
26 Private _BarBuiltin As Integer
' 1 = builtin,
2 = custom stored in LO/AOO (Base),
3 = custom stored in document (Form)
27 Private _BarType As Integer
' See msoBarTypeXxx constants
29 REM -----------------------------------------------------------------------------------------------------------------------
30 REM --- CONSTRUCTORS / DESTRUCTORS ---
31 REM -----------------------------------------------------------------------------------------------------------------------
32 Private Sub Class_Initialize()
37 _ResourceURL =
""
39 _Module =
""
40 Set _Toolbar = Nothing
43 End Sub
' Constructor
45 REM -----------------------------------------------------------------------------------------------------------------------
46 Private Sub Class_Terminate()
47 On Local Error Resume Next
48 Call Class_Initialize()
49 End Sub
' Destructor
51 REM -----------------------------------------------------------------------------------------------------------------------
53 Call Class_Terminate()
54 End Sub
' Explicit destructor
56 REM -----------------------------------------------------------------------------------------------------------------------
57 REM --- CLASS GET/LET/SET PROPERTIES ---
58 REM -----------------------------------------------------------------------------------------------------------------------
60 REM -----------------------------------------------------------------------------------------------------------------------
61 Property Get BuiltIn() As Boolean
62 BuiltIn = _PropertyGet(
"BuiltIn
")
63 End Property
' BuiltIn (get)
65 REM -----------------------------------------------------------------------------------------------------------------------
66 Property Get Name() As String
67 Name = _PropertyGet(
"Name
")
68 End Property
' Name (get)
70 Public Function pName() As String
' For compatibility with
< V0.9
.0
71 pName = _PropertyGet(
"Name
")
72 End Function
' pName (get)
74 REM -----------------------------------------------------------------------------------------------------------------------
75 Property Get ObjectType() As String
76 ObjectType = _PropertyGet(
"ObjectType
")
77 End Property
' ObjectType (get)
79 REM -----------------------------------------------------------------------------------------------------------------------
80 Public Function Parent() As Object
82 End Function
' Parent (get) V6.4
.0
84 REM -----------------------------------------------------------------------------------------------------------------------
85 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
87 ' a Collection object if pvIndex absent
88 ' a Property object otherwise
90 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
91 vPropertiesList = _PropertiesList()
92 sObject = Utils._PCase(_Type)
93 If IsMissing(pvIndex) Then
94 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList)
96 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList, pvIndex)
97 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
101 Set Properties = vProperty
103 End Function
' Properties
105 REM -----------------------------------------------------------------------------------------------------------------------
106 Property Get Visible() As Variant
107 Visible = _PropertyGet(
"Visible
")
108 End Property
' Visible (get)
110 Property Let Visible(ByVal pvValue As Variant)
111 Call _PropertySet(
"Visible
", pvValue)
112 End Property
' Visible (set)
114 REM -----------------------------------------------------------------------------------------------------------------------
115 REM --- CLASS METHODS ---
116 REM -----------------------------------------------------------------------------------------------------------------------
118 REM -----------------------------------------------------------------------------------------------------------------------
119 Public Function CommandBarControls(Optional ByVal pvIndex As Variant) As Variant
120 ' Return an object of type CommandBarControl indicated by its index
121 ' Index is different from UNO index: separators do not count
122 ' If no pvIndex argument, return a Collection type
124 If _ErrorHandler() Then On Local Error Goto Error_Function
125 Const cstThisSub =
"CommandBar.CommandBarControls
"
126 Utils._SetCalledSub(cstThisSub)
128 Dim oLayout As Object, vElements() As Variant, iIndexToolbar As Integer, oToolbar As Object
129 Dim i As Integer, iItemsCount As Integer, oSettings As Object, vItem() As Variant, bSeparator As Boolean
130 Dim oObject As Object
132 Set oObject = Nothing
133 If Not IsMissing(pvIndex) Then
134 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric()) Then Goto Exit_Function
135 If pvIndex
< 0 Then Goto Trace_IndexError
139 Case msoBarTypeNormal, msoBarTypeMenuBar
140 Case Else : Goto Error_NotApplicable
' Status bar not supported
143 Set oLayout = _Window.LayoutManager
144 vElements = oLayout.getElements()
145 iIndexToolbar = _FindElement(vElements())
146 If iIndexToolbar
< 0 Then Goto Error_NotApplicable
' Toolbar not visible
147 Set oToolbar = vElements(iIndexToolbar)
150 Set oSettings = oToolbar.getSettings(False)
153 For i =
0 To oSettings.getCount() -
1
154 Set vItem() = oSettings.getByIndex(i)
155 If _GetPropertyValue(vItem,
"Type
",
1)
<> 1 Then
' Type =
1 indicates separator
156 iItemsCount = iItemsCount +
1
157 If Not IsMissing(pvIndex) Then
158 If pvIndex = iItemsCount -
1 Then
159 Set oObject = New CommandBarControl
163 ._ParentCommandBarName = _Name
164 ._ParentCommandBar = oToolbar
165 ._ParentBuiltin = ( _BarBuiltin =
1 )
168 ._Index = iItemsCount
' Indexes start at
1
169 ._BeginGroup = bSeparator
179 If IsNull(oObject) Then
181 Case IsMissing(pvIndex)
182 Set oObject = New Collect
183 Set oObject._This = oObject
184 oObject._CollType = COLLCOMMANDBARCONTROLS
185 Set oObject._Parent = _This
186 oObject._Count = iItemsCount
187 Case Else
' pvIndex is numeric
188 Goto Trace_IndexError
193 Set CommandBarControls = oObject
194 Set oObject = Nothing
195 Utils._ResetCalledSub(cstThisSub)
198 TraceError(TRACEABORT, Err, cstThisSub, Erl)
201 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0)
204 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0,
1, cstThisSub)
206 End Function
' CommandBarControls V1,
3,
0
208 REM -----------------------------------------------------------------------------------------------------------------------
209 Public Function Controls(Optional ByVal pvIndex As Variant) As Variant
210 ' Alias for CommandBarControls (VBA)
212 If _ErrorHandler() Then On Local Error Goto Error_Function
213 Const cstThisSub =
"CommandBar.Controls
"
214 Utils._SetCalledSub(cstThisSub)
216 Dim oObject As Object
218 If IsMissing(pvIndex) Then Set oObject = CommandBarControls() Else Set oObject = CommandBarControls(pvIndex)
221 Set Controls = oObject
222 Set oObject = Nothing
223 Utils._ResetCalledSub(cstThisSub)
226 TraceError(TRACEABORT, Err, cstThisSub, Erl)
228 End Function
' Controls V1,
3,
0
230 REM -----------------------------------------------------------------------------------------------------------------------
231 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
232 ' Return property value of psProperty property name
234 Utils._SetCalledSub(
"CommandBar.getProperty
")
235 If IsMissing(pvProperty) Then Call _TraceArguments()
236 getProperty = _PropertyGet(pvProperty)
237 Utils._ResetCalledSub(
"CommandBar.getProperty
")
239 End Function
' getProperty
241 REM -----------------------------------------------------------------------------------------------------------------------
242 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
243 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
245 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
248 End Function
' hasProperty
250 REM -----------------------------------------------------------------------------------------------------------------------
251 Public Function Reset() As Boolean
252 ' Reset a whole command bar to its initial values
254 If _ErrorHandler() Then On Local Error Goto Error_Function
255 Const cstThisSub =
"CommandBar.Reset
"
256 Utils._SetCalledSub(cstThisSub)
262 Utils._ResetCalledSub(cstThisSub)
265 TraceError(TRACEABORT, Err, cstThisSub, Erl)
268 End Function
' Reset V1.3
.0
270 REM -----------------------------------------------------------------------------------------------------------------------
271 REM --- PRIVATE FUNCTIONS ---
272 REM -----------------------------------------------------------------------------------------------------------------------
274 REM -----------------------------------------------------------------------------------------------------------------------
275 Private Function _FindElement(pvElements As Variant) As Integer
276 ' Return -
1 if not found, otherwise return index in elements table of LayoutManager
281 If Not IsArray(pvElements) Then Exit Function
283 For i =
0 To UBound(pvElements)
284 If _ResourceURL = pvElements(i).ResourceURL Then
292 REM -----------------------------------------------------------------------------------------------------------------------
293 Private Function _PropertiesList() As Variant
294 _PropertiesList = Array(
"BuiltIn
",
"Name
",
"ObjectType
",
"Visible
")
295 End Function
' _PropertiesList
297 REM -----------------------------------------------------------------------------------------------------------------------
298 Private Function _PropertyGet(ByVal psProperty As String) As Variant
299 ' Return property value of the psProperty property name
301 If _ErrorHandler() Then On Local Error Goto Error_Function
302 Dim cstThisSub As String
303 cstThisSub =
"CommandBar.get
" & psProperty
304 Utils._SetCalledSub(cstThisSub)
305 _PropertyGet = Nothing
307 Dim oLayout As Object, iElementIndex As Integer
309 Select Case UCase(psProperty)
310 Case UCase(
"BuiltIn
")
311 _PropertyGet = ( _BarBuiltin =
1 )
312 Case UCase(
"Name
")
314 Case UCase(
"ObjectType
")
316 Case UCase(
"Visible
")
317 Set oLayout = _Window.LayoutManager
318 iElementIndex = _FindElement(oLayout.getElements())
319 If iElementIndex
< 0 Then _PropertyGet = False Else _PropertyGet = oLayout.isElementVisible(_ResourceURL)
325 Utils._ResetCalledSub(cstThisSub)
328 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
329 _PropertyGet = Nothing
332 TraceError(TRACEABORT, Err, Utils._CalledSub(), Erl)
333 _PropertyGet = Nothing
335 End Function
' _PropertyGet
337 REM -----------------------------------------------------------------------------------------------------------------------
338 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
339 ' Return True if property setting OK
341 If _ErrorHandler() Then On Local Error Goto Error_Function
342 Dim cstThisSub As String
343 cstThisSub =
"CommandBar.set
" & psProperty
344 Utils._SetCalledSub(cstThisSub)
346 Dim iArgNr As Integer
347 Dim oLayout As Object, iElementIndex As Integer
350 Select Case UCase(_A2B_.CalledSub)
351 Case UCase(
"setProperty
") : iArgNr =
3
352 Case UCase(
"CommandBar.setProperty
") : iArgNr =
2
353 Case UCase(cstThisSub) : iArgNr =
1
356 If Not hasProperty(psProperty) Then Goto Trace_Error
358 Select Case UCase(psProperty)
359 Case UCase(
"Visible
")
360 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
361 Set oLayout = _Window.LayoutManager
363 iElementIndex = _FindElement(.getElements())
364 If iElementIndex
< 0 Then
366 .createElement(_ResourceURL)
367 .showElement(_ResourceURL)
370 If pvValue
<> .isElementVisible(_ResourceURL) Then
371 If pvValue Then .showElement(_ResourceURL) Else .hideElement(_ResourceURL)
380 Utils._ResetCalledSub(cstThisSub)
383 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
387 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
391 TraceError(TRACEABORT, Err, cstThisSub, Erl)
394 End Function
' _PropertySet