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 CreateMenu()
26 ''' - _NewPopupMenu
27 ''' Create a new popup menu service instance.
28 ''' Called from CreateScriptService()
29 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
31 REM ================================================================== EXCEPTIONS
33 REM ================================================================= DEFINITIONS
35 REM ============================================================== PUBLIC METHODS
37 REM -----------------------------------------------------------------------------
38 Public Sub RegisterScriptServices() As Variant
39 ''' Register into ScriptForge the list of the services implemented by the current library
40 ''' Each library pertaining to the framework must implement its own version of this method
42 ''' It consists in successive calls to the RegisterService() and RegisterEventManager() methods
43 ''' with
2 arguments:
44 ''' ServiceName: the name of the service as a case-insensitive string
45 ''' ServiceReference: the reference as an object
46 ''' If the reference refers to a module, then return the module as an object:
47 ''' GlobalScope.Library.Module
48 ''' If the reference is a class instance, then return a string referring to the method
49 ''' containing the New statement creating the instance
50 ''' "libraryname.modulename.function
"
52 With GlobalScope.ScriptForge.SF_Services
53 .RegisterService(
"Menu
",
"SFWidgets.SF_Register._NewMenu
")
' Reference to the function initializing the service
54 .RegisterService(
"PopupMenu
",
"SFWidgets.SF_Register._NewPopupMenu
")
' id.
55 .RegisterService(
"Toolbar
",
"SFWidgets.SF_Register._NewToolbar
")
' id.
56 .RegisterService(
"ToolbarButton
",
"SFWidgets.SF_Register._NewToolbarButton
")
' id.
59 End Sub
' SFWidgets.SF_Register.RegisterScriptServices
61 REM =========================================================== PRIVATE FUNCTIONS
63 REM -----------------------------------------------------------------------------
64 Public Function _NewMenu(Optional ByVal pvArgs As Variant) As Object
65 ''' Create a new instance of the SF_Menu class
66 ''' [called internally from SFDocuments.Document.CreateMenu() ONLY]
67 ''' Args:
68 ''' Component: the com.sun.star.lang.XComponent where to find the menubar to plug the new menu in
69 ''' Header: the name/header of the menu
70 ''' Before: the place where to put the new menu on the menubar (string or number
>=
1)
71 ''' When not found =
> last position
72 ''' SubmenuChar: the delimiter used in menu trees. Default =
">"
73 ''' Returns: the instance or Nothing
75 Dim oMenu As Object
' Return value
76 Dim oComponent As Object
' The document or formdocument
's component - com.sun.star.lang.XComponent
77 Dim sHeader As String
' Menu header
78 Dim sBefore As String
' Position of menu as a string
79 Dim iBefore As Integer
' as a number
80 Dim sSubmenuChar As String
' Delimiter in menu trees
82 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
86 ' Types and number of arguments are not checked because internal call only
87 Set oComponent = pvArgs(
0)
89 Select Case VarType(pvArgs(
2))
90 Case V_STRING : sBefore = pvArgs(
2)
92 Case Else : sBefore =
""
95 sSubmenuChar = pvArgs(
3)
98 If Not IsNull(oComponent) Then
99 Set oMenu = New SF_Menu
102 ._Initialize(oComponent, sHeader, sBefore, iBefore, sSubmenuChar)
111 End Function
' SFWidgets.SF_Register._NewMenu
113 REM -----------------------------------------------------------------------------
114 Public Function _NewPopupMenu(Optional ByVal pvArgs As Variant) As Object
115 ''' Create a new instance of the SF_PopupMenu class
116 ''' Args:
117 ''' Event: a mouse event
118 ''' If the event has no source or is not a mouse event, the menu is displayed above the actual window
119 ''' X, Y: forced coordinates
120 ''' SubmenuChar: Delimiter used in menu trees
121 ''' Returns: the instance or Nothing
123 Dim oMenu As Object
' Return value
124 Dim Event As Variant
' Mouse event
125 Dim X As Long
' Mouse click coordinates
127 Dim SubmenuChar As String
' Delimiter in menu trees
128 Dim vUno As Variant
' UNO type split into an array
129 Dim sEventType As String
' Event type, must be
"MouseEvent
"
130 Dim oControl As Object
' The dialog or form control view which triggered the event
131 Dim oWindow As Object
' ui.Window type
132 Dim oSession As Object : Set oSession = ScriptForge.SF_Services.CreateScriptService(
"ScriptForge.Session
")
133 Dim oUi As Object : Set oUi = ScriptForge.SF_Services.CreateScriptService(
"ScriptForge.UI
")
135 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
139 ' 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)
>=
0 Then Event = pvArgs(
0) Else Event = Nothing
143 If IsEmpty(Event) Then Event = Nothing
144 If UBound(pvArgs)
>=
1 Then X = pvArgs(
1) Else X =
0
145 If UBound(pvArgs)
>=
2 Then Y = pvArgs(
2) Else Y =
0
146 If UBound(pvArgs)
>=
3 Then SubmenuChar = pvArgs(
3) Else SubmenuChar =
""
147 If Not ScriptForge.SF_Utils._Validate(Event,
"Event
", ScriptForge.V_OBJECT) Then GoTo Finally
148 If Not ScriptForge.SF_Utils._Validate(X,
"X
", ScriptForge.V_NUMERIC) Then GoTo Finally
149 If Not ScriptForge.SF_Utils._Validate(Y,
"Y
", ScriptForge.V_NUMERIC) Then GoTo Finally
150 If Not ScriptForge.SF_Utils._Validate(SubmenuChar,
"SubmenuChar
", V_STRING) Then GoTo Finally
153 ' Find and identify the control that triggered the popup menu
154 Set oControl = Nothing
155 If Not IsNull(Event) Then
156 ' Determine the X, Y coordinates
157 vUno = Split(oSession.UnoObjectType(Event),
".
")
158 sEventType = vUno(UBound(vUno))
159 If UCase(sEventType) =
"MOUSEEVENT
" Then
162 ' Determine the window peer target
163 If oSession.HasUnoProperty(Event,
"Source
") Then Set oControl = Event.Source.Peer
166 ' 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())
' A menu has been clicked necessarily in the current window
170 If Not IsNull(.Frame) Then Set oControl = .Frame.getContainerWindow()
174 If Not IsNull(oControl) Then
175 Set oMenu = New SF_PopupMenu
178 ._Initialize(oControl, X, Y, SubmenuChar)
185 Set _NewPopupMenu = oMenu
189 End Function
' SFWidgets.SF_Register._NewPopupMenu
191 REM -----------------------------------------------------------------------------
192 Public Function _NewToolbar(Optional ByVal pvArgs As Variant) As Object
193 ''' Create a new instance of the SF_Toolbar class
194 ''' The
"Toolbar
" service must not be invoked directly in a user script
195 ''' Args:
196 ''' ToolbarDesc: a proto-toolbar object type. See ScriptForge.SF_UI for a detailed description
197 ''' Returns:
198 ''' the instance or Nothing
200 Dim oToolbar As Object
' Return value
201 Dim oToolbarDesc As Object
' A proto-toolbar description
203 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
204 Set oToolbar = Nothing
207 Set oToolbarDesc = pvArgs(
0)
210 Set oToolbar = New SF_Toolbar
213 ._Initialize(oToolbarDesc)
217 Set _NewToolbar = oToolbar
221 End Function
' SFWidgets.SF_Register._NewToolbar
223 REM -----------------------------------------------------------------------------
224 Public Function _NewToolbarButton(Optional ByVal pvArgs As Variant) As Object
225 ''' Create a new instance of the SF_ToolbarButton class
226 ''' The
"ToolbarButton
" service must not be invoked directly in a user script
227 ''' Args:
228 ''' ToolbarButtonDesc: a proto-toolbarButton object type. See SFWidgets.SF_Toolbar for a detailed description
229 ''' Returns:
230 ''' the instance or Nothing
232 Dim oToolbarButton As Object
' Return value
233 Dim oToolbarButtonDesc As Object
' A proto-toolbarbutton description
235 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
236 Set oToolbarButton = Nothing
239 Set oToolbarButtonDesc = pvArgs(
0)
242 Set oToolbarButton = New SF_ToolbarButton
244 Set .[Me] = oToolbarButton
245 ._Initialize(oToolbarButtonDesc)
249 Set _NewToolbarButton = oToolbarButton
253 End Function
' SFWidgets.SF_Register._NewToolbarButton
256 REM ============================================== END OF SFWIDGETS.SF_REGISTER