summaryrefslogtreecommitdiffstats
path: root/wizards/source/sfdocuments/SF_DocumentListener.xba
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

&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
&apos;&apos;&apos;	SF_DocumentListener
&apos;&apos;&apos;	===================
&apos;&apos;&apos;		The current module is dedicated to the management of document events + listeners, triggered by user actions,
&apos;&apos;&apos;		which cannot be defined with the Basic IDE
&apos;&apos;&apos;
&apos;&apos;&apos;		Concerned listeners:
&apos;&apos;&apos;			com.sun.star.sheet.XRangeSelectionListener
&apos;&apos;&apos;				allowing a user to select a cell range at any moment
&apos;&apos;&apos;
&apos;&apos;&apos;		The described events/listeners are processed by UNO listeners
&apos;&apos;&apos;
&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;

REM ================================================================= DEFINITIONS

REM ============================================================= PRIVATE MEMBERS

Private _SelectedRange			As String			&apos;	The selected range is returned by a &quot;done&quot; event
Private _RangeSelectionFinished	As Boolean			&apos;	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
&apos;&apos;&apos;	Called from the SF_Calc.OpenRangeSelector() method
&apos;&apos;&apos;	Opens a non-modal dialog with a text box,
&apos;&apos;&apos;	let the user make a selection in the current or another sheet and
&apos;&apos;&apos;	returns the selected area as a string.

Dim oController As Object						&apos;	com.sun.star.frame.Controller
Dim oListener As Object							&apos;	com.sun.star.sheet.XRangeSelectionListener
Dim lCountLoops As Long							&apos;	Sleep cycles counter

Const cstListenerPrefix = &quot;_SFRGSEL_&quot;			&apos;	Prefix used for naming events Subs
Const cstSleep = 50								&apos;	Sleep steps in ms while waiting for the end of the interaction
Const cstMaxSleep = (60 * 5 * 1000) / cstSleep	&apos;	Never sleep more than 5 minutes. Afterwards, processing continues

	On Local Error GoTo Catch		&apos;	Avoid stopping event scripts

Try:
	&apos;	Create the listener
	Set oController = poComponent.CurrentController
	Set oListener = CreateUnoListener(cstListenerPrefix, &quot;com.sun.star.sheet.XRangeSelectionListener&quot;)
	oController.addRangeSelectionListener(oListener)

	&apos;	Open the selector
	_SelectedRange = &quot;&quot;
	_RangeSelectionFinished = False
	oController.startRangeSelection(pvPropertyValues)

	&apos;	Dummy thread synchronization
	lCountLoops = 0
	Do While Not _RangeSelectionFinished And lCountLoops &lt; 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	&apos;	SFDocuments.SF_DocumentListener.RunRangeSelector

REM ============================================================= PRIVATE METHODS

REM -----------------------------------------------------------------------------
Sub _SFRGSEL_done(Optional poEvent As Object)		&apos;	com.sun.star.sheet.RangeSelectionEvent

	On Local Error GoTo Catch		&apos;	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)	&apos;	com.sun.star.sheet.RangeSelectionEvent

	On Local Error GoTo Catch		&apos;	Avoid stopping event scripts

Try:
	_RangeSelectionFinished = True

Finally:
	Exit Sub
Catch:
	GoTo Finally
End Sub

REM ============================================ END OF SFDIALOGS.SF_DIALOGLISTENER
</script:module>