tdf#164434 Correct SvgSymbolNode SVG import
[LibreOffice.git] / wizards / source / sfdocuments / SF_DocumentListener.xba
blobfbb0271bbc383731258fbc140c153e4c6f136601
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_DocumentListener" 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 SFDocuments 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_DocumentListener
14 &apos;&apos;&apos; ===================
15 &apos;&apos;&apos; The current module is dedicated to the management of document events + listeners, triggered by user actions,
16 &apos;&apos;&apos; which cannot be defined with the Basic IDE
17 &apos;&apos;&apos;
18 &apos;&apos;&apos; Concerned listeners:
19 &apos;&apos;&apos; com.sun.star.sheet.XRangeSelectionListener
20 &apos;&apos;&apos; allowing a user to select a cell range at any moment
21 &apos;&apos;&apos;
22 &apos;&apos;&apos; The described events/listeners are processed by UNO listeners
23 &apos;&apos;&apos;
24 &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;
26 REM ================================================================= DEFINITIONS
28 REM ============================================================= PRIVATE MEMBERS
30 Private _SelectedRange As String &apos; The selected range is returned by a &quot;done&quot; event
31 Private _RangeSelectionFinished As Boolean &apos; Flag indicating that the interaction with the user has stopped
33 REM ================================================================== EXCEPTIONS
35 REM ============================================================== PUBLIC METHODS
37 REM -----------------------------------------------------------------------------
38 Public Function RunRangeSelector(ByRef poComponent As Object _
39 , ByRef pvPropertyValues As Variant _
40 ) As String
41 &apos;&apos;&apos; Called from the SF_Calc.OpenRangeSelector() method
42 &apos;&apos;&apos; Opens a non-modal dialog with a text box,
43 &apos;&apos;&apos; let the user make a selection in the current or another sheet and
44 &apos;&apos;&apos; returns the selected area as a string.
46 Dim oController As Object &apos; com.sun.star.frame.Controller
47 Dim oListener As Object &apos; com.sun.star.sheet.XRangeSelectionListener
48 Dim lCountLoops As Long &apos; Sleep cycles counter
50 Const cstListenerPrefix = &quot;_SFRGSEL_&quot; &apos; Prefix used for naming events Subs
51 Const cstSleep = 50 &apos; Sleep steps in ms while waiting for the end of the interaction
52 Const cstMaxSleep = (60 * 5 * 1000) / cstSleep &apos; Never sleep more than 5 minutes. Afterwards, processing continues
54 On Local Error GoTo Catch &apos; Avoid stopping event scripts
56 Try:
57 &apos; Create the listener
58 Set oController = poComponent.CurrentController
59 Set oListener = CreateUnoListener(cstListenerPrefix, &quot;com.sun.star.sheet.XRangeSelectionListener&quot;)
60 oController.addRangeSelectionListener(oListener)
62 &apos; Open the selector
63 _SelectedRange = &quot;&quot;
64 _RangeSelectionFinished = False
65 oController.startRangeSelection(pvPropertyValues)
67 &apos; Dummy thread synchronization
68 lCountLoops = 0
69 Do While Not _RangeSelectionFinished And lCountLoops &lt; cstMaxSleep
70 Wait(cstSleep)
71 lCountLoops = lCountLoops + 1
72 Loop
74 Finally:
75 If Not IsNull(oListener) Then oController.removeRangeSelectionListener(oListener)
76 RunRangeSelector = _SelectedRange
77 Exit Function
78 Catch:
79 GoTo Finally
80 End Function &apos; SFDocuments.SF_DocumentListener.RunRangeSelector
82 REM ============================================================= PRIVATE METHODS
84 REM -----------------------------------------------------------------------------
85 Sub _SFRGSEL_done(Optional poEvent As Object) &apos; com.sun.star.sheet.RangeSelectionEvent
87 On Local Error GoTo Catch &apos; Avoid stopping event scripts
89 Try:
90 _SelectedRange = poEvent.RangeDescriptor
91 _RangeSelectionFinished = True
93 Finally:
94 Exit Sub
95 Catch:
96 GoTo Finally
97 End Sub
99 REM -----------------------------------------------------------------------------
100 Sub _SFRGSEL_aborted(Optional poEvent As Object) &apos; com.sun.star.sheet.RangeSelectionEvent
102 On Local Error GoTo Catch &apos; Avoid stopping event scripts
104 Try:
105 _RangeSelectionFinished = True
107 Finally:
108 Exit Sub
109 Catch:
110 GoTo Finally
111 End Sub
113 REM ============================================ END OF SFDIALOGS.SF_DIALOGLISTENER
114 </script:module>