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 =======================================================================================================================
12 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
13 ''' SF_Register
14 ''' ===========
15 ''' The ScriptForge framework includes
16 ''' the master ScriptForge library
17 ''' a number of
"associated
" libraries SF*
18 ''' any user/contributor extension wanting to fit into the framework
20 ''' The main methods in this module allow the current library to cling to ScriptForge
21 ''' - RegisterScriptServices
22 ''' Register the list of services implemented by the current library
23 ''' - _NewMenu
24 ''' Create a new menu service instance.
25 ''' Called from SFDocuments services with doc.CreateMenu(...)
26 ''' - _NewContextMenu
27 ''' Create a new context menu service instance.
28 ''' Called from SFDocuments services with doc.ContextMenus(...)
29 ''' - _NewPopupMenu
30 ''' Create a new popup menu service instance.
31 ''' Called from CreateScriptService(
"PopupMenu, ...)
32 ''' - _NewToolbar
33 ''' Create a new toolbar service instance.
34 ''' Called from SFDocuments services with doc.Toolbars(...)
35 ''' - _NewToolbarButton
36 ''' Create a new toolbarbutton service instance.
37 ''' Called from a Toolbar service with toolbar.ToolbarButtons(...)
38 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
40 REM ================================================================== EXCEPTIONS
42 REM ================================================================= DEFINITIONS
44 REM ============================================================== PUBLIC METHODS
46 REM -----------------------------------------------------------------------------
47 Public Sub RegisterScriptServices() As Variant
48 ''' Register into ScriptForge the list of the services implemented by the current library
49 ''' Each library pertaining to the framework must implement its own version of this method
51 ''' It consists in successive calls to the RegisterService() and RegisterEventManager() methods
52 ''' with
2 arguments:
53 ''' ServiceName: the name of the service as a case-insensitive string
54 ''' ServiceReference: the reference as an object
55 ''' If the reference refers to a module, then return the module as an object:
56 ''' GlobalScope.Library.Module
57 ''' If the reference is a class instance, then return a string referring to the method
58 ''' containing the New statement creating the instance
59 ''' "libraryname.modulename.function
"
61 With GlobalScope.ScriptForge.SF_Services
62 .RegisterService(
"Menu
",
"SFWidgets.SF_Register._NewMenu
")
' Reference to the function initializing the service
63 .RegisterService(
"ContextMenu
",
"SFWidgets.SF_Register._NewContextMenu
")
' id.
64 .RegisterService(
"PopupMenu
",
"SFWidgets.SF_Register._NewPopupMenu
")
' id.
65 .RegisterService(
"Toolbar
",
"SFWidgets.SF_Register._NewToolbar
")
' id.
66 .RegisterService(
"ToolbarButton
",
"SFWidgets.SF_Register._NewToolbarButton
")
' id.
69 End Sub
' SFWidgets.SF_Register.RegisterScriptServices
71 REM =========================================================== PRIVATE FUNCTIONS
73 REM -----------------------------------------------------------------------------
74 Public Function _NewContextMenu(Optional ByVal pvArgs As Variant) As Object
75 ''' Create a new instance of the SF_ContextMenu class
76 ''' Args:
77 ''' Component: the document
's Component requesting a context menu
78 ''' ContextMenuName: a private:resource/popupmenu/... reference
79 ''' SubmenuChar: Delimiter used in menu trees
80 ''' Returns: the instance or Nothing
82 Dim oMenu As Object
' Return value
83 Dim Component As Object
' The document
's component requesting a context menu
84 Dim ContextMenuName As String
' A
"private:resource/popupmenu/...
" reference
85 Dim SubmenuChar As String
' Delimiter in menu trees
87 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
91 ' Get arguments, their check has been done upstream
92 If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
93 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
94 If UBound(pvArgs)
>=
0 Then Set Component = pvArgs(
0) Else Set Component = Nothing
95 If UBound(pvArgs)
>=
1 Then ContextMenuName = pvArgs(
1) Else ContextMenuName =
""
96 If UBound(pvArgs)
>=
2 Then SubmenuChar = pvArgs(
2) Else SubmenuChar =
">"
99 If Not IsNull(Component) Then
100 Set oMenu = New SF_ContextMenu
103 ._Initialize(Component, ContextMenuName, SubmenuChar)
110 Set _NewContextMenu = oMenu
114 End Function
' SFWidgets.SF_Register._NewContextMenu
116 REM -----------------------------------------------------------------------------
117 Public Function _NewMenu(Optional ByVal pvArgs As Variant) As Object
118 ''' Create a new instance of the SF_Menu class
119 ''' [called internally from SFDocuments.Document.CreateMenu() ONLY]
120 ''' Args:
121 ''' Component: the com.sun.star.lang.XComponent where to find the menubar to plug the new menu in
122 ''' Header: the name/header of the menu
123 ''' Before: the place where to put the new menu on the menubar (string or number
>=
1)
124 ''' When not found =
> last position
125 ''' SubmenuChar: the delimiter used in menu trees. Default =
">"
126 ''' Returns: the instance or Nothing
128 Dim oMenu As Object
' Return value
129 Dim oComponent As Object
' The document or formdocument
's component - com.sun.star.lang.XComponent
130 Dim sHeader As String
' Menu header
131 Dim sBefore As String
' Position of menu as a string
132 Dim iBefore As Integer
' as a number
133 Dim sSubmenuChar As String
' Delimiter in menu trees
135 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
139 ' Types and number of arguments are not checked because internal call only
140 Set oComponent = pvArgs(
0)
142 Select Case VarType(pvArgs(
2))
143 Case V_STRING : sBefore = pvArgs(
2)
145 Case Else : sBefore =
""
148 sSubmenuChar = pvArgs(
3)
151 If Not IsNull(oComponent) Then
152 Set oMenu = New SF_Menu
155 ._Initialize(oComponent, sHeader, sBefore, iBefore, sSubmenuChar)
164 End Function
' SFWidgets.SF_Register._NewMenu
166 REM -----------------------------------------------------------------------------
167 Public Function _NewPopupMenu(Optional ByVal pvArgs As Variant) As Object
168 ''' Create a new instance of the SF_PopupMenu class
169 ''' Args:
170 ''' Event: a mouse event
171 ''' If the event has no source or is not a mouse event, the menu is displayed above the actual window
172 ''' X, Y: forced coordinates
173 ''' SubmenuChar: Delimiter used in menu trees
174 ''' Returns: the instance or Nothing
176 Dim oMenu As Object
' Return value
177 Dim Event As Variant
' Mouse event
178 Dim X As Long
' Mouse click coordinates
180 Dim SubmenuChar As String
' Delimiter in menu trees
181 Dim vUno As Variant
' UNO type split into an array
182 Dim sEventType As String
' Event type, must be
"MouseEvent
"
183 Dim oControl As Object
' The dialog or form control view which triggered the event
184 Dim oWindow As Object
' ui.Window type
185 Dim oSession As Object : Set oSession = ScriptForge.SF_Services.CreateScriptService(
"ScriptForge.Session
")
186 Dim oUi As Object : Set oUi = ScriptForge.SF_Services.CreateScriptService(
"ScriptForge.UI
")
188 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
192 ' Check and get arguments, their number may vary
193 If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
194 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
195 If UBound(pvArgs)
>=
0 Then Event = pvArgs(
0) Else Event = Nothing
196 If IsEmpty(Event) Then Event = Nothing
197 If UBound(pvArgs)
>=
1 Then X = pvArgs(
1) Else X =
0
198 If UBound(pvArgs)
>=
2 Then Y = pvArgs(
2) Else Y =
0
199 If UBound(pvArgs)
>=
3 Then SubmenuChar = pvArgs(
3) Else SubmenuChar =
""
200 If Not ScriptForge.SF_Utils._Validate(Event,
"Event
", ScriptForge.V_OBJECT) Then GoTo Finally
201 If Not ScriptForge.SF_Utils._Validate(X,
"X
", ScriptForge.V_NUMERIC) Then GoTo Finally
202 If Not ScriptForge.SF_Utils._Validate(Y,
"Y
", ScriptForge.V_NUMERIC) Then GoTo Finally
203 If Not ScriptForge.SF_Utils._Validate(SubmenuChar,
"SubmenuChar
", V_STRING) Then GoTo Finally
206 ' Find and identify the control that triggered the popup menu
207 Set oControl = Nothing
208 If Not IsNull(Event) Then
209 ' Determine the X, Y coordinates
210 vUno = Split(oSession.UnoObjectType(Event),
".
")
211 sEventType = vUno(UBound(vUno))
212 If UCase(sEventType) =
"MOUSEEVENT
" Then
215 ' Determine the window peer target
216 If oSession.HasUnoProperty(Event,
"Source
") Then Set oControl = Event.Source.Peer
219 ' If not a mouse event, if no control, find what can be decent alternatives: (a menu header in) the actual window
220 If IsNull(oControl) Then
221 Set oWindow = oUi._IdentifyWindow(StarDesktop.getCurrentComponent())
' A menu has been clicked necessarily in the current window
223 If Not IsNull(.Frame) Then Set oControl = .Frame.getContainerWindow()
227 If Not IsNull(oControl) Then
228 Set oMenu = New SF_PopupMenu
231 ._Initialize(oControl, X, Y, SubmenuChar)
238 Set _NewPopupMenu = oMenu
242 End Function
' SFWidgets.SF_Register._NewPopupMenu
244 REM -----------------------------------------------------------------------------
245 Public Function _NewToolbar(Optional ByVal pvArgs As Variant) As Object
246 ''' Create a new instance of the SF_Toolbar class
247 ''' The
"Toolbar
" service must not be invoked directly in a user script
248 ''' Args:
249 ''' ToolbarDesc: a proto-toolbar object type. See ScriptForge.SF_UI for a detailed description
250 ''' Returns:
251 ''' the instance or Nothing
253 Dim oToolbar As Object
' Return value
254 Dim oToolbarDesc As Object
' A proto-toolbar description
256 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
257 Set oToolbar = Nothing
260 Set oToolbarDesc = pvArgs(
0)
263 Set oToolbar = New SF_Toolbar
266 ._Initialize(oToolbarDesc)
270 Set _NewToolbar = oToolbar
274 End Function
' SFWidgets.SF_Register._NewToolbar
276 REM -----------------------------------------------------------------------------
277 Public Function _NewToolbarButton(Optional ByVal pvArgs As Variant) As Object
278 ''' Create a new instance of the SF_ToolbarButton class
279 ''' The
"ToolbarButton
" service must not be invoked directly in a user script
280 ''' Args:
281 ''' ToolbarButtonDesc: a proto-toolbarButton object type. See SFWidgets.SF_Toolbar for a detailed description
282 ''' Returns:
283 ''' the instance or Nothing
285 Dim oToolbarButton As Object
' Return value
286 Dim oToolbarButtonDesc As Object
' A proto-toolbarbutton description
288 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
289 Set oToolbarButton = Nothing
292 Set oToolbarButtonDesc = pvArgs(
0)
295 Set oToolbarButton = New SF_ToolbarButton
297 Set .[Me] = oToolbarButton
298 ._Initialize(oToolbarButtonDesc)
302 Set _NewToolbarButton = oToolbarButton
306 End Function
' SFWidgets.SF_Register._NewToolbarButton
309 REM ============================================== END OF SFWIDGETS.SF_REGISTER