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 _MainForm As String
22 Private _DocEntry As Integer
23 Private _DbEntry As Integer
24 Private _ButtonsGroup() As Variant
25 Private _ButtonsIndex() As Variant
26 Private _Count As Long
28 REM -----------------------------------------------------------------------------------------------------------------------
29 REM --- CONSTRUCTORS / DESTRUCTORS ---
30 REM -----------------------------------------------------------------------------------------------------------------------
31 Private Sub Class_Initialize()
32 _Type = OBJOPTIONGROUP
34 _ParentType =
""
35 _ParentComponent = Nothing
38 _ButtonsGroup = Array()
39 _ButtonsIndex = Array()
41 End Sub
' Constructor
43 REM -----------------------------------------------------------------------------------------------------------------------
44 Private Sub Class_Terminate()
45 On Local Error Resume Next
46 Call Class_Initialize()
47 End Sub
' Destructor
49 REM -----------------------------------------------------------------------------------------------------------------------
51 Call Class_Terminate()
52 End Sub
' Explicit destructor
54 REM -----------------------------------------------------------------------------------------------------------------------
55 REM --- CLASS GET/LET/SET PROPERTIES ---
56 REM -----------------------------------------------------------------------------------------------------------------------
57 Property Get Count() As Variant
58 Count = _PropertyGet(
"Count
")
59 End Property
' Count (get)
61 REM -----------------------------------------------------------------------------------------------------------------------
62 Property Get Name() As String
63 Name = _PropertyGet(
"Name
")
64 End Property
' Name (get)
66 Public Function pName() As String
' For compatibility with
< V0.9
.0
67 pName = _PropertyGet(
"Name
")
68 End Function
' pName (get)
70 REM -----------------------------------------------------------------------------------------------------------------------
71 Property Get ObjectType() As String
72 ObjectType = _PropertyGet(
"ObjectType
")
73 End Property
' ObjectType (get)
75 REM -----------------------------------------------------------------------------------------------------------------------
76 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
78 ' a Collection object if pvIndex absent
79 ' a Property object otherwise
81 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
82 vPropertiesList = _PropertiesList()
83 sObject = Utils._PCase(_Type)
84 If IsMissing(pvIndex) Then
85 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList)
87 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList, pvIndex)
88 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
92 Set Properties = vProperty
94 End Function
' Properties
96 REM -----------------------------------------------------------------------------------------------------------------------
97 Property Get Value() As Variant
98 Value = _PropertyGet(
"Value
")
99 End Property
' Value (get)
101 Property Let Value(ByVal pvValue As Variant)
102 Call _PropertySet(
"Value
", pvValue)
103 End Property
' Value (set)
105 REM -----------------------------------------------------------------------------------------------------------------------
106 REM --- CLASS METHODS ---
107 REM -----------------------------------------------------------------------------------------------------------------------
108 Public Function Controls(Optional ByVal pvIndex As Variant) As Variant
109 ' Return a Control object with name or index = pvIndex
111 If _ErrorHandler() Then On Local Error Goto Error_Function
112 Utils._SetCalledSub(
"OptionGroup.Controls
")
114 Dim ocControl As Variant, iArgNr As Integer, i As Integer
116 Set ocControl = Nothing
118 If IsMissing(pvIndex) Then
' No argument, return Collection object
119 Set oCounter = New Collect
120 oCounter._SubType = OBJCONTROL
121 oCounter._ParentType = OBJOPTIONGROUP
122 oCounter._ParentName = _Name
123 oCounter._Count = _Count
124 Set Controls = oCounter
128 If _IsLeft(_A2B_.CalledSub,
"OptionGroup.
") Then iArgNr =
1 Else iArgNr =
2
129 If Not Utils._CheckArgument(pvIndex, iArgNr, Utils._AddNumeric()) Then Goto Exit_Function
130 If pvIndex
< 0 Or pvIndex
> _Count -
1 Then Goto Trace_Error_Index
132 ' Start building the ocControl object
133 ' Determine exact name
134 Set ocControl = New Control
135 ocControl._ParentType = CTLPARENTISGROUP
137 ocControl._Shortcut =
""
138 For i =
0 To _Count -
1
139 If _ButtonsIndex(i) = pvIndex Then
140 Set ocControl.ControlModel = _ButtonsGroup(i)
141 Select Case _ParentType
142 Case CTLPARENTISDIALOG : ocControl._Name = _ButtonsGroup(i).Name
143 Case Else : ocControl._Name = _Name
' OptionGroup and individual radio buttons share the same name
145 ocControl._ImplementationName = ocControl.ControlModel.getImplementationName()
149 ocControl._FormComponent = _ParentComponent
150 ocControl._ClassId = acRadioButton
151 Select Case _ParentType
152 Case CTLPARENTISDIALOG : Set ocControl.ControlView = _ParentComponent.getControl(ocControl._Name)
153 Case Else : Set ocControl.ControlView = _ParentComponent.CurrentController.getControl(ocControl.ControlModel)
156 ocControl._Initialize()
157 ocControl._DocEntry = _DocEntry
158 ocControl._DbEntry = _DbEntry
159 Set Controls = ocControl
162 Utils._ResetCalledSub(
"OptionGroup.Controls
")
165 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
166 Set Controls = Nothing
169 TraceError(TRACEABORT, Err,
"OptionGroup.Controls
", Erl)
170 Set Controls = Nothing
172 End Function
' Controls
174 REM -----------------------------------------------------------------------------------------------------------------------
175 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
176 ' Return property value of psProperty property name
178 Utils._SetCalledSub(
"OptionGroup.getProperty
")
179 If IsMissing(pvProperty) Then Call _TraceArguments()
180 getProperty = _PropertyGet(pvProperty)
181 Utils._ResetCalledSub(
"OptionGroup.getProperty
")
183 End Function
' getProperty
185 REM -----------------------------------------------------------------------------------------------------------------------
186 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
187 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
189 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
192 End Function
' hasProperty
194 REM -----------------------------------------------------------------------------------------------------------------------
195 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
196 ' Return True if property setting OK
197 Utils._SetCalledSub(
"OptionGroup.setProperty
")
198 setProperty = _PropertySet(psProperty, pvValue)
199 Utils._ResetCalledSub(
"OptionGroup.setProperty
")
202 REM -----------------------------------------------------------------------------------------------------------------------
203 REM --- PRIVATE FUNCTIONS ---
204 REM -----------------------------------------------------------------------------------------------------------------------
205 REM -----------------------------------------------------------------------------------------------------------------------
206 Private Function _PropertiesList() As Variant
208 _PropertiesList = Array(
"Count
",
"Name
",
"ObjectType
",
"Value
")
210 End Function
' _PropertiesList
212 REM -----------------------------------------------------------------------------------------------------------------------
213 Private Function _PropertyGet(ByVal psProperty As String) As Variant
214 ' Return property value of the psProperty property name
216 If _ErrorHandler() Then On Local Error Goto Error_Function
217 Utils._SetCalledSub(
"OptionGroup.get
" & psProperty)
220 Dim oDatabase As Object, vBookmark As Variant
221 Dim iValue As Integer, i As Integer
223 Select Case UCase(psProperty)
224 Case UCase(
"Count
")
225 _PropertyGet = _Count
226 Case UCase(
"Name
")
228 Case UCase(
"ObjectType
")
230 Case UCase(
"Value
")
232 For i =
0 To _Count -
1 ' Find the selected RadioButton
233 If _ButtonsGroup(i).State =
1 Then
234 iValue = _ButtonsIndex(i)
238 _PropertyGet = iValue
244 Utils._ResetCalledSub(
"OptionGroup.get
" & psProperty)
247 TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
251 TraceError(TRACEFATAL, ERRINDEXVALUE, Utils._CalledSub(),
0,
1, psProperty)
255 TraceError(TRACEABORT, Err,
"OptionGroup._PropertyGet
", Erl)
258 End Function
' _PropertyGet
260 REM -----------------------------------------------------------------------------------------------------------------------
261 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
263 Utils._SetCalledSub(
"OptionGroup.set
" & psProperty)
264 If _ErrorHandler() Then On Local Error Goto Error_Function
268 Dim i As Integer, iRadioIndex As Integer, oModel As Object, iArgNr As Integer
270 If _IsLeft(_A2B_.CalledSub,
"OptionGroup.
") Then iArgNr =
1 Else iArgNr =
2
271 Select Case UCase(psProperty)
272 Case UCase(
"Value
")
273 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
274 If pvValue
< 0 Or pvValue
> _Count -
1 Then Goto Trace_Error_Value
275 For i =
0 To _Count -
1
276 _ButtonsGroup(i).State =
0
277 If _ButtonsIndex(i) = pvValue Then iRadioIndex = i
279 _ButtonsGroup(iRadioIndex).State =
1
280 Set oModel = _ButtonsGroup(iRadioIndex)
281 If Utils._hasUNOProperty(oModel,
"DataField
") Then
282 If Not IsNull(oModel.Datafield) And Not IsEmpty(oModel.Datafield) Then
283 If oModel.Datafield
<> "" And Utils._hasUNOMethod(oModel,
"commit
") Then oModel.commit()
' f.i. checkboxes have no commit method ?? [PASTIM]
291 Utils._ResetCalledSub(
"OptionGroup.set
" & psProperty)
294 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
298 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
302 TraceError(TRACEABORT, Err,
"OptionGroup._PropertySet
", Erl)
305 End Function
' _PropertySet