Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / wizards / source / sfdialogs / SF_DialogListener.xba
blob54dc8754529c1ca585ddfd6fa7a2fd27f996e6b2
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_DialogListener" 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 =======================================================================================================================
9 Option Compatible
10 Option Explicit
12 &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;
13 &apos;&apos;&apos; SF_Listener
14 &apos;&apos;&apos; ===========
15 &apos;&apos;&apos; The current module is dedicated to the management of dialog control events, triggered by user actions,
16 &apos;&apos;&apos; which are not defined with the Basic IDE
17 &apos;&apos;&apos;
18 &apos;&apos;&apos; Concerned events:
19 &apos;&apos;&apos; TreeControl control type, prefix = _SFEXP_
20 &apos;&apos;&apos; -----------
21 &apos;&apos;&apos; The OnNodeSelected event, triggered when a user selects a node
22 &apos;&apos;&apos; A typical action is to display additional info about the selected item elsewhere in the dialog
23 &apos;&apos;&apos; The OnNodeExpanded event, triggered when a user clicks on the expansion symbol
24 &apos;&apos;&apos; A typical action is to create dynamically a subnode or a subtree below the expanded item
25 &apos;&apos;&apos;
26 &apos;&apos;&apos; PageManager facility, prefix = _SFTAB_
27 &apos;&apos;&apos; -----------
28 &apos;&apos;&apos; Depending on the piloting control(s), next event types are implemented
29 &apos;&apos;&apos; XActionListener: for buttons
30 &apos;&apos;&apos; XItemListener: for listboxes, comboboxes and radio buttons
31 &apos;&apos;&apos;
32 &apos;&apos;&apos; The described events are processed thru UNO listeners
33 &apos;&apos;&apos;
34 &apos;&apos;&apos; &quot;On&quot; events defined by code, prefix = _SFFOCUS_, _SFKEY_, _SFMOUSE_, _SFMOVE_, _SFITEM_, _SFADJUST_, _SFTEXT_
35 &apos;&apos;&apos; -----------
36 &apos;&apos;&apos; All event types applicable on dialogs and control types &lt;&gt; TreeControl
37 &apos;&apos;&apos; The events MUST NOT be preset in the Basic IDE
38 &apos;&apos;&apos;
39 &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;
41 REM ================================================================= DEFINITIONS
43 REM ================================================================== EXCEPTIONS
45 REM ================================================ PUBLIC METHODS (TREECONTROL)
47 REM -----------------------------------------------------------------------------
48 Public Sub _SFEXP_requestChildNodes(Optional ByRef poEvent As Object)
49 &apos;&apos;&apos; Triggered by the OnNodeExpanded event of a tree control
50 &apos;&apos;&apos; The event is triggered thru a com.sun.star.view.XTreeExpansionListener
51 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_DialogControl instance
52 &apos;&apos;&apos; as a scripting framework URI
54 Dim oControl As Object &apos; The SF_DialogControl object having triggered the event
56 On Local Error GoTo Catch &apos; Avoid stopping event scripts
58 Check:
59 &apos; Ensure there is a node
60 If IsNull(poEvent) Or IsMissing(poEvent) Then Exit Sub
61 If IsNull(poEvent.Node) Then Exit Sub
63 Try:
64 Set oControl = ScriptForge.SF_Services.CreateScriptService(&quot;SFDialogs.DialogEvent&quot;, poEvent)
65 ScriptForge.SF_Session._ExecuteScript(oControl.OnNodeExpanded, poEvent)
67 Finally:
68 Exit Sub
69 Catch:
70 GoTo Finally
71 End Sub &apos; SFDialogs.SF_Dialoglistener._SFEXP_requestChildNodes
73 Sub _SFEXP_disposing(ByRef poEvent As Object)
74 End Sub
76 Sub _SFEXP_treeExpanding(Optional ByRef poEvent As Object)
77 End Sub
79 Sub _SFEXP_treeCollapsing(ByRef poEvent As Object)
80 End Sub
82 Sub _SFEXP_treeExpanded(ByRef poEvent As Object)
83 End Sub
85 Sub _SFEXP_treeCollapsed(ByRef poEvent As Object)
86 End Sub
88 REM -----------------------------------------------------------------------------
89 Public Sub _SFSEL_selectionChanged(Optional ByRef poEvent As Object)
90 &apos;&apos;&apos; Triggered by the OnNodeSelected event of a tree control
91 &apos;&apos;&apos; The event is triggered thru a com.sun.star.view.XSelectionChangeListener
92 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_DialogControl instance
93 &apos;&apos;&apos; as a scripting framework URI
94 &apos;&apos;&apos;
95 &apos;&apos;&apos; Nothing happens if there are several selected nodes or none
97 Dim vSelection As Variant &apos; Variant, not object !!
98 Dim oControl As Object &apos; The SF_DialogControl object having triggered the event
100 On Local Error GoTo Catch &apos; Avoid stopping event scripts
102 Check:
103 &apos; Ensure there is a selection
104 If IsNull(poEvent) Or IsMissing(poEvent) Then Exit Sub
105 vSelection = poEvent.Source.getSelection()
106 If IsEmpty(vSelection) Or IsArray(vSelection) Then Exit Sub
108 Try:
109 Set oControl = ScriptForge.SF_Services.CreateScriptService(&quot;SFDialogs.DialogEvent&quot;, poEvent)
110 ScriptForge.SF_Session._ExecuteScript(oControl.OnNodeSelected, poEvent)
112 Finally:
113 Exit Sub
114 Catch:
115 GoTo Finally
116 End Sub &apos; SFDialogs.SF_Dialoglistener._SFSEL_selectionChanged
118 Sub _SFSEL_disposing(ByRef poEvent As Object)
119 End Sub
121 REM ============================================ PUBLIC METHODS (PAGE MANAGEMENT)
123 REM -----------------------------------------------------------------------------
124 Public Sub _SFTAB_actionPerformed(Optional ByRef poEvent As Object)
125 &apos;&apos;&apos; Event triggered by a button configured through the dialog page manager
126 &apos;&apos;&apos; Buttons may be of type TABCONTROL, BACKCONTROL or NEXTCONTROL
128 Dim oControl As Object &apos; The DialogControl instance having caused the event
129 Dim sName As String &apos; Control name
130 Dim oDialog As Object &apos; The parent Dialog instance
131 Dim oPageManager As Object &apos; An entry in dialog._PageManagement
132 Const TABCONTROL = 2
133 Const BACKCONTROL = 3
134 Const NEXTCONTROL = 4
136 Check:
137 On Local Error GoTo Finally &apos; Never interrupt !!
138 Set oControl = CreateScriptService(&quot;DialogEvent&quot;, poEvent)
139 If IsNull(oControl) Then GoTo Finally
141 Try:
142 Set oDialog = oControl.Parent
143 With oDialog
144 sName = oControl.Name
145 &apos; Find entry in page manager settings
146 For Each oPageManager In ._PageManagement
147 If oPageManager.ControlName = sName Then
148 Select Case oPageManager.PageMgtType
149 Case TABCONTROL : .Page = oPageManager.PageNumber
150 Case BACKCONTROL : .Page = .Page - 1
151 Case NEXTCONTROL : .Page = .Page + 1
152 Case Else
153 End Select
154 Exit For
155 End If
156 Next oPageManager
157 End With
159 Finally:
160 Exit Sub
161 End Sub &apos; SFDialogs.SF_Dialoglistener._SFTAB_actionPerformed
163 REM -----------------------------------------------------------------------------
164 Public Sub _SFTAB_itemStateChanged(Optional ByRef poEvent As Object)
165 &apos;&apos;&apos; Event triggered by a listbox, combobox or radiobutton configured through the dialog page manager
166 &apos;&apos;&apos; Buttons are of type PILOTCONTROL
168 Dim oControl As Object &apos; The DialogControl instance having caused the event
169 Dim sName As String &apos; Control name
170 Dim oDialog As Object &apos; The parent Dialog instance
171 Dim oPageManager As Object &apos; An entry in dialog._PageManagement
172 Dim lPage As Long &apos; Actual page number
174 Check:
175 On Local Error GoTo Finally &apos; Never interrupt !!
176 Set oControl = CreateScriptService(&quot;DialogEvent&quot;, poEvent)
177 If IsNull(oControl) Then GoTo Finally
179 Try:
180 Set oDialog = oControl.Parent
181 With oDialog
182 sName = oControl.Name
183 &apos; Find entry in page manager settings
184 For Each oPageManager In ._PageManagement
185 If oPageManager.ControlName = sName Then
186 lPage = oPageManager.PageNumber
187 If lPage = 0 Then .Page = oControl.ListIndex + 1 Else .Page = lPage
188 Exit For
189 End If
190 Next oPageManager
191 End With
193 Finally:
194 Exit Sub
195 End Sub &apos; SFDialogs.SF_Dialoglistener._SFTAB_itemStateChanged
197 REM -----------------------------------------------------------------------------
198 Public Sub _SFTAB_disposing(Optional ByRef poEvent As Object)
199 End Sub
201 REM ========================== PUBLIC METHODS (GENERIC DIALOG AND CONTROL EVENTS)
203 &apos;&apos;&apos; Next methods SIMULATE the behaviour of events set on dialogs and dialog controls
204 &apos;&apos;&apos; in the Events tab of a dialog editing page in the Basic IDE.
205 &apos;&apos;&apos; They are not triggered by events preset in the Basic IDE.
206 &apos;&apos;&apos; They are triggered ONLY when the event has been set by code with one of the OnXxxYyyy properties,
207 &apos;&apos;&apos; like in:
208 &apos;&apos;&apos; dialog.OnActionPerformed = &quot;vnd....&quot; &apos; URI notation
210 REM -----------------------------------------------------------------------------
211 Public Sub _SFACTION_actionPerformed(Optional ByRef poEvent As Object)
212 &apos;&apos;&apos; Triggered by the OnActionPerformed event in a dialog control
213 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XActionListener
214 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_DialogControl instance
215 &apos;&apos;&apos; as a scripting framework URI
217 _TriggerEvent(&quot;actionPerformed&quot;, poEvent)
219 End Sub &apos; SFDialogs.SF_Dialoglistener. _SFACTION_actionPerformed
221 REM -----------------------------------------------------------------------------
222 Public Sub _SFACTION_disposing()
223 End Sub
225 REM -----------------------------------------------------------------------------
226 Public Sub _SFADJUST_adjustmentValueChanged(Optional ByRef poEvent As Object)
227 &apos;&apos;&apos; Triggered by the OnAdjustmentValueChanged event in a scrollbar
228 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XAdjustmentListener
229 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_DialogControl instance
230 &apos;&apos;&apos; as a scripting framework URI
232 _TriggerEvent(&quot;adjustmentValueChanged&quot;, poEvent)
234 End Sub &apos; SFDialogs.SF_Dialoglistener. _SFADJUST_adjustmentValueChanged
236 REM -----------------------------------------------------------------------------
237 Public Sub _SFADJUST_disposing()
238 End Sub
240 REM -----------------------------------------------------------------------------
241 Public Sub _SFFOCUS_focusGained(Optional ByRef poEvent As Object)
242 &apos;&apos;&apos; Triggered by the OnFocusGained event in a dialog or dialog control
243 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XFocusListener
244 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
245 &apos;&apos;&apos; as a scripting framework URI
247 _TriggerEvent(&quot;focusGained&quot;, poEvent)
249 End Sub &apos; SFDialogs.SF_Dialoglistener._SFFOCUS_focusGained
251 REM -----------------------------------------------------------------------------
252 Public Sub _SFFOCUS_focusLost(Optional ByRef poEvent As Object)
253 &apos;&apos;&apos; Triggered by the OnFocusLost event in a dialog or dialog control
254 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XFocusListener
255 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
256 &apos;&apos;&apos; as a scripting framework URI
258 _TriggerEvent(&quot;focusLost&quot;, poEvent)
260 End Sub &apos; SFDialogs.SF_Dialoglistener._SFFOCUS_focusLost
262 REM -----------------------------------------------------------------------------
263 Public Sub _SFFOCUS_disposing()
264 End Sub
266 REM -----------------------------------------------------------------------------
267 Public Sub _SFITEM_itemStateChanged(Optional ByRef poEvent As Object)
268 &apos;&apos;&apos; Triggered by the OnItemStateChanged event in a dialog control
269 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XItemListener
270 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_DialogControl instance
271 &apos;&apos;&apos; as a scripting framework URI
273 _TriggerEvent(&quot;itemStateChanged&quot;, poEvent)
275 End Sub &apos; SFDialogs.SF_Dialoglistener. _SFACTION_actionPerformed
277 REM -----------------------------------------------------------------------------
278 Public Sub _SFITEM_disposing()
279 End Sub
281 REM -----------------------------------------------------------------------------
282 Public Sub _SFKEY_keyPressed(Optional ByRef poEvent As Object)
283 &apos;&apos;&apos; Triggered by the OnKeyPressed event in a dialog or dialog control
284 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XKeyListener
285 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
286 &apos;&apos;&apos; as a scripting framework URI
288 _TriggerEvent(&quot;keyPressed&quot;, poEvent)
290 End Sub &apos; SFDialogs.SF_Dialoglistener._SFKEY_keyPressed
292 REM -----------------------------------------------------------------------------
293 Public Sub _SFKEY_keyReleased(Optional ByRef poEvent As Object)
294 &apos;&apos;&apos; Triggered by the OnKeyReleased event in a dialog or dialog control
295 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XKeyListener
296 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
297 &apos;&apos;&apos; as a scripting framework URI
299 _TriggerEvent(&quot;keyReleased&quot;, poEvent)
301 End Sub &apos; SFDialogs.SF_Dialoglistener._SFKEY_keyReleased
303 REM -----------------------------------------------------------------------------
304 Public Sub _SFKEY_disposing()
305 End Sub
307 REM -----------------------------------------------------------------------------
308 Public Sub _SFMOUSE_mouseEntered(Optional ByRef poEvent As Object)
309 &apos;&apos;&apos; Triggered by the OnMouseEntered event in a dialog or dialog control
310 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XMouseListener
311 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
312 &apos;&apos;&apos; as a scripting framework URI
314 _TriggerEvent(&quot;mouseEntered&quot;, poEvent)
316 End Sub &apos; SFDialogs.SF_Dialoglistener._SFMOUSE_mouseEntered
318 REM -----------------------------------------------------------------------------
319 Public Sub _SFMOUSE_mouseExited(Optional ByRef poEvent As Object)
320 &apos;&apos;&apos; Triggered by the OnMouseExited event in a dialog or dialog control
321 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XMouseListener
322 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
323 &apos;&apos;&apos; as a scripting framework URI
325 _TriggerEvent(&quot;mouseExited&quot;, poEvent)
327 End Sub &apos; SFDialogs.SF_Dialoglistener._SFMOUSE_mouseExited
329 REM -----------------------------------------------------------------------------
330 Public Sub _SFMOUSE_mousePressed(Optional ByRef poEvent As Object)
331 &apos;&apos;&apos; Triggered by the OnMousePressed event in a dialog or dialog control
332 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XMouseListener
333 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
334 &apos;&apos;&apos; as a scripting framework URI
336 _TriggerEvent(&quot;mousePressed&quot;, poEvent)
338 End Sub &apos; SFDialogs.SF_Dialoglistener._SFMOUSE_mousePressed
340 REM -----------------------------------------------------------------------------
341 Public Sub _SFMOUSE_mouseReleased(Optional ByRef poEvent As Object)
342 &apos;&apos;&apos; Triggered by the OnMouseReleased event in a dialog or dialog control
343 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XMouseListener
344 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
345 &apos;&apos;&apos; as a scripting framework URI
347 _TriggerEvent(&quot;mouseReleased&quot;, poEvent)
349 End Sub &apos; SFDialogs.SF_Dialoglistener._SFMOUSE_mouseReleased
351 REM -----------------------------------------------------------------------------
352 Public Sub _SFMOUSE_disposing()
353 End Sub
355 REM -----------------------------------------------------------------------------
356 Public Sub _SFMOVE_mouseDragged(Optional ByRef poEvent As Object)
357 &apos;&apos;&apos; Triggered by the OnMouseDragged event in a dialog or dialog control
358 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XMouseMotionListener
359 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
360 &apos;&apos;&apos; as a scripting framework URI
362 _TriggerEvent(&quot;mouseDragged&quot;, poEvent)
364 End Sub &apos; SFDialogs.SF_Dialoglistener._SFMOUSE_mouseDragged
366 REM -----------------------------------------------------------------------------
367 Public Sub _SFMOVE_mouseMoved(Optional ByRef poEvent As Object)
368 &apos;&apos;&apos; Triggered by the OnMouseMoved event in a dialog or dialog control
369 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XMouseMotionListener
370 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
371 &apos;&apos;&apos; as a scripting framework URI
373 _TriggerEvent(&quot;mouseMoved&quot;, poEvent)
375 End Sub &apos; SFDialogs.SF_Dialoglistener._SFMOUSE_mouseMoved
377 REM -----------------------------------------------------------------------------
378 Public Sub _SFMOVE_disposing()
379 End Sub
381 REM -----------------------------------------------------------------------------
382 Public Sub _SFTEXT_textChanged(Optional ByRef poEvent As Object)
383 &apos;&apos;&apos; Triggered by the OnTextChanged event in a dialog control
384 &apos;&apos;&apos; The event is triggered thru a com.sun.star.awt.XTextListener
385 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_DialogControl instance
386 &apos;&apos;&apos; as a scripting framework URI
388 _TriggerEvent(&quot;textChanged&quot;, poEvent)
390 End Sub &apos; SFDialogs.SF_Dialoglistener. _SFTEXT_textChanged
392 REM -----------------------------------------------------------------------------
393 Public Sub _SFTEXT_disposing()
394 End Sub
396 REM ============================================================= PRIVATE METHODS
398 REM -----------------------------------------------------------------------------
399 Public Function _SetOnProperty(ByRef poInstance As Object _
400 , ByVal psProperty As String _
401 , ByVal psScript As String _
402 ) As Boolean
403 &apos;&apos;&apos; Set one of the On properties related to either a SF_Dialog or SF_DialogControl instance
404 &apos;&apos;&apos; Such a property is typically set by next pseudo-code:
405 &apos;&apos;&apos; poInstance.psProperty = psScript
406 &apos;&apos;&apos; It requires a strictly identical nomenclature of internal variables in both classes.
407 &apos;&apos;&apos; Args:
408 &apos;&apos;&apos; poInstance: a SF_Dialog or a SF_DialogControl instance
409 &apos;&apos;&apos; psProperty: one of the applicable On properties (&quot;OnFocusGained&quot;, &quot;OnMouseMoved&quot;, ...)
410 &apos;&apos;&apos; psScript: the script to run when the event is triggered
411 &apos;&apos;&apos; When the zero-length string, the trigger is deactivated
413 Dim bSet As Boolean &apos; Return value
414 Dim oModel As Object &apos; com.sun.star.awt.XControlModel
415 Dim oView As Object &apos; com.sun.star.awt.XControl
416 Dim oDialogEvents As Object &apos; com.sun.star.container.XNameContainer
417 Dim sListener As String &apos; Applicable listener, depending on property, f.i. &quot;XMouseListener&quot;
418 Dim sEventName As String &apos; Internal event name
419 Dim iCounterIncrement As Integer &apos; Increment to be applied on listener counter
420 Dim sPrevious As String &apos; Actual value of script before the change
422 Const cstPrefix = &quot;com.sun.star.awt.&quot;
424 bSet = True
426 Check:
427 If IsNull(poInstance) Or Len(psProperty) = 0 Then GoTo Catch
428 With poInstance
430 &apos; Initialize local variables depending on instance type
431 If .ObjectType = &quot;DIALOG&quot; Then
432 Set oModel = ._DialogModel
433 Set oView = ._DialogControl
434 Else &apos; DIALOGCONTROL
435 Set oModel = ._ControlModel
436 Set oView = ._ControlView
437 End If
438 If IsNull(oModel) Or IsNull(oView) Then GoTo Catch
440 &apos; Ignore request if an event has been statically preset (in the Basic IDE) with the same name
441 Set oDialogEvents = oModel.getEvents()
442 sListener = ._GetListener(psProperty)
443 sEventName = cstPrefix &amp; sListener &amp; &quot;::&quot; &amp; ._GetEventName(psProperty)
444 If oDialogEvents.hasByName(sEventName) Then GoTo Catch
446 Try:
447 &apos; Note the target scripts. Compare previous and new values. Fix the increment to be applied on counter
448 Select Case UCase(psProperty)
449 Case UCase(&quot;OnActionPerformed&quot;)
450 sPrevious = ._OnActionPerformed
451 ._OnActionPerformed = psScript
452 Case UCase(&quot;OnAdjustmentValueChanged&quot;)
453 sPrevious = ._OnAdjustmentValueChanged
454 ._OnAdjustmentValueChanged = psScript
455 Case UCase(&quot;OnFocusGained&quot;)
456 sPrevious = ._OnfocusGained
457 ._OnFocusGained = psScript
458 Case UCase(&quot;OnFocusLost&quot;)
459 sPrevious = ._OnFocusLost
460 ._OnFocusLost = psScript
461 Case UCase(&quot;OnItemStateChanged&quot;)
462 sPrevious = ._OnItemStateChanged
463 ._OnItemStateChanged = psScript
464 Case UCase(&quot;OnKeyPressed&quot;)
465 sPrevious = ._OnKeyPressed
466 ._OnKeyPressed = psScript
467 Case UCase(&quot;OnKeyReleased&quot;)
468 sPrevious = ._OnKeyReleased
469 ._OnKeyReleased = psScript
470 Case UCase(&quot;OnMouseDragged&quot;)
471 sPrevious = ._OnMouseDragged
472 ._OnMouseDragged = psScript
473 Case UCase(&quot;OnMouseEntered&quot;)
474 sPrevious = ._OnMouseEntered
475 ._OnMouseEntered = psScript
476 Case UCase(&quot;OnMouseExited&quot;)
477 sPrevious = ._OnMouseExited
478 ._OnMouseExited = psScript
479 Case UCase(&quot;OnMouseMoved&quot;)
480 sPrevious = ._OnMouseMoved
481 ._OnMouseMoved = psScript
482 Case UCase(&quot;OnMousePressed&quot;)
483 sPrevious = ._OnMousePressed
484 ._OnMousePressed = psScript
485 Case UCase(&quot;OnMouseReleased&quot;)
486 sPrevious = ._OnMouseReleased
487 ._OnMouseReleased = psScript
488 Case UCase(&quot;OnTextChanged&quot;)
489 sPrevious = ._OnTextChanged
490 ._OnTextChanged = psScript
491 End Select
492 &apos; Compare previous and new event to know what to do next with the listener
493 If sPrevious = psScript Then GoTo Finally &apos; No change
494 If Len(sPrevious) = 0 Then &apos; New event
495 iCounterIncrement = +1
496 ElseIf Len(psScript) = 0 Then &apos; Cancel event
497 iCounterIncrement = -1
498 Else &apos; Event replacement
499 iCounterIncrement = 0
500 End If
502 &apos; Setup a new fresh listener, only once by listener during dialog or control life time,
503 &apos; (re)add it to the instance view or remove the existing one if not needed anymore
504 Select Case sListener
505 Case &quot;XActionListener&quot;
506 ._ActionCounter = ._ActionCounter + iCounterIncrement
507 If ._ActionCounter = 1 Then
508 If IsNull(._ActionListener) Then Set ._ActionListener = CreateUnoListener(&quot;_SFACTION_&quot;, cstPrefix &amp; sListener)
509 If iCounterIncrement = 1 Then oView.addActionListener(._ActionListener)
510 ElseIf ._ActionCounter &lt;= 0 Then
511 If Not IsNull(._ActionListener) Then oView.removeActionListener(._ActionListener)
512 ._ActionCounter = 0 &apos; Prevent negative values
513 End If
514 Case &quot;XAdjustmentListener&quot;
515 ._AdjustmentCounter = ._AdjustmentCounter + iCounterIncrement
516 If ._AdjustmentCounter = 1 Then
517 If IsNull(._AdjustmentListener) Then Set ._AdjustmentListener = CreateUnoListener(&quot;_SFADJUST_&quot;, cstPrefix &amp; sListener)
518 If iCounterIncrement = 1 Then oView.addAdjustmentListener(._AdjustmentListener)
519 ElseIf ._AdjustmentCounter &lt;= 0 Then
520 If Not IsNull(._AdjustmentListener) Then oView.removeAdjustmentListener(._AdjustmentListener)
521 ._AdjustmentCounter = 0 &apos; Prevent negative values
522 End If
523 Case &quot;XFocusListener&quot;
524 ._FocusCounter = ._FocusCounter + iCounterIncrement
525 If ._FocusCounter = 1 Then
526 If IsNull(._FocusListener) Then Set ._FocusListener = CreateUnoListener(&quot;_SFFOCUS_&quot;, cstPrefix &amp; sListener)
527 If iCounterIncrement = 1 Then oView.addFocusListener(._FocusListener)
528 ElseIf ._FocusCounter &lt;= 0 Then
529 If Not IsNull(._FocusListener) Then oView.removeFocusListener(._FocusListener)
530 ._FocusCounter = 0 &apos; Prevent negative values
531 End If
532 Case &quot;XItemListener&quot;
533 ._ItemCounter = ._ItemCounter + iCounterIncrement
534 If ._ItemCounter = 1 Then
535 If IsNull(._ItemListener) Then Set ._ItemListener = CreateUnoListener(&quot;_SFITEM_&quot;, cstPrefix &amp; sListener)
536 If iCounterIncrement = 1 Then oView.addItemListener(._ItemListener)
537 ElseIf ._ItemCounter &lt;= 0 Then
538 If Not IsNull(._ItemListener) Then oView.removeItemListener(._ItemListener)
539 ._ItemCounter = 0 &apos; Prevent negative values
540 End If
541 Case &quot;XKeyListener&quot;
542 ._KeyCounter = ._KeyCounter + iCounterIncrement
543 If ._KeyCounter= 1 Then
544 If IsNull(._KeyListener) Then Set ._KeyListener = CreateUnoListener(&quot;_SFKEY_&quot;, cstPrefix &amp; sListener)
545 If iCounterIncrement = 1 Then oView.addKeyListener(._KeyListener)
546 ElseIf ._KeyCounter &lt;= 0 Then
547 If Not IsNull(._KeyListener) Then oView.removeKeyListener(._KeyListener)
548 ._KeyCounter = 0 &apos; Prevent negative values
549 End If
550 Case &quot;XMouseListener&quot;
551 ._MouseCounter = ._MouseCounter + iCounterIncrement
552 If ._MouseCounter= 1 Then
553 If IsNull(._MouseListener) Then Set ._MouseListener = CreateUnoListener(&quot;_SFMOUSE_&quot;, cstPrefix &amp; sListener)
554 If iCounterIncrement = 1 Then oView.addMouseListener(._MouseListener)
555 ElseIf ._MouseCounter &lt;= 0 Then
556 If Not IsNull(._MouseListener) Then oView.removeMouseListener(._MouseListener)
557 ._MouseCounter = 0 &apos; Prevent negative values
558 End If
559 Case &quot;XMouseMotionListener&quot;
560 ._MouseMotionCounter = ._MouseMotionCounter + iCounterIncrement
561 If ._MouseMotionCounter = 1 Then
562 If IsNull(._MouseMotionListener) Then Set ._MouseMotionListener = CreateUnoListener(&quot;_SFMOVE_&quot;, cstPrefix &amp; sListener)
563 If iCounterIncrement = 1 Then oView.addMouseMotionListener(._MouseMotionListener)
564 ElseIf ._MouseMotionCounter &lt;= 0 Then
565 If Not IsNull(._MouseMotionListener) Then oView.removeMouseMotionListener(._MouseMotionListener)
566 ._MouseMotionCounter = 0 &apos; Prevent negative values
567 End If
568 Case &quot;XTextListener&quot;
569 ._TextCounter = ._TextCounter + iCounterIncrement
570 If ._TextCounter = 1 Then
571 If IsNull(._TextListener) Then Set ._TextListener = CreateUnoListener(&quot;_SFTEXT_&quot;, cstPrefix &amp; sListener)
572 If iCounterIncrement = 1 Then oView.addTextListener(._TextListener)
573 ElseIf ._TextCounter &lt;= 0 Then
574 If Not IsNull(._TextListener) Then oView.removeTextListener(._TextListener)
575 ._TextCounter = 0 &apos; Prevent negative values
576 End If
577 End Select
579 End With
581 Finally:
582 _SetOnProperty = bSet
583 Exit Function
584 Catch:
585 bSet = False
586 GoTo Finally
587 End Function &apos; SFDialogs.SF_Dialoglistener._SetOnProperty
589 REM -----------------------------------------------------------------------------
590 Public Sub _TriggerEvent(ByVal EventType, Optional ByRef poEvent As Object)
591 &apos;&apos;&apos; Triggered by the EventType event in a dialog or dialog control
592 &apos;&apos;&apos; The argument is passed to a user routine stored in the SF_Dialog or SF_DialogControl instance
593 &apos;&apos;&apos; as a scripting framework URI
595 Dim oDialog As Object &apos; The SF_Dialog or SF_DialogControl object having triggered the event
596 Dim sScript As String &apos; Script to be invoked
598 On Local Error GoTo Catch &apos; Avoid stopping event scripts
600 Check:
601 If IsNull(poEvent) Or IsMissing(poEvent) Then Exit Sub
603 Try:
604 Set oDialog = ScriptForge.SF_Services.CreateScriptService(&quot;SFDialogs.DialogEvent&quot;, poEvent)
605 If IsNull(oDialog) Then Exit Sub
606 With oDialog
607 Select Case EventType
608 Case &quot;actionPerformed&quot; : sScript = .OnActionPerformed
609 Case &quot;adjustmentValueChanged&quot; : sScript = .OnAdjustmentValueChanged
610 Case &quot;focusGained&quot; : sScript = .OnFocusGained
611 Case &quot;focusLost&quot; : sScript = .OnFocusLost
612 Case &quot;itemStateChanged&quot; : sScript = .OnItemStateChanged
613 Case &quot;mouseDragged&quot; : sScript = .OnMouseDragged
614 Case &quot;mouseEntered&quot; : sScript = .OnMouseEntered
615 Case &quot;mouseExited&quot; : sScript = .OnMouseExited
616 Case &quot;mouseMoved&quot; : sScript = .OnMouseMoved
617 Case &quot;mousePressed&quot; : sScript = .OnMousePressed
618 Case &quot;mouseReleased&quot; : sScript = .OnMouseReleased
619 Case &quot;textChanged&quot; : sScript = .OnTextChanged
620 Case Else : sScript = &quot;&quot; &apos; Should not happen
621 End Select
622 If Len(sScript) = 0 Then Exit Sub
623 ScriptForge.SF_Session._ExecuteScript(sScript, poEvent)
624 End With
626 Finally:
627 Exit Sub
628 Catch:
629 GoTo Finally
630 End Sub &apos; SFDialogs.SF_Dialoglistener._TriggerEvent
632 REM ============================================ END OF SFDIALOGS.SF_DIALOGLISTENER
633 </script:module>