blob: fbb0271bbc383731258fbc140c153e4c6f136601 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_DocumentListener" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
REM === The SFDocuments library is one of the associated libraries. ===
REM === Full documentation is available on https://help.libreoffice.org/ ===
REM =======================================================================================================================
Option Compatible
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' SF_DocumentListener
''' ===================
''' The current module is dedicated to the management of document events + listeners, triggered by user actions,
''' which cannot be defined with the Basic IDE
'''
''' Concerned listeners:
''' com.sun.star.sheet.XRangeSelectionListener
''' allowing a user to select a cell range at any moment
'''
''' The described events/listeners are processed by UNO listeners
'''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
REM ================================================================= DEFINITIONS
REM ============================================================= PRIVATE MEMBERS
Private _SelectedRange As String ' The selected range is returned by a "done" event
Private _RangeSelectionFinished As Boolean ' Flag indicating that the interaction with the user has stopped
REM ================================================================== EXCEPTIONS
REM ============================================================== PUBLIC METHODS
REM -----------------------------------------------------------------------------
Public Function RunRangeSelector(ByRef poComponent As Object _
, ByRef pvPropertyValues As Variant _
) As String
''' Called from the SF_Calc.OpenRangeSelector() method
''' Opens a non-modal dialog with a text box,
''' let the user make a selection in the current or another sheet and
''' returns the selected area as a string.
Dim oController As Object ' com.sun.star.frame.Controller
Dim oListener As Object ' com.sun.star.sheet.XRangeSelectionListener
Dim lCountLoops As Long ' Sleep cycles counter
Const cstListenerPrefix = "_SFRGSEL_" ' Prefix used for naming events Subs
Const cstSleep = 50 ' Sleep steps in ms while waiting for the end of the interaction
Const cstMaxSleep = (60 * 5 * 1000) / cstSleep ' Never sleep more than 5 minutes. Afterwards, processing continues
On Local Error GoTo Catch ' Avoid stopping event scripts
Try:
' Create the listener
Set oController = poComponent.CurrentController
Set oListener = CreateUnoListener(cstListenerPrefix, "com.sun.star.sheet.XRangeSelectionListener")
oController.addRangeSelectionListener(oListener)
' Open the selector
_SelectedRange = ""
_RangeSelectionFinished = False
oController.startRangeSelection(pvPropertyValues)
' Dummy thread synchronization
lCountLoops = 0
Do While Not _RangeSelectionFinished And lCountLoops < cstMaxSleep
Wait(cstSleep)
lCountLoops = lCountLoops + 1
Loop
Finally:
If Not IsNull(oListener) Then oController.removeRangeSelectionListener(oListener)
RunRangeSelector = _SelectedRange
Exit Function
Catch:
GoTo Finally
End Function ' SFDocuments.SF_DocumentListener.RunRangeSelector
REM ============================================================= PRIVATE METHODS
REM -----------------------------------------------------------------------------
Sub _SFRGSEL_done(Optional poEvent As Object) ' com.sun.star.sheet.RangeSelectionEvent
On Local Error GoTo Catch ' Avoid stopping event scripts
Try:
_SelectedRange = poEvent.RangeDescriptor
_RangeSelectionFinished = True
Finally:
Exit Sub
Catch:
GoTo Finally
End Sub
REM -----------------------------------------------------------------------------
Sub _SFRGSEL_aborted(Optional poEvent As Object) ' com.sun.star.sheet.RangeSelectionEvent
On Local Error GoTo Catch ' Avoid stopping event scripts
Try:
_RangeSelectionFinished = True
Finally:
Exit Sub
Catch:
GoTo Finally
End Sub
REM ============================================ END OF SFDIALOGS.SF_DIALOGLISTENER
</script:module>
|