OptionGroup.xba 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 =======================================================================================================================
  8. Option Compatible
  9. Option ClassModule
  10. Option Explicit
  11. REM -----------------------------------------------------------------------------------------------------------------------
  12. REM --- CLASS ROOT FIELDS ---
  13. REM -----------------------------------------------------------------------------------------------------------------------
  14. Private _Type As String &apos; Must be FORM
  15. Private _This As Object &apos; Workaround for absence of This builtin function
  16. Private _Parent As Object
  17. Private _Name As String
  18. Private _ParentType As String
  19. Private _ParentComponent As Object
  20. Private _MainForm As String
  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
  26. REM -----------------------------------------------------------------------------------------------------------------------
  27. REM --- CONSTRUCTORS / DESTRUCTORS ---
  28. REM -----------------------------------------------------------------------------------------------------------------------
  29. Private Sub Class_Initialize()
  30. _Type = OBJOPTIONGROUP
  31. Set _This = Nothing
  32. Set _Parent = Nothing
  33. _Name = &quot;&quot;
  34. _ParentType = &quot;&quot;
  35. _ParentComponent = Nothing
  36. _DocEntry = -1
  37. _DbEntry = -1
  38. _ButtonsGroup = Array()
  39. _ButtonsIndex = Array()
  40. _Count = 0
  41. End Sub &apos; Constructor
  42. REM -----------------------------------------------------------------------------------------------------------------------
  43. Private Sub Class_Terminate()
  44. On Local Error Resume Next
  45. Call Class_Initialize()
  46. End Sub &apos; Destructor
  47. REM -----------------------------------------------------------------------------------------------------------------------
  48. Public Sub Dispose()
  49. Call Class_Terminate()
  50. End Sub &apos; Explicit destructor
  51. REM -----------------------------------------------------------------------------------------------------------------------
  52. REM --- CLASS GET/LET/SET PROPERTIES ---
  53. REM -----------------------------------------------------------------------------------------------------------------------
  54. Property Get Count() As Variant
  55. Count = _PropertyGet(&quot;Count&quot;)
  56. End Property &apos; Count (get)
  57. REM -----------------------------------------------------------------------------------------------------------------------
  58. Property Get Name() As String
  59. Name = _PropertyGet(&quot;Name&quot;)
  60. End Property &apos; Name (get)
  61. Public Function pName() As String &apos; For compatibility with &lt; V0.9.0
  62. pName = _PropertyGet(&quot;Name&quot;)
  63. End Function &apos; pName (get)
  64. REM -----------------------------------------------------------------------------------------------------------------------
  65. Property Get ObjectType() As String
  66. ObjectType = _PropertyGet(&quot;ObjectType&quot;)
  67. End Property &apos; ObjectType (get)
  68. REM -----------------------------------------------------------------------------------------------------------------------
  69. Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
  70. &apos; Return
  71. &apos; a Collection object if pvIndex absent
  72. &apos; a Property object otherwise
  73. Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
  74. vPropertiesList = _PropertiesList()
  75. sObject = Utils._PCase(_Type)
  76. If IsMissing(pvIndex) Then
  77. vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList)
  78. Else
  79. vProperty = PropertiesGet._Properties(sObject, _This, vPropertiesList, pvIndex)
  80. vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
  81. End If
  82. Exit_Function:
  83. Set Properties = vProperty
  84. Exit Function
  85. End Function &apos; Properties
  86. REM -----------------------------------------------------------------------------------------------------------------------
  87. Property Get Value() As Variant
  88. Value = _PropertyGet(&quot;Value&quot;)
  89. End Property &apos; Value (get)
  90. Property Let Value(ByVal pvValue As Variant)
  91. Call _PropertySet(&quot;Value&quot;, pvValue)
  92. End Property &apos; Value (set)
  93. REM -----------------------------------------------------------------------------------------------------------------------
  94. REM --- CLASS METHODS ---
  95. REM -----------------------------------------------------------------------------------------------------------------------
  96. Public Function Controls(Optional ByVal pvIndex As Variant) As Variant
  97. &apos; Return a Control object with name or index = pvIndex
  98. If _ErrorHandler() Then On Local Error Goto Error_Function
  99. Utils._SetCalledSub(&quot;OptionGroup.Controls&quot;)
  100. Dim ocControl As Variant, iArgNr As Integer, i As Integer
  101. Dim oCounter As Object
  102. Set ocControl = Nothing
  103. If IsMissing(pvIndex) Then &apos; No argument, return Collection object
  104. Set oCounter = New Collect
  105. Set oCounter._This = oCounter
  106. oCounter._CollType = COLLCONTROLS
  107. Set oCounter._Parent = _This
  108. oCounter._Count = _Count
  109. Set Controls = oCounter
  110. Goto Exit_Function
  111. End If
  112. If _IsLeft(_A2B_.CalledSub, &quot;OptionGroup.&quot;) Then iArgNr = 1 Else iArgNr = 2
  113. If Not Utils._CheckArgument(pvIndex, iArgNr, Utils._AddNumeric()) Then Goto Exit_Function
  114. If pvIndex &lt; 0 Or pvIndex &gt; _Count - 1 Then Goto Trace_Error_Index
  115. &apos; Start building the ocControl object
  116. &apos; Determine exact name
  117. Set ocControl = New Control
  118. Set ocControl._This = ocControl
  119. Set ocControl._Parent = _This
  120. ocControl._ParentType = CTLPARENTISGROUP
  121. ocControl._Shortcut = &quot;&quot;
  122. For i = 0 To _Count - 1
  123. If _ButtonsIndex(i) = pvIndex Then
  124. Set ocControl.ControlModel = _ButtonsGroup(i)
  125. Select Case _ParentType
  126. Case CTLPARENTISDIALOG : ocControl._Name = _ButtonsGroup(i).Name
  127. Case Else : ocControl._Name = _Name &apos; OptionGroup and individual radio buttons share the same name
  128. End Select
  129. ocControl._ImplementationName = ocControl.ControlModel.getImplementationName()
  130. Exit For
  131. End If
  132. Next i
  133. ocControl._FormComponent = _ParentComponent
  134. ocControl._ClassId = acRadioButton
  135. Select Case _ParentType
  136. Case CTLPARENTISDIALOG : Set ocControl.ControlView = _ParentComponent.getControl(ocControl._Name)
  137. Case Else : Set ocControl.ControlView = _ParentComponent.CurrentController.getControl(ocControl.ControlModel)
  138. End Select
  139. ocControl._Initialize()
  140. ocControl._DocEntry = _DocEntry
  141. ocControl._DbEntry = _DbEntry
  142. Set Controls = ocControl
  143. Exit_Function:
  144. Utils._ResetCalledSub(&quot;OptionGroup.Controls&quot;)
  145. Exit Function
  146. Trace_Error_Index:
  147. TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(), 0, 1)
  148. Set Controls = Nothing
  149. Goto Exit_Function
  150. Error_Function:
  151. TraceError(TRACEABORT, Err, &quot;OptionGroup.Controls&quot;, Erl)
  152. Set Controls = Nothing
  153. GoTo Exit_Function
  154. End Function &apos; Controls
  155. REM -----------------------------------------------------------------------------------------------------------------------
  156. Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
  157. &apos; Return property value of psProperty property name
  158. Utils._SetCalledSub(&quot;OptionGroup.getProperty&quot;)
  159. If IsMissing(pvProperty) Then Call _TraceArguments()
  160. getProperty = _PropertyGet(pvProperty)
  161. Utils._ResetCalledSub(&quot;OptionGroup.getProperty&quot;)
  162. End Function &apos; getProperty
  163. REM -----------------------------------------------------------------------------------------------------------------------
  164. Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
  165. &apos; Return True if object has a valid property called pvProperty (case-insensitive comparison !)
  166. If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
  167. Exit Function
  168. End Function &apos; hasProperty
  169. REM -----------------------------------------------------------------------------------------------------------------------
  170. Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
  171. &apos; Return True if property setting OK
  172. Utils._SetCalledSub(&quot;OptionGroup.setProperty&quot;)
  173. setProperty = _PropertySet(psProperty, pvValue)
  174. Utils._ResetCalledSub(&quot;OptionGroup.setProperty&quot;)
  175. End Function
  176. REM -----------------------------------------------------------------------------------------------------------------------
  177. REM --- PRIVATE FUNCTIONS ---
  178. REM -----------------------------------------------------------------------------------------------------------------------
  179. REM -----------------------------------------------------------------------------------------------------------------------
  180. Private Function _PropertiesList() As Variant
  181. _PropertiesList = Array(&quot;Count&quot;, &quot;Name&quot;, &quot;ObjectType&quot;, &quot;Value&quot;)
  182. End Function &apos; _PropertiesList
  183. REM -----------------------------------------------------------------------------------------------------------------------
  184. Private Function _PropertyGet(ByVal psProperty As String) As Variant
  185. &apos; Return property value of the psProperty property name
  186. If _ErrorHandler() Then On Local Error Goto Error_Function
  187. Utils._SetCalledSub(&quot;OptionGroup.get&quot; &amp; psProperty)
  188. &apos;Execute
  189. Dim oDatabase As Object, vBookmark As Variant
  190. Dim iValue As Integer, i As Integer
  191. _PropertyGet = EMPTY
  192. Select Case UCase(psProperty)
  193. Case UCase(&quot;Count&quot;)
  194. _PropertyGet = _Count
  195. Case UCase(&quot;Name&quot;)
  196. _PropertyGet = _Name
  197. Case UCase(&quot;ObjectType&quot;)
  198. _PropertyGet = _Type
  199. Case UCase(&quot;Value&quot;)
  200. iValue = -1
  201. For i = 0 To _Count - 1 &apos; Find the selected RadioButton
  202. If _ButtonsGroup(i).State = 1 Then
  203. iValue = _ButtonsIndex(i)
  204. Exit For
  205. End If
  206. Next i
  207. _PropertyGet = iValue
  208. Case Else
  209. Goto Trace_Error
  210. End Select
  211. Exit_Function:
  212. Utils._ResetCalledSub(&quot;OptionGroup.get&quot; &amp; psProperty)
  213. Exit Function
  214. Trace_Error:
  215. TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(), 0, 1, psProperty)
  216. _PropertyGet = EMPTY
  217. Goto Exit_Function
  218. Trace_Error_Index:
  219. TraceError(TRACEFATAL, ERRINDEXVALUE, Utils._CalledSub(), 0, 1, psProperty)
  220. _PropertyGet = EMPTY
  221. Goto Exit_Function
  222. Error_Function:
  223. TraceError(TRACEABORT, Err, &quot;OptionGroup._PropertyGet&quot;, Erl)
  224. _PropertyGet = EMPTY
  225. GoTo Exit_Function
  226. End Function &apos; _PropertyGet
  227. REM -----------------------------------------------------------------------------------------------------------------------
  228. Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
  229. Utils._SetCalledSub(&quot;OptionGroup.set&quot; &amp; psProperty)
  230. If _ErrorHandler() Then On Local Error Goto Error_Function
  231. _PropertySet = True
  232. &apos;Execute
  233. Dim i As Integer, iRadioIndex As Integer, oModel As Object, iArgNr As Integer
  234. If _IsLeft(_A2B_.CalledSub, &quot;OptionGroup.&quot;) Then iArgNr = 1 Else iArgNr = 2
  235. Select Case UCase(psProperty)
  236. Case UCase(&quot;Value&quot;)
  237. If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
  238. If pvValue &lt; 0 Or pvValue &gt; _Count - 1 Then Goto Trace_Error_Value
  239. For i = 0 To _Count - 1
  240. _ButtonsGroup(i).State = 0
  241. If _ButtonsIndex(i) = pvValue Then iRadioIndex = i
  242. Next i
  243. _ButtonsGroup(iRadioIndex).State = 1
  244. Set oModel = _ButtonsGroup(iRadioIndex)
  245. If Utils._hasUNOProperty(oModel, &quot;DataField&quot;) Then
  246. If Not IsNull(oModel.Datafield) And Not IsEmpty(oModel.Datafield) Then
  247. If oModel.Datafield &lt;&gt; &quot;&quot; And Utils._hasUNOMethod(oModel, &quot;commit&quot;) Then oModel.commit() &apos; f.i. checkboxes have no commit method ?? [PASTIM]
  248. End If
  249. End If
  250. Case Else
  251. Goto Trace_Error
  252. End Select
  253. Exit_Function:
  254. Utils._ResetCalledSub(&quot;OptionGroup.set&quot; &amp; psProperty)
  255. Exit Function
  256. Trace_Error:
  257. TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(), 0, 1, psProperty)
  258. _PropertySet = False
  259. Goto Exit_Function
  260. Trace_Error_Value:
  261. TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(), 0, 1, Array(pvValue, psProperty))
  262. _PropertySet = False
  263. Goto Exit_Function
  264. Error_Function:
  265. TraceError(TRACEABORT, Err, &quot;OptionGroup._PropertySet&quot;, Erl)
  266. _PropertySet = False
  267. GoTo Exit_Function
  268. End Function &apos; _PropertySet
  269. </script:module>