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">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 FORM
18 Private _Name As String
19 Private _ParentType As String
20 Private _ParentComponent As Object
21 Private _DocEntry As Integer
22 Private _DbEntry As Integer
23 Private _ButtonsGroup() As Variant
24 Private _ButtonsIndex() As Variant
25 Private _Count As Long
27 REM -----------------------------------------------------------------------------------------------------------------------
28 REM --- CONSTRUCTORS / DESTRUCTORS ---
29 REM -----------------------------------------------------------------------------------------------------------------------
30 Private Sub Class_Initialize()
31 _Type = OBJOPTIONGROUP
33 _ParentType =
""
34 _ParentComponent = Nothing
37 _ButtonsGroup = Array()
38 _ButtonsIndex = Array()
40 End Sub
' Constructor
42 REM -----------------------------------------------------------------------------------------------------------------------
43 Private Sub Class_Terminate()
44 On Local Error Resume Next
45 Call Class_Initialize()
46 End Sub
' Destructor
48 REM -----------------------------------------------------------------------------------------------------------------------
50 Call Class_Terminate()
51 End Sub
' Explicit destructor
53 REM -----------------------------------------------------------------------------------------------------------------------
54 REM --- CLASS GET/LET/SET PROPERTIES ---
55 REM -----------------------------------------------------------------------------------------------------------------------
56 Property Get Count() As Variant
57 Count = _PropertyGet(
"Count
")
58 End Property
' Count (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 Value() As Variant
97 Value = _PropertyGet(
"Value
")
98 End Property
' Value (get)
100 Property Let Value(ByVal pvValue As Variant)
101 Call _PropertySet(
"Value
", pvValue)
102 End Property
' Value (set)
104 REM -----------------------------------------------------------------------------------------------------------------------
105 REM --- CLASS METHODS ---
106 REM -----------------------------------------------------------------------------------------------------------------------
107 Public Function Controls(Optional ByVal pvIndex As Variant) As Variant
108 ' Return a Control object with name or index = pvIndex
110 If _ErrorHandler() Then On Local Error Goto Error_Function
111 Utils._SetCalledSub(
"OptionGroup.Controls
")
113 Dim ocControl As Variant, iArgNr As Integer, i As Integer
115 Set ocControl = Nothing
117 If IsMissing(pvIndex) Then
' No argument, return Collection object
118 Set oCounter = New Collect
119 oCounter._SubType = OBJCONTROL
120 oCounter._ParentType = OBJOPTIONGROUP
121 oCounter._ParentName = _Name
122 oCounter._Count = _Count
123 Set Controls = oCounter
127 If _IsLeft(_A2B_.CalledSub,
"OptionGroup.
") Then iArgNr =
1 Else iArgNr =
2
128 If Not Utils._CheckArgument(pvIndex, iArgNr, Utils._AddNumeric()) Then Goto Exit_Function
129 If pvIndex
< 0 Or pvIndex
> _Count -
1 Then Goto Trace_Error_Index
131 ' Start building the ocControl object
132 ' Determine exact name
133 Set ocControl = New Control
134 ocControl._ParentType = CTLPARENTISGROUP
136 ocControl._Shortcut =
""
137 For i =
0 To _Count -
1
138 If _ButtonsIndex(i) = pvIndex Then
139 Set ocControl.ControlModel = _ButtonsGroup(i)
140 Select Case _ParentType
141 Case CTLPARENTISDIALOG : ocControl._Name = _ButtonsGroup(i).Name
142 Case Else : ocControl._Name = _Name
' OptionGroup and individual radio buttons share the same name
144 ocControl._ImplementationName = ocControl.ControlModel.getImplementationName()
148 ocControl._FormComponent = _ParentComponent
149 ocControl._ClassId = acRadioButton
150 Select Case _ParentType
151 Case CTLPARENTISDIALOG : Set ocControl.ControlView = _ParentComponent.getControl(ocControl._Name)
152 Case Else : Set ocControl.ControlView = _ParentComponent.CurrentController.getControl(ocControl.ControlModel)
155 ocControl._Initialize()
156 ocControl._DocEntry = _DocEntry
157 ocControl._DbEntry = _DbEntry
158 Set Controls = ocControl
161 Utils._ResetCalledSub(
"OptionGroup.Controls
")
164 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
165 Set Controls = Nothing
168 TraceError(TRACEABORT, Err,
"OptionGroup.Controls
", Erl)
169 Set Controls = Nothing
171 End Function
' Controls
173 REM -----------------------------------------------------------------------------------------------------------------------
174 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
175 ' Return property value of psProperty property name
177 Utils._SetCalledSub(
"OptionGroup.getProperty
")
178 If IsMissing(pvProperty) Then Call _TraceArguments()
179 getProperty = _PropertyGet(pvProperty)
180 Utils._ResetCalledSub(
"OptionGroup.getProperty
")
182 End Function
' getProperty
184 REM -----------------------------------------------------------------------------------------------------------------------
185 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
186 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
188 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
191 End Function
' hasProperty
193 REM -----------------------------------------------------------------------------------------------------------------------
194 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
195 ' Return True if property setting OK
196 Utils._SetCalledSub(
"OptionGroup.setProperty
")
197 setProperty = _PropertySet(psProperty, pvValue)
198 Utils._ResetCalledSub(
"OptionGroup.setProperty
")
201 REM -----------------------------------------------------------------------------------------------------------------------
202 REM --- PRIVATE FUNCTIONS ---
203 REM -----------------------------------------------------------------------------------------------------------------------
204 REM -----------------------------------------------------------------------------------------------------------------------
205 Private Function _PropertiesList() As Variant
207 _PropertiesList = Array(
"Count
",
"Name
",
"ObjectType
",
"Value
")
209 End Function
' _PropertiesList
211 REM -----------------------------------------------------------------------------------------------------------------------
212 Private Function _PropertyGet(ByVal psProperty As String) As Variant
213 ' Return property value of the psProperty property name
215 If _ErrorHandler() Then On Local Error Goto Error_Function
216 Utils._SetCalledSub(
"OptionGroup.get
" & psProperty)
219 Dim oDatabase As Object, vBookmark As Variant, vEMPTY As Variant
220 Dim iValue As Integer, i As Integer
221 _PropertyGet = vEMPTY
222 Select Case UCase(psProperty)
223 Case UCase(
"Count
")
224 _PropertyGet = _Count
225 Case UCase(
"Name
")
227 Case UCase(
"ObjectType
")
229 Case UCase(
"Value
")
231 For i =
0 To _Count -
1 ' Find the selected RadioButton
232 If _ButtonsGroup(i).State =
1 Then
233 iValue = _ButtonsIndex(i)
237 _PropertyGet = iValue
243 Utils._ResetCalledSub(
"OptionGroup.get
" & psProperty)
246 TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
247 _PropertyGet = vEMPTY
250 TraceError(TRACEFATAL, ERRINDEXVALUE, Utils._CalledSub(),
0,
1, psProperty)
251 _PropertyGet = vEMPTY
254 TraceError(TRACEABORT, Err,
"OptionGroup._PropertyGet
", Erl)
255 _PropertyGet = vEMPTY
257 End Function
' _PropertyGet
259 REM -----------------------------------------------------------------------------------------------------------------------
260 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
262 Utils._SetCalledSub(
"OptionGroup.set
" & psProperty)
263 If _ErrorHandler() Then On Local Error Goto Error_Function
267 Dim i As Integer, iRadioIndex As Integer, oModel As Object, iArgNr As Integer
269 If _IsLeft(_A2B_.CalledSub,
"OptionGroup.
") Then iArgNr =
1 Else iArgNr =
2
270 Select Case UCase(psProperty)
271 Case UCase(
"Value
")
272 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
273 If pvValue
< 0 Or pvValue
> _Count -
1 Then Goto Trace_Error_Value
274 For i =
0 To _Count -
1
275 _ButtonsGroup(i).State =
0
276 If _ButtonsIndex(i) = pvValue Then iRadioIndex = i
278 _ButtonsGroup(iRadioIndex).State =
1
279 Set oModel = _ButtonsGroup(iRadioIndex)
280 If Utils._hasUNOProperty(oModel,
"DataField
") Then
281 If Not IsNull(oModel.Datafield) And Not IsEmpty(oModel.Datafield) Then
282 If oModel.Datafield
<> "" And Utils._hasUNOMethod(oModel,
"commit
") Then oModel.commit()
' f.i. checkboxes have no commit method ?? [PASTIM]
290 Utils._ResetCalledSub(
"OptionGroup.set
" & psProperty)
293 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
297 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
301 TraceError(TRACEABORT, Err,
"OptionGroup._PropertySet
", Erl)
304 End Function
' _PropertySet