SF_Dialog.xba 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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="SF_Dialog" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
  4. REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
  5. REM === The SFDialogs library is one of the associated libraries. ===
  6. REM === Full documentation is available on https://help.libreoffice.org/ ===
  7. REM =======================================================================================================================
  8. Option Compatible
  9. Option ClassModule
  10. Option Explicit
  11. &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
  12. &apos;&apos;&apos; SF_Dialog
  13. &apos;&apos;&apos; =========
  14. &apos;&apos;&apos; Management of dialogs defined with the Basic IDE
  15. &apos;&apos;&apos; Each instance of the current class represents a single dialog box displayed to the user
  16. &apos;&apos;&apos;
  17. &apos;&apos;&apos; A dialog box can be displayed in modal or in non-modal modes
  18. &apos;&apos;&apos; In modal mode, the box is displayed and the execution of the macro process is suspended
  19. &apos;&apos;&apos; until one of the OK or Cancel buttons is pressed. In the meantime, other user actions
  20. &apos;&apos;&apos; executed on the box can trigger specific actions.
  21. &apos;&apos;&apos; In non-modal mode, the dialog box is &quot;floating&quot; on the user desktop and the execution
  22. &apos;&apos;&apos; of the macro process continues normally
  23. &apos;&apos;&apos; A dialog box disappears from memory after its explicit termination.
  24. &apos;&apos;&apos;
  25. &apos;&apos;&apos; Service invocation and usage:
  26. &apos;&apos;&apos; Dim myDialog As Object, lButton As Long
  27. &apos;&apos;&apos; Set myDialog = CreateScriptService(&quot;SFDialogs.Dialog&quot;, Container, Library, DialogName)
  28. &apos;&apos;&apos; &apos; Args:
  29. &apos;&apos;&apos; &apos; Container: &quot;GlobalScope&quot; for preinstalled libraries
  30. &apos;&apos;&apos; &apos; A window name (see its definition in the ScriptForge.UI service)
  31. &apos;&apos;&apos; &apos; &quot;&quot; (default) = the current document
  32. &apos;&apos;&apos; &apos; Library: The (case-sensitive) name of a library contained in the container
  33. &apos;&apos;&apos; &apos; Default = &quot;Standard&quot;
  34. &apos;&apos;&apos; &apos; DialogName: a case-sensitive string designating the dialog where it is about
  35. &apos;&apos;&apos; &apos; ... Initialize controls ...
  36. &apos;&apos;&apos; lButton = myDialog.Execute() &apos; Default mode = Modal
  37. &apos;&apos;&apos; If lButton = myDialog.OKBUTTON Then
  38. &apos;&apos;&apos; &apos; ... Process controls and do what is needed
  39. &apos;&apos;&apos; End If
  40. &apos;&apos;&apos; myDialog.Terminate()
  41. &apos;&apos;&apos;
  42. &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
  43. REM ================================================================== EXCEPTIONS
  44. Private Const DIALOGDEADERROR = &quot;DIALOGDEADERROR&quot;
  45. REM ============================================================= PRIVATE MEMBERS
  46. Private [Me] As Object
  47. Private [_Parent] As Object
  48. Private ObjectType As String &apos; Must be DIALOG
  49. Private ServiceName As String
  50. &apos; Dialog location
  51. Private _Container As String
  52. Private _Library As String
  53. Private _Name As String
  54. Private _CacheIndex As Long &apos; Index in cache storage
  55. &apos; Dialog UNO references
  56. Private _DialogProvider As Object &apos; com.sun.star.io.XInputStreamProvider
  57. Private _DialogControl As Object &apos; com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
  58. Private _DialogModel As Object &apos; com.sun.star.awt.XControlModel - stardiv.Toolkit.UnoControlDialogModel
  59. &apos; Dialog attributes
  60. Private _Displayed As Boolean &apos; True after Execute()
  61. Private _Modal As Boolean &apos; Set by Execute()
  62. REM ============================================================ MODULE CONSTANTS
  63. Private Const OKBUTTON = 1
  64. Private Const CANCELBUTTON = 0
  65. REM ===================================================== CONSTRUCTOR/DESTRUCTOR
  66. REM -----------------------------------------------------------------------------
  67. Private Sub Class_Initialize()
  68. Set [Me] = Nothing
  69. Set [_Parent] = Nothing
  70. ObjectType = &quot;DIALOG&quot;
  71. ServiceName = &quot;SFDialogs.Dialog&quot;
  72. _Container = &quot;&quot;
  73. _Library = &quot;&quot;
  74. _Name = &quot;&quot;
  75. _CacheIndex = -1
  76. Set _DialogProvider = Nothing
  77. Set _DialogControl = Nothing
  78. Set _DialogModel = Nothing
  79. _Displayed = False
  80. _Modal = True
  81. End Sub &apos; SFDialogs.SF_Dialog Constructor
  82. REM -----------------------------------------------------------------------------
  83. Private Sub Class_Terminate()
  84. Call Class_Initialize()
  85. End Sub &apos; SFDialogs.SF_Dialog Destructor
  86. REM -----------------------------------------------------------------------------
  87. Public Function Dispose() As Variant
  88. If _CacheIndex &gt;= 0 Then Terminate()
  89. Call Class_Terminate()
  90. Set Dispose = Nothing
  91. End Function &apos; SFDialogs.SF_Dialog Explicit Destructor
  92. REM ================================================================== PROPERTIES
  93. REM -----------------------------------------------------------------------------
  94. Property Get Caption() As Variant
  95. &apos;&apos;&apos; The Caption property refers to the title of the dialog
  96. Caption = _PropertyGet(&quot;Caption&quot;)
  97. End Property &apos; SFDialogs.SF_Dialog.Caption (get)
  98. REM -----------------------------------------------------------------------------
  99. Property Let Caption(Optional ByVal pvCaption As Variant)
  100. &apos;&apos;&apos; Set the updatable property Caption
  101. _PropertySet(&quot;Caption&quot;, pvCaption)
  102. End Property &apos; SFDialogs.SF_Dialog.Caption (let)
  103. REM -----------------------------------------------------------------------------
  104. Property Get Height() As Variant
  105. &apos;&apos;&apos; The Height property refers to the height of the dialog box
  106. Height = _PropertyGet(&quot;Height&quot;)
  107. End Property &apos; SFDialogs.SF_Dialog.Height (get)
  108. REM -----------------------------------------------------------------------------
  109. Property Let Height(Optional ByVal pvHeight As Variant)
  110. &apos;&apos;&apos; Set the updatable property Height
  111. _PropertySet(&quot;Height&quot;, pvHeight)
  112. End Property &apos; SFDialogs.SF_Dialog.Height (let)
  113. REM -----------------------------------------------------------------------------
  114. Property Get Modal() As Boolean
  115. &apos;&apos;&apos; The Modal property specifies if the dialog box has been executed in modal mode
  116. Modal = _PropertyGet(&quot;Modal&quot;)
  117. End Property &apos; SFDialogs.SF_Dialog.Modal (get)
  118. REM -----------------------------------------------------------------------------
  119. Property Get Name() As String
  120. &apos;&apos;&apos; Return the name of the actual dialog
  121. Name = _PropertyGet(&quot;Name&quot;)
  122. End Property &apos; SFDialogs.SF_Dialog.Name
  123. REM -----------------------------------------------------------------------------
  124. Property Get Page() As Variant
  125. &apos;&apos;&apos; A dialog may have several pages that can be traversed by the user step by step. The Page property of the Dialog object defines which page of the dialog is active.
  126. &apos;&apos;&apos; The Page property of a control defines the page of the dialog on which the control is visible.
  127. &apos;&apos;&apos; For example, if a control has a page value of 1, it is only visible on page 1 of the dialog.
  128. &apos;&apos;&apos; If the page value of the dialog is increased from 1 to 2, then all controls with a page value of 1 disappear and all controls with a page value of 2 become visible.
  129. Page = _PropertyGet(&quot;Page&quot;)
  130. End Property &apos; SFDialogs.SF_Dialog.Page (get)
  131. REM -----------------------------------------------------------------------------
  132. Property Let Page(Optional ByVal pvPage As Variant)
  133. &apos;&apos;&apos; Set the updatable property Page
  134. _PropertySet(&quot;Page&quot;, pvPage)
  135. End Property &apos; SFDialogs.SF_Dialog.Page (let)
  136. REM -----------------------------------------------------------------------------
  137. Property Get Visible() As Variant
  138. &apos;&apos;&apos; The Visible property is False before the Execute() statement
  139. Visible = _PropertyGet(&quot;Visible&quot;)
  140. End Property &apos; SFDialogs.SF_Dialog.Visible (get)
  141. REM -----------------------------------------------------------------------------
  142. Property Let Visible(Optional ByVal pvVisible As Variant)
  143. &apos;&apos;&apos; Set the updatable property Visible
  144. _PropertySet(&quot;Visible&quot;, pvVisible)
  145. End Property &apos; SFDialogs.SF_Dialog.Visible (let)
  146. REM -----------------------------------------------------------------------------
  147. Property Get Width() As Variant
  148. &apos;&apos;&apos; The Width property refers to the Width of the dialog box
  149. Width = _PropertyGet(&quot;Width&quot;)
  150. End Property &apos; SFDialogs.SF_Dialog.Width (get)
  151. REM -----------------------------------------------------------------------------
  152. Property Let Width(Optional ByVal pvWidth As Variant)
  153. &apos;&apos;&apos; Set the updatable property Width
  154. _PropertySet(&quot;Width&quot;, pvWidth)
  155. End Property &apos; SFDialogs.SF_Dialog.Width (let)
  156. REM -----------------------------------------------------------------------------
  157. Property Get XDialogModel() As Object
  158. &apos;&apos;&apos; The XDialogModel property returns the model UNO object of the dialog
  159. XDialogModel = _PropertyGet(&quot;XDialogModel&quot;)
  160. End Property &apos; SFDialogs.SF_Dialog.XDialogModel (get)
  161. REM -----------------------------------------------------------------------------
  162. Property Get XDialogView() As Object
  163. &apos;&apos;&apos; The XDialogView property returns the view UNO object of the dialog
  164. XDialogView = _PropertyGet(&quot;XDialogView&quot;)
  165. End Property &apos; SFDialogs.SF_Dialog.XDialogView (get)
  166. REM ===================================================================== METHODS
  167. REM -----------------------------------------------------------------------------
  168. Public Function Activate() As Boolean
  169. &apos;&apos;&apos; Set the focus on the current dialog instance
  170. &apos;&apos;&apos; Probably called from after an event occurrence or to focus on a non-modal dialog
  171. &apos;&apos;&apos; Args:
  172. &apos;&apos;&apos; Returns:
  173. &apos;&apos;&apos; True if focusing is successful
  174. &apos;&apos;&apos; Example:
  175. &apos;&apos;&apos; Dim oDlg As Object
  176. &apos;&apos;&apos; Set oDlg = CreateScriptService(,, &quot;myDialog&quot;) &apos; Dialog stored in current document&apos;s standard library
  177. &apos;&apos;&apos; oDlg.Activate()
  178. Dim bActivate As Boolean &apos; Return value
  179. Const cstThisSub = &quot;SFDialogs.Dialog.Activate&quot;
  180. Const cstSubArgs = &quot;&quot;
  181. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  182. bActivate = False
  183. Check:
  184. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  185. If Not _IsStillAlive() Then GoTo Finally
  186. End If
  187. Try:
  188. If Not IsNull(_DialogControl) Then
  189. _DialogControl.setFocus()
  190. bActivate = True
  191. End If
  192. Finally:
  193. Activate = bActivate
  194. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  195. Exit Function
  196. Catch:
  197. GoTo Finally
  198. End Function &apos; SFDialogs.SF_Dialog.Activate
  199. REM -----------------------------------------------------------------------------
  200. Public Function Controls(Optional ByVal ControlName As Variant) As Variant
  201. &apos;&apos;&apos; Return either
  202. &apos;&apos;&apos; - the list of the controls contained in the dialog
  203. &apos;&apos;&apos; - a dialog control object based on its name
  204. &apos;&apos;&apos; Args:
  205. &apos;&apos;&apos; ControlName: a valid control name as a case-sensitive string. If absent the list is returned
  206. &apos;&apos;&apos; Returns:
  207. &apos;&apos;&apos; A zero-base array of strings if ControlName is absent
  208. &apos;&apos;&apos; An instance of the SF_DialogControl class if ControlName exists
  209. &apos;&apos;&apos; Exceptions:
  210. &apos;&apos;&apos; ControlName is invalid
  211. &apos;&apos;&apos; Example:
  212. &apos;&apos;&apos; Dim myDialog As Object, myList As Variant, myControl As Object
  213. &apos;&apos;&apos; Set myDialog = CreateScriptService(&quot;SFDialogs.Dialog&quot;, Container, Library, DialogName)
  214. &apos;&apos;&apos; myList = myDialog.Controls()
  215. &apos;&apos;&apos; Set myControl = myDialog.Controls(&quot;myTextBox&quot;)
  216. Dim oControl As Object &apos; The new control class instance
  217. Const cstThisSub = &quot;SFDialogs.Dialog.Controls&quot;
  218. Const cstSubArgs = &quot;[ControlName]&quot;
  219. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  220. Check:
  221. If IsMissing(ControlName) Or IsEmpty(ControlName) Then ControlName = &quot;&quot;
  222. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  223. If Not _IsStillAlive() Then GoTo Finally
  224. If Not ScriptForge.SF_Utils._Validate(ControlName, &quot;ControlName&quot;, V_STRING) Then GoTo Finally
  225. End If
  226. Try:
  227. If Len(ControlName) = 0 Then
  228. Controls = _DialogModel.getElementNames()
  229. Else
  230. If Not _DialogModel.hasByName(ControlName) Then GoTo CatchNotFound
  231. &apos; Create the new dialog control class instance
  232. Set oControl = New SF_DialogControl
  233. With oControl
  234. ._Name = ControlName
  235. Set .[Me] = oControl
  236. Set .[_Parent] = [Me]
  237. ._DialogName = _Name
  238. Set ._ControlModel = _DialogModel.getByName(ControlName)
  239. Set ._ControlView = _DialogControl.getControl(ControlName)
  240. ._Initialize()
  241. End With
  242. Set Controls = oControl
  243. End If
  244. Finally:
  245. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  246. Exit Function
  247. Catch:
  248. GoTo Finally
  249. CatchNotFound:
  250. ScriptForge.SF_Utils._Validate(ControlName, &quot;ControlName&quot;, V_STRING, _DialogModel.getElementNames())
  251. GoTo Finally
  252. End Function &apos; SFDialogs.SF_Dialog.Controls
  253. REM -----------------------------------------------------------------------------
  254. Public Sub EndExecute(Optional ByVal ReturnValue As Variant)
  255. &apos;&apos;&apos; Ends the display of a modal dialog and gives back the argument
  256. &apos;&apos;&apos; as return value for the current Execute() action
  257. &apos;&apos;&apos; EndExecute is usually contained in the processing of a macro
  258. &apos;&apos;&apos; triggered by a dialog or control event
  259. &apos;&apos;&apos; Args:
  260. &apos;&apos;&apos; ReturnValue: must be numeric. The value passed to the running Execute() method
  261. &apos;&apos;&apos; Example:
  262. &apos;&apos;&apos; Sub OnEvent(poEvent As Variant)
  263. &apos;&apos;&apos; Dim oDlg As Object
  264. &apos;&apos;&apos; Set oDlg = CreateScriptService(&quot;SFDialogs.DialogEvent&quot;, poEvent)
  265. &apos;&apos;&apos; oDlg.EndExecute(25)
  266. &apos;&apos;&apos; End Sub
  267. Dim lExecute As Long &apos; Alias of ReturnValue
  268. Const cstThisSub = &quot;SFDialogs.Dialog.EndExecute&quot;
  269. Const cstSubArgs = &quot;ReturnValue&quot;
  270. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  271. Check:
  272. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  273. If Not _IsStillAlive() Then GoTo Finally
  274. If Not ScriptForge.SF_Utils._Validate(ReturnValue, &quot;ReturnValue&quot;, V_NUMERIC) Then GoTo Finally
  275. End If
  276. Try:
  277. lExecute = CLng(ReturnValue)
  278. Call _DialogControl.endDialog(lExecute)
  279. Finally:
  280. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  281. Exit Sub
  282. Catch:
  283. GoTo Finally
  284. End Sub &apos; SFDialogs.SF_Dialog.EndExecute
  285. REM -----------------------------------------------------------------------------
  286. Public Function Execute(Optional ByVal Modal As Variant) As Long
  287. &apos;&apos;&apos; Display the dialog and wait for its termination by the user
  288. &apos;&apos;&apos; Args:
  289. &apos;&apos;&apos; Modal: False when non-modal dialog. Default = True
  290. &apos;&apos;&apos; Returns:
  291. &apos;&apos;&apos; 0 = Cancel button pressed
  292. &apos;&apos;&apos; 1 = OK button pressed
  293. &apos;&apos;&apos; Otherwise: the dialog stopped with an EndExecute statement executed from a dialog or control event
  294. &apos;&apos;&apos; Example:
  295. &apos;&apos;&apos; Dim oDlg As Object, lReturn As Long
  296. &apos;&apos;&apos; Set oDlg = CreateScriptService(,, &quot;myDialog&quot;) &apos; Dialog stored in current document&apos;s standard library
  297. &apos;&apos;&apos; lReturn = oDlg.Execute()
  298. &apos;&apos;&apos; Select Case lReturn
  299. Dim lExecute As Long &apos; Return value
  300. Const cstThisSub = &quot;SFDialogs.Dialog.Execute&quot;
  301. Const cstSubArgs = &quot;[Modal=True]&quot;
  302. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  303. lExecute = -1
  304. Check:
  305. If IsMissing(Modal) Or IsEmpty(Modal) Then Modal = True
  306. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  307. If Not _IsStillAlive() Then GoTo Finally
  308. If Not ScriptForge.SF_Utils._Validate(Modal, &quot;Modal&quot;, V_BOOLEAN) Then GoTo Finally
  309. End If
  310. Try:
  311. If Modal Then
  312. _Modal = True
  313. _Displayed = True
  314. lExecute = _DialogControl.execute()
  315. Select Case lExecute
  316. Case 1 : lExecute = OKBUTTON
  317. Case 0 : lExecute = CANCELBUTTON
  318. Case Else
  319. End Select
  320. _Displayed = False
  321. Else
  322. _Modal = False
  323. _Displayed = True
  324. _DialogModel.DesktopAsParent = True
  325. _DialogControl.setVisible(True)
  326. lExecute = 0
  327. End If
  328. Finally:
  329. Execute = lExecute
  330. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  331. Exit Function
  332. Catch:
  333. GoTo Finally
  334. End Function &apos; SFDialogs.SF_Dialog.Execute
  335. REM -----------------------------------------------------------------------------
  336. Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
  337. &apos;&apos;&apos; Return the actual value of the given property
  338. &apos;&apos;&apos; Args:
  339. &apos;&apos;&apos; PropertyName: the name of the property as a string
  340. &apos;&apos;&apos; Returns:
  341. &apos;&apos;&apos; The actual value of the property
  342. &apos;&apos;&apos; Exceptions:
  343. &apos;&apos;&apos; ARGUMENTERROR The property does not exist
  344. &apos;&apos;&apos; Examples:
  345. &apos;&apos;&apos; oDlg.GetProperty(&quot;Caption&quot;)
  346. Const cstThisSub = &quot;Model.GetProperty&quot;
  347. Const cstSubArgs = &quot;&quot;
  348. If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  349. GetProperty = Null
  350. Check:
  351. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  352. If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
  353. End If
  354. Try:
  355. GetProperty = _PropertyGet(PropertyName)
  356. Finally:
  357. SF_Utils._ExitFunction(cstThisSub)
  358. Exit Function
  359. Catch:
  360. GoTo Finally
  361. End Function &apos; SFDialogs.SF_Dialog.GetProperty
  362. REM -----------------------------------------------------------------------------
  363. Public Function Methods() As Variant
  364. &apos;&apos;&apos; Return the list of public methods of the Model service as an array
  365. Methods = Array( _
  366. &quot;Activate&quot; _
  367. , &quot;Controls&quot; _
  368. , &quot;EndExecute&quot; _
  369. , &quot;Execute&quot; _
  370. , &quot;Terminate&quot; _
  371. )
  372. End Function &apos; SFDialogs.SF_Dialog.Methods
  373. REM -----------------------------------------------------------------------------
  374. Public Function Properties() As Variant
  375. &apos;&apos;&apos; Return the list or properties of the Timer class as an array
  376. Properties = Array( _
  377. &quot;Caption&quot; _
  378. , &quot;Height&quot; _
  379. , &quot;Modal&quot; _
  380. , &quot;Name&quot; _
  381. , &quot;Page&quot; _
  382. , &quot;Visible&quot; _
  383. , &quot;Width&quot; _
  384. )
  385. End Function &apos; SFDialogs.SF_Dialog.Properties
  386. REM -----------------------------------------------------------------------------
  387. Public Function SetProperty(Optional ByVal PropertyName As Variant _
  388. , Optional ByRef Value As Variant _
  389. ) As Boolean
  390. &apos;&apos;&apos; Set a new value to the given property
  391. &apos;&apos;&apos; Args:
  392. &apos;&apos;&apos; PropertyName: the name of the property as a string
  393. &apos;&apos;&apos; Value: its new value
  394. &apos;&apos;&apos; Exceptions
  395. &apos;&apos;&apos; ARGUMENTERROR The property does not exist
  396. Const cstThisSub = &quot;SFDialogs.Dialog.SetProperty&quot;
  397. Const cstSubArgs = &quot;PropertyName, Value&quot;
  398. If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  399. SetProperty = False
  400. Check:
  401. If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  402. If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
  403. End If
  404. Try:
  405. SetProperty = _PropertySet(PropertyName, Value)
  406. Finally:
  407. SF_Utils._ExitFunction(cstThisSub)
  408. Exit Function
  409. Catch:
  410. GoTo Finally
  411. End Function &apos; SFDialogs.SF_Dialog.SetProperty
  412. REM -----------------------------------------------------------------------------
  413. Public Function Terminate() As Boolean
  414. &apos;&apos;&apos; Terminate the dialog service for the current dialog instance
  415. &apos;&apos;&apos; After termination any action on the current instance will be ignored
  416. &apos;&apos;&apos; Args:
  417. &apos;&apos;&apos; Returns:
  418. &apos;&apos;&apos; True if termination is successful
  419. &apos;&apos;&apos; Example:
  420. &apos;&apos;&apos; Dim oDlg As Object, lReturn As Long
  421. &apos;&apos;&apos; Set oDlg = CreateScriptService(,, &quot;myDialog&quot;) &apos; Dialog stored in current document&apos;s standard library
  422. &apos;&apos;&apos; lreturn = oDlg.Execute()
  423. &apos;&apos;&apos; Select Case lReturn
  424. &apos;&apos;&apos; &apos; ...
  425. &apos;&apos;&apos; End Select
  426. &apos;&apos;&apos; oDlg.Terminate()
  427. Dim bTerminate As Boolean &apos; Return value
  428. Const cstThisSub = &quot;SFDialogs.Dialog.Terminate&quot;
  429. Const cstSubArgs = &quot;&quot;
  430. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  431. bTerminate = False
  432. Check:
  433. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  434. If Not _IsStillAlive() Then GoTo Finally
  435. End If
  436. Try:
  437. _DialogControl.dispose()
  438. Set _DialogControl = Nothing
  439. SF_Register._CleanCacheEntry(_CacheIndex)
  440. _CacheIndex = -1
  441. Dispose()
  442. bTerminate = True
  443. Finally:
  444. Terminate = bTerminate
  445. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  446. Exit Function
  447. Catch:
  448. GoTo Finally
  449. End Function &apos; SFDialogs.SF_Dialog.Terminate
  450. REM =========================================================== PRIVATE FUNCTIONS
  451. REM -----------------------------------------------------------------------------
  452. Public Sub _Initialize()
  453. &apos;&apos;&apos; Complete the object creation process:
  454. &apos;&apos;&apos; - Initialization of private members
  455. &apos;&apos;&apos; - Creation of the dialog graphical interface
  456. &apos;&apos;&apos; - Addition of the new object in the Dialogs buffer
  457. Try:
  458. &apos; Create the graphical interface
  459. Set _DialogControl = CreateUnoDialog(_DialogProvider)
  460. Set _DialogModel = _DialogControl.Model
  461. &apos; Add dialog reference to cache
  462. _CacheIndex = SF_Register._AddDialogToCache(_DialogControl, [Me])
  463. 85
  464. Finally:
  465. Exit Sub
  466. End Sub &apos; SFDialogs.SF_Dialog._Initialize
  467. REM -----------------------------------------------------------------------------
  468. Private Function _IsStillAlive(Optional ByVal pbError As Boolean) As Boolean
  469. &apos;&apos;&apos; Return True if the dialog service is still active
  470. &apos;&apos;&apos; If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
  471. &apos;&apos;&apos; Args:
  472. &apos;&apos;&apos; pbError: if True (default), raise a fatal error
  473. Dim bAlive As Boolean &apos; Return value
  474. Dim sDialog As String &apos; Alias of DialogName
  475. Check:
  476. On Local Error GoTo Catch &apos; Anticipate DisposedException errors or alike
  477. If IsMissing(pbError) Then pbError = True
  478. Try:
  479. bAlive = ( Not IsNull(_DialogProvider) And Not IsNull(_DialogControl) )
  480. If Not bAlive Then GoTo Catch
  481. Finally:
  482. _IsStillAlive = bAlive
  483. Exit Function
  484. Catch:
  485. bAlive = False
  486. On Error GoTo 0
  487. sDialog = _Name
  488. Dispose()
  489. If pbError Then ScriptForge.SF_Exception.RaiseFatal(DIALOGDEADERROR, sDialog)
  490. GoTo Finally
  491. End Function &apos; SFDialogs.SF_Dialog._IsStillAlive
  492. REM -----------------------------------------------------------------------------
  493. Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
  494. &apos;&apos;&apos; Return the value of the named property
  495. &apos;&apos;&apos; Args:
  496. &apos;&apos;&apos; psProperty: the name of the property
  497. Static oSession As Object &apos; Alias of SF_Session
  498. Dim cstThisSub As String
  499. Const cstSubArgs = &quot;&quot;
  500. cstThisSub = &quot;SFDialogs.Dialog.get&quot; &amp; psProperty
  501. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  502. ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
  503. If Not _IsStillAlive() Then GoTo Finally
  504. If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
  505. Select Case psProperty
  506. Case &quot;Caption&quot;
  507. If oSession.HasUNOProperty(_DialogModel, &quot;Title&quot;) Then _PropertyGet = _DialogModel.Title
  508. Case &quot;Height&quot;
  509. If oSession.HasUNOProperty(_DialogModel, &quot;Height&quot;) Then _PropertyGet = _DialogModel.Height
  510. Case &quot;Modal&quot;
  511. _PropertyGet = _Modal
  512. Case &quot;Name&quot;
  513. _PropertyGet = _Name
  514. Case &quot;Page&quot;
  515. If oSession.HasUNOProperty(_DialogModel, &quot;Step&quot;) Then _PropertyGet = _DialogModel.Step
  516. Case &quot;Visible&quot;
  517. If oSession.HasUnoMethod(_DialogControl, &quot;isVisible&quot;) Then _PropertyGet = CBool(_DialogControl.isVisible())
  518. Case &quot;Width&quot;
  519. If oSession.HasUNOProperty(_DialogModel, &quot;Width&quot;) Then _PropertyGet = _DialogModel.Width
  520. Case &quot;XDialogModel&quot;
  521. Set _PropertyGet = _DialogModel
  522. Case &quot;XDialogView&quot;
  523. Set _PropertyGet = _DialogControl
  524. Case Else
  525. _PropertyGet = Null
  526. End Select
  527. Finally:
  528. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  529. Exit Function
  530. Catch:
  531. GoTo Finally
  532. End Function &apos; SFDialogs.SF_Dialog._PropertyGet
  533. REM -----------------------------------------------------------------------------
  534. Private Function _PropertySet(Optional ByVal psProperty As String _
  535. , Optional ByVal pvValue As Variant _
  536. ) As Boolean
  537. &apos;&apos;&apos; Set the new value of the named property
  538. &apos;&apos;&apos; Args:
  539. &apos;&apos;&apos; psProperty: the name of the property
  540. &apos;&apos;&apos; pvValue: the new value of the given property
  541. &apos;&apos;&apos; Returns:
  542. &apos;&apos;&apos; True if successful
  543. Dim bSet As Boolean &apos; Return value
  544. Static oSession As Object &apos; Alias of SF_Session
  545. Dim cstThisSub As String
  546. Const cstSubArgs = &quot;Value&quot;
  547. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  548. bSet = False
  549. cstThisSub = &quot;SFDialogs.Dialog.set&quot; &amp; psProperty
  550. ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
  551. If Not _IsStillAlive() Then GoTo Finally
  552. If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
  553. bSet = True
  554. Select Case UCase(psProperty)
  555. Case UCase(&quot;Caption&quot;)
  556. If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Caption&quot;, V_STRING) Then GoTo Finally
  557. If oSession.HasUNOProperty(_DialogModel, &quot;Title&quot;) Then _DialogModel.Title = pvValue
  558. Case UCase(&quot;Height&quot;)
  559. If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Height&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
  560. If oSession.HasUNOProperty(_DialogModel, &quot;Height&quot;) Then _DialogModel.Height = pvValue
  561. Case UCase(&quot;Page&quot;)
  562. If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Page&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
  563. If oSession.HasUNOProperty(_DialogModel, &quot;Step&quot;) Then _DialogModel.Step = CLng(pvValue)
  564. Case UCase(&quot;Visible&quot;)
  565. If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Visible&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  566. If oSession.HasUnoMethod(_DialogControl, &quot;setVisible&quot;) Then _DialogControl.setVisible(pvValue)
  567. Case UCase(&quot;Width&quot;)
  568. If Not ScriptForge.SF_Utils._Validate(pvValue, &quot;Width&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
  569. If oSession.HasUNOProperty(_DialogModel, &quot;Width&quot;) Then _DialogModel.Width = pvValue
  570. Case Else
  571. bSet = False
  572. End Select
  573. Finally:
  574. _PropertySet = bSet
  575. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  576. Exit Function
  577. Catch:
  578. GoTo Finally
  579. End Function &apos; SFDialogs.SF_Dialog._PropertySet
  580. REM -----------------------------------------------------------------------------
  581. Private Function _Repr() As String
  582. &apos;&apos;&apos; Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
  583. &apos;&apos;&apos; Args:
  584. &apos;&apos;&apos; Return:
  585. &apos;&apos;&apos; &quot;[DIALOG]: Container.Library.Name&quot;
  586. _Repr = &quot;[DIALOG]: &quot; &amp; _Container &amp; &quot;.&quot; &amp; _Library &amp; &quot;.&quot; &amp; _Name
  587. End Function &apos; SFDialogs.SF_Dialog._Repr
  588. REM ============================================ END OF SFDIALOGS.SF_DIALOG
  589. </script:module>