tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / wizards / source / scriptforge / SF_UI.xba
blob442b182915f08cff9c0a3157e0f05d7e803417d3
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;)
33 &apos;&apos;&apos;
34 &apos;&apos;&apos; Detailed user documentation:
35 &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_ui.html?DbPAR=BASIC
36 &apos;&apos;&apos;
37 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
39 REM ================================================================== EXCEPTIONS
41 Const DOCUMENTERROR = &quot;DOCUMENTERROR&quot; &apos; Requested document was not found
42 Const DOCUMENTCREATIONERROR = &quot;DOCUMENTCREATIONERROR&quot; &apos; Incoherent arguments, new document could not be created
43 Const DOCUMENTOPENERROR = &quot;DOCUMENTOPENERROR&quot; &apos; Document could not be opened, check the arguments
44 Const BASEDOCUMENTOPENERROR = &quot;BASEDOCUMENTOPENERROR&quot; &apos; Id. for Base document
45 Const UNKNOWNFILEERROR = &quot;UNKNOWNFILEERROR&quot; &apos; Calc datasource does not exist
47 REM ============================================================= PRIVATE MEMBERS
49 Type Window
50 Component As Object &apos; com.sun.star.lang.XComponent
51 Frame As Object &apos; com.sun.star.comp.framework.Frame
52 WindowName As String &apos; Object Name
53 WindowTitle As String &apos; Only mean to identify new documents
54 WindowFileName As String &apos; URL of file name
55 DocumentType As String &apos; Writer, Calc, ...
56 ParentName As String &apos; Identifier of the parent Base file when Window is a subcomponent
57 End Type
59 Type _Toolbar &apos; Proto-toolbar object. Passed to the &quot;Toolbar&quot; service, a full ScriptForge Toolbar object will be returned
60 Component As Object &apos; com.sun.star.lang.XComponent
61 ResourceURL As String &apos; Toolbar internal name
62 UIName As String &apos; Toolbar external name, may be &quot;&quot;
63 UIConfigurationManager As Object &apos; com.sun.star.ui.XUIConfigurationManager
64 ElementsInfoIndex As Long &apos; Index of the toolbar in the getElementsInfo(0) array
65 Storage As Long &apos; One of the toolbar location constants
66 End Type
68 &apos; The progress/status bar of the active window
69 &apos;Private oStatusBar As Object &apos; com.sun.star.task.XStatusIndicator
71 REM ============================================================ MODULE CONSTANTS
73 &apos; Special windows
74 Const BASICIDE = &quot;BASICIDE&quot;
75 Const WELCOMESCREEN = &quot;WELCOMESCREEN&quot;
77 &apos; Document types (only if not 1 of the special windows)
78 Const BASEDOCUMENT = &quot;Base&quot;
79 Const CALCDOCUMENT = &quot;Calc&quot;
80 Const DRAWDOCUMENT = &quot;Draw&quot;
81 Const FORMDOCUMENT = &quot;FormDocument&quot;
82 Const IMPRESSDOCUMENT = &quot;Impress&quot;
83 Const MATHDOCUMENT = &quot;Math&quot;
84 Const WRITERDOCUMENT = &quot;Writer&quot;
86 &apos; Window subtypes
87 Const TABLEDATA = &quot;TableData&quot;
88 Const QUERYDATA = &quot;QueryData&quot;
89 Const SQLDATA = &quot;SqlData&quot;
90 Const BASEREPORT = &quot;BaseReport&quot;
91 Const BASEDIAGRAM = &quot;BaseDiagram&quot;
93 &apos; Macro execution modes
94 Const cstMACROEXECNORMAL = 0 &apos; Default, execution depends on user configuration and choice
95 Const cstMACROEXECNEVER = 1 &apos; Macros are not executed
96 Const cstMACROEXECALWAYS = 2 &apos; Macros are always executed
98 &apos; Toolbar locations
99 Const cstBUILTINTOOLBAR = 0 &apos; Standard toolbar
100 Const cstCUSTOMTOOLBAR = 1 &apos; Toolbar added by user and stored in the LibreOffice application
101 Const cstCUSTOMDOCTOOLBAR = 2 &apos; Toolbar added by user solely for a single document
103 REM ===================================================== CONSTRUCTOR/DESTRUCTOR
105 REM -----------------------------------------------------------------------------
106 Public Function Dispose() As Variant
107 Set Dispose = Nothing
108 End Function &apos; ScriptForge.SF_UI Explicit destructor
110 REM ================================================================== PROPERTIES
112 REM -----------------------------------------------------------------------------
113 Public Function ActiveWindow() As String
114 &apos;&apos;&apos; Returns a valid WindowName for the currently active window
115 &apos;&apos;&apos; When &quot;&quot; is returned, the window could not be identified
117 Dim vWindow As Window &apos; A component
118 Dim oComp As Object &apos; com.sun.star.lang.XComponent
120 Set oComp = StarDesktop.CurrentComponent
121 If Not IsNull(oComp) Then
122 vWindow = SF_UI._IdentifyWindow(oComp)
123 With vWindow
124 If Len(.WindowFileName) &gt; 0 Then
125 ActiveWindow = SF_FileSystem._ConvertFromUrl(.WindowFileName)
126 ElseIf Len(.WindowName) &gt; 0 Then
127 ActiveWindow = .WindowName
128 ElseIf Len(.WindowTitle) &gt; 0 Then
129 ActiveWindow = .WindowTitle
130 Else
131 ActiveWindow = &quot;&quot;
132 End If
133 End With
134 End If
136 End Function &apos; ScriptForge.SF_UI.ActiveWindow
138 REM -----------------------------------------------------------------------------
139 Property Get Height() As Long
140 &apos;&apos;&apos; Returns the height of the active window
141 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
142 Set oPosSize = SF_UI._PosSize()
143 If Not IsNull(oPosSize) Then Height = oPosSize.Height Else Height = -1
144 End Property &apos; ScriptForge.SF_UI.Height
146 REM -----------------------------------------------------------------------------
147 Property Get MACROEXECALWAYS As Integer
148 &apos;&apos;&apos; Macros are always executed
149 MACROEXECALWAYS = cstMACROEXECALWAYS
150 End Property &apos; ScriptForge.SF_UI.MACROEXECALWAYS
152 REM -----------------------------------------------------------------------------
153 Property Get MACROEXECNEVER As Integer
154 &apos;&apos;&apos; Macros are not executed
155 MACROEXECNEVER = cstMACROEXECNEVER
156 End Property &apos; ScriptForge.SF_UI.MACROEXECNEVER
158 REM -----------------------------------------------------------------------------
159 Property Get MACROEXECNORMAL As Integer
160 &apos;&apos;&apos; Default, execution depends on user configuration and choice
161 MACROEXECNORMAL = cstMACROEXECNORMAL
162 End Property &apos; ScriptForge.SF_UI.MACROEXECNORMAL
164 REM -----------------------------------------------------------------------------
165 Property Get ObjectType As String
166 &apos;&apos;&apos; Only to enable object representation
167 ObjectType = &quot;SF_UI&quot;
168 End Property &apos; ScriptForge.SF_UI.ObjectType
170 REM -----------------------------------------------------------------------------
171 Property Get ServiceName As String
172 &apos;&apos;&apos; Internal use
173 ServiceName = &quot;ScriptForge.UI&quot;
174 End Property &apos; ScriptForge.SF_UI.ServiceName
176 REM -----------------------------------------------------------------------------
177 Property Get Width() As Long
178 &apos;&apos;&apos; Returns the width of the active window
179 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
180 Set oPosSize = SF_UI._PosSize()
181 If Not IsNull(oPosSize) Then Width = oPosSize.Width Else Width = -1
182 End Property &apos; ScriptForge.SF_UI.Width
184 REM -----------------------------------------------------------------------------
185 Property Get X() As Long
186 &apos;&apos;&apos; Returns the X coordinate of the active window
187 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
188 Set oPosSize = SF_UI._PosSize()
189 If Not IsNull(oPosSize) Then X = oPosSize.X Else X = -1
190 End Property &apos; ScriptForge.SF_UI.X
192 REM -----------------------------------------------------------------------------
193 Property Get Y() As Long
194 &apos;&apos;&apos; Returns the Y coordinate of the active window
195 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
196 Set oPosSize = SF_UI._PosSize()
197 If Not IsNull(oPosSize) Then Y = oPosSize.Y Else Y = -1
198 End Property &apos; ScriptForge.SF_UI.Y
200 REM ===================================================================== METHODS
202 REM -----------------------------------------------------------------------------
203 Public Function Activate(Optional ByVal WindowName As Variant) As Boolean
204 &apos;&apos;&apos; Make the specified window active
205 &apos;&apos;&apos; Args:
206 &apos;&apos;&apos; WindowName: see definitions
207 &apos;&apos;&apos; Returns:
208 &apos;&apos;&apos; True if the given window is found and can be activated
209 &apos;&apos;&apos; There is no change in the actual user interface if no window matches the selection
210 &apos;&apos;&apos; Examples:
211 &apos;&apos;&apos; ui.Activate(&quot;C:\Me\My file.odt&quot;)
213 Dim bActivate As Boolean &apos; Return value
214 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
215 Dim oComp As Object &apos; com.sun.star.lang.XComponent
216 Dim vWindow As Window &apos; A single component
217 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
218 Const cstThisSub = &quot;UI.Activate&quot;
219 Const cstSubArgs = &quot;WindowName&quot;
221 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
222 bActivate = False
224 Check:
225 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
226 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
227 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;) Then GoTo Finally
228 End If
230 Try:
231 Set oEnum = StarDesktop.Components().createEnumeration
232 Do While oEnum.hasMoreElements
233 Set oComp = oEnum.nextElement
234 vWindow = SF_UI._IdentifyWindow(oComp)
235 With vWindow
236 &apos; Does the current window match the arguments ?
237 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem._ConvertToUrl(WindowName)) _
238 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
239 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then
240 Set oContainer = vWindow.Frame.ContainerWindow
241 With oContainer
242 If .isVisible() = False Then .setVisible(True)
243 .IsMinimized = False
244 .setFocus()
245 .toFront() &apos; Force window change in Linux
246 Wait 1 &apos; Bypass desynchro issue in Linux
247 End With
248 bActivate = True
249 Exit Do
250 End If
251 End With
252 Loop
254 Finally:
255 Activate = bActivate
256 SF_Utils._ExitFunction(cstThisSub)
257 Exit Function
258 Catch:
259 GoTo Finally
260 End Function &apos; ScriptForge.SF_UI.Activate
262 REM -----------------------------------------------------------------------------
263 Public Function CreateBaseDocument(Optional ByVal FileName As Variant _
264 , Optional ByVal EmbeddedDatabase As Variant _
265 , Optional ByVal RegistrationName As Variant _
266 , Optional ByVal CalcFileName As Variant _
267 ) As Object
268 &apos;&apos;&apos; Create a new LibreOffice Base document embedding an empty database of the given type
269 &apos;&apos;&apos; Args:
270 &apos;&apos;&apos; FileName: Identifies the file to create. It must follow the SF_FileSystem.FileNaming notation
271 &apos;&apos;&apos; If the file already exists, it is overwritten without warning
272 &apos;&apos;&apos; EmbeddedDatabase: either &quot;HSQLDB&quot; (default) or &quot;FIREBIRD&quot; or &quot;CALC&quot;
273 &apos;&apos;&apos; RegistrationName: the name used to store the new database in the databases register
274 &apos;&apos;&apos; If &quot;&quot; (default), no registration takes place
275 &apos;&apos;&apos; If the name already exists it is overwritten without warning
276 &apos;&apos;&apos; CalcFileName: only when EmbedddedDatabase = &quot;CALC&quot;, the name of the file containing the tables as Calc sheets
277 &apos;&apos;&apos; The name of the file must be given in SF_FileSystem.FileNaming notation
278 &apos;&apos;&apos; The file must exist
279 &apos;&apos;&apos; Returns:
280 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
281 &apos;&apos;&apos; Exceptions
282 &apos;&apos;&apos; UNKNOWNFILEERROR Calc datasource does not exist
283 &apos;&apos;&apos; Examples:
284 &apos;&apos;&apos; Dim myBase As Object, myCalcBase As Object
285 &apos;&apos;&apos; Set myBase = ui.CreateBaseDocument(&quot;C:\Databases\MyBaseFile.odb&quot;, &quot;FIREBIRD&quot;)
286 &apos;&apos;&apos; Set myCalcBase = ui.CreateBaseDocument(&quot;C:\Databases\MyCalcBaseFile.odb&quot;, &quot;CALC&quot;, , &quot;C:\Databases\MyCalcFile.ods&quot;)
288 Dim oCreate As Variant &apos; Return value
289 Dim oDBContext As Object &apos; com.sun.star.sdb.DatabaseContext
290 Dim oDatabase As Object &apos; com.sun.star.comp.dba.ODatabaseSource
291 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
292 Dim sFileName As String &apos; Alias of FileName
293 Dim FSO As Object &apos; Alias for FileSystem service
294 Const cstDocType = &quot;private:factory/s&quot;
295 Const cstThisSub = &quot;UI.CreateBaseDocument&quot;
296 Const cstSubArgs = &quot;FileName, [EmbeddedDatabase=&quot;&quot;HSQLDB&quot;&quot;|&quot;&quot;FIREBIRD&quot;&quot;|&quot;&quot;CALC&quot;&quot;], [RegistrationName=&quot;&quot;&quot;&quot;], [CalcFileName]&quot;
298 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
299 Set oCreate = Nothing
300 Set FSO = CreateScriptService(&quot;FileSystem&quot;)
302 Check:
303 If IsMissing(EmbeddedDatabase) Or IsEmpty(EmbeddedDatabase) Then EmbeddedDatabase = &quot;HSQLDB&quot;
304 If IsMissing(RegistrationName) Or IsEmpty(RegistrationName) Then RegistrationName = &quot;&quot;
305 If IsMissing(CalcFileName) Or IsEmpty(CalcFileName) Then CalcFileName = &quot;&quot;
306 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
307 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
308 If Not SF_Utils._Validate(EmbeddedDatabase, &quot;EmbeddedDatabase&quot;, V_STRING, Array(&quot;CALC&quot;, &quot;HSQLDB&quot;, &quot;FIREBIRD&quot;)) Then GoTo Finally
309 If Not SF_Utils._Validate(RegistrationName, &quot;RegistrationName&quot;, V_STRING) Then GoTo Finally
310 If UCase(EmbeddedDatabase) = &quot;CALC&quot; Then
311 If Not SF_Utils._ValidateFile(CalcFileName, &quot;CalcFileName&quot;) Then GoTo Finally
312 If Not FSO.FileExists(CalcFileName) Then GoTo CatchNotExists
313 End If
314 End If
316 Try:
317 Set oDBContext = SF_Utils._GetUNOService(&quot;DatabaseContext&quot;)
318 With oDBContext
319 Set oDatabase = .createInstance()
320 &apos; Build the url link to the database
321 Select Case UCase(EmbeddedDatabase)
322 Case &quot;HSQLDB&quot;, &quot;FIREBIRD&quot;
323 oDatabase.URL = &quot;sdbc:embedded:&quot; &amp; LCase(EmbeddedDatabase)
324 Case &quot;CALC&quot;
325 oDatabase.URL = &quot;sdbc:calc:&quot; &amp; FSO._ConvertToUrl(CalcFileName)
326 End Select
327 &apos; Create empty Base document
328 sFileName = FSO._ConvertToUrl(FileName)
329 &apos; An existing file is overwritten without warning
330 If FSO.FileExists(FileName) Then FSO.DeleteFile(FileName)
331 If FSO.FileExists(FileName &amp; &quot;.lck&quot;) Then FSO.DeleteFile(FileName &amp; &quot;.lck&quot;)
332 oDatabase.DatabaseDocument.storeAsURL(sFileName, Array(SF_Utils._MakePropertyValue(&quot;Overwrite&quot;, True)))
333 &apos; Register database if requested
334 If Len(RegistrationName) &gt; 0 Then
335 If .hasRegisteredDatabase(RegistrationName) Then
336 .changeDatabaseLocation(RegistrationName, sFileName)
337 Else
338 .registerDatabaseLocation(RegistrationName, sFileName)
339 End If
340 End If
341 End With
343 Set oCreate = OpenBaseDocument(FileName)
345 Finally:
346 Set CreateBaseDocument = oCreate
347 SF_Utils._ExitFunction(cstThisSub)
348 Exit Function
349 Catch:
350 GoTo Finally
351 CatchNotExists:
352 SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;CalcFileName&quot;, CalcFileName)
353 GoTo Finally
354 End Function &apos; ScriptForge.SF_UI.CreateBaseDocument
356 REM -----------------------------------------------------------------------------
357 Public Function CreateDocument(Optional ByVal DocumentType As Variant _
358 , Optional ByVal TemplateFile As Variant _
359 , Optional ByVal Hidden As Variant _
360 ) As Object
361 &apos;&apos;&apos; Create a new LibreOffice document of a given type or based on a given template
362 &apos;&apos;&apos; Args:
363 &apos;&apos;&apos; DocumentType: &quot;Calc&quot;, &quot;Writer&quot;, etc. If absent, a TemplateFile must be given
364 &apos;&apos;&apos; TemplateFile: the full FileName of the template to build the new document on
365 &apos;&apos;&apos; If the file does not exist, the argument is ignored
366 &apos;&apos;&apos; The &quot;FileSystem&quot; service provides the TemplatesFolder and UserTemplatesFolder
367 &apos;&apos;&apos; properties to help to build the argument
368 &apos;&apos;&apos; Hidden: if True, open in the background (default = False)
369 &apos;&apos;&apos; To use with caution: activation or closure can only happen programmatically
370 &apos;&apos;&apos; Returns:
371 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
372 &apos;&apos;&apos; Exceptions:
373 &apos;&apos;&apos; DOCUMENTCREATIONERROR Wrong arguments
374 &apos;&apos;&apos; Examples:
375 &apos;&apos;&apos; Dim myDoc1 As Object, myDoc2 As Object, FSO As Object
376 &apos;&apos;&apos; Set myDoc1 = ui.CreateDocument(&quot;Calc&quot;)
377 &apos;&apos;&apos; Set FSO = CreateScriptService(&quot;FileSystem&quot;)
378 &apos;&apos;&apos; Set myDoc2 = ui.CreateDocument(, FSO.BuildPath(FSO.TemplatesFolder, &quot;personal/CV.ott&quot;))
380 Dim oCreate As Variant &apos; Return value
381 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
382 Dim bTemplateExists As Boolean &apos; True if TemplateFile is valid
383 Dim sNew As String &apos; File url
384 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
385 Const cstDocType = &quot;private:factory/s&quot;
386 Const cstThisSub = &quot;UI.CreateDocument&quot;
387 Const cstSubArgs = &quot;[DocumentType=&quot;&quot;&quot;&quot;], [TemplateFile=&quot;&quot;&quot;&quot;], [Hidden=False]&quot;
389 &apos;&gt;&gt;&gt; If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
390 Set oCreate = Nothing
392 Check:
393 If IsMissing(DocumentType) Or IsEmpty(DocumentType) Then DocumentType = &quot;&quot;
394 If IsMissing(TemplateFile) Or IsEmpty(TemplateFile) Then TemplateFile = &quot;&quot;
395 If IsMissing(Hidden) Or IsEmpty(Hidden) Then Hidden = False
397 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
398 If Not SF_Utils._Validate(DocumentType, &quot;DocumentType&quot;, V_STRING _
399 , Array(&quot;&quot;, BASEDOCUMENT, CALCDOCUMENT, DRAWDOCUMENT _
400 , IMPRESSDOCUMENT, MATHDOCUMENT, WRITERDOCUMENT)) Then GoTo Finally
401 If Not SF_Utils._ValidateFile(TemplateFile, &quot;TemplateFile&quot;, , True) Then GoTo Finally
402 If Not SF_Utils._Validate(Hidden, &quot;Hidden&quot;, V_BOOLEAN) Then GoTo Finally
403 End If
405 If Len(DocumentType) + Len(TemplateFile) = 0 Then GoTo CatchError
406 If Len(TemplateFile) &gt; 0 Then bTemplateExists = SF_FileSystem.FileExists(TemplateFile) Else bTemplateExists = False
407 If Len(DocumentType) = 0 Then
408 If Not bTemplateExists Then GoTo CatchError
409 End If
411 Try:
412 If bTemplateExists Then sNew = SF_FileSystem._ConvertToUrl(TemplateFile) Else sNew = cstDocType &amp; LCase(DocumentType)
413 vProperties = Array( _
414 SF_Utils._MakePropertyValue(&quot;AsTemplate&quot;, bTemplateExists) _
415 , SF_Utils._MakePropertyValue(&quot;Hidden&quot;, Hidden) _
417 Set oComp = StarDesktop.loadComponentFromURL(sNew, &quot;_blank&quot;, 0, vProperties)
418 If Not IsNull(oComp) Then Set oCreate = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
420 Finally:
421 Set CreateDocument = oCreate
422 SF_Utils._ExitFunction(cstThisSub)
423 Exit Function
424 Catch:
425 GoTo Finally
426 CatchError:
427 SF_Exception.RaiseFatal(DOCUMENTCREATIONERROR, &quot;DocumentType&quot;, DocumentType, &quot;TemplateFile&quot;, TemplateFile)
428 GoTo Finally
429 End Function &apos; ScriptForge.SF_UI.CreateDocument
431 REM -----------------------------------------------------------------------------
432 Public Function Documents() As Variant
433 &apos;&apos;&apos; Returns the list of the currently open documents. Special windows are ignored.
434 &apos;&apos;&apos; Returns:
435 &apos;&apos;&apos; A zero-based 1D array of filenames (in SF_FileSystem.FileNaming notation)
436 &apos;&apos;&apos; or of window titles for unsaved documents
437 &apos;&apos;&apos; Examples:
438 &apos;&apos;&apos; Dim vDocs As Variant, sDoc As String
439 &apos;&apos;&apos; vDocs = ui.Documents()
440 &apos;&apos;&apos; For each sDoc In vDocs
441 &apos;&apos;&apos; ...
443 Dim vDocuments As Variant &apos; Return value
444 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
445 Dim oComp As Object &apos; com.sun.star.lang.XComponent
446 Dim vWindow As Window &apos; A single component
447 Const cstThisSub = &quot;UI.Documents&quot;
448 Const cstSubArgs = &quot;&quot;
450 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
451 vDocuments = Array()
453 Check:
454 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
456 Try:
457 Set oEnum = StarDesktop.Components().createEnumeration
458 Do While oEnum.hasMoreElements
459 Set oComp = oEnum.nextElement
460 vWindow = SF_UI._IdentifyWindow(oComp)
461 With vWindow
462 If Len(.WindowFileName) &gt; 0 Then
463 vDocuments = SF_Array.Append(vDocuments, SF_FileSystem._ConvertFromUrl(.WindowFileName))
464 ElseIf Len(.WindowTitle) &gt; 0 Then
465 vDocuments = SF_Array.Append(vDocuments, .WindowTitle)
466 End If
467 End With
468 Loop
470 Finally:
471 Documents = vDocuments
472 SF_Utils._ExitFunction(cstThisSub)
473 Exit Function
474 Catch:
475 GoTo Finally
476 End Function &apos; ScriptForge.SF_UI.Documents
478 REM -----------------------------------------------------------------------------
479 Public Function GetDocument(Optional ByVal WindowName As Variant) As Variant
480 &apos;&apos;&apos; Returns a SFDocuments.Document object referring to the active window or the given window
481 &apos;&apos;&apos; Args:
482 &apos;&apos;&apos; WindowName: when a string, see definitions. If absent the active window is considered.
483 &apos;&apos;&apos; when an object, must be a UNO object of types
484 &apos;&apos;&apos; com.sun.star.lang.XComponent or com.sun.star.comp.dba.ODatabaseDocument
485 &apos;&apos;&apos; Exceptions:
486 &apos;&apos;&apos; DOCUMENTERROR The targeted window could not be found
487 &apos;&apos;&apos; Examples:
488 &apos;&apos;&apos; Dim oDoc As Object
489 &apos;&apos;&apos; Set oDoc = ui.GetDocument &apos; or Set oDoc = ui.GetDocument(ThisComponent)
490 &apos;&apos;&apos; oDoc.Save()
492 Dim oDocument As Object &apos; Return value
493 Const cstThisSub = &quot;UI.GetDocument&quot;
494 Const cstSubArgs = &quot;[WindowName]&quot;
496 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
497 Set oDocument = Nothing
499 Check:
500 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
501 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
502 If Not SF_Utils._Validate(WindowName, &quot;WindowName&quot;, Array(V_STRING, V_OBJECT)) Then GoTo Finally
503 If VarType(WindowName) = V_STRING Then
504 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
505 End If
506 End If
508 Try:
509 Set oDocument = SF_Services.CreateScriptService(&quot;SFDocuments.Document&quot;, WindowName)
510 If IsNull(oDocument) Then GoTo CatchDeliver
512 Finally:
513 Set GetDocument = oDocument
514 SF_Utils._ExitFunction(cstThisSub)
515 Exit Function
516 Catch:
517 GoTo Finally
518 CatchDeliver:
519 SF_Exception.RaiseFatal(DOCUMENTERROR, &quot;WindowName&quot;, WindowName)
520 GoTo Finally
521 End Function &apos; ScriptForge.SF_UI.GetDocument
523 REM -----------------------------------------------------------------------------
524 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
525 &apos;&apos;&apos; Return the actual value of the given property
526 &apos;&apos;&apos; Args:
527 &apos;&apos;&apos; PropertyName: the name of the property as a string
528 &apos;&apos;&apos; Returns:
529 &apos;&apos;&apos; The actual value of the property
530 &apos;&apos;&apos; Exceptions
531 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
533 Const cstThisSub = &quot;UI.GetProperty&quot;
534 Const cstSubArgs = &quot;PropertyName&quot;
536 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
537 GetProperty = Null
539 Check:
540 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
541 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
542 End If
544 Try:
545 Select Case UCase(PropertyName)
546 Case &quot;ACTIVEWINDOW&quot; : GetProperty = ActiveWindow()
547 Case &quot;HEIGHT&quot; : GetProperty = SF_UI.Height
548 Case &quot;WIDTH&quot; : GetProperty = SF_UI.Width
549 Case &quot;X&quot; : GetProperty = SF_UI.X
550 Case &quot;Y&quot; : GetProperty = SF_UI.Y
552 Case Else
553 End Select
555 Finally:
556 SF_Utils._ExitFunction(cstThisSub)
557 Exit Function
558 Catch:
559 GoTo Finally
560 End Function &apos; ScriptForge.SF_UI.GetProperty
562 REM -----------------------------------------------------------------------------
563 Public Sub Maximize(Optional ByVal WindowName As Variant)
564 &apos;&apos;&apos; Maximizes the active window or the given window
565 &apos;&apos;&apos; Args:
566 &apos;&apos;&apos; WindowName: see definitions. If absent the active window is considered
567 &apos;&apos;&apos; Examples:
568 &apos;&apos;&apos; ui.Maximize
569 &apos;&apos;&apos; ...
571 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
572 Dim oComp As Object &apos; com.sun.star.lang.XComponent
573 Dim vWindow As Window &apos; A single component
574 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
575 Dim bFound As Boolean &apos; True if window found
576 Const cstThisSub = &quot;UI.Maximize&quot;
577 Const cstSubArgs = &quot;[WindowName]&quot;
579 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
581 Check:
582 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
583 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
584 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
585 End If
587 Try:
588 bFound = False
589 If Len(WindowName) &gt; 0 Then
590 Set oEnum = StarDesktop.Components().createEnumeration
591 Do While oEnum.hasMoreElements And Not bFound
592 Set oComp = oEnum.nextElement
593 vWindow = SF_UI._IdentifyWindow(oComp)
594 With vWindow
595 &apos; Does the current window match the arguments ?
596 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
597 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
598 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then bFound = True
599 End With
600 Loop
601 Else
602 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
603 bFound = True
604 End If
606 If bFound Then
607 Set oContainer = vWindow.Frame.ContainerWindow
608 oContainer.IsMaximized = True
609 End If
611 Finally:
612 SF_Utils._ExitFunction(cstThisSub)
613 Exit Sub
614 Catch:
615 GoTo Finally
616 End Sub &apos; ScriptForge.SF_UI.Maximize
618 REM -----------------------------------------------------------------------------
619 Public Sub Minimize(Optional ByVal WindowName As Variant)
620 &apos;&apos;&apos; Minimizes the current window or the given window
621 &apos;&apos;&apos; Args:
622 &apos;&apos;&apos; WindowName: see definitions. If absent the current window is considered
623 &apos;&apos;&apos; Examples:
624 &apos;&apos;&apos; ui.Minimize(&quot;myFile.ods&quot;)
625 &apos;&apos;&apos; ...
627 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
628 Dim oComp As Object &apos; com.sun.star.lang.XComponent
629 Dim vWindow As Window &apos; A single component
630 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
631 Dim bFound As Boolean &apos; True if window found
632 Const cstThisSub = &quot;UI.Minimize&quot;
633 Const cstSubArgs = &quot;[WindowName]&quot;
635 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
637 Check:
638 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
639 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
640 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
641 End If
643 Try:
644 bFound = False
645 If Len(WindowName) &gt; 0 Then
646 Set oEnum = StarDesktop.Components().createEnumeration
647 Do While oEnum.hasMoreElements And Not bFound
648 Set oComp = oEnum.nextElement
649 vWindow = SF_UI._IdentifyWindow(oComp)
650 With vWindow
651 &apos; Does the current window match the arguments ?
652 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
653 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
654 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then bFound = True
655 End With
656 Loop
657 Else
658 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
659 bFound = True
660 End If
662 If bFound Then
663 Set oContainer = vWindow.Frame.ContainerWindow
664 oContainer.IsMinimized = True
665 End If
667 Finally:
668 SF_Utils._ExitFunction(cstThisSub)
669 Exit Sub
670 Catch:
671 GoTo Finally
672 End Sub &apos; ScriptForge.SF_UI.Minimize
674 REM -----------------------------------------------------------------------------
675 Public Function Methods() As Variant
676 &apos;&apos;&apos; Return the list of public methods of the UI service as an array
678 Methods = Array(&quot;Activate&quot; _
679 , &quot;CreateBaseDocument&quot; _
680 , &quot;CreateDocument&quot; _
681 , &quot;Documents&quot; _
682 , &quot;GetDocument&quot; _
683 , &quot;Maximize&quot; _
684 , &quot;Minimize&quot; _
685 , &quot;OpenBaseDocument&quot; _
686 , &quot;OpenDocument&quot; _
687 , &quot;Resize&quot; _
688 , &quot;RunCommand&quot; _
689 , &quot;SetStatusbar&quot; _
690 , &quot;ShowProgressBar&quot; _
691 , &quot;WindowExists&quot; _
694 End Function &apos; ScriptForge.SF_UI.Methods
696 REM -----------------------------------------------------------------------------
697 Public Function OpenBaseDocument(Optional ByVal FileName As Variant _
698 , Optional ByVal RegistrationName As Variant _
699 , Optional ByVal MacroExecution As Variant _
700 ) As Object
701 &apos;&apos;&apos; Open an existing LibreOffice Base document and return a SFDocuments.Document object
702 &apos;&apos;&apos; Args:
703 &apos;&apos;&apos; FileName: Identifies the file to open. It must follow the SF_FileSystem.FileNaming notation
704 &apos;&apos;&apos; RegistrationName: the name of a registered database
705 &apos;&apos;&apos; It is ignored if FileName &lt;&gt; &quot;&quot;
706 &apos;&apos;&apos; MacroExecution: one of the MACROEXECxxx constants
707 &apos;&apos;&apos; Returns:
708 &apos;&apos;&apos; A SFDocuments.SF_Base object
709 &apos;&apos;&apos; Null if the opening failed, including when due to a user decision
710 &apos;&apos;&apos; Exceptions:
711 &apos;&apos;&apos; BASEDOCUMENTOPENERROR Wrong arguments
712 &apos;&apos;&apos; Examples:
713 &apos;&apos;&apos; Dim mBasec As Object, FSO As Object
714 &apos;&apos;&apos; Set myBase = ui.OpenBaseDocument(&quot;C:\Temp\myDB.odb&quot;, MacroExecution := ui.MACROEXECNEVER)
716 Dim oOpen As Variant &apos; Return value
717 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
718 Dim oDBContext As Object &apos; com.sun.star.sdb.DatabaseContext
719 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
720 Dim sFile As String &apos; Alias for FileName
721 Dim iMacro As Integer &apos; Alias for MacroExecution
722 Const cstThisSub = &quot;UI.OpenBaseDocument&quot;
723 Const cstSubArgs = &quot;[FileName=&quot;&quot;&quot;&quot;], [RegistrationName=&quot;&quot;&quot;&quot;], [MacroExecution=0|1|2]&quot;
725 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
726 Set oOpen = Nothing
728 Check:
729 If IsMissing(FileName) Or IsEmpty(FileName) Then FileName = &quot;&quot;
730 If IsMissing(RegistrationName) Or IsEmpty(RegistrationName) Then RegistrationName = &quot;&quot;
731 If IsMissing(MacroExecution) Or IsEmpty(MacroExecution) Then MacroExecution = MACROEXECNORMAL
733 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
734 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;, , True) Then GoTo Finally
735 If Not SF_Utils._Validate(RegistrationName, &quot;RegistrationName&quot;, V_STRING) Then GoTo Finally
736 If Not SF_Utils._Validate(MacroExecution, &quot;MacroExecution&quot;, V_NUMERIC _
737 , Array(MACROEXECNORMAL, MACROEXECNEVER, MACROEXECALWAYS)) Then GoTo Finally
738 End If
740 &apos; Check the existence of FileName
741 If Len(FileName) = 0 Then &apos; FileName has precedence over RegistrationName
742 If Len(RegistrationName) = 0 Then GoTo CatchError
743 Set oDBContext = SF_Utils._GetUNOService(&quot;DatabaseContext&quot;)
744 If Not oDBContext.hasRegisteredDatabase(RegistrationName) Then GoTo CatchError
745 FileName = SF_FileSystem._ConvertFromUrl(oDBContext.getDatabaseLocation(RegistrationName))
746 End If
747 If Not SF_FileSystem.FileExists(FileName) Then GoTo CatchError
749 Try:
750 With com.sun.star.document.MacroExecMode
751 Select Case MacroExecution
752 Case 0 : iMacro = .USE_CONFIG
753 Case 1 : iMacro = .NEVER_EXECUTE
754 Case 2 : iMacro = .ALWAYS_EXECUTE_NO_WARN
755 End Select
756 End With
758 vProperties = Array(SF_Utils._MakePropertyValue(&quot;MacroExecutionMode&quot;, iMacro))
760 sFile = SF_FileSystem._ConvertToUrl(FileName)
761 Set oComp = StarDesktop.loadComponentFromURL(sFile, &quot;_blank&quot;, 0, vProperties)
762 If Not IsNull(oComp) Then Set oOpen = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
764 Finally:
765 Set OpenBaseDocument = oOpen
766 SF_Utils._ExitFunction(cstThisSub)
767 Exit Function
768 Catch:
769 GoTo Finally
770 CatchError:
771 SF_Exception.RaiseFatal(BASEDOCUMENTOPENERROR, &quot;FileName&quot;, FileName, &quot;RegistrationName&quot;, RegistrationName)
772 GoTo Finally
773 End Function &apos; ScriptForge.SF_UI.OpenBaseDocument
775 REM -----------------------------------------------------------------------------
776 Public Function OpenDocument(Optional ByVal FileName As Variant _
777 , Optional ByVal Password As Variant _
778 , Optional ByVal ReadOnly As Variant _
779 , Optional ByVal Hidden As Variant _
780 , Optional ByVal MacroExecution As Variant _
781 , Optional ByVal FilterName As Variant _
782 , Optional ByVal FilterOptions As Variant _
783 ) As Object
784 &apos;&apos;&apos; Open an existing LibreOffice document with the given options
785 &apos;&apos;&apos; Args:
786 &apos;&apos;&apos; FileName: Identifies the file to open. It must follow the SF_FileSystem.FileNaming notation
787 &apos;&apos;&apos; Password: To use when the document is protected
788 &apos;&apos;&apos; If wrong or absent while the document is protected, the user will be prompted to enter a password
789 &apos;&apos;&apos; ReadOnly: Default = False
790 &apos;&apos;&apos; Hidden: if True, open in the background (default = False)
791 &apos;&apos;&apos; To use with caution: activation or closure can only happen programmatically
792 &apos;&apos;&apos; MacroExecution: one of the MACROEXECxxx constants
793 &apos;&apos;&apos; FilterName: the name of a filter that should be used for loading the document
794 &apos;&apos;&apos; If present, the filter must exist
795 &apos;&apos;&apos; FilterOptions: an optional string of options associated with the filter
796 &apos;&apos;&apos; Returns:
797 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
798 &apos;&apos;&apos; Null if the opening failed, including when due to a user decision
799 &apos;&apos;&apos; Exceptions:
800 &apos;&apos;&apos; DOCUMENTOPENERROR Wrong arguments
801 &apos;&apos;&apos; Examples:
802 &apos;&apos;&apos; Dim myDoc As Object, FSO As Object
803 &apos;&apos;&apos; Set myDoc = ui.OpenDocument(&quot;C:\Temp\myFile.odt&quot;, MacroExecution := ui.MACROEXECNEVER)
805 Dim oOpen As Variant &apos; Return value
806 Dim oFilterFactory As Object &apos; com.sun.star.document.FilterFactory
807 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
808 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
809 Dim sFile As String &apos; Alias for FileName
810 Dim iMacro As Integer &apos; Alias for MacroExecution
811 Const cstThisSub = &quot;UI.OpenDocument&quot;
812 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;
814 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
815 Set oOpen = Nothing
817 Check:
818 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
819 If IsMissing(ReadOnly) Or IsEmpty(ReadOnly) Then ReadOnly = False
820 If IsMissing(Hidden) Or IsEmpty(Hidden) Then Hidden = False
821 If IsMissing(MacroExecution) Or IsEmpty(MacroExecution) Then MacroExecution = MACROEXECNORMAL
822 If IsMissing(FilterName) Or IsEmpty(FilterName) Then FilterName = &quot;&quot;
823 If IsMissing(FilterOptions) Or IsEmpty(FilterOptions) Then FilterOptions = &quot;&quot;
825 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
826 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
827 If Not SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
828 If Not SF_Utils._Validate(ReadOnly, &quot;ReadOnly&quot;, V_BOOLEAN) Then GoTo Finally
829 If Not SF_Utils._Validate(Hidden, &quot;Hidden&quot;, V_BOOLEAN) Then GoTo Finally
830 If Not SF_Utils._Validate(MacroExecution, &quot;MacroExecution&quot;, V_NUMERIC _
831 , Array(MACROEXECNORMAL, MACROEXECNEVER, MACROEXECALWAYS)) Then GoTo Finally
832 If Not SF_Utils._Validate(FilterName, &quot;FilterName&quot;, V_STRING) Then GoTo Finally
833 If Not SF_Utils._Validate(FilterOptions, &quot;FilterOptions&quot;, V_STRING) Then GoTo Finally
834 End If
836 &apos; Check the existence of FileName and FilterName
837 If Not SF_FileSystem.FileExists(FileName) Then GoTo CatchError
838 If Len(FilterName) &gt; 0 Then
839 Set oFilterFactory = SF_Utils._GetUNOService(&quot;FilterFactory&quot;)
840 If Not oFilterFactory.hasByName(FilterName) Then GoTo CatchError
841 End If
843 Try:
844 With com.sun.star.document.MacroExecMode
845 Select Case MacroExecution
846 Case 0 : iMacro = .USE_CONFIG
847 Case 1 : iMacro = .NEVER_EXECUTE
848 Case 2 : iMacro = .ALWAYS_EXECUTE_NO_WARN
849 End Select
850 End With
852 vProperties = Array( _
853 SF_Utils._MakePropertyValue(&quot;ReadOnly&quot;, ReadOnly) _
854 , SF_Utils._MakePropertyValue(&quot;Hidden&quot;, Hidden) _
855 , SF_Utils._MakePropertyValue(&quot;MacroExecutionMode&quot;, iMacro) _
856 , SF_Utils._MakePropertyValue(&quot;FilterName&quot;, FilterName) _
857 , SF_Utils._MakePropertyValue(&quot;FilterOptions&quot;, FilterOptions) _
859 If Len(Password) &gt; 0 Then &apos; Password is to add only if &lt;&gt; &quot;&quot; !?
860 vProperties = SF_Array.Append(vProperties, SF_Utils._MakePropertyValue(&quot;Password&quot;, Password))
861 End If
863 sFile = SF_FileSystem._ConvertToUrl(FileName)
864 Set oComp = StarDesktop.loadComponentFromURL(sFile, &quot;_blank&quot;, 0, vProperties)
865 If Not IsNull(oComp) Then Set oOpen = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
867 Finally:
868 Set OpenDocument = oOpen
869 SF_Utils._ExitFunction(cstThisSub)
870 Exit Function
871 Catch:
872 GoTo Finally
873 CatchError:
874 SF_Exception.RaiseFatal(DOCUMENTOPENERROR, &quot;FileName&quot;, FileName, &quot;Password&quot;, Password, &quot;FilterName&quot;, FilterName)
875 GoTo Finally
876 End Function &apos; ScriptForge.SF_UI.OpenDocument
878 REM -----------------------------------------------------------------------------
879 Public Function Properties() As Variant
880 &apos;&apos;&apos; Return the list or properties of the Timer class as an array
882 Properties = Array( _
883 &quot;ActiveWindow&quot; _
884 , &quot;Height&quot; _
885 , &quot;Width&quot; _
886 , &quot;X&quot; _
887 , &quot;Y&quot; _
890 End Function &apos; ScriptForge.SF_UI.Properties
892 REM -----------------------------------------------------------------------------
893 Public Sub Resize(Optional ByVal Left As Variant _
894 , Optional ByVal Top As Variant _
895 , Optional ByVal Width As Variant _
896 , Optional ByVal Height As Variant _
898 &apos;&apos;&apos; Resizes and/or moves the active window. Negative arguments are ignored.
899 &apos;&apos;&apos; If the window was minimized or without arguments, it is restored
900 &apos;&apos;&apos; Args:
901 &apos;&apos;&apos; Left, Top: Distances from top and left edges of the screen
902 &apos;&apos;&apos; Width, Height: Dimensions of the window
903 &apos;&apos;&apos; Examples:
904 &apos;&apos;&apos; ui.Resize(10,,500) &apos; Top and Height are unchanged
905 &apos;&apos;&apos; ...
907 Dim vWindow As Window &apos; A single component
908 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
909 Dim iPosSize As Integer &apos; Computes which of the 4 arguments should be considered
910 Const cstThisSub = &quot;UI.Resize&quot;
911 Const cstSubArgs = &quot;[Left], [Top], [Width], [Height]&quot;
913 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
915 Check:
916 If IsMissing(Left) Or IsEmpty(Left) Then Left = -1
917 If IsMissing(Top) Or IsEmpty(Top) Then Top = -1
918 If IsMissing(Width) Or IsEmpty(Width) Then Width = -1
919 If IsMissing(Height) Or IsEmpty(Height) Then Height = -1
920 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
921 If Not SF_Utils._Validate(Left, &quot;Left&quot;, V_NUMERIC) Then GoTo Finally
922 If Not SF_Utils._Validate(Top, &quot;Top&quot;, V_NUMERIC) Then GoTo Finally
923 If Not SF_Utils._Validate(Width, &quot;Width&quot;, V_NUMERIC) Then GoTo Finally
924 If Not SF_Utils._Validate(Height, &quot;Height&quot;, V_NUMERIC) Then GoTo Finally
925 End If
927 Try:
928 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
929 If Not IsNull(vWindow.Frame) Then
930 Set oContainer = vWindow.Frame.ContainerWindow
931 iPosSize = 0
932 If Left &gt;= 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.X
933 If Top &gt;= 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.Y
934 If Width &gt; 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.WIDTH
935 If Height &gt; 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.HEIGHT
936 With oContainer
937 .IsMaximized = False
938 .IsMinimized = False
939 .setPosSize(Left, Top, Width, Height, iPosSize)
940 End With
941 End If
943 Finally:
944 SF_Utils._ExitFunction(cstThisSub)
945 Exit Sub
946 Catch:
947 GoTo Finally
948 End Sub &apos; ScriptForge.SF_UI.Resize
950 REM -----------------------------------------------------------------------------
951 Public Sub RunCommand(Optional ByVal Command As Variant _
952 , ParamArray Args As Variant _
954 &apos;&apos;&apos; Run on the current window the given menu command. The command is executed with or without arguments
955 &apos;&apos;&apos; A few typical commands:
956 &apos;&apos;&apos; About, Delete, Edit, Undo, Copy, Paste, ...
957 &apos;&apos;&apos; Dozens can be found on next page: https://wiki.documentfoundation.org/Development/DispatchCommands
958 &apos;&apos;&apos; Args:
959 &apos;&apos;&apos; Command: Case-sensitive. The command itself is not checked.
960 &apos;&apos;&apos; If the command does not contain the &quot;.uno:&quot; prefix, it is added.
961 &apos;&apos;&apos; If nothing happens, then the command is probably wrong
962 &apos;&apos;&apos; Args: Pairs of arguments name (string), value (any)
963 &apos;&apos;&apos; Returns:
964 &apos;&apos;&apos; Examples:
965 &apos;&apos;&apos; ui.RunCommand(&quot;BasicIDEAppear&quot;, _
966 &apos;&apos;&apos; &quot;Document&quot;, &quot;LibreOffice Macros &amp; Dialogs&quot;, _
967 &apos;&apos;&apos; &quot;LibName&quot;, &quot;ScriptForge&quot;, _
968 &apos;&apos;&apos; &quot;Name&quot;, &quot;SF_Session&quot;, _
969 &apos;&apos;&apos; &quot;Line&quot;, 600)
971 Dim oDispatch &apos; com.sun.star.frame.DispatchHelper
972 Dim vProps As Variant &apos; Array of PropertyValues
973 Dim vValue As Variant &apos; A single value argument
974 Dim sCommand As String &apos; Alias of Command
975 Dim i As Long
976 Const cstPrefix = &quot;.uno:&quot;
978 Const cstThisSub = &quot;UI.RunCommand&quot;
979 Const cstSubArgs = &quot;Command, [arg0Name, arg0Value], [arg1Name, arg1Value], ...&quot;
981 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
983 Check:
984 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
985 If Not SF_Utils._Validate(Command, &quot;Command&quot;, V_STRING) Then GoTo Finally
986 If Not SF_Utils._ValidateArray(Args, &quot;Args&quot;, 1) Then GoTo Finally
987 For i = 0 To UBound(Args) - 1 Step 2
988 If Not SF_Utils._Validate(Args(i), &quot;Arg&quot; &amp; CStr(i/2) &amp; &quot;Name&quot;, V_STRING) Then GoTo Finally
989 Next i
990 End If
992 Try:
993 &apos; Build array of property values
994 vProps = Array()
995 For i = 0 To UBound(Args) - 1 Step 2
996 If IsEmpty(Args(i + 1)) Then vValue = Null Else vValue = Args(i + 1)
997 vProps = SF_Array.Append(vProps, SF_Utils._MakePropertyValue(Args(i), vValue))
998 Next i
999 Set oDispatch = SF_Utils._GetUNOService(&quot;DispatchHelper&quot;)
1000 If SF_String.StartsWith(Command, cstPrefix) Then sCommand = Command Else sCommand = cstPrefix &amp; Command
1001 oDispatch.executeDispatch(StarDesktop.ActiveFrame, sCommand, &quot;&quot;, 0, vProps)
1003 Finally:
1004 SF_Utils._ExitFunction(cstThisSub)
1005 Exit Sub
1006 Catch:
1007 GoTo Finally
1008 End Sub &apos; ScriptForge.SF_UI.RunCommand
1010 REM -----------------------------------------------------------------------------
1011 Public Function SetProperty(Optional ByVal PropertyName As Variant _
1012 , Optional ByRef Value As Variant _
1013 ) As Boolean
1014 &apos;&apos;&apos; Set a new value to the given property
1015 &apos;&apos;&apos; Args:
1016 &apos;&apos;&apos; PropertyName: the name of the property as a string
1017 &apos;&apos;&apos; Value: its new value
1018 &apos;&apos;&apos; Exceptions
1019 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
1021 Const cstThisSub = &quot;UI.SetProperty&quot;
1022 Const cstSubArgs = &quot;PropertyName, Value&quot;
1024 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1025 SetProperty = False
1027 Check:
1028 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1029 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
1030 End If
1032 Try:
1033 Select Case UCase(PropertyName)
1034 Case Else
1035 End Select
1037 Finally:
1038 SF_Utils._ExitFunction(cstThisSub)
1039 Exit Function
1040 Catch:
1041 GoTo Finally
1042 End Function &apos; ScriptForge.SF_UI.SetProperty
1044 REM -----------------------------------------------------------------------------
1045 Public Sub SetStatusbar(Optional ByVal Text As Variant _
1046 , Optional ByVal Percentage As Variant _
1048 &apos;&apos;&apos; Display a text and a progressbar in the status bar of the active window
1049 &apos;&apos;&apos; Any subsequent calls in the same macro run refer to the same status bar of the same window,
1050 &apos;&apos;&apos; even if the window is not active anymore
1051 &apos;&apos;&apos; A call without arguments resets the status bar to its normal state.
1052 &apos;&apos;&apos; Args:
1053 &apos;&apos;&apos; Text: the optional text to be displayed before the progress bar
1054 &apos;&apos;&apos; Percentage: the optional degree of progress between 0 and 100
1055 &apos;&apos;&apos; Examples:
1056 &apos;&apos;&apos; Dim i As Integer
1057 &apos;&apos;&apos; For i = 0 To 100
1058 &apos;&apos;&apos; ui.SetStatusbar(&quot;Progress ...&quot;, i)
1059 &apos;&apos;&apos; Wait 50
1060 &apos;&apos;&apos; Next i
1061 &apos;&apos;&apos; ui.SetStatusbar
1063 Dim oComp As Object
1064 Dim oControl As Object
1065 Dim oStatusbar As Object
1066 Const cstThisSub = &quot;UI.SetStatusbar&quot;
1067 Const cstSubArgs = &quot;[Text], [Percentage]&quot;
1069 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1071 Check:
1072 If IsMissing(Text) Or IsEmpty(Text) Then Text = &quot;&quot;
1073 If IsMissing(Percentage) Or IsEmpty(Percentage) Then Percentage = -1
1074 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1075 If Not SF_Utils._Validate(Text, &quot;Text&quot;, V_STRING) Then GoTo Finally
1076 If Not SF_Utils._Validate(Percentage, &quot;Percentage&quot;, V_NUMERIC) Then GoTo Finally
1077 End If
1079 Try:
1080 Set oStatusbar = _SF_.Statusbar
1081 If IsNull(oStatusbar) Then &apos; Initial call
1082 Set oComp = StarDesktop.CurrentComponent
1083 If Not IsNull(oComp) Then
1084 Set oControl = Nothing
1085 If SF_Session.HasUnoProperty(oComp, &quot;CurrentController&quot;) Then Set oControl = oComp.CurrentController
1086 If Not IsNull(oControl) Then
1087 If SF_Session.HasUnoMethod(oControl, &quot;getStatusIndicator&quot;) Then oStatusbar = oControl.getStatusIndicator()
1088 End If
1089 End If
1090 If Not IsNull(oStatusbar) Then oStatusBar.start(&quot;&quot;, 100)
1091 End If
1092 If Not IsNull(oStatusbar) Then
1093 With oStatusbar
1094 If Len(Text) = 0 And Percentage = -1 Then
1095 .end()
1096 Set oStatusbar = Nothing
1097 Else
1098 If Len(Text) &gt; 0 Then .setText(Text)
1099 If Percentage &gt;= 0 And Percentage &lt;= 100 Then .setValue(Percentage)
1100 End If
1101 End With
1102 End If
1104 Finally:
1105 Set _SF_.Statusbar = oStatusbar
1106 SF_Utils._ExitFunction(cstThisSub)
1107 Exit Sub
1108 Catch:
1109 GoTo Finally
1110 End Sub &apos; ScriptForge.SF_UI.SetStatusbar
1112 REM -----------------------------------------------------------------------------
1113 Public Sub ShowProgressBar(Optional Title As Variant _
1114 , Optional ByVal Text As Variant _
1115 , Optional ByVal Percentage As Variant _
1116 , Optional ByRef _Context As Variant _
1118 &apos;&apos;&apos; Display a non-modal dialog box. Specify its title, an explicatory text and the progress on a progressbar
1119 &apos;&apos;&apos; A call without arguments erases the progress bar dialog.
1120 &apos;&apos;&apos; The box will anyway vanish at the end of the macro run.
1121 &apos;&apos;&apos; Args:
1122 &apos;&apos;&apos; Title: the title appearing on top of the dialog box (Default = &quot;ScriptForge&quot;)
1123 &apos;&apos;&apos; Text: the optional text to be displayed above the progress bar (default = zero-length string)
1124 &apos;&apos;&apos; Percentage: the degree of progress between 0 and 100. Default = 0
1125 &apos;&apos;&apos; _Context: from Python, the XComponentXontext (FOR INTERNAL USE ONLY)
1126 &apos;&apos;&apos; Examples:
1127 &apos;&apos;&apos; Dim i As Integer
1128 &apos;&apos;&apos; For i = 0 To 100
1129 &apos;&apos;&apos; ui.ShowProgressBar(, &quot;Progress ... &quot; &amp; i &amp; &quot;/100&quot;, i)
1130 &apos;&apos;&apos; Wait 50
1131 &apos;&apos;&apos; Next i
1132 &apos;&apos;&apos; ui.ShowProgressBar
1134 Dim bFirstCall As Boolean &apos; True at first invocation of method
1135 Dim oDialog As Object &apos; SFDialogs.Dialog object
1136 Dim oFixedText As Object &apos; SFDialogs.DialogControl object
1137 Dim oProgressBar As Object &apos; SFDialogs.DialogControl object
1138 Dim sTitle As String &apos; Alias of Title
1139 Const cstThisSub = &quot;UI.ShowProgressBar&quot;
1140 Const cstSubArgs = &quot;[Title], [Text], [Percentage]&quot;
1142 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1144 Check:
1145 If IsMissing(Title) Or IsEmpty(Title) Then Title = &quot;&quot;
1146 If IsMissing(Text) Or IsEmpty(Text) Then Text = &quot;&quot;
1147 If IsMissing(Percentage) Or IsEmpty(Percentage) Then Percentage = -1
1148 If IsMissing(_Context) Or IsEmpty(_Context) Then _Context = Nothing
1149 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1150 If Not SF_Utils._Validate(Title, &quot;Title&quot;, V_STRING) Then GoTo Finally
1151 If Not SF_Utils._Validate(Text, &quot;Text&quot;, V_STRING) Then GoTo Finally
1152 If Not SF_Utils._Validate(Percentage, &quot;Percentage&quot;, V_NUMERIC) Then GoTo Finally
1153 End If
1155 Try:
1156 With _SF_
1157 Set oDialog = .ProgressBarDialog
1158 Set oFixedText = .ProgressBarText
1159 Set oProgressBar = .ProgressBarBar
1160 End With
1162 bFirstCall = ( IsNull(oDialog) )
1163 If Not bFirstCall Then bFirstCall = Not oDialog._IsStillAlive(False) &apos; False to not raise an error
1164 If bFirstCall Then Set oDialog = CreateScriptService(&quot;SFDialogs.Dialog&quot;, &quot;GlobalScope&quot;, &quot;ScriptForge&quot;, &quot;dlgProgress&quot;, _Context)
1165 With oDialog
1166 If Not IsNull(oDialog) Then
1167 If Len(Title) = 0 And Len(Text) = 0 And Percentage = -1 Then
1168 Set oDialog = .Dispose()
1169 Else
1170 .Caption = Iif(Len(Title) &gt; 0, Title, &quot;ScriptForge&quot;)
1171 If bFirstCall Then
1172 Set oFixedText = .Controls(&quot;ProgressText&quot;)
1173 Set oProgressBar = .Controls(&quot;ProgressBar&quot;)
1174 .Execute(Modal := False)
1175 End If
1176 If Len(Text) &gt; 0 Then oFixedText.Caption = Text
1177 oProgressBar.Value = Iif(Percentage &gt;= 0 And Percentage &lt;= 100, Percentage, 0)
1178 End If
1179 End If
1180 End With
1182 Finally:
1183 With _SF_
1184 Set .ProgressBarDialog = oDialog
1185 Set .ProgressBarText = oFixedText
1186 Set .ProgressBarBar = oProgressBar
1187 End With
1188 SF_Utils._ExitFunction(cstThisSub)
1189 Exit Sub
1190 Catch:
1191 GoTo Finally
1192 End Sub &apos; ScriptForge.SF_UI.ShowProgressBar
1194 REM -----------------------------------------------------------------------------
1195 Public Function WindowExists(Optional ByVal WindowName As Variant) As Boolean
1196 &apos;&apos;&apos; Returns True if the specified window exists
1197 &apos;&apos;&apos; Args:
1198 &apos;&apos;&apos; WindowName: see definitions
1199 &apos;&apos;&apos; Returns:
1200 &apos;&apos;&apos; True if the given window is found
1201 &apos;&apos;&apos; Examples:
1202 &apos;&apos;&apos; ui.WindowExists(&quot;C:\Me\My file.odt&quot;)
1204 Dim bWindowExists As Boolean &apos; Return value
1205 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
1206 Dim oComp As Object &apos; com.sun.star.lang.XComponent
1207 Dim vWindow As Window &apos; A single component
1208 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
1209 Const cstThisSub = &quot;UI.WindowExists&quot;
1210 Const cstSubArgs = &quot;WindowName&quot;
1212 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1213 bWindowExists = False
1215 Check:
1216 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
1217 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1218 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;) Then GoTo Finally
1219 End If
1221 Try:
1222 Set oEnum = StarDesktop.Components().createEnumeration
1223 Do While oEnum.hasMoreElements
1224 Set oComp = oEnum.nextElement
1225 vWindow = SF_UI._IdentifyWindow(oComp)
1226 With vWindow
1227 &apos; Does the current window match the arguments ?
1228 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
1229 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
1230 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then
1231 bWindowExists = True
1232 Exit Do
1233 End If
1234 End With
1235 Loop
1237 Finally:
1238 WindowExists = bWindowExists
1239 SF_Utils._ExitFunction(cstThisSub)
1240 Exit Function
1241 Catch:
1242 GoTo Finally
1243 End Function &apos; ScriptForge.SF_UI.WindowExists
1245 REM =========================================================== PRIVATE FUNCTIONS
1247 REM -----------------------------------------------------------------------------
1248 Public Sub _CloseProgressBar(Optional ByRef poEvent As Object)
1249 &apos;&apos;&apos; Triggered by the Close button in the dlgProgress dialog
1250 &apos;&apos;&apos; to simply close the dialog
1252 ShowProgressBar() &apos; Without arguments =&gt; close the dialog
1254 End Sub &apos; ScriptForge.SF_UI._CloseProgressBar
1256 REM -----------------------------------------------------------------------------
1257 Function _GetConfigurationManager(ByRef poComponent) As String
1258 &apos;&apos;&apos; Derives the argument to be passed to a configuration manager
1259 &apos;&apos;&apos; (managing the user interface elements like menus, toolbars, ...)
1260 &apos;&apos;&apos; from the nature of the component
1261 &apos;&apos;&apos; Args:
1262 &apos;&apos;&apos; poComponent: any component in desktop, typically a document but not only
1264 Dim sConfigurationManager As String &apos; Return value
1265 Dim oWindow As Object &apos; Window type
1267 Check:
1268 &apos; On Local Error GoTo Catch
1269 If IsNull(poComponent) Then GoTo Catch
1271 Try:
1272 Set oWindow = _IdentifyWindow(poComponent)
1274 &apos; Derive the name of the UI configuration manager from the component type
1275 With oWindow
1276 Select Case .WindowName
1277 Case BASICIDE : sConfigurationManager = &quot;com.sun.star.script.BasicIDE&quot;
1278 Case WELCOMESCREEN : sConfigurationManager = &quot;com.sun.star.frame.StartModule&quot;
1279 Case Else
1280 Select Case .DocumentType
1281 Case BASEDOCUMENT : sConfigurationManager = &quot;com.sun.star.sdb.OfficeDatabaseDocument&quot;
1282 Case CALCDOCUMENT : sConfigurationManager = &quot;com.sun.star.sheet.SpreadsheetDocument&quot;
1283 Case DRAWDOCUMENT : sConfigurationManager = &quot;com.sun.star.drawing.DrawingDocument&quot;
1284 Case FORMDOCUMENT : sConfigurationManager = &quot;com.sun.star.sdb.FormDesign&quot;
1285 Case IMPRESSDOCUMENT : sConfigurationManager = &quot;com.sun.star.presentation.PresentationDocument&quot;
1286 Case MATHDOCUMENT : sConfigurationManager = &quot;com.sun.star.formula.FormulaProperties&quot;
1287 Case WRITERDOCUMENT : sConfigurationManager = &quot;com.sun.star.text.TextDocument&quot;
1288 Case TABLEDATA, QUERYDATA, SQLDATA
1289 sConfigurationManager = &quot;com.sun.star.sdb.DataSourceBrowser&quot;
1290 Case Else : sConfigurationManager = &quot;&quot;
1291 End Select
1292 End Select
1293 End With
1295 Finally:
1296 _GetConfigurationManager = sConfigurationManager
1297 Exit Function
1298 Catch:
1299 On Local Error GoTo 0
1300 GoTo Finally
1301 End Function &apos; ScriptForge.SF_UI._GetConfigurationManager
1303 REM -----------------------------------------------------------------------------
1304 Public Function _IdentifyWindow(ByRef poComponent As Object) As Object
1305 &apos;&apos;&apos; Return a Window object (definition on top of module) based on component given as argument
1306 &apos;&apos;&apos; Is a shortcut to explore the most relevant properties or objects bound to a UNO component
1308 Dim oWindow As Window &apos; Return value
1309 Dim sImplementation As String &apos; Component&apos;s implementationname
1310 Dim sIdentifier As String &apos; Component&apos;s identifier
1311 Dim vSelection As Variant &apos; Array of poCOmponent.Selection property values
1312 Dim iCommandType As Integer &apos; Datasheet type
1313 Dim FSO As Object &apos; Alias for SF_FileSystem
1315 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1316 Set _IdentifyWindow = Nothing
1317 sImplementation = &quot;&quot; : sIdentifier = &quot;&quot;
1319 Set FSO = SF_FileSystem
1320 With oWindow
1321 Set .Frame = Nothing
1322 Set .Component = Nothing
1323 .WindowName = &quot;&quot;
1324 .WindowTitle = &quot;&quot;
1325 .WindowFileName = &quot;&quot;
1326 .DocumentType = &quot;&quot;
1327 .ParentName = &quot;&quot;
1328 If IsNull(poComponent) Then GoTo Finally
1329 If SF_Session.HasUnoProperty(poComponent, &quot;ImplementationName&quot;) Then sImplementation = poComponent.ImplementationName
1330 If SF_Session.HasUnoProperty(poComponent, &quot;Identifier&quot;) Then sIdentifier = poComponent.Identifier
1331 Set .Component = poComponent
1332 Select Case sImplementation
1333 Case &quot;com.sun.star.comp.basic.BasicIDE&quot;
1334 .WindowName = BASICIDE
1335 Case &quot;com.sun.star.comp.dba.ODatabaseDocument&quot; &apos; No identifier
1336 .WindowFileName = SF_Utils._GetPropertyValue(poComponent.Args, &quot;URL&quot;)
1337 If Len(.WindowFileName) &gt; 0 Then .WindowName = FSO.GetName(FSO._ConvertFromUrl(.WindowFileName))
1338 .DocumentType = BASEDOCUMENT
1339 Case &quot;org.openoffice.comp.dbu.ODatasourceBrowser&quot; &apos; Base datasheet (table, query or sql) in read mode
1340 Set .Frame = poComponent.Frame
1341 If Not IsEmpty(poComponent.Selection) Then &apos; Empty for (F4) DatasourceBrowser !!
1342 vSelection = poComponent.Selection
1343 .WindowName = SF_Utils._GetPropertyValue(vSelection, &quot;Command&quot;)
1344 iCommandType = SF_Utils._GetPropertyValue(vSelection, &quot;CommandType&quot;)
1345 Select Case iCommandType
1346 Case com.sun.star.sdb.CommandType.TABLE : .DocumentType = TABLEDATA
1347 Case com.sun.star.sdb.CommandType.QUERY : .DocumentType = QUERYDATA
1348 Case com.sun.star.sdb.CommandType.COMMAND : .DocumentType = SQLDATA
1349 End Select
1350 .ParentName = SF_Utils._GetPropertyValue(vSelection, &quot;DataSourceName&quot;)
1351 .WindowTitle = .WindowName
1352 End If
1353 Case &quot;org.openoffice.comp.dbu.OTableDesign&quot;, &quot;org.openoffice.comp.dbu.OQueryDesign&quot; &apos; Table or Query in Edit mode
1354 Case &quot;org.openoffice.comp.dbu.ORelationDesign&quot;
1355 Case &quot;com.sun.star.comp.sfx2.BackingComp&quot; &apos; Welcome screen
1356 Set .Frame = poComponent.Frame
1357 .WindowName = WELCOMESCREEN
1358 Case Else
1359 If Len(sIdentifier) &gt; 0 Then
1360 &apos; Do not use URL : it contains the TemplateFile when new documents are created from a template
1361 .WindowFileName = poComponent.Location
1362 If Len(.WindowFileName) &gt; 0 Then .WindowName = FSO.GetName(FSO._ConvertFromUrl(.WindowFileName))
1363 If SF_Session.HasUnoProperty(poComponent, &quot;Title&quot;) Then .WindowTitle = poComponent.Title
1364 Select Case sIdentifier
1365 Case &quot;com.sun.star.sdb.FormDesign&quot; &apos; Form
1366 .DocumentType = FORMDOCUMENT
1367 Case &quot;com.sun.star.sdb.TextReportDesign&quot; &apos; Report
1368 Case &quot;com.sun.star.text.TextDocument&quot; &apos; Writer
1369 .DocumentType = WRITERDOCUMENT
1370 Case &quot;com.sun.star.sheet.SpreadsheetDocument&quot; &apos; Calc
1371 .DocumentType = CALCDOCUMENT
1372 Case &quot;com.sun.star.presentation.PresentationDocument&quot; &apos; Impress
1373 .DocumentType = IMPRESSDOCUMENT
1374 Case &quot;com.sun.star.drawing.DrawingDocument&quot; &apos; Draw
1375 .DocumentType = DRAWDOCUMENT
1376 Case &quot;com.sun.star.formula.FormulaProperties&quot; &apos; Math
1377 .DocumentType = MATHDOCUMENT
1378 Case Else
1379 End Select
1380 End If
1381 End Select
1382 If IsNull(.Frame) Then
1383 If Not IsNull(poComponent.CurrentController) Then Set .Frame = poComponent.CurrentController.Frame
1384 End If
1385 End With
1387 Finally:
1388 Set _IdentifyWindow = oWindow
1389 Exit Function
1390 Catch:
1391 GoTo Finally
1392 End Function &apos; ScriptForge.SF_UI._IdentifyWindow
1394 REM -----------------------------------------------------------------------------
1395 Public Function _ListToolbars(ByRef poComponent As Object) As Object
1396 &apos;&apos;&apos; Returns a SF_Dictionary object containing a list of all available
1397 &apos;&apos;&apos; toolbars in the given component
1398 &apos;&apos;&apos; A toolbar may be located:
1399 &apos;&apos;&apos; - builtin in the LibreOffice configuration, but dependent on the component type
1400 &apos;&apos;&apos; - added by the user and stored in the LibreOffice configuration of the user
1401 &apos;&apos;&apos; - added by the user and stored in the component/document itself
1402 &apos;&apos;&apos; The output dictionary has as
1403 &apos;&apos;&apos; key: the UIName of the toolbar when not blank, otherwise the last component of its ResourceURL
1404 &apos;&apos;&apos; item: a _Toolbar object (see top of module)
1405 &apos;&apos;&apos; Menubar, statusbar and popup menus are ignored.
1406 &apos;&apos;&apos; Args:
1407 &apos;&apos;&apos; poComponent: any component in desktop, typically a document but not only
1409 Dim oToolbarsDict As Object &apos; Return value
1410 Dim oConfigMgr As Object &apos; com.sun.star.ui.ModuleUIConfigurationManagerSupplier
1411 Dim sConfigurationManager As String &apos; Derived from the component&apos;s type
1412 Dim oUIConfigMgr As Object &apos; com.sun.star.comp.framework.ModuleUIConfigurationManager
1413 Dim vCommandBars As Variant &apos; Array of bars in component
1414 Dim vCommandBar As Variant &apos; Array of PropertyValue about a single bar
1415 Dim oToolbar As Object &apos; Toolbar description as a _Toolbar object
1416 Dim sResourceURL As String &apos; Toolbar internal name as &quot;private:resource/toolbar/...&quot;
1417 Dim sUIName As String &apos; Toolbar external name, may be zero-length string
1418 Dim sBarName As String &apos; External bar name: either UIName or last component of resource URL
1419 Dim i As Long
1421 Const cstCUSTOM = &quot;custom_&quot;
1423 Check:
1424 &apos; On Local Error GoTo Catch
1425 If IsNull(poComponent) Then GoTo Catch
1427 Try:
1428 Set oToolbarsDict = CreateScriptService(&quot;Dictionary&quot;, True) &apos; with case-sensitive comparison of keys
1430 &apos; 1. Collect all builtin and custom toolbars stored in the LibreOffice configuration files
1432 &apos; Derive the name of the UI configuration manager from the component type
1433 sConfigurationManager = _GetConfigurationManager(poComponent)
1435 Set oConfigMgr = SF_Utils._GetUNOService(&quot;ModuleUIConfigurationManagerSupplier&quot;)
1436 Set oUIConfigMgr = oConfigMgr.getUIConfigurationManager(sConfigurationManager)
1437 vCommandBars = oUIConfigMgr.getUIElementsInfo(com.sun.star.ui.UIElementType.TOOLBAR)
1439 &apos; Ignore statusbar, menubar and popup menus. Store toolbars in dictionary
1440 For i = 0 To UBound(vCommandBars)
1441 vCommandBar = vCommandBars(i)
1442 sResourceURL = SF_Utils._GetPropertyValue(vCommandBar, &quot;ResourceURL&quot;)
1443 sUIName = SF_Utils._GetPropertyValue(vCommandBar, &quot;UIName&quot;)
1444 If Len(sUIName) &gt; 0 Then sBarName = sUIName Else sBarName = Split(sResourceURL, &quot;/&quot;)(2)
1445 &apos; Store a new entry in the returned dictionary
1446 If Not oToolbarsDict.Exists(sBarName) Then
1447 Set oToolbar = New _Toolbar
1448 With oToolbar
1449 Set .Component = poComponent
1450 .ResourceURL = sResourceURL
1451 .UIName = sUIName
1452 Set .UIConfigurationManager = oUIConfigMgr
1453 .ElementsInfoIndex = i
1454 &apos; Distinguish builtin and custom toolbars stored in the application
1455 If SF_String.StartsWith(sBarName, cstCUSTOM, CaseSensitive := True) Then
1456 .Storage = cstCUSTOMTOOLBAR
1457 sBarName = Mid(sBarName, Len(cstCUSTOM) + 1)
1458 Else
1459 .Storage = cstBUILTINTOOLBAR
1460 End If
1461 End With
1462 oToolbarsDict.Add(sBarName, oToolbar)
1463 End If
1464 Next i
1466 &apos; 2. Collect all toolbars stored in the current component/document
1468 &apos; Some components (e.g. datasheets) cannot contain own toolbars
1469 If SF_Session.HasUnoMethod(poComponent, &quot;getUIConfigurationManager&quot;) Then
1470 Set oUIConfigMgr = poComponent.getUIConfigurationManager
1471 vCommandBars = oUIConfigMgr.getUIElementsInfo(com.sun.star.ui.UIElementType.TOOLBAR)
1472 For i = 0 To UBound(vCommandBars)
1473 vCommandBar = vCommandBars(i)
1474 sResourceURL = SF_Utils._GetPropertyValue(vCommandBar, &quot;ResourceURL&quot;)
1475 sUIName = SF_Utils._GetPropertyValue(vCommandBar, &quot;UIName&quot;)
1476 If Len(sUIName) &gt; 0 Then sBarName = sUIName Else sBarName = Split(sResourceURL, &quot;/&quot;)(2)
1477 &apos; Store a new entry in the returned dictionary
1478 If Not oToolbarsDict.Exists(sBarName) Then
1479 Set oToolbar = New _Toolbar
1480 With oToolbar
1481 Set .Component = poComponent
1482 .ResourceURL = sResourceURL
1483 .UIName = sUIName
1484 Set .UIConfigurationManager = oUIConfigMgr
1485 .ElementsInfoIndex = i
1486 .Storage = cstCUSTOMDOCTOOLBAR
1487 End With
1488 oToolbarsDict.Add(sBarName, oToolbar)
1489 End If
1490 Next i
1491 End If
1493 Finally:
1494 Set _ListToolbars = oToolbarsDict
1495 Exit Function
1496 Catch:
1497 Set oToolbarsDict = Nothing
1498 GoTo Finally
1499 End Function &apos; ScriptForge.SF_UI._ListToolbars
1501 REM -----------------------------------------------------------------------------
1502 Public Function _PosSize() As Object
1503 &apos;&apos;&apos; Returns the PosSize structure of the active window
1505 Dim vWindow As Window &apos; A single component
1506 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
1507 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
1509 Set oPosSize = Nothing
1511 Try:
1512 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
1513 If Not IsNull(vWindow.Frame) Then
1514 Set oContainer = vWindow.Frame.ContainerWindow
1515 Set oPosSize = oContainer.getPosSize()
1516 End If
1518 Finally:
1519 Set _PosSize = oPosSize
1520 Exit Function
1521 End Function &apos; ScriptForge.SF_UI._PosSize
1523 REM -----------------------------------------------------------------------------
1524 Private Function _Repr() As String
1525 &apos;&apos;&apos; Convert the UI instance to a readable string, typically for debugging purposes (DebugPrint ...)
1526 &apos;&apos;&apos; Args:
1527 &apos;&apos;&apos; Return:
1528 &apos;&apos;&apos; &quot;[UI]&quot;
1530 _Repr = &quot;[UI]&quot;
1532 End Function &apos; ScriptForge.SF_UI._Repr
1534 REM ============================================ END OF SCRIPTFORGE.SF_UI
1535 </script:module>