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 =======================================================================================================================
12 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
13 ''' SF_DocumentListener
14 ''' ===================
15 ''' The current module is dedicated to the management of document events + listeners, triggered by user actions,
16 ''' which cannot be defined with the Basic IDE
18 ''' Concerned listeners:
19 ''' com.sun.star.sheet.XRangeSelectionListener
20 ''' allowing a user to select a cell range at any moment
22 ''' The described events/listeners are processed by UNO listeners
24 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
26 REM ================================================================= DEFINITIONS
28 REM ============================================================= PRIVATE MEMBERS
30 Private _SelectedRange As String
' The selected range is returned by a
"done
" event
31 Private _RangeSelectionFinished As Boolean
' 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 _
41 ''' Called from the SF_Calc.OpenRangeSelector() method
42 ''' Opens a non-modal dialog with a text box,
43 ''' let the user make a selection in the current or another sheet and
44 ''' returns the selected area as a string.
46 Dim oController As Object
' com.sun.star.frame.Controller
47 Dim oListener As Object
' com.sun.star.sheet.XRangeSelectionListener
48 Dim lCountLoops As Long
' Sleep cycles counter
50 Const cstListenerPrefix =
"_SFRGSEL_
" ' Prefix used for naming events Subs
51 Const cstSleep =
50 ' Sleep steps in ms while waiting for the end of the interaction
52 Const cstMaxSleep = (
60 *
5 *
1000) / cstSleep
' Never sleep more than
5 minutes. Afterwards, processing continues
54 On Local Error GoTo Catch
' Avoid stopping event scripts
57 ' Create the listener
58 Set oController = poComponent.CurrentController
59 Set oListener = CreateUnoListener(cstListenerPrefix,
"com.sun.star.sheet.XRangeSelectionListener
")
60 oController.addRangeSelectionListener(oListener)
62 ' Open the selector
63 _SelectedRange =
""
64 _RangeSelectionFinished = False
65 oController.startRangeSelection(pvPropertyValues)
67 ' Dummy thread synchronization
69 Do While Not _RangeSelectionFinished And lCountLoops
< cstMaxSleep
71 lCountLoops = lCountLoops +
1
75 If Not IsNull(oListener) Then oController.removeRangeSelectionListener(oListener)
76 RunRangeSelector = _SelectedRange
80 End Function
' SFDocuments.SF_DocumentListener.RunRangeSelector
82 REM ============================================================= PRIVATE METHODS
84 REM -----------------------------------------------------------------------------
85 Sub _SFRGSEL_done(Optional poEvent As Object)
' com.sun.star.sheet.RangeSelectionEvent
87 On Local Error GoTo Catch
' Avoid stopping event scripts
90 _SelectedRange = poEvent.RangeDescriptor
91 _RangeSelectionFinished = True
99 REM -----------------------------------------------------------------------------
100 Sub _SFRGSEL_aborted(Optional poEvent As Object)
' com.sun.star.sheet.RangeSelectionEvent
102 On Local Error GoTo Catch
' Avoid stopping event scripts
105 _RangeSelectionFinished = True
113 REM ============================================ END OF SFDIALOGS.SF_DIALOGLISTENER