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=
"OptionGroup" 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 FORM
19 Private _This As Object
' Workaround for absence of This builtin function
20 Private _Parent As Object
21 Private _Name As String
22 Private _ParentType As String
23 Private _ParentComponent As Object
24 Private _MainForm As String
25 Private _DocEntry As Integer
26 Private _DbEntry As Integer
27 Private _ButtonsGroup() As Variant
28 Private _ButtonsIndex() As Variant
29 Private _Count As Long
31 REM -----------------------------------------------------------------------------------------------------------------------
32 REM --- CONSTRUCTORS / DESTRUCTORS ---
33 REM -----------------------------------------------------------------------------------------------------------------------
34 Private Sub Class_Initialize()
35 _Type = OBJOPTIONGROUP
39 _ParentType =
""
40 _ParentComponent = Nothing
43 _ButtonsGroup = Array()
44 _ButtonsIndex = Array()
46 End Sub
' Constructor
48 REM -----------------------------------------------------------------------------------------------------------------------
49 Private Sub Class_Terminate()
50 On Local Error Resume Next
51 Call Class_Initialize()
52 End Sub
' Destructor
54 REM -----------------------------------------------------------------------------------------------------------------------
56 Call Class_Terminate()
57 End Sub
' Explicit destructor
59 REM -----------------------------------------------------------------------------------------------------------------------
60 REM --- CLASS GET/LET/SET PROPERTIES ---
61 REM -----------------------------------------------------------------------------------------------------------------------
62 Property Get Count() As Variant
63 Count = _PropertyGet(
"Count
")
64 End Property
' Count (get)
66 REM -----------------------------------------------------------------------------------------------------------------------
67 Property Get Name() As String
68 Name = _PropertyGet(
"Name
")
69 End Property
' Name (get)
71 Public Function pName() As String
' For compatibility with
< V0.9
.0
72 pName = _PropertyGet(
"Name
")
73 End Function
' pName (get)
75 REM -----------------------------------------------------------------------------------------------------------------------
76 Property Get ObjectType() As String
77 ObjectType = _PropertyGet(
"ObjectType
")
78 End Property
' ObjectType (get)
80 REM -----------------------------------------------------------------------------------------------------------------------
81 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
83 ' a Collection object if pvIndex absent
84 ' a Property object otherwise
86 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
87 vPropertiesList = _PropertiesList()
88 sObject = Utils._PCase(_Type)
89 If IsMissing(pvIndex) Then
90 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList)
92 vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList, pvIndex)
93 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
97 Set Properties = vProperty
99 End Function
' Properties
101 REM -----------------------------------------------------------------------------------------------------------------------
102 Property Get Value() As Variant
103 Value = _PropertyGet(
"Value
")
104 End Property
' Value (get)
106 Property Let Value(ByVal pvValue As Variant)
107 Call _PropertySet(
"Value
", pvValue)
108 End Property
' Value (set)
110 REM -----------------------------------------------------------------------------------------------------------------------
111 REM --- CLASS METHODS ---
112 REM -----------------------------------------------------------------------------------------------------------------------
113 Public Function Controls(Optional ByVal pvIndex As Variant) As Variant
114 ' Return a Control object with name or index = pvIndex
116 If _ErrorHandler() Then On Local Error Goto Error_Function
117 Utils._SetCalledSub(
"OptionGroup.Controls
")
119 Dim ocControl As Variant, iArgNr As Integer, i As Integer
120 Dim oCounter As Object
122 Set ocControl = Nothing
124 If IsMissing(pvIndex) Then
' No argument, return Collection object
125 Set oCounter = New Collect
126 Set oCounter._This = oCounter
127 oCounter._CollType = COLLCONTROLS
128 Set oCounter._Parent = _This
129 oCounter._Count = _Count
130 Set Controls = oCounter
134 If _IsLeft(_A2B_.CalledSub,
"OptionGroup.
") Then iArgNr =
1 Else iArgNr =
2
135 If Not Utils._CheckArgument(pvIndex, iArgNr, Utils._AddNumeric()) Then Goto Exit_Function
136 If pvIndex
< 0 Or pvIndex
> _Count -
1 Then Goto Trace_Error_Index
138 ' Start building the ocControl object
139 ' Determine exact name
140 Set ocControl = New Control
141 Set ocControl._This = ocControl
142 Set ocControl._Parent = _This
143 ocControl._ParentType = CTLPARENTISGROUP
145 ocControl._Shortcut =
""
146 For i =
0 To _Count -
1
147 If _ButtonsIndex(i) = pvIndex Then
148 Set ocControl.ControlModel = _ButtonsGroup(i)
149 Select Case _ParentType
150 Case CTLPARENTISDIALOG : ocControl._Name = _ButtonsGroup(i).Name
151 Case Else : ocControl._Name = _Name
' OptionGroup and individual radio buttons share the same name
153 ocControl._ImplementationName = ocControl.ControlModel.getImplementationName()
157 ocControl._FormComponent = _ParentComponent
158 ocControl._ClassId = acRadioButton
159 Select Case _ParentType
160 Case CTLPARENTISDIALOG : Set ocControl.ControlView = _ParentComponent.getControl(ocControl._Name)
161 Case Else : Set ocControl.ControlView = _ParentComponent.CurrentController.getControl(ocControl.ControlModel)
164 ocControl._Initialize()
165 ocControl._DocEntry = _DocEntry
166 ocControl._DbEntry = _DbEntry
167 Set Controls = ocControl
170 Utils._ResetCalledSub(
"OptionGroup.Controls
")
173 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
174 Set Controls = Nothing
177 TraceError(TRACEABORT, Err,
"OptionGroup.Controls
", Erl)
178 Set Controls = Nothing
180 End Function
' Controls
182 REM -----------------------------------------------------------------------------------------------------------------------
183 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
184 ' Return property value of psProperty property name
186 Utils._SetCalledSub(
"OptionGroup.getProperty
")
187 If IsMissing(pvProperty) Then Call _TraceArguments()
188 getProperty = _PropertyGet(pvProperty)
189 Utils._ResetCalledSub(
"OptionGroup.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 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
204 ' Return True if property setting OK
205 Utils._SetCalledSub(
"OptionGroup.setProperty
")
206 setProperty = _PropertySet(psProperty, pvValue)
207 Utils._ResetCalledSub(
"OptionGroup.setProperty
")
210 REM -----------------------------------------------------------------------------------------------------------------------
211 REM --- PRIVATE FUNCTIONS ---
212 REM -----------------------------------------------------------------------------------------------------------------------
213 REM -----------------------------------------------------------------------------------------------------------------------
214 Private Function _PropertiesList() As Variant
216 _PropertiesList = Array(
"Count
",
"Name
",
"ObjectType
",
"Value
")
218 End Function
' _PropertiesList
220 REM -----------------------------------------------------------------------------------------------------------------------
221 Private Function _PropertyGet(ByVal psProperty As String) As Variant
222 ' Return property value of the psProperty property name
224 If _ErrorHandler() Then On Local Error Goto Error_Function
225 Utils._SetCalledSub(
"OptionGroup.get
" & psProperty)
228 Dim oDatabase As Object, vBookmark As Variant
229 Dim iValue As Integer, i As Integer
231 Select Case UCase(psProperty)
232 Case UCase(
"Count
")
233 _PropertyGet = _Count
234 Case UCase(
"Name
")
236 Case UCase(
"ObjectType
")
238 Case UCase(
"Value
")
240 For i =
0 To _Count -
1 ' Find the selected RadioButton
241 If _ButtonsGroup(i).State =
1 Then
242 iValue = _ButtonsIndex(i)
246 _PropertyGet = iValue
252 Utils._ResetCalledSub(
"OptionGroup.get
" & psProperty)
255 TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
259 TraceError(TRACEFATAL, ERRINDEXVALUE, Utils._CalledSub(),
0,
1, psProperty)
263 TraceError(TRACEABORT, Err,
"OptionGroup._PropertyGet
", Erl)
266 End Function
' _PropertyGet
268 REM -----------------------------------------------------------------------------------------------------------------------
269 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
271 Utils._SetCalledSub(
"OptionGroup.set
" & psProperty)
272 If _ErrorHandler() Then On Local Error Goto Error_Function
276 Dim i As Integer, iRadioIndex As Integer, oModel As Object, iArgNr As Integer
278 If _IsLeft(_A2B_.CalledSub,
"OptionGroup.
") Then iArgNr =
1 Else iArgNr =
2
279 Select Case UCase(psProperty)
280 Case UCase(
"Value
")
281 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
282 If pvValue
< 0 Or pvValue
> _Count -
1 Then Goto Trace_Error_Value
283 For i =
0 To _Count -
1
284 _ButtonsGroup(i).State =
0
285 If _ButtonsIndex(i) = pvValue Then iRadioIndex = i
287 _ButtonsGroup(iRadioIndex).State =
1
288 Set oModel = _ButtonsGroup(iRadioIndex)
289 If Utils._hasUNOProperty(oModel,
"DataField
") Then
290 If Not IsNull(oModel.Datafield) And Not IsEmpty(oModel.Datafield) Then
291 If oModel.Datafield
<> "" And Utils._hasUNOMethod(oModel,
"commit
") Then oModel.commit()
' f.i. checkboxes have no commit method ?? [PASTIM]
299 Utils._ResetCalledSub(
"OptionGroup.set
" & psProperty)
302 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
306 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
310 TraceError(TRACEABORT, Err,
"OptionGroup._PropertySet
", Erl)
313 End Function
' _PropertySet