summaryrefslogtreecommitdiff
path: root/wizards/source/sfwidgets/SF_Register.xba
blob: b7f366102be4fa1cdb72d65c57685bb92b05b082 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
<?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_Register" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
REM ===			The ScriptForge library and its associated libraries are part of the LibreOffice project.				===
REM	===						The SFWidgets 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_Register
&apos;&apos;&apos;	===========
&apos;&apos;&apos;		The ScriptForge framework includes
&apos;&apos;&apos;			the master ScriptForge library
&apos;&apos;&apos;			a number of &quot;associated&quot; libraries SF*
&apos;&apos;&apos;			any user/contributor extension wanting to fit into the framework 
&apos;&apos;&apos;
&apos;&apos;&apos;		The main methods in this module allow the current library to cling to ScriptForge
&apos;&apos;&apos;			- RegisterScriptServices
&apos;&apos;&apos;				Register the list of services implemented by the current library
&apos;&apos;&apos;			- _NewPopupMenu
&apos;&apos;&apos;				Create a new popup menu service instance
&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&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 ================================================================== EXCEPTIONS

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

REM ============================================================== PUBLIC METHODS

REM -----------------------------------------------------------------------------
Public Sub RegisterScriptServices() As Variant
&apos;&apos;&apos;	Register into ScriptForge the list of the services implemented by the current library
&apos;&apos;&apos;	Each library pertaining to the framework must implement its own version of this method
&apos;&apos;&apos;
&apos;&apos;&apos;	It consists in successive calls to the RegisterService() and RegisterEventManager() methods
&apos;&apos;&apos;	with 2 arguments:
&apos;&apos;&apos;		ServiceName: the name of the service as a case-insensitive string
&apos;&apos;&apos;		ServiceReference: the reference as an object
&apos;&apos;&apos;			If the reference refers to a module, then return the module as an object:
&apos;&apos;&apos;				GlobalScope.Library.Module
&apos;&apos;&apos;			If the reference is a class instance, then return a string referring to the method
&apos;&apos;&apos;			containing the New statement creating the instance
&apos;&apos;&apos;				&quot;libraryname.modulename.function&quot;

	With GlobalScope.ScriptForge.SF_Services
		.RegisterService(&quot;PopupMenu&quot;,			&quot;SFWidgets.SF_Register._NewPopupMenu&quot;)		&apos;	Reference to the function initializing the service
	End With

End Sub			&apos;	SFWidgets.SF_Register.RegisterScriptServices

REM =========================================================== PRIVATE FUNCTIONS

REM -----------------------------------------------------------------------------
Public Function _NewPopupMenu(Optional ByVal pvArgs As Variant) As Object
&apos;&apos;&apos;	Create a new instance of the SF_PopupMenu class
&apos;	Args:
&apos;&apos;&apos;		Event: a mouse event
&apos;&apos;&apos;			If the event has no source or is not a mouse event, the menu is displayed above ThisComponent
&apos;&apos;&apos;		X, Y: forced coordinates
&apos;&apos;&apos;		SubmenuChar: Delimiter in menu trees
&apos;&apos;&apos;	Returns: the instance or Nothing

Dim oMenu As Object					&apos;	Return value
Dim Event As Variant				&apos;	Mouse event		
Dim X As Long						&apos;	Mouse click coordinates
Dim Y As Long
Dim SubmenuChar As String			&apos;	Delimiter in menu trees
Dim oSession As Object				&apos;	ScriptForge.SF_Session
Dim vUno As Variant					&apos;	UNO type split into an array
Dim sEventType As String			&apos;	Event type, must be &quot;MouseEvent&quot;
Dim oControl As Object				&apos;	The dialog or form control view which triggered the event

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch

Check:
	If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
	If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
	If UBound(pvArgs) &gt;= 0 Then Event = pvArgs(0) Else Event = Nothing
	If UBound(pvArgs) &gt;= 1 Then X = pvArgs(1) Else X = 0
	If UBound(pvArgs) &gt;= 2 Then Y = pvArgs(2) Else Y = 0
	If UBound(pvArgs) &gt;= 3 Then SubmenuChar = pvArgs(3) Else SubmenuChar = &quot;&quot;
	If Not ScriptForge.SF_Utils._Validate(Event, &quot;Event&quot;, ScriptForge.V_OBJECT) Then GoTo Finally
	If Not ScriptForge.SF_Utils._Validate(X, &quot;X&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
	If Not ScriptForge.SF_Utils._Validate(Y, &quot;Y&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
	Set oMenu = Nothing

Try:
	Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
	Set oControl = Nothing
	If Not IsNull(Event) Then
		&apos;	Determine the X, Y coordinates
		vUno = Split(oSession.UnoObjectType(Event), &quot;.&quot;)
		sEventType = vUno(UBound(vUno))
		If UCase(sEventType) = &quot;MOUSEEVENT&quot; Then
			X = Event.X
			Y = Event.Y
			&apos;	Determine the window peer target
			If oSession.HasUnoProperty(Event, &quot;Source&quot;) Then Set oControl = Event.Source.Peer
		End If
	End If
	&apos;	If not a mouse event, if no control, ...
	If IsNull(oControl) Then
		If Not IsNull(ThisComponent) Then Set oControl = ThisComponent.CurrentController.Frame.getContainerWindow()
	End If

	If Not IsNull(oControl) Then
		Set oMenu = New SF_PopupMenu
		With oMenu
			Set .[Me] = oMenu
			._Initialize(oControl, X, Y, SubmenuChar)
		End With
	Else
		Set oMenu = Nothing
	End If

Finally:
	Set _NewPopupMenu = oMenu
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFWidgets.SF_Register._NewPopupMenu

REM ============================================== END OF SFWidgets.SF_REGISTER
</script:module>