nss: upgrade to release 3.73
[LibreOffice.git] / wizards / source / sfdocuments / SF_Register.xba
blob40f327bb0d41864965a40620de0cc1f3c15cb924
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 SFDocuments 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;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
25 REM ================================================================== EXCEPTIONS
27 REM ============================================================== PUBLIC METHODS
29 REM -----------------------------------------------------------------------------
30 Public Sub RegisterScriptServices() As Variant
31 &apos;&apos;&apos; Register into ScriptForge the list of the services implemented by the current library
32 &apos;&apos;&apos; Each library pertaining to the framework must implement its own version of this method
33 &apos;&apos;&apos;
34 &apos;&apos;&apos; It consists in successive calls to the RegisterService() and RegisterEventManager() methods
35 &apos;&apos;&apos; with 2 arguments:
36 &apos;&apos;&apos; ServiceName: the name of the service as a case-insensitive string
37 &apos;&apos;&apos; ServiceReference: the reference as an object
38 &apos;&apos;&apos; If the reference refers to a module, then return the module as an object:
39 &apos;&apos;&apos; GlobalScope.Library.Module
40 &apos;&apos;&apos; If the reference is a class instance, then return a string referring to the method
41 &apos;&apos;&apos; containing the New statement creating the instance
42 &apos;&apos;&apos; &quot;libraryname.modulename.function&quot;
44 With GlobalScope.ScriptForge.SF_Services
45 .RegisterService(&quot;Document&quot;, &quot;SFDocuments.SF_Register._NewDocument&quot;) &apos; Reference to the function initializing the service
46 .RegisterService(&quot;Calc&quot;, &quot;SFDocuments.SF_Register._NewDocument&quot;) &apos; Same references, distinction is made inside the function
47 .RegisterService(&quot;Base&quot;, &quot;SFDocuments.SF_Register._NewDocument&quot;) &apos; Same references, distinction is made inside the function
48 .RegisterEventManager(&quot;DocumentEvent&quot;, &quot;SFDocuments.SF_Register._EventManager&quot;) &apos; Reference to the events manager
49 &apos;TODO
50 End With
52 End Sub &apos; SFDocuments.SF_Register.RegisterScriptServices
54 REM =========================================================== PRIVATE FUNCTIONS
56 REM -----------------------------------------------------------------------------
57 Public Function _EventManager(Optional ByRef pvArgs As Variant) As Object
58 &apos;&apos;&apos; Returns a Document or Calc object corresponding with the active component
59 &apos;&apos;&apos; which triggered the event in argument
60 &apos;&apos;&apos; This method should be triggered only thru the invocation of CreateScriptService
61 &apos;&apos;&apos; Args:
62 &apos;&apos;&apos; pvEvent: com.sun.star.document.DocumentEvent
63 &apos;&apos;&apos; Returns:
64 &apos;&apos;&apos; the output of a Document, Calc, ... service or Nothing
65 &apos;&apos;&apos; Example:
66 &apos;&apos;&apos; Sub TriggeredByEvent(ByRef poEvent As Object)
67 &apos;&apos;&apos; Dim oDoc As Object
68 &apos;&apos;&apos; Set oDoc = CreateScriptService(&quot;SFDocuments.DocumentEvent&quot;, poEvent)
69 &apos;&apos;&apos; If Not IsNull(oDoc) Then
70 &apos;&apos;&apos; &apos; ... (a valid document has been identified)
71 &apos;&apos;&apos; End Sub
73 Dim oSource As Object &apos; Return value
74 Dim vEvent As Variant &apos; Alias of pvArgs(0)
76 &apos; Never abort while an event is processed
77 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Finally
78 Set oSource = Nothing
80 Check:
81 If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
82 If UBound(pvArgs) &gt;= 0 Then vEvent = pvArgs(0) Else Set vEvent = Empty
83 If VarType(vEvent) &lt;&gt; ScriptForge.V_OBJECT Then GoTo Finally
85 Try:
86 If ScriptForge.SF_Session.UnoObjectType(vEvent) = &quot;com.sun.star.document.DocumentEvent&quot; Then
87 If ScriptForge.SF_Session.UnoObjectType(vEvent.Source) = &quot;SwXTextDocument&quot; Then
88 Set oSource = SF_Register._NewDocument(vEvent.Source)
89 End If
90 End If
92 Finally:
93 Set _EventManager = oSource
94 Exit Function
95 End Function &apos; SFDocuments.SF_Documents._EventManager
97 REM -----------------------------------------------------------------------------
98 Public Function _NewDocument(Optional ByVal pvArgs As Variant) As Object
99 &apos;&apos;&apos; Create a new instance of the (super) SF_Document class or of one of its subclasses (SF_Calc, ...)
100 &apos; Args:
101 &apos;&apos;&apos; WindowName: see the definition of WindowName in the description of the UI service
102 &apos;&apos;&apos; If absent, the document is presumed to be in the active window
103 &apos;&apos;&apos; If WindowName is an object, it must be a component
104 &apos;&apos;&apos; (com.sun.star.lang.XComponent or com.sun.star.comp.dba.ODatabaseDocument)
105 &apos;&apos;&apos; Returns: the instance or Nothing
107 Dim oDocument As Object &apos; Return value
108 Dim oSuperDocument As Object &apos; Companion superclass document
109 Dim vWindowName As Variant &apos; Alias of pvArgs(0)
110 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
111 Dim oComp As Object &apos; com.sun.star.lang.XComponent
112 Dim vWindow As Window &apos; A single component
113 Dim oUi As Object &apos; &quot;UI&quot; service
114 Dim bFound As Boolean &apos; True if the document is found on the desktop
116 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
118 Check:
119 If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
120 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs) &apos; Needed when _NewDocument called from _EventManager
121 If UBound(pvArgs) &gt;= 0 Then vWindowName = pvArgs(0) Else vWindowName = &quot;&quot;
122 If Not ScriptForge.SF_Utils._Validate(vWindowName, &quot;WindowName&quot;, Array(V_STRING, ScriptForge.V_OBJECT)) Then GoTo Finally
123 Set oDocument = Nothing
125 Try:
126 Set oUi = ScriptForge.SF_Register.CreateScriptService(&quot;UI&quot;)
127 Select Case VarType(vWindowName)
128 Case V_STRING
129 If Len(vWindowName) &gt; 0 Then
130 bFound = False
131 Set oEnum = StarDesktop.Components().createEnumeration
132 Do While oEnum.hasMoreElements
133 Set oComp = oEnum.nextElement
134 vWindow = oUi._IdentifyWindow(oComp)
135 With vWindow
136 &apos; Does the current window match the argument ?
137 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = ScriptForge.SF_FileSystem._ConvertToUrl(vWindowName)) _
138 Or (Len(.WindowName) &gt; 0 And .WindowName = vWindowName) _
139 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = vWindowName) Then
140 bFound = True
141 Exit Do
142 End If
143 End With
144 Loop
145 Else
146 bFound = True
147 vWindow = oUi._IdentifyWindow(StarDesktop.CurrentComponent)
148 End If
149 Case ScriptForge.V_OBJECT &apos; com.sun.star.lang.XComponent
150 bFound = True
151 vWindow = oUi._IdentifyWindow(vWindowName)
152 End Select
154 If bFound And Not IsNull(vWindow.Frame) And Len(vWindow.DocumentType) &gt; 0 Then
155 &apos; Create the right subclass and associate to it a new instance of the superclass
156 Select Case vWindow.DocumentType
157 Case &quot;Base&quot;
158 Set oDocument = New SF_Base
159 Set oSuperDocument = New SF_Document
160 Set oDocument.[_Super] = oSuperDocument &apos; Now both super and subclass are twinned
161 Case &quot;Calc&quot;
162 Set oDocument = New SF_Calc
163 Set oSuperDocument = New SF_Document
164 Set oDocument.[_Super] = oSuperDocument &apos; Now both super and subclass are twinned
165 Case Else &apos; Only superclass
166 Set oDocument = New SF_Document
167 Set oSuperDocument = oDocument
168 End Select
169 With oDocument &apos; Initialize attributes of subclass
170 Set .[Me] = oDocument
171 Set ._Component = vWindow.Component
172 &apos; Initialize specific attributes
173 Select Case vWindow.DocumentType
174 Case &quot;Base&quot;
175 Set ._DataSource = ._Component.DataSource
176 Case Else
177 End Select
178 End With
179 With oSuperDocument &apos; Initialize attributes of superclass
180 Set .[Me] = oSuperDocument
181 Set ._Component = vWindow.Component
182 Set ._Frame = vWindow.Frame
183 ._WindowName = vWindow.WindowName
184 ._WindowTitle = vWindow.WindowTitle
185 ._WindowFileName = vWindow.WindowFileName
186 ._DocumentType = vWindow.DocumentType
187 End With
188 End If
190 Finally:
191 Set _NewDocument = oDocument
192 Exit Function
193 Catch:
194 GoTo Finally
195 End Function &apos; SFDocuments.SF_Register._NewDocument
197 REM ============================================== END OF SFDOCUMENTS.SF_REGISTER
198 </script:module>