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">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 COMMANDBAR
18 Private _Name As String
19 Private _ResourceURL As String
20 Private _Window As Object
' com.sun.star.frame.XFrame
21 Private _Module As String
22 Private _Toolbar As Object
23 Private _BarBuiltin As Integer
' 1 = builtin,
2 = custom stored in LO/AOO (Base),
3 = custom stored in document (Form)
24 Private _BarType As Integer
' See msoBarTypeXxx constants
26 REM -----------------------------------------------------------------------------------------------------------------------
27 REM --- CONSTRUCTORS / DESTRUCTORS ---
28 REM -----------------------------------------------------------------------------------------------------------------------
29 Private Sub Class_Initialize()
32 _ResourceURL =
""
34 _Module =
""
35 Set _Toolbar = Nothing
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 BuiltIn() As Boolean
57 BuiltIn = _PropertyGet(
"BuiltIn
")
58 End Property
' BuiltIn (get)
60 REM -----------------------------------------------------------------------------------------------------------------------
61 Property Get Name() As String
62 Name = _PropertyGet(
"Name
")
63 End Property
' Name (get)
65 Public Function pName() As String
' For compatibility with
< V0.9
.0
66 pName = _PropertyGet(
"Name
")
67 End Function
' pName (get)
69 REM -----------------------------------------------------------------------------------------------------------------------
70 Property Get ObjectType() As String
71 ObjectType = _PropertyGet(
"ObjectType
")
72 End Property
' ObjectType (get)
74 REM -----------------------------------------------------------------------------------------------------------------------
75 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
77 ' a Collection object if pvIndex absent
78 ' a Property object otherwise
80 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
81 vPropertiesList = _PropertiesList()
82 sObject = Utils._PCase(_Type)
83 If IsMissing(pvIndex) Then
84 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList)
86 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList, pvIndex)
87 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
91 Set Properties = vProperty
93 End Function
' Properties
95 REM -----------------------------------------------------------------------------------------------------------------------
96 Property Get Visible() As Variant
97 Visible = _PropertyGet(
"Visible
")
98 End Property
' Visible (get)
100 Property Let Visible(ByVal pvValue As Variant)
101 Call _PropertySet(
"Visible
", pvValue)
102 End Property
' Visible (set)
104 REM -----------------------------------------------------------------------------------------------------------------------
105 REM --- CLASS METHODS ---
106 REM -----------------------------------------------------------------------------------------------------------------------
108 REM -----------------------------------------------------------------------------------------------------------------------
109 Public Function CommandBarControls(Optional ByVal pvIndex As Variant) As Variant
110 ' Return an object of type CommandBarControl indicated by its index
111 ' Index is different from UNO index: separators do not count
112 ' If no pvIndex argument, return a Collection type
114 If _ErrorHandler() Then On Local Error Goto Error_Function
115 Const cstThisSub =
"CommandBar.CommandBarControls
"
116 Utils._SetCalledSub(cstThisSub)
118 Dim oLayout As Object, vElements() As Variant, iIndexToolbar As Integer, oToolbar As Object
119 Dim i As Integer, iItemsCount As Integer, oSettings As Object, vItem() As Variant, bSeparator As Boolean
120 Dim oObject As Object
122 Set oObject = Nothing
123 If Not IsMissing(pvIndex) Then
124 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric()) Then Goto Exit_Function
125 If pvIndex
< 0 Then Goto Trace_IndexError
129 Case msoBarTypeNormal, msoBarTypeMenuBar
130 Case Else : Goto Error_NotApplicable
' Status bar not supported
133 Set oLayout = _Window.LayoutManager
134 vElements = oLayout.getElements()
135 iIndexToolbar = _FindElement(vElements())
136 If iIndexToolbar
< 0 Then Goto Error_NotApplicable
' Toolbar not visible
137 Set oToolbar = vElements(iIndexToolbar)
140 Set oSettings = oToolbar.getSettings(False)
143 For i =
0 To oSettings.getCount() -
1
144 Set vItem() = oSettings.getByIndex(i)
145 If _GetPropertyValue(vItem,
"Type
",
1)
<> 1 Then
' Type =
1 indicates separator
146 iItemsCount = iItemsCount +
1
147 If Not IsMissing(pvIndex) Then
148 If pvIndex = iItemsCount -
1 Then
149 Set oObject = New CommandBarControl
151 ._ParentCommandBarName = _Name
152 ._ParentCommandBar = oToolbar
153 ._ParentBuiltin = ( _BarBuiltin =
1 )
156 ._Index = iItemsCount
' Indexes start at
1
157 ._BeginGroup = bSeparator
167 If IsNull(oObject) Then
169 Case IsMissing(pvIndex)
170 Set oObject = New Collect
171 oObject._CollType = COLLCOMMANDBARCONTROLS
172 oObject._ParentType = OBJCOMMANDBAR
173 oObject._ParentName = _Name
174 oObject._Count = iItemsCount
175 Case Else
' pvIndex is numeric
176 Goto Trace_IndexError
181 Set CommandBarControls = oObject
182 Set oObject = Nothing
183 Utils._ResetCalledSub(cstThisSub)
186 TraceError(TRACEABORT, Err, cstThisSub, Erl)
189 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0)
192 TraceError(TRACEFATAL, ERRMETHOD, Utils._CalledSub(),
0,
1, cstThisSub)
194 End Function
' CommandBarControls V1,
3,
0
196 REM -----------------------------------------------------------------------------------------------------------------------
197 Public Function Controls(Optional ByVal pvIndex As Variant) As Variant
198 ' Alias for CommandBarControls (VBA)
200 If _ErrorHandler() Then On Local Error Goto Error_Function
201 Const cstThisSub =
"CommandBar.Controls
"
202 Utils._SetCalledSub(cstThisSub)
204 Dim oObject As Object
206 If IsMissing(pvIndex) Then Set oObject = CommandBarControls() Else Set oObject = CommandBarControls(pvIndex)
209 Set Controls = oObject
210 Set oObject = Nothing
211 Utils._ResetCalledSub(cstThisSub)
214 TraceError(TRACEABORT, Err, cstThisSub, Erl)
216 End Function
' Controls V1,
3,
0
218 REM -----------------------------------------------------------------------------------------------------------------------
219 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
220 ' Return property value of psProperty property name
222 Utils._SetCalledSub(
"CommandBar.getProperty
")
223 If IsMissing(pvProperty) Then Call _TraceArguments()
224 getProperty = _PropertyGet(pvProperty)
225 Utils._ResetCalledSub(
"CommandBar.getProperty
")
227 End Function
' getProperty
229 REM -----------------------------------------------------------------------------------------------------------------------
230 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
231 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
233 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
236 End Function
' hasProperty
238 REM -----------------------------------------------------------------------------------------------------------------------
239 Public Function Reset() As Boolean
240 ' Reset a whole command bar to its initial values
242 If _ErrorHandler() Then On Local Error Goto Error_Function
243 Const cstThisSub =
"CommandBar.Reset
"
244 Utils._SetCalledSub(cstThisSub)
250 Utils._ResetCalledSub(cstThisSub)
253 TraceError(TRACEABORT, Err, cstThisSub, Erl)
256 End Function
' Reset V1.3
.0
258 REM -----------------------------------------------------------------------------------------------------------------------
259 REM --- PRIVATE FUNCTIONS ---
260 REM -----------------------------------------------------------------------------------------------------------------------
262 REM -----------------------------------------------------------------------------------------------------------------------
263 Private Function _FindElement(pvElements As Variant) As Integer
264 ' Return -
1 if not found, otherwise return index in elements table of LayoutManager
269 If Not IsArray(pvElements) Then Exit Function
271 For i =
0 To UBound(pvElements)
272 If _ResourceURL = pvElements(i).ResourceURL Then
280 REM -----------------------------------------------------------------------------------------------------------------------
281 Private Function _PropertiesList() As Variant
282 _PropertiesList = Array(
"BuiltIn
",
"Name
",
"ObjectType
",
"Visible
")
283 End Function
' _PropertiesList
285 REM -----------------------------------------------------------------------------------------------------------------------
286 Private Function _PropertyGet(ByVal psProperty As String) As Variant
287 ' Return property value of the psProperty property name
289 If _ErrorHandler() Then On Local Error Goto Error_Function
290 Dim cstThisSub As String
291 cstThisSub =
"CommandBar.get
" & psProperty
292 Utils._SetCalledSub(cstThisSub)
293 _PropertyGet = Nothing
295 Dim oLayout As Object, iElementIndex As Integer
297 Select Case UCase(psProperty)
298 Case UCase(
"BuiltIn
")
299 _PropertyGet = ( _BarBuiltin =
1 )
300 Case UCase(
"Name
")
302 Case UCase(
"ObjectType
")
304 Case UCase(
"Visible
")
305 Set oLayout = _Window.LayoutManager
306 iElementIndex = _FindElement(oLayout.getElements())
307 If iElementIndex
< 0 Then _PropertyGet = False Else _PropertyGet = oLayout.isElementVisible(_ResourceURL)
313 Utils._ResetCalledSub(cstThisSub)
316 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
317 _PropertyGet = Nothing
320 TraceError(TRACEABORT, Err, Utils._CalledSub(), Erl)
321 _PropertyGet = Nothing
323 End Function
' _PropertyGet
325 REM -----------------------------------------------------------------------------------------------------------------------
326 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
327 ' Return True if property setting OK
329 If _ErrorHandler() Then On Local Error Goto Error_Function
330 Dim cstThisSub As String
331 cstThisSub =
"CommandBar.set
" & psProperty
332 Utils._SetCalledSub(cstThisSub)
334 Dim iArgNr As Integer
335 Dim oLayout As Object, iElementIndex As Integer
338 Select Case UCase(_A2B_.CalledSub)
339 Case UCase(
"setProperty
") : iArgNr =
3
340 Case UCase(
"CommandBar.setProperty
") : iArgNr =
2
341 Case UCase(cstThisSub) : iArgNr =
1
344 If Not hasProperty(psProperty) Then Goto Trace_Error
346 Select Case UCase(psProperty)
347 Case UCase(
"Visible
")
348 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
349 Set oLayout = _Window.LayoutManager
351 iElementIndex = _FindElement(.getElements())
352 If iElementIndex
< 0 Then
354 .createElement(_ResourceURL)
355 .showElement(_ResourceURL)
358 If pvValue
<> .isElementVisible(_ResourceURL) Then
359 If pvValue Then .showElement(_ResourceURL) Else .hideElement(_ResourceURL)
368 Utils._ResetCalledSub(cstThisSub)
371 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
375 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
379 TraceError(TRACEABORT, Err, cstThisSub, Erl)
382 End Function
' _PropertySet