calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / wizards / source / scriptforge / SF_UI.xba
blob186d88244d75ef7ba3367c8763c1d55194c0846c
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 &apos; The progress/status bar of the active window
60 &apos;Private oStatusBar As Object &apos; com.sun.star.task.XStatusIndicator
62 REM ============================================================ MODULE CONSTANTS
64 &apos; Special windows
65 Const BASICIDE = &quot;BASICIDE&quot;
66 Const WELCOMESCREEN = &quot;WELCOMESCREEN&quot;
68 &apos; Document types (only if not 1 of the special windows)
69 Const BASEDOCUMENT = &quot;Base&quot;
70 Const CALCDOCUMENT = &quot;Calc&quot;
71 Const DRAWDOCUMENT = &quot;Draw&quot;
72 Const IMPRESSDOCUMENT = &quot;Impress&quot;
73 Const MATHDOCUMENT = &quot;Math&quot;
74 Const WRITERDOCUMENT = &quot;Writer&quot;
76 &apos; Window subtypes
77 Const TABLEDATA = &quot;TableData&quot;
78 Const QUERYDATA = &quot;QueryData&quot;
79 Const SQLDATA = &quot;SqlData&quot;
80 Const BASEREPORT = &quot;BaseReport&quot;
81 Const BASEDIAGRAM = &quot;BaseDiagram&quot;
83 &apos; Macro execution modes
84 Const cstMACROEXECNORMAL = 0 &apos; Default, execution depends on user configuration and choice
85 Const cstMACROEXECNEVER = 1 &apos; Macros are not executed
86 Const cstMACROEXECALWAYS = 2 &apos; Macros are always executed
88 REM ===================================================== CONSTRUCTOR/DESTRUCTOR
90 REM -----------------------------------------------------------------------------
91 Public Function Dispose() As Variant
92 Set Dispose = Nothing
93 End Function &apos; ScriptForge.SF_UI Explicit destructor
95 REM ================================================================== PROPERTIES
97 REM -----------------------------------------------------------------------------
98 Public Function ActiveWindow() As String
99 &apos;&apos;&apos; Returns a valid WindowName for the currently active window
100 &apos;&apos;&apos; When &quot;&quot; is returned, the window could not be identified
102 Dim vWindow As Window &apos; A component
103 Dim oComp As Object &apos; com.sun.star.lang.XComponent
105 Set oComp = StarDesktop.CurrentComponent
106 If Not IsNull(oComp) Then
107 vWindow = SF_UI._IdentifyWindow(oComp)
108 With vWindow
109 If Len(.WindowFileName) &gt; 0 Then
110 ActiveWindow = SF_FileSystem._ConvertFromUrl(.WindowFileName)
111 ElseIf Len(.WindowName) &gt; 0 Then
112 ActiveWindow = .WindowName
113 ElseIf Len(.WindowTitle) &gt; 0 Then
114 ActiveWindow = .WindowTitle
115 Else
116 ActiveWindow = &quot;&quot;
117 End If
118 End With
119 End If
121 End Function &apos; ScriptForge.SF_UI.ActiveWindow
123 REM -----------------------------------------------------------------------------
124 Property Get Height() As Long
125 &apos;&apos;&apos; Returns the height of the active window
126 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
127 Set oPosSize = SF_UI._PosSize()
128 If Not IsNull(oPosSize) Then Height = oPosSize.Height Else Height = -1
129 End Property &apos; ScriptForge.SF_UI.Height
131 REM -----------------------------------------------------------------------------
132 Property Get MACROEXECALWAYS As Integer
133 &apos;&apos;&apos; Macros are always executed
134 MACROEXECALWAYS = cstMACROEXECALWAYS
135 End Property &apos; ScriptForge.SF_UI.MACROEXECALWAYS
137 REM -----------------------------------------------------------------------------
138 Property Get MACROEXECNEVER As Integer
139 &apos;&apos;&apos; Macros are not executed
140 MACROEXECNEVER = cstMACROEXECNEVER
141 End Property &apos; ScriptForge.SF_UI.MACROEXECNEVER
143 REM -----------------------------------------------------------------------------
144 Property Get MACROEXECNORMAL As Integer
145 &apos;&apos;&apos; Default, execution depends on user configuration and choice
146 MACROEXECNORMAL = cstMACROEXECNORMAL
147 End Property &apos; ScriptForge.SF_UI.MACROEXECNORMAL
149 REM -----------------------------------------------------------------------------
150 Property Get ObjectType As String
151 &apos;&apos;&apos; Only to enable object representation
152 ObjectType = &quot;SF_UI&quot;
153 End Property &apos; ScriptForge.SF_UI.ObjectType
155 REM -----------------------------------------------------------------------------
156 Property Get ServiceName As String
157 &apos;&apos;&apos; Internal use
158 ServiceName = &quot;ScriptForge.UI&quot;
159 End Property &apos; ScriptForge.SF_UI.ServiceName
161 REM -----------------------------------------------------------------------------
162 Property Get Width() As Long
163 &apos;&apos;&apos; Returns the width of the active window
164 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
165 Set oPosSize = SF_UI._PosSize()
166 If Not IsNull(oPosSize) Then Width = oPosSize.Width Else Width = -1
167 End Property &apos; ScriptForge.SF_UI.Width
169 REM -----------------------------------------------------------------------------
170 Property Get X() As Long
171 &apos;&apos;&apos; Returns the X coordinate of the active window
172 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
173 Set oPosSize = SF_UI._PosSize()
174 If Not IsNull(oPosSize) Then X = oPosSize.X Else X = -1
175 End Property &apos; ScriptForge.SF_UI.X
177 REM -----------------------------------------------------------------------------
178 Property Get Y() As Long
179 &apos;&apos;&apos; Returns the Y coordinate of the active window
180 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
181 Set oPosSize = SF_UI._PosSize()
182 If Not IsNull(oPosSize) Then Y = oPosSize.Y Else Y = -1
183 End Property &apos; ScriptForge.SF_UI.Y
185 REM ===================================================================== METHODS
187 REM -----------------------------------------------------------------------------
188 Public Function Activate(Optional ByVal WindowName As Variant) As Boolean
189 &apos;&apos;&apos; Make the specified window active
190 &apos;&apos;&apos; Args:
191 &apos;&apos;&apos; WindowName: see definitions
192 &apos;&apos;&apos; Returns:
193 &apos;&apos;&apos; True if the given window is found and can be activated
194 &apos;&apos;&apos; There is no change in the actual user interface if no window matches the selection
195 &apos;&apos;&apos; Examples:
196 &apos;&apos;&apos; ui.Activate(&quot;C:\Me\My file.odt&quot;)
198 Dim bActivate As Boolean &apos; Return value
199 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
200 Dim oComp As Object &apos; com.sun.star.lang.XComponent
201 Dim vWindow As Window &apos; A single component
202 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
203 Const cstThisSub = &quot;UI.Activate&quot;
204 Const cstSubArgs = &quot;WindowName&quot;
206 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
207 bActivate = False
209 Check:
210 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
211 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
212 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;) Then GoTo Finally
213 End If
215 Try:
216 Set oEnum = StarDesktop.Components().createEnumeration
217 Do While oEnum.hasMoreElements
218 Set oComp = oEnum.nextElement
219 vWindow = SF_UI._IdentifyWindow(oComp)
220 With vWindow
221 &apos; Does the current window match the arguments ?
222 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem._ConvertToUrl(WindowName)) _
223 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
224 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then
225 Set oContainer = vWindow.Frame.ContainerWindow
226 With oContainer
227 If .isVisible() = False Then .setVisible(True)
228 .IsMinimized = False
229 .setFocus()
230 .toFront() &apos; Force window change in Linux
231 Wait 1 &apos; Bypass desynchro issue in Linux
232 End With
233 bActivate = True
234 Exit Do
235 End If
236 End With
237 Loop
239 Finally:
240 Activate = bActivate
241 SF_Utils._ExitFunction(cstThisSub)
242 Exit Function
243 Catch:
244 GoTo Finally
245 End Function &apos; ScriptForge.SF_UI.Activate
247 REM -----------------------------------------------------------------------------
248 Public Function CreateBaseDocument(Optional ByVal FileName As Variant _
249 , Optional ByVal EmbeddedDatabase As Variant _
250 , Optional ByVal RegistrationName As Variant _
251 , Optional ByVal CalcFileName As Variant _
252 ) As Object
253 &apos;&apos;&apos; Create a new LibreOffice Base document embedding an empty database of the given type
254 &apos;&apos;&apos; Args:
255 &apos;&apos;&apos; FileName: Identifies the file to create. It must follow the SF_FileSystem.FileNaming notation
256 &apos;&apos;&apos; If the file already exists, it is overwritten without warning
257 &apos;&apos;&apos; EmbeddedDatabase: either &quot;HSQLDB&quot; (default) or &quot;FIREBIRD&quot; or &quot;CALC&quot;
258 &apos;&apos;&apos; RegistrationName: the name used to store the new database in the databases register
259 &apos;&apos;&apos; If &quot;&quot; (default), no registration takes place
260 &apos;&apos;&apos; If the name already exists it is overwritten without warning
261 &apos;&apos;&apos; CalcFileName: only when EmbedddedDatabase = &quot;CALC&quot;, the name of the file containing the tables as Calc sheets
262 &apos;&apos;&apos; The name of the file must be given in SF_FileSystem.FileNaming notation
263 &apos;&apos;&apos; The file must exist
264 &apos;&apos;&apos; Returns:
265 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
266 &apos;&apos;&apos; Exceptions
267 &apos;&apos;&apos; UNKNOWNFILEERROR Calc datasource does not exist
268 &apos;&apos;&apos; Examples:
269 &apos;&apos;&apos; Dim myBase As Object, myCalcBase As Object
270 &apos;&apos;&apos; Set myBase = ui.CreateBaseDocument(&quot;C:\Databases\MyBaseFile.odb&quot;, &quot;FIREBIRD&quot;)
271 &apos;&apos;&apos; Set myCalcBase = ui.CreateBaseDocument(&quot;C:\Databases\MyCalcBaseFile.odb&quot;, &quot;CALC&quot;, , &quot;C:\Databases\MyCalcFile.ods&quot;)
273 Dim oCreate As Variant &apos; Return value
274 Dim oDBContext As Object &apos; com.sun.star.sdb.DatabaseContext
275 Dim oDatabase As Object &apos; com.sun.star.comp.dba.ODatabaseSource
276 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
277 Dim sFileName As String &apos; Alias of FileName
278 Dim FSO As Object &apos; Alias for FileSystem service
279 Const cstDocType = &quot;private:factory/s&quot;
280 Const cstThisSub = &quot;UI.CreateBaseDocument&quot;
281 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;
283 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
284 Set oCreate = Nothing
285 Set FSO = CreateScriptService(&quot;FileSystem&quot;)
287 Check:
288 If IsMissing(EmbeddedDatabase) Or IsEmpty(EmbeddedDatabase) Then EmbeddedDatabase = &quot;HSQLDB&quot;
289 If IsMissing(RegistrationName) Or IsEmpty(RegistrationName) Then RegistrationName = &quot;&quot;
290 If IsMissing(CalcFileName) Or IsEmpty(CalcFileName) Then CalcFileName = &quot;&quot;
291 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
292 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
293 If Not SF_Utils._Validate(EmbeddedDatabase, &quot;EmbeddedDatabase&quot;, V_STRING, Array(&quot;CALC&quot;, &quot;HSQLDB&quot;, &quot;FIREBIRD&quot;)) Then GoTo Finally
294 If Not SF_Utils._Validate(RegistrationName, &quot;RegistrationName&quot;, V_STRING) Then GoTo Finally
295 If UCase(EmbeddedDatabase) = &quot;CALC&quot; Then
296 If Not SF_Utils._ValidateFile(CalcFileName, &quot;CalcFileName&quot;) Then GoTo Finally
297 If Not FSO.FileExists(CalcFileName) Then GoTo CatchNotExists
298 End If
299 End If
301 Try:
302 Set oDBContext = SF_Utils._GetUNOService(&quot;DatabaseContext&quot;)
303 With oDBContext
304 Set oDatabase = .createInstance()
305 &apos; Build the url link to the database
306 Select Case UCase(EmbeddedDatabase)
307 Case &quot;HSQLDB&quot;, &quot;FIREBIRD&quot;
308 oDatabase.URL = &quot;sdbc:embedded:&quot; &amp; LCase(EmbeddedDatabase)
309 Case &quot;CALC&quot;
310 oDatabase.URL = &quot;sdbc:calc:&quot; &amp; FSO._ConvertToUrl(CalcFileName)
311 End Select
312 &apos; Create empty Base document
313 sFileName = FSO._ConvertToUrl(FileName)
314 &apos; An existing file is overwritten without warning
315 If FSO.FileExists(FileName) Then FSO.DeleteFile(FileName)
316 If FSO.FileExists(FileName &amp; &quot;.lck&quot;) Then FSO.DeleteFile(FileName &amp; &quot;.lck&quot;)
317 oDatabase.DatabaseDocument.storeAsURL(sFileName, Array(SF_Utils._MakePropertyValue(&quot;Overwrite&quot;, True)))
318 &apos; Register database if requested
319 If Len(RegistrationName) &gt; 0 Then
320 If .hasRegisteredDatabase(RegistrationName) Then
321 .changeDatabaseLocation(RegistrationName, sFileName)
322 Else
323 .registerDatabaseLocation(RegistrationName, sFileName)
324 End If
325 End If
326 End With
328 Set oCreate = OpenBaseDocument(FileName)
330 Finally:
331 Set CreateBaseDocument = oCreate
332 SF_Utils._ExitFunction(cstThisSub)
333 Exit Function
334 Catch:
335 GoTo Finally
336 CatchNotExists:
337 SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;CalcFileName&quot;, CalcFileName)
338 GoTo Finally
339 End Function &apos; ScriptForge.SF_UI.CreateBaseDocument
341 REM -----------------------------------------------------------------------------
342 Public Function CreateDocument(Optional ByVal DocumentType As Variant _
343 , Optional ByVal TemplateFile As Variant _
344 , Optional ByVal Hidden As Variant _
345 ) As Object
346 &apos;&apos;&apos; Create a new LibreOffice document of a given type or based on a given template
347 &apos;&apos;&apos; Args:
348 &apos;&apos;&apos; DocumentType: &quot;Calc&quot;, &quot;Writer&quot;, etc. If absent, a TemplateFile must be given
349 &apos;&apos;&apos; TemplateFile: the full FileName of the template to build the new document on
350 &apos;&apos;&apos; If the file does not exist, the argument is ignored
351 &apos;&apos;&apos; The &quot;FileSystem&quot; service provides the TemplatesFolder and UserTemplatesFolder
352 &apos;&apos;&apos; properties to help to build the argument
353 &apos;&apos;&apos; Hidden: if True, open in the background (default = False)
354 &apos;&apos;&apos; To use with caution: activation or closure can only happen programmatically
355 &apos;&apos;&apos; Returns:
356 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
357 &apos;&apos;&apos; Exceptions:
358 &apos;&apos;&apos; DOCUMENTCREATIONERROR Wrong arguments
359 &apos;&apos;&apos; Examples:
360 &apos;&apos;&apos; Dim myDoc1 As Object, myDoc2 As Object, FSO As Object
361 &apos;&apos;&apos; Set myDoc1 = ui.CreateDocument(&quot;Calc&quot;)
362 &apos;&apos;&apos; Set FSO = CreateScriptService(&quot;FileSystem&quot;)
363 &apos;&apos;&apos; Set myDoc2 = ui.CreateDocument(, FSO.BuildPath(FSO.TemplatesFolder, &quot;personal/CV.ott&quot;))
365 Dim oCreate As Variant &apos; Return value
366 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
367 Dim bTemplateExists As Boolean &apos; True if TemplateFile is valid
368 Dim sNew As String &apos; File url
369 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
370 Const cstDocType = &quot;private:factory/s&quot;
371 Const cstThisSub = &quot;UI.CreateDocument&quot;
372 Const cstSubArgs = &quot;[DocumentType=&quot;&quot;&quot;&quot;], [TemplateFile=&quot;&quot;&quot;&quot;], [Hidden=False]&quot;
374 &apos;&gt;&gt;&gt; If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
375 Set oCreate = Nothing
377 Check:
378 If IsMissing(DocumentType) Or IsEmpty(DocumentType) Then DocumentType = &quot;&quot;
379 If IsMissing(TemplateFile) Or IsEmpty(TemplateFile) Then TemplateFile = &quot;&quot;
380 If IsMissing(Hidden) Or IsEmpty(Hidden) Then Hidden = False
382 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
383 If Not SF_Utils._Validate(DocumentType, &quot;DocumentType&quot;, V_STRING _
384 , Array(&quot;&quot;, BASEDOCUMENT, CALCDOCUMENT, DRAWDOCUMENT _
385 , IMPRESSDOCUMENT, MATHDOCUMENT, WRITERDOCUMENT)) Then GoTo Finally
386 If Not SF_Utils._ValidateFile(TemplateFile, &quot;TemplateFile&quot;, , True) Then GoTo Finally
387 If Not SF_Utils._Validate(Hidden, &quot;Hidden&quot;, V_BOOLEAN) Then GoTo Finally
388 End If
390 If Len(DocumentType) + Len(TemplateFile) = 0 Then GoTo CatchError
391 If Len(TemplateFile) &gt; 0 Then bTemplateExists = SF_FileSystem.FileExists(TemplateFile) Else bTemplateExists = False
392 If Len(DocumentType) = 0 Then
393 If Not bTemplateExists Then GoTo CatchError
394 End If
396 Try:
397 If bTemplateExists Then sNew = SF_FileSystem._ConvertToUrl(TemplateFile) Else sNew = cstDocType &amp; LCase(DocumentType)
398 vProperties = Array( _
399 SF_Utils._MakePropertyValue(&quot;AsTemplate&quot;, bTemplateExists) _
400 , SF_Utils._MakePropertyValue(&quot;Hidden&quot;, Hidden) _
402 Set oComp = StarDesktop.loadComponentFromURL(sNew, &quot;_blank&quot;, 0, vProperties)
403 If Not IsNull(oComp) Then Set oCreate = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
405 Finally:
406 Set CreateDocument = oCreate
407 SF_Utils._ExitFunction(cstThisSub)
408 Exit Function
409 Catch:
410 GoTo Finally
411 CatchError:
412 SF_Exception.RaiseFatal(DOCUMENTCREATIONERROR, &quot;DocumentType&quot;, DocumentType, &quot;TemplateFile&quot;, TemplateFile)
413 GoTo Finally
414 End Function &apos; ScriptForge.SF_UI.CreateDocument
416 REM -----------------------------------------------------------------------------
417 Public Function Documents() As Variant
418 &apos;&apos;&apos; Returns the list of the currently open documents. Special windows are ignored.
419 &apos;&apos;&apos; Returns:
420 &apos;&apos;&apos; A zero-based 1D array of filenames (in SF_FileSystem.FileNaming notation)
421 &apos;&apos;&apos; or of window titles for unsaved documents
422 &apos;&apos;&apos; Examples:
423 &apos;&apos;&apos; Dim vDocs As Variant, sDoc As String
424 &apos;&apos;&apos; vDocs = ui.Documents()
425 &apos;&apos;&apos; For each sDoc In vDocs
426 &apos;&apos;&apos; ...
428 Dim vDocuments As Variant &apos; Return value
429 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
430 Dim oComp As Object &apos; com.sun.star.lang.XComponent
431 Dim vWindow As Window &apos; A single component
432 Const cstThisSub = &quot;UI.Documents&quot;
433 Const cstSubArgs = &quot;&quot;
435 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
436 vDocuments = Array()
438 Check:
439 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
441 Try:
442 Set oEnum = StarDesktop.Components().createEnumeration
443 Do While oEnum.hasMoreElements
444 Set oComp = oEnum.nextElement
445 vWindow = SF_UI._IdentifyWindow(oComp)
446 With vWindow
447 If Len(.WindowFileName) &gt; 0 Then
448 vDocuments = SF_Array.Append(vDocuments, SF_FileSystem._ConvertFromUrl(.WindowFileName))
449 ElseIf Len(.WindowTitle) &gt; 0 Then
450 vDocuments = SF_Array.Append(vDocuments, .WindowTitle)
451 End If
452 End With
453 Loop
455 Finally:
456 Documents = vDocuments
457 SF_Utils._ExitFunction(cstThisSub)
458 Exit Function
459 Catch:
460 GoTo Finally
461 End Function &apos; ScriptForge.SF_UI.Documents
463 REM -----------------------------------------------------------------------------
464 Public Function GetDocument(Optional ByVal WindowName As Variant) As Variant
465 &apos;&apos;&apos; Returns a SFDocuments.Document object referring to the active window or the given window
466 &apos;&apos;&apos; Args:
467 &apos;&apos;&apos; WindowName: when a string, see definitions. If absent the active window is considered.
468 &apos;&apos;&apos; when an object, must be a UNO object of types
469 &apos;&apos;&apos; com.sun.star.lang.XComponent or com.sun.star.comp.dba.ODatabaseDocument
470 &apos;&apos;&apos; Exceptions:
471 &apos;&apos;&apos; DOCUMENTERROR The targeted window could not be found
472 &apos;&apos;&apos; Examples:
473 &apos;&apos;&apos; Dim oDoc As Object
474 &apos;&apos;&apos; Set oDoc = ui.GetDocument &apos; or Set oDoc = ui.GetDocument(ThisComponent)
475 &apos;&apos;&apos; oDoc.Save()
477 Dim oDocument As Object &apos; Return value
478 Const cstThisSub = &quot;UI.GetDocument&quot;
479 Const cstSubArgs = &quot;[WindowName]&quot;
481 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
482 Set oDocument = Nothing
484 Check:
485 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
486 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
487 If Not SF_Utils._Validate(WindowName, &quot;WindowName&quot;, Array(V_STRING, V_OBJECT)) Then GoTo Finally
488 If VarType(WindowName) = V_STRING Then
489 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
490 End If
491 End If
493 Try:
494 Set oDocument = SF_Services.CreateScriptService(&quot;SFDocuments.Document&quot;, WindowName)
495 If IsNull(oDocument) Then GoTo CatchDeliver
497 Finally:
498 Set GetDocument = oDocument
499 SF_Utils._ExitFunction(cstThisSub)
500 Exit Function
501 Catch:
502 GoTo Finally
503 CatchDeliver:
504 SF_Exception.RaiseFatal(DOCUMENTERROR, &quot;WindowName&quot;, WindowName)
505 GoTo Finally
506 End Function &apos; ScriptForge.SF_UI.GetDocument
508 REM -----------------------------------------------------------------------------
509 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
510 &apos;&apos;&apos; Return the actual value of the given property
511 &apos;&apos;&apos; Args:
512 &apos;&apos;&apos; PropertyName: the name of the property as a string
513 &apos;&apos;&apos; Returns:
514 &apos;&apos;&apos; The actual value of the property
515 &apos;&apos;&apos; Exceptions
516 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
518 Const cstThisSub = &quot;UI.GetProperty&quot;
519 Const cstSubArgs = &quot;PropertyName&quot;
521 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
522 GetProperty = Null
524 Check:
525 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
526 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
527 End If
529 Try:
530 Select Case UCase(PropertyName)
531 Case &quot;ACTIVEWINDOW&quot; : GetProperty = ActiveWindow()
532 Case &quot;HEIGHT&quot; : GetProperty = SF_UI.Height
533 Case &quot;WIDTH&quot; : GetProperty = SF_UI.Width
534 Case &quot;X&quot; : GetProperty = SF_UI.X
535 Case &quot;Y&quot; : GetProperty = SF_UI.Y
537 Case Else
538 End Select
540 Finally:
541 SF_Utils._ExitFunction(cstThisSub)
542 Exit Function
543 Catch:
544 GoTo Finally
545 End Function &apos; ScriptForge.SF_UI.GetProperty
547 REM -----------------------------------------------------------------------------
548 Public Sub Maximize(Optional ByVal WindowName As Variant)
549 &apos;&apos;&apos; Maximizes the active window or the given window
550 &apos;&apos;&apos; Args:
551 &apos;&apos;&apos; WindowName: see definitions. If absent the active window is considered
552 &apos;&apos;&apos; Examples:
553 &apos;&apos;&apos; ui.Maximize
554 &apos;&apos;&apos; ...
556 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
557 Dim oComp As Object &apos; com.sun.star.lang.XComponent
558 Dim vWindow As Window &apos; A single component
559 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
560 Dim bFound As Boolean &apos; True if window found
561 Const cstThisSub = &quot;UI.Maximize&quot;
562 Const cstSubArgs = &quot;[WindowName]&quot;
564 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
566 Check:
567 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
568 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
569 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
570 End If
572 Try:
573 bFound = False
574 If Len(WindowName) &gt; 0 Then
575 Set oEnum = StarDesktop.Components().createEnumeration
576 Do While oEnum.hasMoreElements And Not bFound
577 Set oComp = oEnum.nextElement
578 vWindow = SF_UI._IdentifyWindow(oComp)
579 With vWindow
580 &apos; Does the current window match the arguments ?
581 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
582 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
583 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then bFound = True
584 End With
585 Loop
586 Else
587 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
588 bFound = True
589 End If
591 If bFound Then
592 Set oContainer = vWindow.Frame.ContainerWindow
593 oContainer.IsMaximized = True
594 End If
596 Finally:
597 SF_Utils._ExitFunction(cstThisSub)
598 Exit Sub
599 Catch:
600 GoTo Finally
601 End Sub &apos; ScriptForge.SF_UI.Maximize
603 REM -----------------------------------------------------------------------------
604 Public Sub Minimize(Optional ByVal WindowName As Variant)
605 &apos;&apos;&apos; Minimizes the current window or the given window
606 &apos;&apos;&apos; Args:
607 &apos;&apos;&apos; WindowName: see definitions. If absent the current window is considered
608 &apos;&apos;&apos; Examples:
609 &apos;&apos;&apos; ui.Minimize(&quot;myFile.ods&quot;)
610 &apos;&apos;&apos; ...
612 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
613 Dim oComp As Object &apos; com.sun.star.lang.XComponent
614 Dim vWindow As Window &apos; A single component
615 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
616 Dim bFound As Boolean &apos; True if window found
617 Const cstThisSub = &quot;UI.Minimize&quot;
618 Const cstSubArgs = &quot;[WindowName]&quot;
620 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
622 Check:
623 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
624 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
625 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;, , True) Then GoTo Finally
626 End If
628 Try:
629 bFound = False
630 If Len(WindowName) &gt; 0 Then
631 Set oEnum = StarDesktop.Components().createEnumeration
632 Do While oEnum.hasMoreElements And Not bFound
633 Set oComp = oEnum.nextElement
634 vWindow = SF_UI._IdentifyWindow(oComp)
635 With vWindow
636 &apos; Does the current window match the arguments ?
637 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
638 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
639 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then bFound = True
640 End With
641 Loop
642 Else
643 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
644 bFound = True
645 End If
647 If bFound Then
648 Set oContainer = vWindow.Frame.ContainerWindow
649 oContainer.IsMinimized = True
650 End If
652 Finally:
653 SF_Utils._ExitFunction(cstThisSub)
654 Exit Sub
655 Catch:
656 GoTo Finally
657 End Sub &apos; ScriptForge.SF_UI.Minimize
659 REM -----------------------------------------------------------------------------
660 Public Function Methods() As Variant
661 &apos;&apos;&apos; Return the list of public methods of the UI service as an array
663 Methods = Array(&quot;Activate&quot; _
664 , &quot;CreateBaseDocument&quot; _
665 , &quot;CreateDocument&quot; _
666 , &quot;Documents&quot; _
667 , &quot;GetDocument&quot; _
668 , &quot;Maximize&quot; _
669 , &quot;Minimize&quot; _
670 , &quot;OpenBaseDocument&quot; _
671 , &quot;OpenDocument&quot; _
672 , &quot;Resize&quot; _
673 , &quot;RunCommand&quot; _
674 , &quot;SetStatusbar&quot; _
675 , &quot;ShowProgressBar&quot; _
676 , &quot;WindowExists&quot; _
679 End Function &apos; ScriptForge.SF_UI.Methods
681 REM -----------------------------------------------------------------------------
682 Public Function OpenBaseDocument(Optional ByVal FileName As Variant _
683 , Optional ByVal RegistrationName As Variant _
684 , Optional ByVal MacroExecution As Variant _
685 ) As Object
686 &apos;&apos;&apos; Open an existing LibreOffice Base document and return a SFDocuments.Document object
687 &apos;&apos;&apos; Args:
688 &apos;&apos;&apos; FileName: Identifies the file to open. It must follow the SF_FileSystem.FileNaming notation
689 &apos;&apos;&apos; RegistrationName: the name of a registered database
690 &apos;&apos;&apos; It is ignored if FileName &lt;&gt; &quot;&quot;
691 &apos;&apos;&apos; MacroExecution: one of the MACROEXECxxx constants
692 &apos;&apos;&apos; Returns:
693 &apos;&apos;&apos; A SFDocuments.SF_Base object
694 &apos;&apos;&apos; Null if the opening failed, including when due to a user decision
695 &apos;&apos;&apos; Exceptions:
696 &apos;&apos;&apos; BASEDOCUMENTOPENERROR Wrong arguments
697 &apos;&apos;&apos; Examples:
698 &apos;&apos;&apos; Dim mBasec As Object, FSO As Object
699 &apos;&apos;&apos; Set myBase = ui.OpenBaseDocument(&quot;C:\Temp\myDB.odb&quot;, MacroExecution := ui.MACROEXECNEVER)
701 Dim oOpen As Variant &apos; Return value
702 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
703 Dim oDBContext As Object &apos; com.sun.star.sdb.DatabaseContext
704 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
705 Dim sFile As String &apos; Alias for FileName
706 Dim iMacro As Integer &apos; Alias for MacroExecution
707 Const cstThisSub = &quot;UI.OpenBaseDocument&quot;
708 Const cstSubArgs = &quot;[FileName=&quot;&quot;&quot;&quot;], [RegistrationName=&quot;&quot;&quot;&quot;], [MacroExecution=0|1|2]&quot;
710 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
711 Set oOpen = Nothing
713 Check:
714 If IsMissing(FileName) Or IsEmpty(FileName) Then FileName = &quot;&quot;
715 If IsMissing(RegistrationName) Or IsEmpty(RegistrationName) Then RegistrationName = &quot;&quot;
716 If IsMissing(MacroExecution) Or IsEmpty(MacroExecution) Then MacroExecution = MACROEXECNORMAL
718 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
719 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;, , True) Then GoTo Finally
720 If Not SF_Utils._Validate(RegistrationName, &quot;RegistrationName&quot;, V_STRING) Then GoTo Finally
721 If Not SF_Utils._Validate(MacroExecution, &quot;MacroExecution&quot;, V_NUMERIC _
722 , Array(MACROEXECNORMAL, MACROEXECNEVER, MACROEXECALWAYS)) Then GoTo Finally
723 End If
725 &apos; Check the existence of FileName
726 If Len(FileName) = 0 Then &apos; FileName has precedence over RegistrationName
727 If Len(RegistrationName) = 0 Then GoTo CatchError
728 Set oDBContext = SF_Utils._GetUNOService(&quot;DatabaseContext&quot;)
729 If Not oDBContext.hasRegisteredDatabase(RegistrationName) Then GoTo CatchError
730 FileName = SF_FileSystem._ConvertFromUrl(oDBContext.getDatabaseLocation(RegistrationName))
731 End If
732 If Not SF_FileSystem.FileExists(FileName) Then GoTo CatchError
734 Try:
735 With com.sun.star.document.MacroExecMode
736 Select Case MacroExecution
737 Case 0 : iMacro = .USE_CONFIG
738 Case 1 : iMacro = .NEVER_EXECUTE
739 Case 2 : iMacro = .ALWAYS_EXECUTE_NO_WARN
740 End Select
741 End With
743 vProperties = Array(SF_Utils._MakePropertyValue(&quot;MacroExecutionMode&quot;, iMacro))
745 sFile = SF_FileSystem._ConvertToUrl(FileName)
746 Set oComp = StarDesktop.loadComponentFromURL(sFile, &quot;_blank&quot;, 0, vProperties)
747 If Not IsNull(oComp) Then Set oOpen = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
749 Finally:
750 Set OpenBaseDocument = oOpen
751 SF_Utils._ExitFunction(cstThisSub)
752 Exit Function
753 Catch:
754 GoTo Finally
755 CatchError:
756 SF_Exception.RaiseFatal(BASEDOCUMENTOPENERROR, &quot;FileName&quot;, FileName, &quot;RegistrationName&quot;, RegistrationName)
757 GoTo Finally
758 End Function &apos; ScriptForge.SF_UI.OpenBaseDocument
760 REM -----------------------------------------------------------------------------
761 Public Function OpenDocument(Optional ByVal FileName As Variant _
762 , Optional ByVal Password As Variant _
763 , Optional ByVal ReadOnly As Variant _
764 , Optional ByVal Hidden As Variant _
765 , Optional ByVal MacroExecution As Variant _
766 , Optional ByVal FilterName As Variant _
767 , Optional ByVal FilterOptions As Variant _
768 ) As Object
769 &apos;&apos;&apos; Open an existing LibreOffice document with the given options
770 &apos;&apos;&apos; Args:
771 &apos;&apos;&apos; FileName: Identifies the file to open. It must follow the SF_FileSystem.FileNaming notation
772 &apos;&apos;&apos; Password: To use when the document is protected
773 &apos;&apos;&apos; If wrong or absent while the document is protected, the user will be prompted to enter a password
774 &apos;&apos;&apos; ReadOnly: Default = False
775 &apos;&apos;&apos; Hidden: if True, open in the background (default = False)
776 &apos;&apos;&apos; To use with caution: activation or closure can only happen programmatically
777 &apos;&apos;&apos; MacroExecution: one of the MACROEXECxxx constants
778 &apos;&apos;&apos; FilterName: the name of a filter that should be used for loading the document
779 &apos;&apos;&apos; If present, the filter must exist
780 &apos;&apos;&apos; FilterOptions: an optional string of options associated with the filter
781 &apos;&apos;&apos; Returns:
782 &apos;&apos;&apos; A SFDocuments.SF_Document object or one of its subclasses
783 &apos;&apos;&apos; Null if the opening failed, including when due to a user decision
784 &apos;&apos;&apos; Exceptions:
785 &apos;&apos;&apos; DOCUMENTOPENERROR Wrong arguments
786 &apos;&apos;&apos; Examples:
787 &apos;&apos;&apos; Dim myDoc As Object, FSO As Object
788 &apos;&apos;&apos; Set myDoc = ui.OpenDocument(&quot;C:\Temp\myFile.odt&quot;, MacroExecution := ui.MACROEXECNEVER)
790 Dim oOpen As Variant &apos; Return value
791 Dim oFilterFactory As Object &apos; com.sun.star.document.FilterFactory
792 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
793 Dim oComp As Object &apos; Loaded component com.sun.star.lang.XComponent
794 Dim sFile As String &apos; Alias for FileName
795 Dim iMacro As Integer &apos; Alias for MacroExecution
796 Const cstThisSub = &quot;UI.OpenDocument&quot;
797 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;
799 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
800 Set oOpen = Nothing
802 Check:
803 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
804 If IsMissing(ReadOnly) Or IsEmpty(ReadOnly) Then ReadOnly = False
805 If IsMissing(Hidden) Or IsEmpty(Hidden) Then Hidden = False
806 If IsMissing(MacroExecution) Or IsEmpty(MacroExecution) Then MacroExecution = MACROEXECNORMAL
807 If IsMissing(FilterName) Or IsEmpty(FilterName) Then FilterName = &quot;&quot;
808 If IsMissing(FilterOptions) Or IsEmpty(FilterOptions) Then FilterOptions = &quot;&quot;
810 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
811 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
812 If Not SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
813 If Not SF_Utils._Validate(ReadOnly, &quot;ReadOnly&quot;, V_BOOLEAN) Then GoTo Finally
814 If Not SF_Utils._Validate(Hidden, &quot;Hidden&quot;, V_BOOLEAN) Then GoTo Finally
815 If Not SF_Utils._Validate(MacroExecution, &quot;MacroExecution&quot;, V_NUMERIC _
816 , Array(MACROEXECNORMAL, MACROEXECNEVER, MACROEXECALWAYS)) Then GoTo Finally
817 If Not SF_Utils._Validate(FilterName, &quot;FilterName&quot;, V_STRING) Then GoTo Finally
818 If Not SF_Utils._Validate(FilterOptions, &quot;FilterOptions&quot;, V_STRING) Then GoTo Finally
819 End If
821 &apos; Check the existence of FileName and FilterName
822 If Not SF_FileSystem.FileExists(FileName) Then GoTo CatchError
823 If Len(FilterName) &gt; 0 Then
824 Set oFilterFactory = SF_Utils._GetUNOService(&quot;FilterFactory&quot;)
825 If Not oFilterFactory.hasByName(FilterName) Then GoTo CatchError
826 End If
828 Try:
829 With com.sun.star.document.MacroExecMode
830 Select Case MacroExecution
831 Case 0 : iMacro = .USE_CONFIG
832 Case 1 : iMacro = .NEVER_EXECUTE
833 Case 2 : iMacro = .ALWAYS_EXECUTE_NO_WARN
834 End Select
835 End With
837 vProperties = Array( _
838 SF_Utils._MakePropertyValue(&quot;ReadOnly&quot;, ReadOnly) _
839 , SF_Utils._MakePropertyValue(&quot;Hidden&quot;, Hidden) _
840 , SF_Utils._MakePropertyValue(&quot;MacroExecutionMode&quot;, iMacro) _
841 , SF_Utils._MakePropertyValue(&quot;FilterName&quot;, FilterName) _
842 , SF_Utils._MakePropertyValue(&quot;FilterOptions&quot;, FilterOptions) _
844 If Len(Password) &gt; 0 Then &apos; Password is to add only if &lt;&gt; &quot;&quot; !?
845 vProperties = SF_Array.Append(vProperties, SF_Utils._MakePropertyValue(&quot;Password&quot;, Password))
846 End If
848 sFile = SF_FileSystem._ConvertToUrl(FileName)
849 Set oComp = StarDesktop.loadComponentFromURL(sFile, &quot;_blank&quot;, 0, vProperties)
850 If Not IsNull(oComp) Then Set oOpen = CreateScriptService(&quot;SFDocuments.Document&quot;, oComp)
852 Finally:
853 Set OpenDocument = oOpen
854 SF_Utils._ExitFunction(cstThisSub)
855 Exit Function
856 Catch:
857 GoTo Finally
858 CatchError:
859 SF_Exception.RaiseFatal(DOCUMENTOPENERROR, &quot;FileName&quot;, FileName, &quot;Password&quot;, Password, &quot;FilterName&quot;, FilterName)
860 GoTo Finally
861 End Function &apos; ScriptForge.SF_UI.OpenDocument
863 REM -----------------------------------------------------------------------------
864 Public Function Properties() As Variant
865 &apos;&apos;&apos; Return the list or properties of the Timer class as an array
867 Properties = Array( _
868 &quot;ActiveWindow&quot; _
869 , &quot;Height&quot; _
870 , &quot;Width&quot; _
871 , &quot;X&quot; _
872 , &quot;Y&quot; _
875 End Function &apos; ScriptForge.SF_UI.Properties
877 REM -----------------------------------------------------------------------------
878 Public Sub Resize(Optional ByVal Left As Variant _
879 , Optional ByVal Top As Variant _
880 , Optional ByVal Width As Variant _
881 , Optional ByVal Height As Variant _
883 &apos;&apos;&apos; Resizes and/or moves the active window. Negative arguments are ignored.
884 &apos;&apos;&apos; If the window was minimized or without arguments, it is restored
885 &apos;&apos;&apos; Args:
886 &apos;&apos;&apos; Left, Top: Distances from top and left edges of the screen
887 &apos;&apos;&apos; Width, Height: Dimensions of the window
888 &apos;&apos;&apos; Examples:
889 &apos;&apos;&apos; ui.Resize(10,,500) &apos; Top and Height are unchanged
890 &apos;&apos;&apos; ...
892 Dim vWindow As Window &apos; A single component
893 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
894 Dim iPosSize As Integer &apos; Computes which of the 4 arguments should be considered
895 Const cstThisSub = &quot;UI.Resize&quot;
896 Const cstSubArgs = &quot;[Left], [Top], [Width], [Height]&quot;
898 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
900 Check:
901 If IsMissing(Left) Or IsEmpty(Left) Then Left = -1
902 If IsMissing(Top) Or IsEmpty(Top) Then Top = -1
903 If IsMissing(Width) Or IsEmpty(Width) Then Width = -1
904 If IsMissing(Height) Or IsEmpty(Height) Then Height = -1
905 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
906 If Not SF_Utils._Validate(Left, &quot;Left&quot;, V_NUMERIC) Then GoTo Finally
907 If Not SF_Utils._Validate(Top, &quot;Top&quot;, V_NUMERIC) Then GoTo Finally
908 If Not SF_Utils._Validate(Width, &quot;Width&quot;, V_NUMERIC) Then GoTo Finally
909 If Not SF_Utils._Validate(Height, &quot;Height&quot;, V_NUMERIC) Then GoTo Finally
910 End If
912 Try:
913 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
914 If Not IsNull(vWindow.Frame) Then
915 Set oContainer = vWindow.Frame.ContainerWindow
916 iPosSize = 0
917 If Left &gt;= 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.X
918 If Top &gt;= 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.Y
919 If Width &gt; 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.WIDTH
920 If Height &gt; 0 Then iPosSize = iPosSize + com.sun.star.awt.PosSize.HEIGHT
921 With oContainer
922 .IsMaximized = False
923 .IsMinimized = False
924 .setPosSize(Left, Top, Width, Height, iPosSize)
925 End With
926 End If
928 Finally:
929 SF_Utils._ExitFunction(cstThisSub)
930 Exit Sub
931 Catch:
932 GoTo Finally
933 End Sub &apos; ScriptForge.SF_UI.Resize
935 REM -----------------------------------------------------------------------------
936 Public Sub RunCommand(Optional ByVal Command As Variant _
937 , ParamArray Args As Variant _
939 &apos;&apos;&apos; Run on the current window the given menu command. The command is executed with or without arguments
940 &apos;&apos;&apos; A few typical commands:
941 &apos;&apos;&apos; About, Delete, Edit, Undo, Copy, Paste, ...
942 &apos;&apos;&apos; Dozens can be found on next page: https://wiki.documentfoundation.org/Development/DispatchCommands
943 &apos;&apos;&apos; Args:
944 &apos;&apos;&apos; Command: Case-sensitive. The command itself is not checked.
945 &apos;&apos;&apos; If the command does not contain the &quot;.uno:&quot; prefix, it is added.
946 &apos;&apos;&apos; If nothing happens, then the command is probably wrong
947 &apos;&apos;&apos; Args: Pairs of arguments name (string), value (any)
948 &apos;&apos;&apos; Returns:
949 &apos;&apos;&apos; Examples:
950 &apos;&apos;&apos; ui.RunCommand(&quot;BasicIDEAppear&quot;, _
951 &apos;&apos;&apos; &quot;Document&quot;, &quot;LibreOffice Macros &amp; Dialogs&quot;, _
952 &apos;&apos;&apos; &quot;LibName&quot;, &quot;ScriptForge&quot;, _
953 &apos;&apos;&apos; &quot;Name&quot;, &quot;SF_Session&quot;, _
954 &apos;&apos;&apos; &quot;Line&quot;, 600)
956 Dim oDispatch &apos; com.sun.star.frame.DispatchHelper
957 Dim vProps As Variant &apos; Array of PropertyValues
958 Dim vValue As Variant &apos; A single value argument
959 Dim sCommand As String &apos; Alias of Command
960 Dim i As Long
961 Const cstPrefix = &quot;.uno:&quot;
963 Const cstThisSub = &quot;UI.RunCommand&quot;
964 Const cstSubArgs = &quot;Command, [arg0Name, arg0Value], [arg1Name, arg1Value], ...&quot;
966 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
968 Check:
969 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
970 If Not SF_Utils._Validate(Command, &quot;Command&quot;, V_STRING) Then GoTo Finally
971 If Not SF_Utils._ValidateArray(Args, &quot;Args&quot;, 1) Then GoTo Finally
972 For i = 0 To UBound(Args) - 1 Step 2
973 If Not SF_Utils._Validate(Args(i), &quot;Arg&quot; &amp; CStr(i/2) &amp; &quot;Name&quot;, V_STRING) Then GoTo Finally
974 Next i
975 End If
977 Try:
978 &apos; Build array of property values
979 vProps = Array()
980 For i = 0 To UBound(Args) - 1 Step 2
981 If IsEmpty(Args(i + 1)) Then vValue = Null Else vValue = Args(i + 1)
982 vProps = SF_Array.Append(vProps, SF_Utils._MakePropertyValue(Args(i), vValue))
983 Next i
984 Set oDispatch = SF_Utils._GetUNOService(&quot;DispatchHelper&quot;)
985 If SF_String.StartsWith(Command, cstPrefix) Then sCommand = Command Else sCommand = cstPrefix &amp; Command
986 oDispatch.executeDispatch(StarDesktop.ActiveFrame, sCommand, &quot;&quot;, 0, vProps)
988 Finally:
989 SF_Utils._ExitFunction(cstThisSub)
990 Exit Sub
991 Catch:
992 GoTo Finally
993 End Sub &apos; ScriptForge.SF_UI.RunCommand
995 REM -----------------------------------------------------------------------------
996 Public Function SetProperty(Optional ByVal PropertyName As Variant _
997 , Optional ByRef Value As Variant _
998 ) As Boolean
999 &apos;&apos;&apos; Set a new value to the given property
1000 &apos;&apos;&apos; Args:
1001 &apos;&apos;&apos; PropertyName: the name of the property as a string
1002 &apos;&apos;&apos; Value: its new value
1003 &apos;&apos;&apos; Exceptions
1004 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
1006 Const cstThisSub = &quot;UI.SetProperty&quot;
1007 Const cstSubArgs = &quot;PropertyName, Value&quot;
1009 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1010 SetProperty = False
1012 Check:
1013 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1014 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
1015 End If
1017 Try:
1018 Select Case UCase(PropertyName)
1019 Case Else
1020 End Select
1022 Finally:
1023 SF_Utils._ExitFunction(cstThisSub)
1024 Exit Function
1025 Catch:
1026 GoTo Finally
1027 End Function &apos; ScriptForge.SF_UI.SetProperty
1029 REM -----------------------------------------------------------------------------
1030 Public Sub SetStatusbar(Optional ByVal Text As Variant _
1031 , Optional ByVal Percentage As Variant _
1033 &apos;&apos;&apos; Display a text and a progressbar in the status bar of the active window
1034 &apos;&apos;&apos; Any subsequent calls in the same macro run refer to the same status bar of the same window,
1035 &apos;&apos;&apos; even if the window is not active anymore
1036 &apos;&apos;&apos; A call without arguments resets the status bar to its normal state.
1037 &apos;&apos;&apos; Args:
1038 &apos;&apos;&apos; Text: the optional text to be displayed before the progress bar
1039 &apos;&apos;&apos; Percentage: the optional degree of progress between 0 and 100
1040 &apos;&apos;&apos; Examples:
1041 &apos;&apos;&apos; Dim i As Integer
1042 &apos;&apos;&apos; For i = 0 To 100
1043 &apos;&apos;&apos; ui.SetStatusbar(&quot;Progress ...&quot;, i)
1044 &apos;&apos;&apos; Wait 50
1045 &apos;&apos;&apos; Next i
1046 &apos;&apos;&apos; ui.SetStatusbar
1048 Dim oComp As Object
1049 Dim oControl As Object
1050 Dim oStatusbar As Object
1051 Const cstThisSub = &quot;UI.SetStatusbar&quot;
1052 Const cstSubArgs = &quot;[Text], [Percentage]&quot;
1054 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1056 Check:
1057 If IsMissing(Text) Or IsEmpty(Text) Then Text = &quot;&quot;
1058 If IsMissing(Percentage) Or IsEmpty(Percentage) Then Percentage = -1
1059 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1060 If Not SF_Utils._Validate(Text, &quot;Text&quot;, V_STRING) Then GoTo Finally
1061 If Not SF_Utils._Validate(Percentage, &quot;Percentage&quot;, V_NUMERIC) Then GoTo Finally
1062 End If
1064 Try:
1065 Set oStatusbar = _SF_.Statusbar
1066 With oStatusbar
1067 If IsNull(oStatusbar) Then &apos; Initial call
1068 Set oComp = StarDesktop.CurrentComponent
1069 If Not IsNull(oComp) Then
1070 Set oControl = Nothing
1071 If SF_Session.HasUnoProperty(oComp, &quot;CurrentController&quot;) Then Set oControl = oComp.CurrentController
1072 If Not IsNull(oControl) Then
1073 If SF_Session.HasUnoMethod(oControl, &quot;getStatusIndicator&quot;) Then oStatusbar = oControl.getStatusIndicator()
1074 End If
1075 End If
1076 If Not IsNull(oStatusbar) Then
1077 .start(&quot;&quot;, 100)
1078 End If
1079 End If
1080 If Not IsNull(oStatusbar) Then
1081 If Len(Text) = 0 And Percentage = -1 Then
1082 .end()
1083 Set oStatusbar = Nothing
1084 Else
1085 If Len(Text) &gt; 0 Then .setText(Text)
1086 If Percentage &gt;= 0 And Percentage &lt;= 100 Then .setValue(Percentage)
1087 End If
1088 End If
1089 End With
1091 Finally:
1092 Set _SF_.Statusbar = oStatusbar
1093 SF_Utils._ExitFunction(cstThisSub)
1094 Exit Sub
1095 Catch:
1096 GoTo Finally
1097 End Sub &apos; ScriptForge.SF_UI.SetStatusbar
1099 REM -----------------------------------------------------------------------------
1100 Public Sub ShowProgressBar(Optional Title As Variant _
1101 , Optional ByVal Text As Variant _
1102 , Optional ByVal Percentage As Variant _
1103 , Optional ByRef _Context As Variant _
1105 &apos;&apos;&apos; Display a non-modal dialog box. Specify its title, an explicatory text and the progress on a progressbar
1106 &apos;&apos;&apos; A call without arguments erases the progress bar dialog.
1107 &apos;&apos;&apos; The box will anyway vanish at the end of the macro run.
1108 &apos;&apos;&apos; Args:
1109 &apos;&apos;&apos; Title: the title appearing on top of the dialog box (Default = &quot;ScriptForge&quot;)
1110 &apos;&apos;&apos; Text: the optional text to be displayed above the progress bar (default = zero-length string)
1111 &apos;&apos;&apos; Percentage: the degree of progress between 0 and 100. Default = 0
1112 &apos;&apos;&apos; _Context: from Python, the XComponentXontext (FOR INTERNAL USE ONLY)
1113 &apos;&apos;&apos; Examples:
1114 &apos;&apos;&apos; Dim i As Integer
1115 &apos;&apos;&apos; For i = 0 To 100
1116 &apos;&apos;&apos; ui.ShowProgressBar(, &quot;Progress ... &quot; &amp; i &amp; &quot;/100&quot;, i)
1117 &apos;&apos;&apos; Wait 50
1118 &apos;&apos;&apos; Next i
1119 &apos;&apos;&apos; ui.ShowProgressBar
1121 Dim bFirstCall As Boolean &apos; True at first invocation of method
1122 Dim oDialog As Object &apos; SFDialogs.Dialog object
1123 Dim oFixedText As Object &apos; SFDialogs.DialogControl object
1124 Dim oProgressBar As Object &apos; SFDialogs.DialogControl object
1125 Dim sTitle As String &apos; Alias of Title
1126 Const cstThisSub = &quot;UI.ShowProgressBar&quot;
1127 Const cstSubArgs = &quot;[Title], [Text], [Percentage]&quot;
1129 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1131 Check:
1132 If IsMissing(Title) Or IsEmpty(Title) Then Title = &quot;&quot;
1133 If IsMissing(Text) Or IsEmpty(Text) Then Text = &quot;&quot;
1134 If IsMissing(Percentage) Or IsEmpty(Percentage) Then Percentage = -1
1135 If IsMissing(_Context) Or IsEmpty(_Context) Then _Context = Nothing
1136 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1137 If Not SF_Utils._Validate(Title, &quot;Title&quot;, V_STRING) Then GoTo Finally
1138 If Not SF_Utils._Validate(Text, &quot;Text&quot;, V_STRING) Then GoTo Finally
1139 If Not SF_Utils._Validate(Percentage, &quot;Percentage&quot;, V_NUMERIC) Then GoTo Finally
1140 End If
1142 Try:
1143 With _SF_
1144 Set oDialog = .ProgressBarDialog
1145 Set oFixedText = .ProgressBarText
1146 Set oProgressBar = .ProgressBarBar
1147 End With
1148 With oDialog
1149 bFirstCall = ( IsNull(oDialog) )
1150 If Not bFirstCall Then bFirstCall = Not ._IsStillAlive(False) &apos; False to not raise an error
1151 If bFirstCall Then Set oDialog = CreateScriptService(&quot;SFDialogs.Dialog&quot;, &quot;GlobalScope&quot;, &quot;ScriptForge&quot;, &quot;dlgProgress&quot;, _Context)
1153 If Not IsNull(oDialog) Then
1154 If Len(Title) = 0 And Len(Text) = 0 And Percentage = -1 Then
1155 Set oDialog = .Dispose()
1156 Else
1157 .Caption = Iif(Len(Title) &gt; 0, Title, &quot;ScriptForge&quot;)
1158 If bFirstCall Then
1159 Set oFixedText = .Controls(&quot;ProgressText&quot;)
1160 Set oProgressBar = .Controls(&quot;ProgressBar&quot;)
1161 .Execute(Modal := False)
1162 End If
1163 If Len(Text) &gt; 0 Then oFixedText.Caption = Text
1164 oProgressBar.Value = Iif(Percentage &gt;= 0 And Percentage &lt;= 100, Percentage, 0)
1165 End If
1166 End If
1167 End With
1169 Finally:
1170 With _SF_
1171 Set .ProgressBarDialog = oDialog
1172 Set .ProgressBarText = oFixedText
1173 Set .ProgressBarBar = oProgressBar
1174 End With
1175 SF_Utils._ExitFunction(cstThisSub)
1176 Exit Sub
1177 Catch:
1178 GoTo Finally
1179 End Sub &apos; ScriptForge.SF_UI.ShowProgressBar
1181 REM -----------------------------------------------------------------------------
1182 Public Function WindowExists(Optional ByVal WindowName As Variant) As Boolean
1183 &apos;&apos;&apos; Returns True if the specified window exists
1184 &apos;&apos;&apos; Args:
1185 &apos;&apos;&apos; WindowName: see definitions
1186 &apos;&apos;&apos; Returns:
1187 &apos;&apos;&apos; True if the given window is found
1188 &apos;&apos;&apos; Examples:
1189 &apos;&apos;&apos; ui.WindowExists(&quot;C:\Me\My file.odt&quot;)
1191 Dim bWindowExists As Boolean &apos; Return value
1192 Dim oEnum As Object &apos; com.sun.star.container.XEnumeration
1193 Dim oComp As Object &apos; com.sun.star.lang.XComponent
1194 Dim vWindow As Window &apos; A single component
1195 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
1196 Const cstThisSub = &quot;UI.WindowExists&quot;
1197 Const cstSubArgs = &quot;WindowName&quot;
1199 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1200 bWindowExists = False
1202 Check:
1203 If IsMissing(WindowName) Or IsEmpty(WindowName) Then WindowName = &quot;&quot;
1204 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1205 If Not SF_Utils._ValidateFile(WindowName, &quot;WindowName&quot;) Then GoTo Finally
1206 End If
1208 Try:
1209 Set oEnum = StarDesktop.Components().createEnumeration
1210 Do While oEnum.hasMoreElements
1211 Set oComp = oEnum.nextElement
1212 vWindow = SF_UI._IdentifyWindow(oComp)
1213 With vWindow
1214 &apos; Does the current window match the arguments ?
1215 If (Len(.WindowFileName) &gt; 0 And .WindowFileName = SF_FileSystem.ConvertToUrl(WindowName)) _
1216 Or (Len(.WindowName) &gt; 0 And .WindowName = WindowName) _
1217 Or (Len(.WindowTitle) &gt; 0 And .WindowTitle = WindowName) Then
1218 bWindowExists = True
1219 Exit Do
1220 End If
1221 End With
1222 Loop
1224 Finally:
1225 WindowExists = bWindowExists
1226 SF_Utils._ExitFunction(cstThisSub)
1227 Exit Function
1228 Catch:
1229 GoTo Finally
1230 End Function &apos; ScriptForge.SF_UI.WindowExists
1232 REM =========================================================== PRIVATE FUNCTIONS
1234 REM -----------------------------------------------------------------------------
1235 Public Sub _CloseProgressBar(Optional ByRef poEvent As Object)
1236 &apos;&apos;&apos; Triggered by the Close button in the dlgProgress dialog
1237 &apos;&apos;&apos; to simply close the dialog
1239 ShowProgressBar() &apos; Without arguments =&gt; close the dialog
1241 End Sub &apos; ScriptForge.SF_UI._CloseProgressBar
1243 REM -----------------------------------------------------------------------------
1244 Public Function _IdentifyWindow(ByRef poComponent As Object) As Object
1245 &apos;&apos;&apos; Return a Window object (definition on top of module) based on component given as argument
1246 &apos;&apos;&apos; Is a shortcut to explore the most relevant properties or objects bound to a UNO component
1248 Dim oWindow As Window &apos; Return value
1249 Dim sImplementation As String &apos; Component&apos;s implementationname
1250 Dim sIdentifier As String &apos; Component&apos;s identifier
1251 Dim vSelection As Variant &apos; Array of poCOmponent.Selection property values
1252 Dim iCommandType As Integer &apos; Datasheet type
1253 Dim FSO As Object &apos; Alias for SF_FileSystem
1255 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1256 Set _IdentifyWindow = Nothing
1257 sImplementation = &quot;&quot; : sIdentifier = &quot;&quot;
1259 Set FSO = SF_FileSystem
1260 With oWindow
1261 Set .Frame = Nothing
1262 Set .Component = Nothing
1263 .WindowName = &quot;&quot;
1264 .WindowTitle = &quot;&quot;
1265 .WindowFileName = &quot;&quot;
1266 .DocumentType = &quot;&quot;
1267 .ParentName = &quot;&quot;
1268 If IsNull(poComponent) Then GoTo Finally
1269 If SF_Session.HasUnoProperty(poComponent, &quot;ImplementationName&quot;) Then sImplementation = poComponent.ImplementationName
1270 If SF_Session.HasUnoProperty(poComponent, &quot;Identifier&quot;) Then sIdentifier = poComponent.Identifier
1271 Set .Component = poComponent
1272 Select Case sImplementation
1273 Case &quot;com.sun.star.comp.basic.BasicIDE&quot;
1274 .WindowName = BASICIDE
1275 Case &quot;com.sun.star.comp.dba.ODatabaseDocument&quot; &apos; No identifier
1276 .WindowFileName = SF_Utils._GetPropertyValue(poComponent.Args, &quot;URL&quot;)
1277 If Len(.WindowFileName) &gt; 0 Then .WindowName = FSO.GetName(FSO._ConvertFromUrl(.WindowFileName))
1278 .DocumentType = BASEDOCUMENT
1279 Case &quot;org.openoffice.comp.dbu.ODatasourceBrowser&quot; &apos; Base datasheet (table, query or sql in read mode
1280 Set .Frame = poComponent.Frame
1281 If Not IsEmpty(poComponent.Selection) Then &apos; Empty for (F4) DatasourceBrowser !!
1282 vSelection = poComponent.Selection
1283 .WindowName = SF_Utils._GetPropertyValue(vSelection, &quot;Command&quot;)
1284 iCommandType = SF_Utils._GetPropertyValue(vSelection, &quot;CommandType&quot;)
1285 Select Case iCommandType
1286 Case com.sun.star.sdb.CommandType.TABLE : .DocumentType = TABLEDATA
1287 Case com.sun.star.sdb.CommandType.QUERY : .DocumentType = QUERYDATA
1288 Case com.sun.star.sdb.CommandType.COMMAND : .DocumentType = SQLDATA
1289 End Select
1290 .ParentName = SF_Utils._GetPropertyValue(vSelection, &quot;DataSourceName&quot;)
1291 .WindowTitle = .WindowName
1292 End If
1293 Case &quot;org.openoffice.comp.dbu.OTableDesign&quot;, &quot;org.openoffice.comp.dbu.OQueryDesign&quot; &apos; Table or Query in Edit mode
1294 Case &quot;org.openoffice.comp.dbu.ORelationDesign&quot;
1295 Case &quot;com.sun.star.comp.sfx2.BackingComp&quot; &apos; Welcome screen
1296 Set .Frame = poComponent.Frame
1297 .WindowName = WELCOMESCREEN
1298 Case Else
1299 If Len(sIdentifier) &gt; 0 Then
1300 &apos; Do not use URL : it contains the TemplateFile when new documents are created from a template
1301 .WindowFileName = poComponent.Location
1302 If Len(.WindowFileName) &gt; 0 Then .WindowName = FSO.GetName(FSO._ConvertFromUrl(.WindowFileName))
1303 If SF_Session.HasUnoProperty(poComponent, &quot;Title&quot;) Then .WindowTitle = poComponent.Title
1304 Select Case sIdentifier
1305 Case &quot;com.sun.star.sdb.FormDesign&quot; &apos; Form
1306 Case &quot;com.sun.star.sdb.TextReportDesign&quot; &apos; Report
1307 Case &quot;com.sun.star.text.TextDocument&quot; &apos; Writer
1308 .DocumentType = WRITERDOCUMENT
1309 Case &quot;com.sun.star.sheet.SpreadsheetDocument&quot; &apos; Calc
1310 .DocumentType = CALCDOCUMENT
1311 Case &quot;com.sun.star.presentation.PresentationDocument&quot; &apos; Impress
1312 .DocumentType = IMPRESSDOCUMENT
1313 Case &quot;com.sun.star.drawing.DrawingDocument&quot; &apos; Draw
1314 .DocumentType = DRAWDOCUMENT
1315 Case &quot;com.sun.star.formula.FormulaProperties&quot; &apos; Math
1316 .DocumentType = MATHDOCUMENT
1317 Case Else
1318 End Select
1319 End If
1320 End Select
1321 If IsNull(.Frame) Then
1322 If Not IsNull(poComponent.CurrentController) Then Set .Frame = poComponent.CurrentController.Frame
1323 End If
1324 End With
1326 Finally:
1327 Set _IdentifyWindow = oWindow
1328 Exit Function
1329 Catch:
1330 GoTo Finally
1331 End Function &apos; ScriptForge.SF_UI._IdentifyWindow
1333 REM -----------------------------------------------------------------------------
1334 Public Function _PosSize() As Object
1335 &apos;&apos;&apos; Returns the PosSize structure of the active window
1337 Dim vWindow As Window &apos; A single component
1338 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
1339 Dim oPosSize As Object &apos; com.sun.star.awt.Rectangle
1341 Set oPosSize = Nothing
1343 Try:
1344 vWindow = SF_UI._IdentifyWindow(StarDesktop.CurrentComponent)
1345 If Not IsNull(vWindow.Frame) Then
1346 Set oContainer = vWindow.Frame.ContainerWindow
1347 Set oPosSize = oContainer.getPosSize()
1348 End If
1350 Finally:
1351 Set _PosSize = oPosSize
1352 Exit Function
1353 End Function &apos; ScriptForge.SF_UI._PosSize
1355 REM -----------------------------------------------------------------------------
1356 Private Function _Repr() As String
1357 &apos;&apos;&apos; Convert the UI instance to a readable string, typically for debugging purposes (DebugPrint ...)
1358 &apos;&apos;&apos; Args:
1359 &apos;&apos;&apos; Return:
1360 &apos;&apos;&apos; &quot;[UI]&quot;
1362 _Repr = &quot;[UI]&quot;
1364 End Function &apos; ScriptForge.SF_UI._Repr
1366 REM ============================================ END OF SCRIPTFORGE.SF_UI
1367 </script:module>