nss: upgrade to release 3.73
[LibreOffice.git] / wizards / source / scriptforge / SF_UI.xba
blobca6bf79e40ab859915232566b8a905a217c80d8b
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_UI" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === Full documentation is available on https://help.libreoffice.org/ ===
6 REM =======================================================================================================================
8 Option Compatible
9 Option Explicit
11 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
12 &apos;&apos;&apos; SF_UI
13 &apos;&apos;&apos; =====
14 &apos;&apos;&apos; Singleton class module for the identification and the manipulation of the
15 &apos;&apos;&apos; different windows composing the whole LibreOffice application:
16 &apos;&apos;&apos; - Windows selection
17 &apos;&apos;&apos; - Windows moving and resizing
18 &apos;&apos;&apos; - Statusbar settings
19 &apos;&apos;&apos; - Creation of new windows
20 &apos;&apos;&apos; - Access to the underlying &quot;documents&quot;
21 &apos;&apos;&apos;
22 &apos;&apos;&apos; WindowName: how to designate a window. It can be either
23 &apos;&apos;&apos; a full FileName given in the notation indicated by the current value of SF_FileSystem.FileNaming
24 &apos;&apos;&apos; or the last component of the full FileName or even only its BaseName
25 &apos;&apos;&apos; or the title of the window
26 &apos;&apos;&apos; or, for new documents, something like &quot;Untitled 1&quot;
27 &apos;&apos;&apos; or one of the special windows &quot;BASICIDE&quot; and &quot;WELCOMESCREEN&quot;
28 &apos;&apos;&apos; The window search is case-sensitive
29 &apos;&apos;&apos;
30 &apos;&apos;&apos; Service invocation example:
31 &apos;&apos;&apos; Dim ui As Variant
32 &apos;&apos;&apos; ui = CreateScriptService(&quot;UI&quot;)
34 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
36 REM ================================================================== EXCEPTIONS
38 Const DOCUMENTERROR = &quot;DOCUMENTERROR&quot; &apos; Requested document was not found
39 Const DOCUMENTCREATIONERROR = &quot;DOCUMENTCREATIONERROR&quot; &apos; Incoherent arguments, new document could not be created
40 Const DOCUMENTOPENERROR = &quot;DOCUMENTOPENERROR&quot; &apos; Document could not be opened, check the arguments
41 Const BASEDOCUMENTOPENERROR = &quot;BASEDOCUMENTOPENERROR&quot; &apos; Id. for Base document
43 REM ============================================================= PRIVATE MEMBERS
45 Type Window
46 Component As Object &apos; com.sun.star.lang.XComponent
47 Frame As Object &apos; com.sun.star.comp.framework.Frame
48 WindowName As String &apos; Object Name
49 WindowTitle As String &apos; Only mean to identify new documents
50 WindowFileName As String &apos; URL of file name
51 DocumentType As String &apos; Writer, Calc, ...
52 End Type
54 &apos; The progress/status bar of the active window
55 &apos;Private oStatusBar As Object &apos; com.sun.star.task.XStatusIndicator
57 REM ============================================================ MODULE CONSTANTS
59 &apos; Special windows
60 Const BASICIDE = &quot;BASICIDE&quot;
61 Const WELCOMESCREEN = &quot;WELCOMESCREEN&quot;
63 &apos; Document types (only if not 1 of the special windows)
64 Const BASEDOCUMENT = &quot;Base&quot;
65 Const CALCDOCUMENT = &quot;Calc&quot;
66 Const DRAWDOCUMENT = &quot;Draw&quot;
67 Const IMPRESSDOCUMENT = &quot;Impress&quot;
68 Const MATHDOCUMENT = &quot;Math&quot;
69 Const WRITERDOCUMENT = &quot;Writer&quot;
71 &apos; Window subtypes - Not supported yet
72 Const BASETABLE = &quot;BASETABLE&quot;
73 Const BASEQUERY = &quot;BASEQUERY&quot;
74 Const BASEREPORT = &quot;BASEREPORT&quot;
75 Const BASEDIAGRAM = &quot;BASEDIAGRAM&quot;
77 &apos; Macro execution modes
78 Const cstMACROEXECNORMAL = 0 &apos; Default, execution depends on user configuration and choice
79 Const cstMACROEXECNEVER = 1 &apos; Macros are not executed
80 Const cstMACROEXECALWAYS = 2 &apos; Macros are always executed
82 REM ===================================================== CONSTRUCTOR/DESTRUCTOR
84 REM -----------------------------------------------------------------------------
85 Public Function Dispose() As Variant
86 Set Dispose = Nothing
87 End Function &apos; ScriptForge.SF_UI Explicit destructor
89 REM ================================================================== PROPERTIES
91 REM -----------------------------------------------------------------------------
92 Public Function ActiveWindow() As String
93 &apos;&apos;&apos; Returns a valid WindowName for the currently active window
94 &apos;&apos;&apos; When &quot;&quot; is returned, the window could not be identified
96 Dim vWindow As Window &apos; A component
97 Dim oComp As Object &apos; com.sun.star.lang.XComponent
99 Set oComp = StarDesktop.CurrentComponent
100 If Not IsNull(oComp) Then
101 vWindow = SF_UI._IdentifyWindow(oComp)
102 With vWindow
103 If Len(.WindowFileName) &gt; 0 Then
104 ActiveWindow = SF_FileSystem._ConvertFromUrl(.WindowFileName)
105 ElseIf Len(.WindowName) &gt; 0 Then
106 ActiveWindow = .WindowName
107 ElseIf Len(.WindowTitle) &gt; 0 Then
108 ActiveWindow = .WindowTitle
109 Else
110 ActiveWindow = &quot;&quot;
111 End If
112 End With
113 End If
115 End Function &apos; ScriptForge.SF_UI.ActiveWindow
117 REM -----------------------------------------------------------------------------
118 Property Get MACROEXECALWAYS As Integer
119 &apos;&apos;&apos; Macros are always executed
120 MACROEXECALWAYS = cstMACROEXECALWAYS
121 End Property &apos; ScriptForge.SF_UI.MACROEXECALWAYS
123 REM -----------------------------------------------------------------------------
124 Property Get MACROEXECNEVER As Integer
125 &apos;&apos;&apos; Macros are not executed
126 MACROEXECNEVER = cstMACROEXECNEVER
127 End Property &apos; ScriptForge.SF_UI.MACROEXECNEVER
129 REM -----------------------------------------------------------------------------
130 Property Get MACROEXECNORMAL As Integer
131 &apos;&apos;&apos; Default, execution depends on user configuration and choice
132 MACROEXECNORMAL = cstMACROEXECNORMAL
133 End Property &apos; ScriptForge.SF_UI.MACROEXECNORMAL
135 REM -----------------------------------------------------------------------------
136 Property Get ObjectType As String
137 &apos;&apos;&apos; Only to enable object representation
138 ObjectType = &quot;SF_UI&quot;
139 End Property &apos; ScriptForge.SF_UI.ObjectType
141 REM ===================================================================== METHODS
143 REM -----------------------------------------------------------------------------
144 Public Function Activate(Optional ByVal WindowName As Variant) As Boolean
145 &apos;&apos;&apos; Make the specified window active
146 &apos;&apos;&apos; Args:
147 &apos;&apos;&apos; WindowName: see definitions
148 &apos;&apos;&apos; Returns:
149 &apos;&apos;&apos; True if the given window is found and can be activated
150 &apos;&apos;&apos; There is no change in the actual user interface if no window matches the selection
151 &apos;&apos;&apos; Examples:
152 &apos;&apos;&apos; ui.Activate(&quot;C:\Me\My file.odt&quot;)
154 Dim bActivate As Boolean &apos; Return value
155 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
156 Dim oComp As Object &apos; com.sun.star.lang.XComponent
157 Dim vWindow As Window &apos; A single component
158 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
159 Const cstThisSub = &quot;UI.Activate&quot;
160 Const cstSubArgs = &quot;WindowName&quot;
162 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
163 bActivate = False
165 Check:
166 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
167 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
168 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;) Then GoTo Finally
169 End If
171 Try:
172 Set oEnum = StarDesktop.Components().createEnumeration
173 Do While oEnum.hasMoreElements
174 Set oComp = oEnum.nextElement
175 vWindow = SF_UI._IdentifyWindow(oComp)
176 With vWindow
177 &apos; Does the current window match the arguments ?
178 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem._ConvertToUrl(WindowName)) _
179 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
180 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then
181 Set oContainer = vWindow.Frame.ContainerWindow
182 With oContainer
183 If .isVisible() = False Then .setVisible(True)
184 .IsMinimized = False
185 .setFocus()
186 .toFront() &apos; Force window change in Linux
187 Wait 1 &apos; Bypass desynchro issue in Linux
188 End With
189 bActivate = True
190 Exit Do
191 End If
192 End With
193 Loop
195 Finally:
196 Activate = bActivate
197 SF_Utils._ExitFunction(cstThisSub)
198 Exit Function
199 Catch:
200 GoTo Finally
201 End Function &apos; ScriptForge.SF_UI.Activate
203 REM -----------------------------------------------------------------------------
204 Public Function CreateBaseDocument(Optional ByVal FileName As Variant _
205 , Optional ByVal EmbeddedDatabase As Variant _
206 , Optional ByVal RegistrationName As Variant _
207 ) As Object
208 &apos;&apos;&apos; Create a new LibreOffice Base document embedding an empty database of the given type
209 &apos;&apos;&apos; Args:
210 &apos;&apos;&apos; FileName: Identifies the file to create. It must follow the SF_FileSystem.FileNaming notation
211 &apos;&apos;&apos; If the file already exists, it is overwritten without warning
212 &apos;&apos;&apos; EmbeddedDatabase: either &quot;HSQLDB&quot; (default) or &quot;FIREBIRD&quot;
213 &apos;&apos;&apos; RegistrationName: the name used to store the new database in the databases register
214 &apos;&apos;&apos; If &quot;&quot; (default), no registration takes place
215 &apos;&apos;&apos; If the name already exists it is overwritten without warning
216 &apos;&apos;&apos; Returns:
217 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
218 &apos;&apos;&apos; Examples:
219 &apos;&apos;&apos; Dim myBase As Object
220 &apos;&apos;&apos; Set myBase = ui.CreateBaseDocument(&quot;C:\Databases\MyBaseFile.odb&quot;, &quot;FIREBIRD&quot;)
222 Dim oCreate As Variant &apos; Return value
223 Dim oDBContext As Object &apos; com.sun.star.sdb.DatabaseContext
224 Dim oDatabase As Object &apos; com.sun.star.comp.dba.ODatabaseSource
225 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
226 Dim sFileName As String &apos; Alias of FileName
227 Dim FSO As Object &apos; Alias for FileSystem service
228 Const cstDocType = &quot;private:factory/s&quot;
229 Const cstThisSub = &quot;UI.CreateBaseDocument&quot;
230 Const cstSubArgs = &quot;FileName, [EmbeddedDatabase=&quot;&quot;HSQLDB&quot;&quot;|&quot;&quot;FIREBIRD&quot;&quot;], [RegistrationName=&quot;&quot;&quot;&quot;]&quot;
232 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
233 Set oCreate = Nothing
235 Check:
236 If IsMissing(EmbeddedDatabase) Or IsEmpty(EmbeddedDatabase) Then EmbeddedDatabase = &quot;HSQLDB&quot;
237 If IsMissing(RegistrationName) Or IsEmpty(RegistrationName) Then RegistrationName = &quot;&quot;
238 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
239 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
240 If Not SF_Utils._Validate(EmbeddedDatabase, &quot;EmbeddedDatabase&quot;, V_STRING, Array(&quot;HSQLDB&quot;, &quot;FIREBIRD&quot;)) Then GoTo Finally
241 If Not SF_Utils._Validate(RegistrationName, &quot;RegistrationName&quot;, V_STRING) Then GoTo Finally
242 End If
244 Try:
245 Set oDBContext = SF_Utils._GetUNOService(&quot;DatabaseContext&quot;)
246 With oDBContext
247 Set oDatabase = .createInstance()
248 oDatabase.URL = &quot;sdbc:embedded:&quot; &amp; LCase(EmbeddedDatabase)
249 &apos; Create empty Base document
250 Set FSO = CreateScriptService(&quot;FileSystem&quot;)
251 sFileName = FSO._ConvertToUrl(FileName)
252 &apos; An existing file is overwritten without warning
253 If FSO.FileExists(FileName) Then FSO.DeleteFile(FileName)
254 If FSO.FileExists(FileName &amp; &quot;.lck&quot;) Then FSO.DeleteFile(FileName &amp; &quot;.lck&quot;)
255 oDatabase.DatabaseDocument.storeAsURL(sFileName, Array(SF_Utils._MakePropertyValue(&quot;Overwrite&quot;, True)))
256 &apos; Register database if requested
257 If Len(RegistrationName) &gt; 0 Then
258 If .hasRegisteredDatabase(RegistrationName) Then
259 .changeDatabaseLocation(RegistrationName, sFileName)
260 Else
261 .registerDatabaseLocation(RegistrationName, sFileName)
262 End If
263 End If
264 End With
266 Set oCreate = OpenBaseDocument(FileName)
268 Finally:
269 Set CreateBaseDocument = oCreate
270 SF_Utils._ExitFunction(cstThisSub)
271 Exit Function
272 Catch:
273 GoTo Finally
274 End Function &apos; ScriptForge.SF_UI.CreateBaseDocument
276 REM -----------------------------------------------------------------------------
277 Public Function CreateDocument(Optional ByVal DocumentType As Variant _
278 , Optional ByVal TemplateFile As Variant _
279 , Optional ByVal Hidden As Variant _
280 ) As Object
281 &apos;&apos;&apos; Create a new LibreOffice document of a given type or based on a given template
282 &apos;&apos;&apos; Args:
283 &apos;&apos;&apos; DocumentType: &quot;Calc&quot;, &quot;Writer&quot;, etc. If absent, a TemplateFile must be given
284 &apos;&apos;&apos; TemplateFile: the full FileName of the template to build the new document on
285 &apos;&apos;&apos; If the file does not exist, the argument is ignored
286 &apos;&apos;&apos; The &quot;FileSystem&quot; service provides the TemplatesFolder and UserTemplatesFolder
287 &apos;&apos;&apos; properties to help to build the argument
288 &apos;&apos;&apos; Hidden: if True, open in the background (default = False)
289 &apos;&apos;&apos; To use with caution: activation or closure can only happen programmatically
290 &apos;&apos;&apos; Returns:
291 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
292 &apos;&apos;&apos; Exceptions:
293 &apos;&apos;&apos; DOCUMENTCREATIONERROR Wrong arguments
294 &apos;&apos;&apos; Examples:
295 &apos;&apos;&apos; Dim myDoc1 As Object, myDoc2 As Object, FSO As Object
296 &apos;&apos;&apos; Set myDoc1 = ui.CreateDocument(&quot;Calc&quot;)
297 &apos;&apos;&apos; Set FSO = CreateScriptService(&quot;FileSystem&quot;)
298 &apos;&apos;&apos; Set myDoc2 = ui.CreateDocument(, FSO.BuildPath(FSO.TemplatesFolder, &quot;personal/CV.ott&quot;))
300 Dim oCreate As Variant &apos; Return value
301 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
302 Dim bTemplateExists As Boolean &apos; True if TemplateFile is valid
303 Dim sNew As String &apos; File url
304 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
305 Const cstDocType = &quot;private:factory/s&quot;
306 Const cstThisSub = &quot;UI.CreateDocument&quot;
307 Const cstSubArgs = &quot;[DocumentType=&quot;&quot;&quot;&quot;], [TemplateFile=&quot;&quot;&quot;&quot;], [Hidden=False]&quot;
309 &apos;&gt;&gt;&gt; If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
310 Set oCreate = Nothing
312 Check:
313 If IsMissing(DocumentType) Or IsEmpty(DocumentType) Then DocumentType = &quot;&quot;
314 If IsMissing(TemplateFile) Or IsEmpty(TemplateFile) Then TemplateFile = &quot;&quot;
315 If IsMissing(Hidden) Or IsEmpty(Hidden) Then Hidden = False
317 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
318 If Not SF_Utils._Validate(DocumentType, &quot;DocumentType&quot;, V_STRING _
319 , Array(&quot;&quot;, BASEDOCUMENT, CALCDOCUMENT, DRAWDOCUMENT _
320 , IMPRESSDOCUMENT, MATHDOCUMENT, WRITERDOCUMENT)) Then GoTo Finally
321 If Not SF_Utils._ValidateFile(TemplateFile, &quot;TemplateFile&quot;, , True) Then GoTo Finally
322 If Not SF_Utils._Validate(Hidden, &quot;Hidden&quot;, V_BOOLEAN) Then GoTo Finally
323 End If
325 If Len(DocumentType) + Len(TemplateFile) = 0 Then GoTo CatchError
326 If Len(TemplateFile) &gt; 0 Then bTemplateExists = SF_FileSystem.FileExists(TemplateFile) Else bTemplateExists = False
327 If Len(DocumentType) = 0 Then
328 If Not bTemplateExists Then GoTo CatchError
329 End If
331 Try:
332 If bTemplateExists Then sNew = SF_FileSystem._ConvertToUrl(TemplateFile) Else sNew = cstDocType &amp; LCase(DocumentType)
333 vProperties = Array( _
334 SF_Utils._MakePropertyValue(&quot;AsTemplate&quot;, bTemplateExists) _
335 , SF_Utils._MakePropertyValue(&quot;Hidden&quot;, Hidden) _
337 Set oComp = StarDesktop.loadComponentFromURL(sNew, &quot;_blank&quot;, 0, vProperties)
338 If Not IsNull(oComp) Then Set oCreate = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
340 Finally:
341 Set CreateDocument = oCreate
342 SF_Utils._ExitFunction(cstThisSub)
343 Exit Function
344 Catch:
345 GoTo Finally
346 CatchError:
347 SF_Exception.RaiseFatal(DOCUMENTCREATIONERROR, &quot;DocumentType&quot;, DocumentType, &quot;TemplateFile&quot;, TemplateFile)
348 GoTo Finally
349 End Function &apos; ScriptForge.SF_UI.CreateDocument
351 REM -----------------------------------------------------------------------------
352 Public Function Documents() As Variant
353 &apos;&apos;&apos; Returns the list of the currently open documents. Special windows are ignored.
354 &apos;&apos;&apos; Returns:
355 &apos;&apos;&apos; A zero-based 1D array of filenames (in SF_FileSystem.FileNaming notation)
356 &apos;&apos;&apos; or of window titles for unsaved documents
357 &apos;&apos;&apos; Examples:
358 &apos;&apos;&apos; Dim vDocs As Variant, sDoc As String
359 &apos;&apos;&apos; vDocs = ui.Documents()
360 &apos;&apos;&apos; For each sDoc In vDocs
361 &apos;&apos;&apos; ...
363 Dim vDocuments As Variant &apos; Return value
364 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
365 Dim oComp As Object &apos; com.sun.star.lang.XComponent
366 Dim vWindow As Window &apos; A single component
367 Const cstThisSub = &quot;UI.Documents&quot;
368 Const cstSubArgs = &quot;&quot;
370 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
371 vDocuments = Array()
373 Check:
374 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
376 Try:
377 Set oEnum = StarDesktop.Components().createEnumeration
378 Do While oEnum.hasMoreElements
379 Set oComp = oEnum.nextElement
380 vWindow = SF_UI._IdentifyWindow(oComp)
381 With vWindow
382 If Len(.WindowFileName) &gt; 0 Then
383 vDocuments = SF_Array.Append(vDocuments, SF_FileSystem._ConvertFromUrl(.WindowFileName))
384 ElseIf Len(.WindowTitle) &gt; 0 Then
385 vDocuments = SF_Array.Append(vDocuments, .WindowTitle)
386 End If
387 End With
388 Loop
390 Finally:
391 Documents = vDocuments
392 SF_Utils._ExitFunction(cstThisSub)
393 Exit Function
394 Catch:
395 GoTo Finally
396 End Function &apos; ScriptForge.SF_UI.Documents
398 REM -----------------------------------------------------------------------------
399 Public Function GetDocument(Optional ByVal WindowName As Variant) As Variant
400 &apos;&apos;&apos; Returns a SFDocuments.Document object referring to the active window or the given window
401 &apos;&apos;&apos; Args:
402 &apos;&apos;&apos; WindowName: see definitions. If absent the active window is considered
403 &apos;&apos;&apos; Exceptions:
404 &apos;&apos;&apos; DOCUMENTERROR The targeted window could not be found
405 &apos;&apos;&apos; Examples:
406 &apos;&apos;&apos; Dim oDoc As Object
407 &apos;&apos;&apos; Set oDoc = ui.GetDocument
408 &apos;&apos;&apos; oDoc.Save()
410 Dim oDocument As Object &apos; Return value
411 Const cstThisSub = &quot;UI.GetDocument&quot;
412 Const cstSubArgs = &quot;[WindowName]&quot;
414 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
415 Set oDocument = Nothing
417 Check:
418 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
419 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
420 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
421 End If
423 Try:
424 Set oDocument = SF_Services.CreateScriptService(&quot;SFDocuments.Document&quot;, WindowName)
425 If IsNull(oDocument) Then GoTo CatchDeliver
427 Finally:
428 Set GetDocument = oDocument
429 SF_Utils._ExitFunction(cstThisSub)
430 Exit Function
431 Catch:
432 GoTo Finally
433 CatchDeliver:
434 SF_Exception.RaiseFatal(DOCUMENTERROR, &quot;WindowName&quot;, WindowName)
435 GoTo Finally
436 End Function &apos; ScriptForge.SF_UI.GetDocument
438 REM -----------------------------------------------------------------------------
439 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
440 &apos;&apos;&apos; Return the actual value of the given property
441 &apos;&apos;&apos; Args:
442 &apos;&apos;&apos; PropertyName: the name of the property as a string
443 &apos;&apos;&apos; Returns:
444 &apos;&apos;&apos; The actual value of the property
445 &apos;&apos;&apos; Exceptions
446 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
448 Const cstThisSub = &quot;UI.GetProperty&quot;
449 Const cstSubArgs = &quot;PropertyName&quot;
451 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
452 GetProperty = Null
454 Check:
455 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
456 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
457 End If
459 Try:
460 Select Case UCase(PropertyName)
461 Case &quot;ACTIVEWINDOW&quot; : GetProperty = ActiveWindow()
462 Case Else
463 End Select
465 Finally:
466 SF_Utils._ExitFunction(cstThisSub)
467 Exit Function
468 Catch:
469 GoTo Finally
470 End Function &apos; ScriptForge.SF_UI.GetProperty
472 REM -----------------------------------------------------------------------------
473 Public Sub Maximize(Optional ByVal WindowName As Variant)
474 &apos;&apos;&apos; Maximizes the active window or the given window
475 &apos;&apos;&apos; Args:
476 &apos;&apos;&apos; WindowName: see definitions. If absent the active window is considered
477 &apos;&apos;&apos; Examples:
478 &apos;&apos;&apos; ui.Maximize
479 &apos;&apos;&apos; ...
481 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
482 Dim oComp As Object &apos; com.sun.star.lang.XComponent
483 Dim vWindow As Window &apos; A single component
484 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
485 Dim bFound As Boolean &apos; True if window found
486 Const cstThisSub = &quot;UI.Maximize&quot;
487 Const cstSubArgs = &quot;[WindowName]&quot;
489 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
491 Check:
492 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
493 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
494 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
495 End If
497 Try:
498 bFound = False
499 If Len(WindowName) &gt; 0 Then
500 Set oEnum = StarDesktop.Components().createEnumeration
501 Do While oEnum.hasMoreElements And Not bFound
502 Set oComp = oEnum.nextElement
503 vWindow = SF_UI._IdentifyWindow(oComp)
504 With vWindow
505 &apos; Does the current window match the arguments ?
506 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
507 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
508 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then bFound = True
509 End With
510 Loop
511 Else
512 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
513 bFound = True
514 End If
516 If bFound Then
517 Set oContainer = vWindow.Frame.ContainerWindow
518 oContainer.IsMaximized = True
519 End If
521 Finally:
522 SF_Utils._ExitFunction(cstThisSub)
523 Exit Sub
524 Catch:
525 GoTo Finally
526 End Sub &apos; ScriptForge.SF_UI.Maximize
528 REM -----------------------------------------------------------------------------
529 Public Sub Minimize(Optional ByVal WindowName As Variant)
530 &apos;&apos;&apos; Minimizes the current window or the given window
531 &apos;&apos;&apos; Args:
532 &apos;&apos;&apos; WindowName: see definitions. If absent the current window is considered
533 &apos;&apos;&apos; Examples:
534 &apos;&apos;&apos; ui.Minimize(&quot;myFile.ods&quot;)
535 &apos;&apos;&apos; ...
537 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
538 Dim oComp As Object &apos; com.sun.star.lang.XComponent
539 Dim vWindow As Window &apos; A single component
540 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
541 Dim bFound As Boolean &apos; True if window found
542 Const cstThisSub = &quot;UI.Minimize&quot;
543 Const cstSubArgs = &quot;[WindowName]&quot;
545 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
547 Check:
548 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
549 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
550 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
551 End If
553 Try:
554 bFound = False
555 If Len(WindowName) &gt; 0 Then
556 Set oEnum = StarDesktop.Components().createEnumeration
557 Do While oEnum.hasMoreElements And Not bFound
558 Set oComp = oEnum.nextElement
559 vWindow = SF_UI._IdentifyWindow(oComp)
560 With vWindow
561 &apos; Does the current window match the arguments ?
562 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
563 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
564 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then bFound = True
565 End With
566 Loop
567 Else
568 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
569 bFound = True
570 End If
572 If bFound Then
573 Set oContainer = vWindow.Frame.ContainerWindow
574 oContainer.IsMinimized = True
575 End If
577 Finally:
578 SF_Utils._ExitFunction(cstThisSub)
579 Exit Sub
580 Catch:
581 GoTo Finally
582 End Sub &apos; ScriptForge.SF_UI.Minimize
584 REM -----------------------------------------------------------------------------
585 Public Function Methods() As Variant
586 &apos;&apos;&apos; Return the list of public methods of the UI service as an array
588 Methods = Array(&quot;Activate&quot; _
589 , &quot;CreateBaseDocument&quot; _
590 , &quot;CreateDocument&quot; _
591 , &quot;Documents&quot; _
592 , &quot;GetDocument&quot; _
593 , &quot;Maximize&quot; _
594 , &quot;Minimize&quot; _
595 , &quot;OpenBaseDocument&quot; _
596 , &quot;OpenDocument&quot; _
597 , &quot;Resize&quot; _
598 , &quot;SetStatusbar&quot; _
599 , &quot;ShowProgressBar&quot; _
600 , &quot;WindowExists&quot; _
603 End Function &apos; ScriptForge.SF_UI.Methods
605 REM -----------------------------------------------------------------------------
606 Public Function OpenBaseDocument(Optional ByVal FileName As Variant _
607 , Optional ByVal RegistrationName As Variant _
608 , Optional ByVal MacroExecution As Variant _
609 ) As Object
610 &apos;&apos;&apos; Open an existing LibreOffice Base document and return a SFDocuments.Document object
611 &apos;&apos;&apos; Args:
612 &apos;&apos;&apos; FileName: Identifies the file to open. It must follow the SF_FileSystem.FileNaming notation
613 &apos;&apos;&apos; RegistrationName: the name of a registered database
614 &apos;&apos;&apos; It is ignored if FileName &lt;&gt; &quot;&quot;
615 &apos;&apos;&apos; MacroExecution: one of the MACROEXECxxx constants
616 &apos;&apos;&apos; Returns:
617 &apos;&apos;&apos; A SFDocuments.SF_Base object
618 &apos;&apos;&apos; Null if the opening failed, including when due to a user decision
619 &apos;&apos;&apos; Exceptions:
620 &apos;&apos;&apos; BASEDOCUMENTOPENERROR Wrong arguments
621 &apos;&apos;&apos; Examples:
622 &apos;&apos;&apos; Dim mBasec As Object, FSO As Object
623 &apos;&apos;&apos; Set myBase = ui.OpenBaseDocument(&quot;C:\Temp\myDB.odb&quot;, MacroExecution := ui.MACROEXECNEVER)
625 Dim oOpen As Variant &apos; Return value
626 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
627 Dim oDBContext As Object &apos; com.sun.star.sdb.DatabaseContext
628 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
629 Dim sFile As String &apos; Alias for FileName
630 Dim iMacro As Integer &apos; Alias for MacroExecution
631 Const cstThisSub = &quot;UI.OpenBaseDocument&quot;
632 Const cstSubArgs = &quot;[FileName=&quot;&quot;&quot;&quot;], [RegistrationName=&quot;&quot;&quot;&quot;], [MacroExecution=0|1|2]&quot;
634 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
635 Set oOpen = Nothing
637 Check:
638 If IsMissing(FileName) Or IsEmpty(FileName) Then FileName = &quot;&quot;
639 If IsMissing(RegistrationName) Or IsEmpty(RegistrationName) Then RegistrationName = &quot;&quot;
640 If IsMissing(MacroExecution) Or IsEmpty(MacroExecution) Then MacroExecution = MACROEXECNORMAL
642 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
643 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;, , True) Then GoTo Finally
644 If Not SF_Utils._Validate(RegistrationName, &quot;RegistrationName&quot;, V_STRING) Then GoTo Finally
645 If Not SF_Utils._Validate(MacroExecution, &quot;MacroExecution&quot;, V_NUMERIC _
646 , Array(MACROEXECNORMAL, MACROEXECNEVER, MACROEXECALWAYS)) Then GoTo Finally
647 End If
649 &apos; Check the existence of FileName
650 If Len(FileName) = 0 Then &apos; FileName has precedence over RegistrationName
651 If Len(RegistrationName) = 0 Then GoTo CatchError
652 Set oDBContext = SF_Utils._GetUNOService(&quot;DatabaseContext&quot;)
653 If Not oDBContext.hasRegisteredDatabase(RegistrationName) Then GoTo CatchError
654 FileName = SF_FileSystem._ConvertFromUrl(oDBContext.getDatabaseLocation(RegistrationName))
655 End If
656 If Not SF_FileSystem.FileExists(FileName) Then GoTo CatchError
658 Try:
659 With com.sun.star.document.MacroExecMode
660 Select Case MacroExecution
661 Case 0 : iMacro = .USE_CONFIG
662 Case 1 : iMacro = .NEVER_EXECUTE
663 Case 2 : iMacro = .ALWAYS_EXECUTE_NO_WARN
664 End Select
665 End With
667 vProperties = Array(SF_Utils._MakePropertyValue(&quot;MacroExecutionMode&quot;, iMacro))
669 sFile = SF_FileSystem._ConvertToUrl(FileName)
670 Set oComp = StarDesktop.loadComponentFromURL(sFile, &quot;_blank&quot;, 0, vProperties)
671 If Not IsNull(oComp) Then Set oOpen = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
673 Finally:
674 Set OpenBaseDocument = oOpen
675 SF_Utils._ExitFunction(cstThisSub)
676 Exit Function
677 Catch:
678 GoTo Finally
679 CatchError:
680 SF_Exception.RaiseFatal(BASEDOCUMENTOPENERROR, &quot;FileName&quot;, FileName, &quot;RegistrationName&quot;, RegistrationName)
681 GoTo Finally
682 End Function &apos; ScriptForge.SF_UI.OpenBaseDocument
684 REM -----------------------------------------------------------------------------
685 Public Function OpenDocument(Optional ByVal FileName As Variant _
686 , Optional ByVal Password As Variant _
687 , Optional ByVal ReadOnly As Variant _
688 , Optional ByVal Hidden As Variant _
689 , Optional ByVal MacroExecution As Variant _
690 , Optional ByVal FilterName As Variant _
691 , Optional ByVal FilterOptions As Variant _
692 ) As Object
693 &apos;&apos;&apos; Open an existing LibreOffice document with the given options
694 &apos;&apos;&apos; Args:
695 &apos;&apos;&apos; FileName: Identifies the file to open. It must follow the SF_FileSystem.FileNaming notation
696 &apos;&apos;&apos; Password: To use when the document is protected
697 &apos;&apos;&apos; If wrong or absent while the document is protected, the user will be prompted to enter a password
698 &apos;&apos;&apos; ReadOnly: Default = False
699 &apos;&apos;&apos; Hidden: if True, open in the background (default = False)
700 &apos;&apos;&apos; To use with caution: activation or closure can only happen programmatically
701 &apos;&apos;&apos; MacroExecution: one of the MACROEXECxxx constants
702 &apos;&apos;&apos; FilterName: the name of a filter that should be used for loading the document
703 &apos;&apos;&apos; If present, the filter must exist
704 &apos;&apos;&apos; FilterOptions: an optional string of options associated with the filter
705 &apos;&apos;&apos; Returns:
706 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
707 &apos;&apos;&apos; Null if the opening failed, including when due to a user decision
708 &apos;&apos;&apos; Exceptions:
709 &apos;&apos;&apos; DOCUMENTOPENERROR Wrong arguments
710 &apos;&apos;&apos; Examples:
711 &apos;&apos;&apos; Dim myDoc As Object, FSO As Object
712 &apos;&apos;&apos; Set myDoc = ui.OpenDocument(&quot;C:\Temp\myFile.odt&quot;, MacroExecution := ui.MACROEXECNEVER)
714 Dim oOpen As Variant &apos; Return value
715 Dim oFilterFactory As Object &apos; com.sun.star.document.FilterFactory
716 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
717 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
718 Dim sFile As String &apos; Alias for FileName
719 Dim iMacro As Integer &apos; Alias for MacroExecution
720 Const cstThisSub = &quot;UI.OpenDocument&quot;
721 Const cstSubArgs = &quot;FileName, [Password=&quot;&quot;&quot;&quot;], [ReadOnly=False], [Hidden=False], [MacroExecution=0|1|2], [FilterName=&quot;&quot;&quot;&quot;], [FilterOptions=&quot;&quot;&quot;&quot;]&quot;
723 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
724 Set oOpen = Nothing
726 Check:
727 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
728 If IsMissing(ReadOnly) Or IsEmpty(ReadOnly) Then ReadOnly = False
729 If IsMissing(Hidden) Or IsEmpty(Hidden) Then Hidden = False
730 If IsMissing(MacroExecution) Or IsEmpty(MacroExecution) Then MacroExecution = MACROEXECNORMAL
731 If IsMissing(FilterName) Or IsEmpty(FilterName) Then FilterName = &quot;&quot;
732 If IsMissing(FilterOptions) Or IsEmpty(FilterOptions) Then FilterOptions = &quot;&quot;
734 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
735 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
736 If Not SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
737 If Not SF_Utils._Validate(ReadOnly, &quot;ReadOnly&quot;, V_BOOLEAN) Then GoTo Finally
738 If Not SF_Utils._Validate(Hidden, &quot;Hidden&quot;, V_BOOLEAN) Then GoTo Finally
739 If Not SF_Utils._Validate(MacroExecution, &quot;MacroExecution&quot;, V_NUMERIC _
740 , Array(MACROEXECNORMAL, MACROEXECNEVER, MACROEXECALWAYS)) Then GoTo Finally
741 If Not SF_Utils._Validate(FilterName, &quot;FilterName&quot;, V_STRING) Then GoTo Finally
742 If Not SF_Utils._Validate(FilterOptions, &quot;FilterOptions&quot;, V_STRING) Then GoTo Finally
743 End If
745 &apos; Check the existence of FileName and FilterName
746 If Not SF_FileSystem.FileExists(FileName) Then GoTo CatchError
747 If Len(FilterName) &gt; 0 Then
748 Set oFilterFactory = SF_Utils._GetUNOService(&quot;FilterFactory&quot;)
749 If Not oFilterFactory.hasByName(FilterName) Then GoTo CatchError
750 End If
752 Try:
753 With com.sun.star.document.MacroExecMode
754 Select Case MacroExecution
755 Case 0 : iMacro = .USE_CONFIG
756 Case 1 : iMacro = .NEVER_EXECUTE
757 Case 2 : iMacro = .ALWAYS_EXECUTE_NO_WARN
758 End Select
759 End With
761 vProperties = Array( _
762 SF_Utils._MakePropertyValue(&quot;ReadOnly&quot;, ReadOnly) _
763 , SF_Utils._MakePropertyValue(&quot;Hidden&quot;, Hidden) _
764 , SF_Utils._MakePropertyValue(&quot;MacroExecutionMode&quot;, iMacro) _
765 , SF_Utils._MakePropertyValue(&quot;FilterName&quot;, FilterName) _
766 , SF_Utils._MakePropertyValue(&quot;FilterOptions&quot;, FilterOptions) _
768 If Len(Password) &gt; 0 Then &apos; Password is to add only if &lt;&gt; &quot;&quot; !?
769 vProperties = SF_Array.Append(vProperties, SF_Utils._MakePropertyValue(&quot;Password&quot;, Password))
770 End If
772 sFile = SF_FileSystem._ConvertToUrl(FileName)
773 Set oComp = StarDesktop.loadComponentFromURL(sFile, &quot;_blank&quot;, 0, vProperties)
774 If Not IsNull(oComp) Then Set oOpen = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
776 Finally:
777 Set OpenDocument = oOpen
778 SF_Utils._ExitFunction(cstThisSub)
779 Exit Function
780 Catch:
781 GoTo Finally
782 CatchError:
783 SF_Exception.RaiseFatal(DOCUMENTOPENERROR, &quot;FileName&quot;, FileName, &quot;Password&quot;, Password, &quot;FilterName&quot;, FilterName)
784 GoTo Finally
785 End Function &apos; ScriptForge.SF_UI.OpenDocument
787 REM -----------------------------------------------------------------------------
788 Public Function Properties() As Variant
789 &apos;&apos;&apos; Return the list or properties of the Timer class as an array
791 Properties = Array( _
792 &quot;ActiveWindow&quot; _
795 End Function &apos; ScriptForge.SF_UI.Properties
797 REM -----------------------------------------------------------------------------
798 Public Sub Resize(Optional ByVal Left As Variant _
799 , Optional ByVal Top As Variant _
800 , Optional ByVal Width As Variant _
801 , Optional ByVal Height As Variant _
803 &apos;&apos;&apos; Resizes and/or moves the active window. Negative arguments are ignored.
804 &apos;&apos;&apos; If the window was minimized or without arguments, it is restored
805 &apos;&apos;&apos; Args:
806 &apos;&apos;&apos; Left, Top: Distances from top and left edges of the screen
807 &apos;&apos;&apos; Width, Height: Dimensions of the window
808 &apos;&apos;&apos; Examples:
809 &apos;&apos;&apos; ui.Resize(10,,500) &apos; Top and Height are unchanged
810 &apos;&apos;&apos; ...
812 Dim vWindow As Window &apos; A single component
813 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
814 Dim iPosSize As Integer &apos; Computes which of the 4 arguments should be considered
815 Const cstThisSub = &quot;UI.Resize&quot;
816 Const cstSubArgs = &quot;[Left], [Top], [Width], [Height]&quot;
818 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
820 Check:
821 If IsMissing(Left) Or IsEmpty(Left) Then Left = -1
822 If IsMissing(Top) Or IsEmpty(Top) Then Top = -1
823 If IsMissing(Width) Or IsEmpty(Width) Then Width = -1
824 If IsMissing(Height) Or IsEmpty(Height) Then Height = -1
825 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
826 If Not SF_Utils._Validate(Left, &quot;Left&quot;, V_NUMERIC) Then GoTo Finally
827 If Not SF_Utils._Validate(Top, &quot;Top&quot;, V_NUMERIC) Then GoTo Finally
828 If Not SF_Utils._Validate(Width, &quot;Width&quot;, V_NUMERIC) Then GoTo Finally
829 If Not SF_Utils._Validate(Height, &quot;Height&quot;, V_NUMERIC) Then GoTo Finally
830 End If
832 Try:
833 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
834 If Not IsNull(vWindow.Frame) Then
835 Set oContainer = vWindow.Frame.ContainerWindow
836 iPosSize = 0
837 If Left &gt;= 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.X
838 If Top &gt;= 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.Y
839 If Width &gt; 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.WIDTH
840 If Height &gt; 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.HEIGHT
841 With oContainer
842 .IsMaximized = False
843 .IsMinimized = False
844 .setPosSize(Left, Top, Width, Height, iPosSize)
845 End With
846 End If
848 Finally:
849 SF_Utils._ExitFunction(cstThisSub)
850 Exit Sub
851 Catch:
852 GoTo Finally
853 End Sub &apos; ScriptForge.SF_UI.Resize
855 REM -----------------------------------------------------------------------------
856 Public Function SetProperty(Optional ByVal PropertyName As Variant _
857 , Optional ByRef Value As Variant _
858 ) As Boolean
859 &apos;&apos;&apos; Set a new value to the given property
860 &apos;&apos;&apos; Args:
861 &apos;&apos;&apos; PropertyName: the name of the property as a string
862 &apos;&apos;&apos; Value: its new value
863 &apos;&apos;&apos; Exceptions
864 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
866 Const cstThisSub = &quot;UI.SetProperty&quot;
867 Const cstSubArgs = &quot;PropertyName, Value&quot;
869 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
870 SetProperty = False
872 Check:
873 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
874 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
875 End If
877 Try:
878 Select Case UCase(PropertyName)
879 Case Else
880 End Select
882 Finally:
883 SF_Utils._ExitFunction(cstThisSub)
884 Exit Function
885 Catch:
886 GoTo Finally
887 End Function &apos; ScriptForge.SF_UI.SetProperty
889 REM -----------------------------------------------------------------------------
890 Public Sub SetStatusbar(Optional ByVal Text As Variant _
891 , Optional ByVal Percentage As Variant _
893 &apos;&apos;&apos; Display a text and a progressbar in the status bar of the active window
894 &apos;&apos;&apos; Any subsequent calls in the same macro run refer to the same status bar of the same window,
895 &apos;&apos;&apos; even if the window is not active anymore
896 &apos;&apos;&apos; A call without arguments resets the status bar to its normal state.
897 &apos;&apos;&apos; Args:
898 &apos;&apos;&apos; Text: the optional text to be displayed before the progress bar
899 &apos;&apos;&apos; Percentage: the optional degree of progress between 0 and 100
900 &apos;&apos;&apos; Examples:
901 &apos;&apos;&apos; Dim i As Integer
902 &apos;&apos;&apos; For i = 0 To 100
903 &apos;&apos;&apos; ui.SetStatusbar(&quot;Progress ...&quot;, i)
904 &apos;&apos;&apos; Wait 50
905 &apos;&apos;&apos; Next i
906 &apos;&apos;&apos; ui.SetStatusbar
908 Dim oComp As Object
909 Dim oControl As Object
910 Static oStatusbar As Object
911 Const cstThisSub = &quot;UI.SetStatusbar&quot;
912 Const cstSubArgs = &quot;[Text], [Percentage]&quot;
914 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
916 Check:
917 If IsMissing(Text) Or IsEmpty(Text) Then Text = &quot;&quot;
918 If IsMissing(Percentage) Or IsEmpty(Percentage) Then Percentage = -1
919 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
920 If Not SF_Utils._Validate(Text, &quot;Text&quot;, V_STRING) Then GoTo Finally
921 If Not SF_Utils._Validate(Percentage, &quot;Percentage&quot;, V_NUMERIC) Then GoTo Finally
922 End If
924 Try:
925 With oStatusbar
926 If IsNull(oStatusbar) Then &apos; Initial call
927 Set oComp = StarDesktop.CurrentComponent
928 If Not IsNull(oComp) Then
929 Set oControl = Nothing
930 If SF_Session.HasUnoProperty(oComp, &quot;CurrentController&quot;) Then Set oControl = oComp.CurrentController
931 If Not IsNull(oControl) Then
932 If SF_Session.HasUnoMethod(oControl, &quot;getStatusIndicator&quot;) Then oStatusbar = oControl.getStatusIndicator()
933 End If
934 End If
935 If Not IsNull(oStatusbar) Then
936 .start(&quot;&quot;, 100)
937 End If
938 End If
939 If Not IsNull(oStatusbar) Then
940 If Len(Text) = 0 And Percentage = -1 Then
941 .end()
942 Else
943 If Len(Text) &gt; 0 Then .setText(Text)
944 If Percentage &gt;= 0 And Percentage &lt;= 100 Then .setValue(Percentage)
945 End If
946 End If
947 End With
949 Finally:
950 SF_Utils._ExitFunction(cstThisSub)
951 Exit Sub
952 Catch:
953 GoTo Finally
954 End Sub &apos; ScriptForge.SF_UI.SetStatusbar
956 REM -----------------------------------------------------------------------------
957 Public Sub ShowProgressBar(Optional Title As Variant _
958 , Optional ByVal Text As Variant _
959 , Optional ByVal Percentage As Variant _
961 &apos;&apos;&apos; Display a non-modal dialog box. Specify its title, an explicatory text and the progress on a progressbar
962 &apos;&apos;&apos; A call without arguments erases the progress bar dialog.
963 &apos;&apos;&apos; The box will anyway vanish at the end of the macro run.
964 &apos;&apos;&apos; Args:
965 &apos;&apos;&apos; Title: the title appearing on top of the dialog box (Default = &quot;ScriptForge&quot;)
966 &apos;&apos;&apos; Text: the optional text to be displayed above the progress bar (default = zero-length string)
967 &apos;&apos;&apos; Percentage: the degree of progress between 0 and 100. Default = 0
968 &apos;&apos;&apos; Examples:
969 &apos;&apos;&apos; Dim i As Integer
970 &apos;&apos;&apos; For i = 0 To 100
971 &apos;&apos;&apos; ui.ShowProgressBar(, &quot;Progress ... &quot; &amp; i &amp; &quot;/100&quot;, i)
972 &apos;&apos;&apos; Wait 50
973 &apos;&apos;&apos; Next i
974 &apos;&apos;&apos; ui.ShowProgressBar
976 Dim bFirstCall As Boolean &apos; True at first invocation of method
977 Static oDialog As Object &apos; SFDialogs.Dialog object
978 Static oFixedText As Object &apos; SFDialogs.DialogControl object
979 Static oProgressBar As Object &apos; SFDialogs.DialogControl object
980 Dim sTitle As String &apos; Alias of Title
981 Const cstThisSub = &quot;UI.ShowProgressBar&quot;
982 Const cstSubArgs = &quot;[Title], [Text], [Percentage]&quot;
984 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
986 Check:
987 If IsMissing(Title) Or IsEmpty(Title) Then Title = &quot;&quot;
988 If IsMissing(Text) Or IsEmpty(Text) Then Text = &quot;&quot;
989 If IsMissing(Percentage) Or IsEmpty(Percentage) Then Percentage = -1
990 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
991 If Not SF_Utils._Validate(Title, &quot;Title&quot;, V_STRING) Then GoTo Finally
992 If Not SF_Utils._Validate(Text, &quot;Text&quot;, V_STRING) Then GoTo Finally
993 If Not SF_Utils._Validate(Percentage, &quot;Percentage&quot;, V_NUMERIC) Then GoTo Finally
994 End If
996 Try:
997 With oDialog
998 bFirstCall = ( IsNull(oDialog) )
999 If Not bFirstCall Then bFirstCall = Not ._IsStillAlive(False) &apos; False to not raise an error
1000 If bFirstCall Then Set oDialog = CreateScriptService(&quot;SFDialogs.Dialog&quot;, &quot;GlobalScope&quot;, &quot;ScriptForge&quot;, &quot;dlgProgress&quot;)
1002 If Not IsNull(oDialog) Then
1003 If Len(Title) = 0 And Len(Text) = 0 And Percentage = -1 Then
1004 Set oDialog = .Dispose()
1005 Else
1006 .Caption = Iif(Len(Title) &gt; 0, Title, &quot;ScriptForge&quot;)
1007 If bFirstCall Then
1008 Set oFixedText = .Controls(&quot;ProgressText&quot;)
1009 Set oProgressBar = .Controls(&quot;ProgressBar&quot;)
1010 .Controls(&quot;CloseButton&quot;).Caption = _SF_.Interface.GetText(&quot;CLOSEBUTTON&quot;)
1011 .Execute(Modal := False)
1012 End If
1013 If Len(Text) &gt; 0 Then oFixedText.Caption = Text
1014 oProgressBar.Value = Iif(Percentage &gt;= 0 And Percentage &lt;= 100, Percentage, 0)
1015 End If
1016 End If
1017 End With
1019 Finally:
1020 SF_Utils._ExitFunction(cstThisSub)
1021 Exit Sub
1022 Catch:
1023 GoTo Finally
1024 End Sub &apos; ScriptForge.SF_UI.ShowProgressBar
1026 REM -----------------------------------------------------------------------------
1027 Public Function WindowExists(Optional ByVal WindowName As Variant) As Boolean
1028 &apos;&apos;&apos; Returns True if the specified window exists
1029 &apos;&apos;&apos; Args:
1030 &apos;&apos;&apos; WindowName: see definitions
1031 &apos;&apos;&apos; Returns:
1032 &apos;&apos;&apos; True if the given window is found
1033 &apos;&apos;&apos; Examples:
1034 &apos;&apos;&apos; ui.WindowExists(&quot;C:\Me\My file.odt&quot;)
1036 Dim bWindowExists As Boolean &apos; Return value
1037 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
1038 Dim oComp As Object &apos; com.sun.star.lang.XComponent
1039 Dim vWindow As Window &apos; A single component
1040 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
1041 Const cstThisSub = &quot;UI.WindowExists&quot;
1042 Const cstSubArgs = &quot;WindowName&quot;
1044 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1045 bWindowExists = False
1047 Check:
1048 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
1049 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1050 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;) Then GoTo Finally
1051 End If
1053 Try:
1054 Set oEnum = StarDesktop.Components().createEnumeration
1055 Do While oEnum.hasMoreElements
1056 Set oComp = oEnum.nextElement
1057 vWindow = SF_UI._IdentifyWindow(oComp)
1058 With vWindow
1059 &apos; Does the current window match the arguments ?
1060 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
1061 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
1062 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then
1063 bWindowExists = True
1064 Exit Do
1065 End If
1066 End With
1067 Loop
1069 Finally:
1070 WindowExists = bWindowExists
1071 SF_Utils._ExitFunction(cstThisSub)
1072 Exit Function
1073 Catch:
1074 GoTo Finally
1075 End Function &apos; ScriptForge.SF_UI.WindowExists
1077 REM =========================================================== PRIVATE FUNCTIONS
1079 REM -----------------------------------------------------------------------------
1080 Public Sub _CloseProgressBar(Optional ByRef poEvent As Object)
1081 &apos;&apos;&apos; Triggered by the Close button in the dlgProgress dialog
1082 &apos;&apos;&apos; to simply close the dialog
1084 ShowProgressBar() &apos; Without arguments =&gt; close the dialog
1086 End Sub &apos; ScriptForge.SF_UI._CloseProgressBar
1088 REM -----------------------------------------------------------------------------
1089 Public Function _IdentifyWindow(ByRef poComponent As Object) As Object
1090 &apos;&apos;&apos; Return a Window object (definition on top of module) based on component given as argument
1091 &apos;&apos;&apos; Is a shortcut to explore the most relevant properties or objects bound to a UNO component
1093 Dim oWindow As Window &apos; Return value
1094 Dim sImplementation As String &apos; Component&apos;s implementationname
1095 Dim sIdentifier As String &apos; Component&apos;s identifier
1096 Dim vArg As Variant &apos; One single item of the Args UNO property
1097 Dim FSO As Object &apos; Alias for SF_FileSystem
1099 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1100 Set _IdentifyWindow = Nothing
1101 sImplementation = &quot;&quot; : sIdentifier = &quot;&quot;
1103 Set FSO = SF_FileSystem
1104 With oWindow
1105 Set .Frame = Nothing
1106 Set .Component = Nothing
1107 .WindowName = &quot;&quot;
1108 .WindowTitle = &quot;&quot;
1109 .WindowFileName = &quot;&quot;
1110 .DocumentType = &quot;&quot;
1111 If IsNull(poComponent) Then GoTo Finally
1112 If SF_Session.HasUnoProperty(poComponent, &quot;ImplementationName&quot;) Then sImplementation = poComponent.ImplementationName
1113 If SF_Session.HasUnoProperty(poComponent, &quot;Identifier&quot;) Then sIdentifier = poComponent.Identifier
1114 Set .Component = poComponent
1115 Select Case sImplementation
1116 Case &quot;com.sun.star.comp.basic.BasicIDE&quot;
1117 .WindowName = BASICIDE
1118 Case &quot;com.sun.star.comp.dba.ODatabaseDocument&quot; &apos; No identifier
1119 .WindowFileName = SF_Utils._GetPropertyValue(poComponent.Args, &quot;URL&quot;)
1120 If Len(.WindowFileName) &gt; 0 Then .WindowName = FSO.GetName(FSO._ConvertFromUrl(.WindowFileName))
1121 .DocumentType = BASEDOCUMENT
1122 Case &quot;org.openoffice.comp.dbu.ODatasourceBrowser&quot;
1123 Case &quot;org.openoffice.comp.dbu.OTableDesign&quot;, &quot;org.openoffice.comp.dbu.OQueryDesign&quot; &apos; Table or Query in Edit mode
1124 Case &quot;org.openoffice.comp.dbu.ORelationDesign&quot;
1125 Case &quot;com.sun.star.comp.sfx2.BackingComp&quot; &apos; Welcome screen
1126 Set .Frame = poComponent.Frame
1127 .WindowName = WELCOMESCREEN
1128 Case Else
1129 If Len(sIdentifier) &gt; 0 Then
1130 &apos; Do not use URL : it contains the TemplateFile when new documents are created from a template
1131 .WindowFileName = poComponent.Location
1132 If Len(.WindowFileName) &gt; 0 Then .WindowName = FSO.GetName(FSO._ConvertFromUrl(.WindowFileName))
1133 If SF_Session.HasUnoProperty(poComponent, &quot;Title&quot;) Then .WindowTitle = poComponent.Title
1134 Select Case sIdentifier
1135 Case &quot;com.sun.star.sdb.FormDesign&quot; &apos; Form
1136 Case &quot;com.sun.star.sdb.TextReportDesign&quot; &apos; Report
1137 Case &quot;com.sun.star.text.TextDocument&quot; &apos; Writer
1138 .DocumentType = WRITERDOCUMENT
1139 Case &quot;com.sun.star.sheet.SpreadsheetDocument&quot; &apos; Calc
1140 .DocumentType = CALCDOCUMENT
1141 Case &quot;com.sun.star.presentation.PresentationDocument&quot; &apos; Impress
1142 .DocumentType = IMPRESSDOCUMENT
1143 Case &quot;com.sun.star.drawing.DrawingDocument&quot; &apos; Draw
1144 .DocumentType = DRAWDOCUMENT
1145 Case &quot;com.sun.star.formula.FormulaProperties&quot; &apos; Math
1146 .DocumentType = MATHDOCUMENT
1147 Case Else
1148 End Select
1149 End If
1150 End Select
1151 If IsNull(.Frame) Then
1152 If Not IsNull(poComponent.CurrentController) Then Set .Frame = poComponent.CurrentController.Frame
1153 End If
1154 End With
1156 Finally:
1157 Set _IdentifyWindow = oWindow
1158 Exit Function
1159 Catch:
1160 GoTo Finally
1161 End Function &apos; ScriptForge.SF_UI._IdentifyWindow
1163 REM -----------------------------------------------------------------------------
1164 Private Function _Repr() As String
1165 &apos;&apos;&apos; Convert the UI instance to a readable string, typically for debugging purposes (DebugPrint ...)
1166 &apos;&apos;&apos; Args:
1167 &apos;&apos;&apos; Return:
1168 &apos;&apos;&apos; &quot;[UI]&quot;
1170 _Repr = &quot;[UI]&quot;
1172 End Function &apos; ScriptForge.SF_UI._Repr
1174 REM ============================================ END OF SCRIPTFORGE.SF_UI
1175 </script:module>