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">
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 COMMANDBARCONTROL
19 Private _This As Object
' Workaround for absence of This builtin function
20 Private _Parent As Object
21 Private _InternalIndex As Integer
' Index in toolbar including separators
22 Private _Index As Integer
' Index in collection, starting at
1 !!
23 Private _ControlType As Integer
' 1 of the msoControl* constants
24 Private _ParentCommandBarName As String
25 Private _ParentCommandBar As Object
' com.sun.star.ui.XUIElement
26 Private _ParentBuiltin As Boolean
27 Private _Element As Variant
28 Private _BeginGroup As Boolean
30 REM -----------------------------------------------------------------------------------------------------------------------
31 REM --- CONSTRUCTORS / DESTRUCTORS ---
32 REM -----------------------------------------------------------------------------------------------------------------------
33 Private Sub Class_Initialize()
34 _Type = OBJCOMMANDBARCONTROL
38 _ParentCommandBarName =
""
39 Set _ParentCommandBar = Nothing
40 _ParentBuiltin = False
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 BeginGroup() As Boolean
62 BeginGroup = _PropertyGet(
"BeginGroup
")
63 End Property
' BeginGroup (get)
65 REM -----------------------------------------------------------------------------------------------------------------------
66 Property Get BuiltIn() As Boolean
67 BuiltIn = _PropertyGet(
"BuiltIn
")
68 End Property
' BuiltIn (get)
70 REM -----------------------------------------------------------------------------------------------------------------------
71 Property Get Caption() As Variant
72 Caption = _PropertyGet(
"Caption
")
73 End Property
' Caption (get)
75 Property Let Caption(ByVal pvValue As Variant)
76 Call _PropertySet(
"Caption
", pvValue)
77 End Property
' Caption (set)
79 REM -----------------------------------------------------------------------------------------------------------------------
80 Property Get Index() As Integer
81 Index = _PropertyGet(
"Index
")
82 End Property
' Index (get)
84 REM -----------------------------------------------------------------------------------------------------------------------
85 Property Get ObjectType() As String
86 ObjectType = _PropertyGet(
"ObjectType
")
87 End Property
' ObjectType (get)
89 REM -----------------------------------------------------------------------------------------------------------------------
90 Property Get OnAction() As Variant
91 OnAction = _PropertyGet(
"OnAction
")
92 End Property
' OnAction (get)
94 Property Let OnAction(ByVal pvValue As Variant)
95 Call _PropertySet(
"OnAction
", pvValue)
96 End Property
' OnAction (set)
98 REM -----------------------------------------------------------------------------------------------------------------------
99 Property Get Parent() As Object
100 Parent = _PropertyGet(
"Parent
")
101 End Property
' Parent (get)
103 REM -----------------------------------------------------------------------------------------------------------------------
104 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
106 ' a Collection object if pvIndex absent
107 ' a Property object otherwise
109 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
110 vPropertiesList = _PropertiesList()
111 sObject = Utils._PCase(_Type)
112 If IsMissing(pvIndex) Then
113 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList)
115 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList, pvIndex)
116 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
120 Set Properties = vProperty
122 End Function
' Properties
124 REM -----------------------------------------------------------------------------------------------------------------------
125 Property Get TooltipText() As Variant
126 TooltipText = _PropertyGet(
"TooltipText
")
127 End Property
' TooltipText (get)
129 Property Let TooltipText(ByVal pvValue As Variant)
130 Call _PropertySet(
"TooltipText
", pvValue)
131 End Property
' TooltipText (set)
133 REM -----------------------------------------------------------------------------------------------------------------------
134 Public Function pType() As Integer
135 pType = _PropertyGet(
"Type
")
136 End Function
' Type (get)
138 REM -----------------------------------------------------------------------------------------------------------------------
139 Property Get Visible() As Variant
140 Visible = _PropertyGet(
"Visible
")
141 End Property
' Visible (get)
143 Property Let Visible(ByVal pvValue As Variant)
144 Call _PropertySet(
"Visible
", pvValue)
145 End Property
' Visible (set)
147 REM -----------------------------------------------------------------------------------------------------------------------
148 REM --- CLASS METHODS ---
149 REM -----------------------------------------------------------------------------------------------------------------------
151 REM -----------------------------------------------------------------------------------------------------------------------
152 Public Function Execute()
153 ' Execute the command stored in a toolbar button
155 If _ErrorHandler() Then On Local Error Goto Error_Function
156 Const cstThisSub =
"CommandBarControl.Execute
"
157 Utils._SetCalledSub(cstThisSub)
159 Dim sExecute As String
162 sExecute = _GetPropertyValue(_Element,
"CommandURL
",
"")
165 Case sExecute =
"" : Execute = False
166 Case _IsLeft(sExecute,
".uno:
")
167 Execute = DoCmd.RunCommand(sExecute)
168 Case _IsLeft(sExecute,
"vnd.sun.star.script:
")
169 Execute = Utils._RunScript(sExecute, Array(Nothing))
174 Utils._ResetCalledSub(cstThisSub)
177 TraceError(TRACEABORT, Err, cstThisSub, Erl)
180 End Function
' Execute V1.3
.0
182 REM -----------------------------------------------------------------------------------------------------------------------
183 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
184 ' Return property value of psProperty property name
186 Utils._SetCalledSub(
"CommandBarControl.getProperty
")
187 If IsMissing(pvProperty) Then Call _TraceArguments()
188 getProperty = _PropertyGet(pvProperty)
189 Utils._ResetCalledSub(
"CommandBar.getProperty
")
191 End Function
' getProperty
193 REM -----------------------------------------------------------------------------------------------------------------------
194 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
195 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
197 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
200 End Function
' hasProperty
202 REM -----------------------------------------------------------------------------------------------------------------------
203 REM --- PRIVATE FUNCTIONS ---
204 REM -----------------------------------------------------------------------------------------------------------------------
206 REM -----------------------------------------------------------------------------------------------------------------------
207 Private Function _PropertiesList() As Variant
208 _PropertiesList = Array(
"BeginGroup
",
"BuiltIn
",
"Caption
",
"Index
" _
209 ,
"ObjectType
",
"OnAction
",
"Parent
" _
210 ,
"TooltipText
",
"Type
",
"Visible
" _
212 End Function
' _PropertiesList
214 REM -----------------------------------------------------------------------------------------------------------------------
215 Private Function _PropertyGet(ByVal psProperty As String) As Variant
216 ' Return property value of the psProperty property name
218 If _ErrorHandler() Then On Local Error Goto Error_Function
219 Dim cstThisSub As String
220 cstThisSub =
"CommandBarControl.get
" & psProperty
221 Utils._SetCalledSub(cstThisSub)
224 Dim oLayout As Object, iElementIndex As Integer
226 Const cstUnoPrefix =
".uno:
"
228 Select Case UCase(psProperty)
229 Case UCase(
"BeginGroup
")
230 _PropertyGet = _BeginGroup
231 Case UCase(
"BuiltIn
")
232 sValue = _GetPropertyValue(_Element,
"CommandURL
",
"")
233 _PropertyGet = ( _IsLeft(sValue, cstUnoPrefix) )
234 Case UCase(
"Caption
")
235 _PropertyGet = _GetPropertyValue(_Element,
"Label
",
"")
236 Case UCase(
"Index
")
237 _PropertyGet = _Index
238 Case UCase(
"ObjectType
")
240 Case UCase(
"OnAction
")
241 _PropertyGet = _GetPropertyValue(_Element,
"CommandURL
",
"")
242 Case UCase(
"Parent
")
243 Set _PropertyGet = _Parent
244 Case UCase(
"TooltipText
")
245 sValue = _GetPropertyValue(_Element,
"Tooltip
",
"")
246 If sValue
<> "" Then _PropertyGet = sValue Else _PropertyGet = _GetPropertyValue(_Element,
"Label
",
"")
247 Case UCase(
"Type
")
248 _PropertyGet = msoControlButton
249 Case UCase(
"Visible
")
250 _PropertyGet = _GetPropertyValue(_Element,
"IsVisible
",
"")
256 Utils._ResetCalledSub(cstThisSub)
259 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
260 _PropertyGet = Nothing
263 TraceError(TRACEABORT, Err, Utils._CalledSub(), Erl)
264 _PropertyGet = Nothing
266 End Function
' _PropertyGet
268 REM -----------------------------------------------------------------------------------------------------------------------
269 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
270 ' Return True if property setting OK
272 If _ErrorHandler() Then On Local Error Goto Error_Function
273 Dim cstThisSub As String
274 cstThisSub =
"CommandBarControl.set
" & psProperty
275 Utils._SetCalledSub(cstThisSub)
277 Dim iArgNr As Integer
278 Dim oSettings As Object, sValue As String
281 Select Case UCase(_A2B_.CalledSub)
282 Case UCase(
"setProperty
") : iArgNr =
3
283 Case UCase(
"CommandBar.setProperty
") : iArgNr =
2
284 Case UCase(cstThisSub) : iArgNr =
1
287 If Not hasProperty(psProperty) Then Goto Trace_Error
288 If _ParentBuiltin Then Goto Trace_Error
' Modifications of individual controls forbidden for builtin toolbars (design choice)
290 Const cstUnoPrefix =
".uno:
"
291 Const cstScript =
"vnd.sun.star.script:
"
293 Set oSettings = _ParentCommandBar.getSettings(True)
294 Select Case UCase(psProperty)
295 Case UCase(
"OnAction
")
296 If Not Utils._CheckArgument(pvValue, iArgNr, _AddNumeric(vbString), , False) Then Goto Trace_Error_Value
297 Select Case VarType(pvValue)
299 If _IsLeft(pvValue, cstUnoPrefix) Then
301 ElseIf _IsLeft(pvValue, cstScript) Then
304 sValue = DoCmd.RunCommand(pvValue, True)
306 Case Else
' Numeric
307 sValue = DoCmd.RunCommand(pvValue, True)
309 _SetPropertyValue(_Element,
"CommandURL
", sValue)
310 Case UCase(
"TooltipText
")
311 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
312 _SetPropertyValue(_Element,
"Tooltip
", pvValue)
313 Case UCase(
"Visible
")
314 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
315 _SetPropertyValue(_Element,
"IsVisible
", pvValue)
319 oSettings.replaceByIndex(_InternalIndex, _Element)
320 _ParentCommandBar.setSettings(oSettings)
323 Utils._ResetCalledSub(cstThisSub)
326 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0, , psProperty)
330 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
334 TraceError(TRACEABORT, Err, cstThisSub, Erl)
337 End Function
' _PropertySet