Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / wizards / source / sfwidgets / SF_Register.xba
blobd2c4245131681d3e542209f0f26b7bb8e68cce7b
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_Register" 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 SFWidgets 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_Register
14 &apos;&apos;&apos; ===========
15 &apos;&apos;&apos; The ScriptForge framework includes
16 &apos;&apos;&apos; the master ScriptForge library
17 &apos;&apos;&apos; a number of &quot;associated&quot; libraries SF*
18 &apos;&apos;&apos; any user/contributor extension wanting to fit into the framework
19 &apos;&apos;&apos;
20 &apos;&apos;&apos; The main methods in this module allow the current library to cling to ScriptForge
21 &apos;&apos;&apos; - RegisterScriptServices
22 &apos;&apos;&apos; Register the list of services implemented by the current library
23 &apos;&apos;&apos; - _NewMenu
24 &apos;&apos;&apos; Create a new menu service instance.
25 &apos;&apos;&apos; Called from SFDocuments services with CreateMenu()
26 &apos;&apos;&apos; - _NewPopupMenu
27 &apos;&apos;&apos; Create a new popup menu service instance.
28 &apos;&apos;&apos; Called from CreateScriptService()
29 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
31 REM ================================================================== EXCEPTIONS
33 REM ================================================================= DEFINITIONS
35 REM ============================================================== PUBLIC METHODS
37 REM -----------------------------------------------------------------------------
38 Public Sub RegisterScriptServices() As Variant
39 &apos;&apos;&apos; Register into ScriptForge the list of the services implemented by the current library
40 &apos;&apos;&apos; Each library pertaining to the framework must implement its own version of this method
41 &apos;&apos;&apos;
42 &apos;&apos;&apos; It consists in successive calls to the RegisterService() and RegisterEventManager() methods
43 &apos;&apos;&apos; with 2 arguments:
44 &apos;&apos;&apos; ServiceName: the name of the service as a case-insensitive string
45 &apos;&apos;&apos; ServiceReference: the reference as an object
46 &apos;&apos;&apos; If the reference refers to a module, then return the module as an object:
47 &apos;&apos;&apos; GlobalScope.Library.Module
48 &apos;&apos;&apos; If the reference is a class instance, then return a string referring to the method
49 &apos;&apos;&apos; containing the New statement creating the instance
50 &apos;&apos;&apos; &quot;libraryname.modulename.function&quot;
52 With GlobalScope.ScriptForge.SF_Services
53 .RegisterService(&quot;Menu&quot;, &quot;SFWidgets.SF_Register._NewMenu&quot;) &apos; Reference to the function initializing the service
54 .RegisterService(&quot;PopupMenu&quot;, &quot;SFWidgets.SF_Register._NewPopupMenu&quot;) &apos; id.
55 .RegisterService(&quot;Toolbar&quot;, &quot;SFWidgets.SF_Register._NewToolbar&quot;) &apos; id.
56 .RegisterService(&quot;ToolbarButton&quot;, &quot;SFWidgets.SF_Register._NewToolbarButton&quot;) &apos; id.
57 End With
59 End Sub &apos; SFWidgets.SF_Register.RegisterScriptServices
61 REM =========================================================== PRIVATE FUNCTIONS
63 REM -----------------------------------------------------------------------------
64 Public Function _NewMenu(Optional ByVal pvArgs As Variant) As Object
65 &apos;&apos;&apos; Create a new instance of the SF_Menu class
66 &apos;&apos;&apos; [called internally from SFDocuments.Document.CreateMenu() ONLY]
67 &apos;&apos;&apos; Args:
68 &apos;&apos;&apos; Component: the com.sun.star.lang.XComponent where to find the menubar to plug the new menu in
69 &apos;&apos;&apos; Header: the name/header of the menu
70 &apos;&apos;&apos; Before: the place where to put the new menu on the menubar (string or number &gt;= 1)
71 &apos;&apos;&apos; When not found =&gt; last position
72 &apos;&apos;&apos; SubmenuChar: the delimiter used in menu trees. Default = &quot;&gt;&quot;
73 &apos;&apos;&apos; Returns: the instance or Nothing
75 Dim oMenu As Object &apos; Return value
76 Dim oComponent As Object &apos; The document or formdocument&apos;s component - com.sun.star.lang.XComponent
77 Dim sHeader As String &apos; Menu header
78 Dim sBefore As String &apos; Position of menu as a string
79 Dim iBefore As Integer &apos; as a number
80 Dim sSubmenuChar As String &apos; Delimiter in menu trees
82 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
83 Set oMenu = Nothing
85 Check:
86 &apos; Types and number of arguments are not checked because internal call only
87 Set oComponent = pvArgs(0)
88 sHeader = pvArgs(1)
89 Select Case VarType(pvArgs(2))
90 Case V_STRING : sBefore = pvArgs(2)
91 iBefore = 0
92 Case Else : sBefore = &quot;&quot;
93 iBefore = pvArgs(2)
94 End Select
95 sSubmenuChar = pvArgs(3)
97 Try:
98 If Not IsNull(oComponent) Then
99 Set oMenu = New SF_Menu
100 With oMenu
101 Set .[Me] = oMenu
102 ._Initialize(oComponent, sHeader, sBefore, iBefore, sSubmenuChar)
103 End With
104 End If
106 Finally:
107 Set _NewMenu = oMenu
108 Exit Function
109 Catch:
110 GoTo Finally
111 End Function &apos; SFWidgets.SF_Register._NewMenu
113 REM -----------------------------------------------------------------------------
114 Public Function _NewPopupMenu(Optional ByVal pvArgs As Variant) As Object
115 &apos;&apos;&apos; Create a new instance of the SF_PopupMenu class
116 &apos;&apos;&apos; Args:
117 &apos;&apos;&apos; Event: a mouse event
118 &apos;&apos;&apos; If the event has no source or is not a mouse event, the menu is displayed above the actual window
119 &apos;&apos;&apos; X, Y: forced coordinates
120 &apos;&apos;&apos; SubmenuChar: Delimiter used in menu trees
121 &apos;&apos;&apos; Returns: the instance or Nothing
123 Dim oMenu As Object &apos; Return value
124 Dim Event As Variant &apos; Mouse event
125 Dim X As Long &apos; Mouse click coordinates
126 Dim Y As Long
127 Dim SubmenuChar As String &apos; Delimiter in menu trees
128 Dim vUno As Variant &apos; UNO type split into an array
129 Dim sEventType As String &apos; Event type, must be &quot;MouseEvent&quot;
130 Dim oControl As Object &apos; The dialog or form control view which triggered the event
131 Dim oWindow As Object &apos; ui.Window type
132 Dim oSession As Object : Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;ScriptForge.Session&quot;)
133 Dim oUi As Object : Set oUi = ScriptForge.SF_Services.CreateScriptService(&quot;ScriptForge.UI&quot;)
135 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
136 Set oMenu = Nothing
138 Check:
139 &apos; Check and get arguments, their number may vary
140 If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
141 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
142 If UBound(pvArgs) &gt;= 0 Then Event = pvArgs(0) Else Event = Nothing
143 If IsEmpty(Event) Then Event = Nothing
144 If UBound(pvArgs) &gt;= 1 Then X = pvArgs(1) Else X = 0
145 If UBound(pvArgs) &gt;= 2 Then Y = pvArgs(2) Else Y = 0
146 If UBound(pvArgs) &gt;= 3 Then SubmenuChar = pvArgs(3) Else SubmenuChar = &quot;&quot;
147 If Not ScriptForge.SF_Utils._Validate(Event, &quot;Event&quot;, ScriptForge.V_OBJECT) Then GoTo Finally
148 If Not ScriptForge.SF_Utils._Validate(X, &quot;X&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
149 If Not ScriptForge.SF_Utils._Validate(Y, &quot;Y&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
150 If Not ScriptForge.SF_Utils._Validate(SubmenuChar, &quot;SubmenuChar&quot;, V_STRING) Then GoTo Finally
152 Try:
153 &apos; Find and identify the control that triggered the popup menu
154 Set oControl = Nothing
155 If Not IsNull(Event) Then
156 &apos; Determine the X, Y coordinates
157 vUno = Split(oSession.UnoObjectType(Event), &quot;.&quot;)
158 sEventType = vUno(UBound(vUno))
159 If UCase(sEventType) = &quot;MOUSEEVENT&quot; Then
160 X = Event.X
161 Y = Event.Y
162 &apos; Determine the window peer target
163 If oSession.HasUnoProperty(Event, &quot;Source&quot;) Then Set oControl = Event.Source.Peer
164 End If
165 End If
166 &apos; If not a mouse event, if no control, find what can be decent alternatives: (a menu header in) the actual window
167 If IsNull(oControl) Then
168 Set oWindow = oUi._IdentifyWindow(StarDesktop.getCurrentComponent()) &apos; A menu has been clicked necessarily in the current window
169 With oWindow
170 If Not IsNull(.Frame) Then Set oControl = .Frame.getContainerWindow()
171 End With
172 End If
174 If Not IsNull(oControl) Then
175 Set oMenu = New SF_PopupMenu
176 With oMenu
177 Set .[Me] = oMenu
178 ._Initialize(oControl, X, Y, SubmenuChar)
179 End With
180 Else
181 Set oMenu = Nothing
182 End If
184 Finally:
185 Set _NewPopupMenu = oMenu
186 Exit Function
187 Catch:
188 GoTo Finally
189 End Function &apos; SFWidgets.SF_Register._NewPopupMenu
191 REM -----------------------------------------------------------------------------
192 Public Function _NewToolbar(Optional ByVal pvArgs As Variant) As Object
193 &apos;&apos;&apos; Create a new instance of the SF_Toolbar class
194 &apos;&apos;&apos; The &quot;Toolbar&quot; service must not be invoked directly in a user script
195 &apos;&apos;&apos; Args:
196 &apos;&apos;&apos; ToolbarDesc: a proto-toolbar object type. See ScriptForge.SF_UI for a detailed description
197 &apos;&apos;&apos; Returns:
198 &apos;&apos;&apos; the instance or Nothing
200 Dim oToolbar As Object &apos; Return value
201 Dim oToolbarDesc As Object &apos; A proto-toolbar description
203 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
204 Set oToolbar = Nothing
206 Check:
207 Set oToolbarDesc = pvArgs(0)
209 Try:
210 Set oToolbar = New SF_Toolbar
211 With oToolbar
212 Set .[Me] = oToolbar
213 ._Initialize(oToolbarDesc)
214 End With
216 Finally:
217 Set _NewToolbar = oToolbar
218 Exit Function
219 Catch:
220 GoTo Finally
221 End Function &apos; SFWidgets.SF_Register._NewToolbar
223 REM -----------------------------------------------------------------------------
224 Public Function _NewToolbarButton(Optional ByVal pvArgs As Variant) As Object
225 &apos;&apos;&apos; Create a new instance of the SF_ToolbarButton class
226 &apos;&apos;&apos; The &quot;ToolbarButton&quot; service must not be invoked directly in a user script
227 &apos;&apos;&apos; Args:
228 &apos;&apos;&apos; ToolbarButtonDesc: a proto-toolbarButton object type. See SFWidgets.SF_Toolbar for a detailed description
229 &apos;&apos;&apos; Returns:
230 &apos;&apos;&apos; the instance or Nothing
232 Dim oToolbarButton As Object &apos; Return value
233 Dim oToolbarButtonDesc As Object &apos; A proto-toolbarbutton description
235 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
236 Set oToolbarButton = Nothing
238 Check:
239 Set oToolbarButtonDesc = pvArgs(0)
241 Try:
242 Set oToolbarButton = New SF_ToolbarButton
243 With oToolbarButton
244 Set .[Me] = oToolbarButton
245 ._Initialize(oToolbarButtonDesc)
246 End With
248 Finally:
249 Set _NewToolbarButton = oToolbarButton
250 Exit Function
251 Catch:
252 GoTo Finally
253 End Function &apos; SFWidgets.SF_Register._NewToolbarButton
256 REM ============================================== END OF SFWIDGETS.SF_REGISTER
257 </script:module>