Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / wizards / source / sfdocuments / SF_Base.xba
blobb7662b7341cdd7a969c988fb2a466efbf48e9495
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_Base" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === The SFDocuments library is one of the associated libraries. ===
6 REM === Full documentation is available on https://help.libreoffice.org/ ===
7 REM =======================================================================================================================
9 Option Compatible
10 Option ClassModule
12 Option Explicit
14 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
15 &apos;&apos;&apos; SF_Base
16 &apos;&apos;&apos; =======
17 &apos;&apos;&apos;
18 &apos;&apos;&apos; The SFDocuments library gathers a number of methods and properties making easy
19 &apos;&apos;&apos; the management and several manipulations of LibreOffice documents
20 &apos;&apos;&apos;
21 &apos;&apos;&apos; Some methods are generic for all types of documents: they are combined in the SF_Document module.
22 &apos;&apos;&apos; Specific properties and methods are implemented in the concerned subclass(es) SF_Calc, SF_Writer, ...
23 &apos;&apos;&apos;
24 &apos;&apos;&apos; To workaround the absence of class inheritance in LibreOffice Basic, some redundancy is necessary
25 &apos;&apos;&apos; Each subclass MUST implement also the generic methods and properties, even if they only call
26 &apos;&apos;&apos; the parent methods and properties.
27 &apos;&apos;&apos; They should also duplicate some generic private members as a subset of their own set of members
28 &apos;&apos;&apos;
29 &apos;&apos;&apos; The SF_Base module is provided mainly to block parent properties that are NOT applicable to Base documents
30 &apos;&apos;&apos; In addition, it provides methods to identify form documents and access their internal forms
31 &apos;&apos;&apos; (read more elsewhere (the &quot;SFDocuments.Form&quot; service) about this subject)
32 &apos;&apos;&apos;
33 &apos;&apos;&apos; The current module is closely related to the &quot;UI&quot; service of the ScriptForge library
34 &apos;&apos;&apos;
35 &apos;&apos;&apos; Service invocation examples:
36 &apos;&apos;&apos; 1) From the UI service
37 &apos;&apos;&apos; Dim ui As Object, oDoc As Object
38 &apos;&apos;&apos; Set ui = CreateScriptService(&quot;UI&quot;)
39 &apos;&apos;&apos; Set oDoc = ui.CreateBaseDocument(&quot;C:\Me\MyFile.odb&quot;, ...)
40 &apos;&apos;&apos; &apos; or Set oDoc = ui.OpenDocument(&quot;C:\Me\MyFile.odb&quot;)
41 &apos;&apos;&apos; 2) Directly if the document is already opened
42 &apos;&apos;&apos; Dim oDoc As Object
43 &apos;&apos;&apos; Set oDoc = CreateScriptService(&quot;SFDocuments.Base&quot;, &quot;MyFile.odb&quot;)
44 &apos;&apos;&apos; &apos; The substring &quot;SFDocuments.&quot; in the service name is optional
45 &apos;&apos;&apos;
46 &apos;&apos;&apos; Detailed user documentation:
47 &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_base.html?DbPAR=BASIC
48 &apos;&apos;&apos;
49 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
51 REM ================================================================== EXCEPTIONS
53 Private Const DBCONNECTERROR = &quot;DBCONNECTERROR&quot;
54 Private Const FORMDEADERROR = &quot;FORMDEADERROR&quot;
55 Private Const BASEFORMNOTFOUNDERROR = &quot;BASEFORMNOTFOUNDERROR&quot;
57 REM ============================================================= PRIVATE MEMBERS
59 Private [Me] As Object
60 Private [_Parent] As Object
61 Private [_Super] As Object &apos; Document superclass, which the current instance is a subclass of
62 Private ObjectType As String &apos; Must be BASE
63 Private ServiceName As String
65 &apos; UNO references
66 Private _Component As Object &apos; com.sun.star.comp.dba.ODatabaseDocument
67 Private _DataSource As Object &apos; com.sun.star.comp.dba.ODatabaseSource
68 Private _Database As Object &apos; SFDatabases.Database service instance
69 Private _FormDocuments As Object
71 REM ============================================================ MODULE CONSTANTS
73 Const ISBASEFORM = 3 &apos; Form is stored in a Base document
74 Const cstToken = &quot;//&quot; &apos; Form names accept special characters but not slashes
76 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
78 REM -----------------------------------------------------------------------------
79 Private Sub Class_Initialize()
80 Set [Me] = Nothing
81 Set [_Parent] = Nothing
82 Set [_Super] = Nothing
83 ObjectType = &quot;BASE&quot;
84 ServiceName = &quot;SFDocuments.Base&quot;
85 Set _Component = Nothing
86 Set _DataSource = Nothing
87 Set _Database = Nothing
88 Set _FormDocuments = Nothing
89 End Sub &apos; SFDocuments.SF_Base Constructor
91 REM -----------------------------------------------------------------------------
92 Private Sub Class_Terminate()
93 Call Class_Initialize()
94 End Sub &apos; SFDocuments.SF_Base Destructor
96 REM -----------------------------------------------------------------------------
97 Public Function Dispose() As Variant
98 If Not IsNull([_Super]) Then Set [_Super] = [_Super].Dispose()
99 Call Class_Terminate()
100 Set Dispose = Nothing
101 End Function &apos; SFDocuments.SF_Base Explicit Destructor
103 REM ================================================================== PROPERTIES
105 REM ===================================================================== METHODS
107 REM -----------------------------------------------------------------------------
108 Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
109 &apos;&apos;&apos; The closure of a Base document requires the closures of
110 &apos;&apos;&apos; 1) the connection =&gt; done in the CloseDatabase() method
111 &apos;&apos;&apos; 2) the data source
112 &apos;&apos;&apos; 3) the document itself =&gt; done in the superclass
114 Const cstThisSub = &quot;SFDocuments.Base.CloseDocument&quot;
115 Const cstSubArgs = &quot;[SaveAsk=True]&quot;
117 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
119 Check:
120 If IsMissing(SaveAsk) Or IsEmpty(SaveAsk) Then SaveAsk = True
121 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
122 If Not _IsStillAlive(True) Then GoTo Finally
123 If Not ScriptForge.SF_Utils._Validate(SaveAsk, &quot;SaveAsk&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
124 End If
126 Try:
127 If Not IsNull(_Database) Then _Database.CloseDatabase()
128 If Not IsNull(_DataSource) Then _DataSource.dispose()
129 CloseDocument = [_Super].CloseDocument(SaveAsk)
131 Finally:
132 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
133 Exit Function
134 Catch:
135 GoTo Finally
136 End Function &apos; SFDocuments.SF_Base.CloseDocument
138 REM -----------------------------------------------------------------------------
139 Public Function CloseFormDocument(Optional ByVal FormDocument As Variant) As Boolean
140 &apos;&apos;&apos; Close the given form document
141 &apos;&apos;&apos; Nothing happens if the form document is not open
142 &apos;&apos;&apos; Args:
143 &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
144 &apos;&apos;&apos; Returns:
145 &apos;&apos;&apos; True if closure is successful
146 &apos;&apos;&apos; Example:
147 &apos;&apos;&apos; oDoc.CloseFormDocument(&quot;Folder1/myFormDocument&quot;)
148 &apos;&apos;&apos; DEPRECATED - Use preferably the CloseDocument() method of the FormDocument service
150 Dim bClose As Boolean &apos; Return value
151 Dim oMainForm As Object &apos; com.sun.star.comp.sdb.Content
152 Dim vFormNames As Variant &apos; Array of all document form names present in the document
154 Const cstThisSub = &quot;SFDocuments.Base.CloseFormDocument&quot;
155 Const cstSubArgs = &quot;FormDocument&quot;
157 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
158 bClose = False
160 Check:
161 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
162 If Not _IsStillAlive() Then GoTo Finally
163 &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
164 If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
165 vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
166 If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
167 End If
168 If Not IsLoaded(FormDocument) Then GoTo Finally
170 Try:
171 Set oMainForm = _FormDocuments.getByHierarchicalName(FormDocument)
172 bClose = oMainForm.close()
174 Finally:
175 CloseFormDocument = bClose
176 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
177 Exit Function
178 Catch:
179 GoTo Finally
180 End Function &apos; SFDocuments.SF_Base.CloseFormDocument
182 REM -----------------------------------------------------------------------------
183 Public Function FormDocuments() As Variant
184 &apos;&apos;&apos; Return the list of the FormDocuments contained in the Base document
185 &apos;&apos;&apos; Args:
186 &apos;&apos;&apos; Returns:
187 &apos;&apos;&apos; A zero-base array of strings
188 &apos;&apos;&apos; Each entry is the full path name of a form document. The path separator is the slash (&quot;/&quot;)
189 &apos;&apos;&apos; Example:
190 &apos;&apos;&apos; Dim myForm As Object, myList As Variant
191 &apos;&apos;&apos; myList = oDoc.FormDocuments()
193 Dim vFormNames As Variant &apos; Array of all form names present in the document
194 Const cstThisSub = &quot;SFDocuments.Base.FormDocuments&quot;
195 Const cstSubArgs = &quot;&quot;
197 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
199 Check:
200 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
201 If Not _IsStillAlive() Then GoTo Finally
202 End If
204 Try:
205 &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
206 If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
207 vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
209 Finally:
210 FormDocuments = vFormNames
211 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
212 Exit Function
213 Catch:
214 GoTo Finally
215 End Function &apos; SFDocuments.SF_Base.FormDocuments
217 REM -----------------------------------------------------------------------------
218 Public Function Forms(Optional ByVal FormDocument As Variant _
219 , Optional ByVal Form As Variant _
220 ) As Variant
221 &apos;&apos;&apos; Return either
222 &apos;&apos;&apos; - the list of the Forms contained in the form document
223 &apos;&apos;&apos; - a SFDocuments.Form object based on its name or its index
224 &apos;&apos;&apos; Args:
225 &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
226 &apos;&apos;&apos; Form: a form stored in the Base document given by its name or its index
227 &apos;&apos;&apos; When absent, the list of available forms is returned
228 &apos;&apos;&apos; To get the first (unique ?) form stored in the form document, set Form = 0
229 &apos;&apos;&apos; Returns:
230 &apos;&apos;&apos; A zero-based array of strings if Form is absent
231 &apos;&apos;&apos; An instance of the SF_Form class if Form exists
232 &apos;&apos;&apos; Exceptions:
233 &apos;&apos;&apos; FORMDEADERROR The form is not open
234 &apos;&apos;&apos; BASEFORMNOTFOUNDERROR FormDocument OK but Form not found
235 &apos;&apos;&apos; Example:
236 &apos;&apos;&apos; Dim myForm As Object, myList As Variant
237 &apos;&apos;&apos; myList = oDoc.Forms(&quot;Folder1/myFormDocument&quot;)
238 &apos;&apos;&apos; Set myForm = oDoc.Forms(&quot;Folder1/myFormDocument&quot;, 0)
239 &apos;&apos;&apos; DEPRECATED - Use preferably the Forms() method of the FormDocument service
241 Dim oForm As Object &apos; The new Form class instance
242 Dim oFormDocument As Object &apos; com.sun.star.comp.sdb.Content
243 Dim oXForm As Object &apos; com.sun.star.form.XForm
244 Dim vFormDocuments As Variant &apos; Array of form documents
245 Dim vFormNames As Variant &apos; Array of form names
246 Dim oForms As Object &apos; Forms collection
247 Const cstDrawPage = 0 &apos; Only 1 drawpage in a Base document
249 Const cstThisSub = &quot;SFDocuments.Base.Forms&quot;
250 Const cstSubArgs = &quot;FormDocument, [Form=&quot;&quot;&quot;&quot;]&quot;
252 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
254 Check:
255 If IsMissing(Form) Or IsEmpty(Form) Then Form = &quot;&quot;
256 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
257 If Not _IsStillAlive() Then GoTo Finally
258 &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
259 If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
260 vFormDocuments = Split(_CollectFormDocuments(_FormDocuments), cstToken)
261 If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormDocuments) Then GoTo Finally
262 If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
263 End If
264 If Not IsLoaded(FormDocument) Then GoTo CatchClosed
266 Try:
267 &apos; Start from the form document and go down to forms
268 Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
269 Set oForms = oFormDocument.Component.DrawPages(cstDrawPage).Forms
270 vFormNames = oForms.getElementNames()
272 If Len(Form) = 0 Then &apos; Return the list of valid form names
273 Forms = vFormNames
274 Else
275 If VarType(Form) = V_STRING Then &apos; Find the form by name
276 If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, V_STRING, vFormNames) Then GoTo Finally
277 Set oXForm = oForms.getByName(Form)
278 Else &apos; Find the form by index
279 If Form &lt; 0 Or Form &gt;= oForms.Count Then GoTo CatchNotFound
280 Set oXForm = oForms.getByIndex(Form)
281 End If
282 &apos; Create the new Form class instance
283 Set oForm = New SF_Form
284 With oForm
285 ._Name = oXForm.Name
286 Set .[Me] = oForm
287 Set .[_Parent] = [Me]
288 Set ._Component = oFormDocument.Component
289 Set ._BaseComponent = _Component
290 ._FormDocumentName = FormDocument
291 Set ._FormDocument = oFormDocument
292 ._FormType = ISBASEFORM
293 Set ._Form = oXForm
294 ._Initialize()
295 End With
296 Set Forms = oForm
297 End If
299 Finally:
300 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
301 Exit Function
302 Catch:
303 GoTo Finally
304 CatchClosed:
305 ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
306 CatchNotFound:
307 ScriptForge.SF_Exception.RaiseFatal(BASEFORMNOTFOUNDERROR, Form, FormDocument, _FileIdent())
308 End Function &apos; SFDocuments.SF_Base.Forms
310 REM -----------------------------------------------------------------------------
311 Public Function GetDatabase(Optional ByVal User As Variant _
312 , Optional ByVal Password As Variant _
313 ) As Object
314 &apos;&apos;&apos; Returns a Database instance (service = SFDatabases.Database) giving access
315 &apos;&apos;&apos; to the execution of SQL commands on the database defined and/or stored in
316 &apos;&apos;&apos; the actual Base document
317 &apos;&apos;&apos; Args:
318 &apos;&apos;&apos; User, Password: the login parameters as strings. Defaults = &quot;&quot;
319 &apos;&apos;&apos; Returns:
320 &apos;&apos;&apos; A SFDatabases.Database instance or Nothing
321 &apos;&apos;&apos; Example:
322 &apos;&apos;&apos; Dim myDb As Object
323 &apos;&apos;&apos; Set myDb = oDoc.GetDatabase()
325 Const cstThisSub = &quot;SFDocuments.Base.GetDatabase&quot;
326 Const cstSubArgs = &quot;[User=&quot;&quot;&quot;&quot;], [Password=&quot;&quot;&quot;&quot;]&quot;
328 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
329 Set GetDatabase = Nothing
331 Check:
332 If IsMissing(User) Or IsEmpty(User) Then User = &quot;&quot;
333 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
334 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
335 If Not _IsStillAlive(True) Then GoTo Finally
336 If Not ScriptForge.SF_Utils._Validate(User, &quot;User&quot;, V_STRING) Then GoTo Finally
337 If Not ScriptForge.SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
338 End If
340 Try:
341 If IsNull(_Database) Then &apos; 1st connection from the current document instance
342 If IsNull(_DataSource) Then GoTo CatchConnect
343 Set _Database = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.DatabaseFromDocument&quot; _
344 , _DataSource, User, Password)
345 If IsNull(_Database) Then GoTo CatchConnect
346 _Database._Location = [_Super]._WindowFileName
347 EndIf
349 Finally:
350 Set GetDatabase = _Database
351 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
352 Exit Function
353 Catch:
354 GoTo Finally
355 CatchConnect:
356 ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR, &quot;User&quot;, User, &quot;Password&quot;, Password, [_Super]._FileIdent())
357 GoTo Finally
358 End Function &apos; SFDocuments.SF_Base.GetDatabase
360 REM -----------------------------------------------------------------------------
361 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
362 &apos;&apos;&apos; Return the actual value of the given property
363 &apos;&apos;&apos; Args:
364 &apos;&apos;&apos; PropertyName: the name of the property as a string
365 &apos;&apos;&apos; Returns:
366 &apos;&apos;&apos; The actual value of the property
367 &apos;&apos;&apos; Exceptions:
368 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
370 Const cstThisSub = &quot;SFDocuments.Base.GetProperty&quot;
371 Const cstSubArgs = &quot;&quot;
373 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
374 GetProperty = Null
376 Check:
377 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
378 If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
379 End If
381 Try:
382 &apos; Superclass or subclass property ?
383 If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
384 GetProperty = [_Super].GetProperty(PropertyName)
385 Else
386 GetProperty = _PropertyGet(PropertyName)
387 End If
389 Finally:
390 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
391 Exit Function
392 Catch:
393 GoTo Finally
394 End Function &apos; SFDocuments.SF_Base.GetProperty
396 REM -----------------------------------------------------------------------------
397 Public Function IsLoaded(Optional ByVal FormDocument As Variant) As Boolean
398 &apos;&apos;&apos; Return True if the given FormDocument is open for the user
399 &apos;&apos;&apos; Args:
400 &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
401 &apos;&apos;&apos; Returns:
402 &apos;&apos;&apos; True if the form document is currently open, otherwise False
403 &apos;&apos;&apos; Exceptions:
404 &apos;&apos;&apos; Form name is invalid
405 &apos;&apos;&apos; Example:
406 &apos;&apos;&apos; MsgBox oDoc.IsLoaded(&quot;Folder1/myFormDocument&quot;)
408 Dim bLoaded As Boolean &apos; Return value
409 Dim vFormNames As Variant &apos; Array of all document form names present in the document
410 Dim oMainForm As Object &apos; com.sun.star.comp.sdb.Content
411 Const cstThisSub = &quot;SFDocuments.Base.IsLoaded&quot;
412 Const cstSubArgs = &quot;FormDocument&quot;
414 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
415 bLoaded = False
417 Check:
418 If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
419 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
420 If Not _IsStillAlive() Then GoTo Finally
421 &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
422 vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
423 If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
424 End If
426 Try:
427 Set oMainForm = _FormDocuments.getByHierarchicalName(FormDocument)
428 &apos; A document form that has never been opened has no component
429 &apos; If ever opened and closed afterwards, it keeps the Component but loses its Controller
430 bLoaded = Not IsNull(oMainForm.Component)
431 If bLoaded Then bLoaded = Not IsNull(oMainForm.Component.CurrentController)
433 Finally:
434 IsLoaded = bLoaded
435 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
436 Exit Function
437 Catch:
438 GoTo Finally
439 End Function &apos; SFDocuments.SF_Base.IsLoaded
441 REM -----------------------------------------------------------------------------
442 Public Function Methods() As Variant
443 &apos;&apos;&apos; Return the list of public methods of the Base class as an array
445 Methods = Array( _
446 &quot;CloseFormDocument&quot; _
447 , &quot;FormDocuments&quot; _
448 , &quot;Forms&quot; _
449 , &quot;GetDatabase&quot; _
450 , &quot;IsLoaded&quot; _
451 , &quot;OpenFormDocument&quot; _
452 , &quot;PrintOut&quot; _
453 , &quot;SetPrinter&quot; _
456 End Function &apos; SFDocuments.SF_Base.Methods
458 REM -----------------------------------------------------------------------------
459 Public Function OpenFormDocument(Optional ByVal FormDocument As Variant _
460 , Optional ByVal DesignMode As Variant _
461 ) As Object
462 &apos;&apos;&apos; Open the FormDocument given by its hierarchical name either in normal or in design mode
463 &apos;&apos;&apos; If the form document is already open, the form document is made active without changing its mode
464 &apos;&apos;&apos; Args:
465 &apos;&apos;&apos; FormDocument: a valid form document name as a case-sensitive string
466 &apos;&apos;&apos; When hierarchical, the hierarchy must be rendered with forward slashes (&quot;/&quot;)
467 &apos;&apos;&apos; DesignMode: when True the form document is opened in design mode (Default = False)
468 &apos;&apos;&apos; Returns:
469 &apos;&apos;&apos; A FormDocument instance or Nothing
470 &apos;&apos;&apos; Exceptions:
471 &apos;&apos;&apos; Form name is invalid
472 &apos;&apos;&apos; Example:
473 &apos;&apos;&apos; Set oForm = oDoc.OpenFormDocument(&quot;Folder1/myFormDocument&quot;)
475 Dim oOpen As Object &apos; Return value
476 Dim vFormNames As Variant &apos; Array of all document form names present in the document
477 Dim oNewForm As Object &apos; Output of loadComponent()
478 Const cstThisSub = &quot;SFDocuments.Base.OpenFormDocument&quot;
479 Const cstSubArgs = &quot;FormDocument, [DesignMode=False]&quot;
481 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
482 Set oOpen = Nothing
484 Check:
485 If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
486 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
487 If Not _IsStillAlive() Then GoTo Finally
488 &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
489 If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
490 vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
491 If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
492 If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
493 End If
495 Try:
496 With _Component.CurrentController
497 If Not .IsConnected Then .connect()
498 &apos; loadComponent activates the form when already loaded
499 Set oNewForm = .loadComponent(com.sun.star.sdb.application.DatabaseObject.FORM, FormDocument, DesignMode)
500 &apos; When user opened manually the form in design mode and closed it, the next execution in normal mode needs to be confirmed as below
501 With oNewForm.CurrentController
502 If .isFormDesignMode() &lt;&gt; DesignMode Then .setFormDesignMode(DesignMode)
503 End With
504 End With
506 Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDocuments.FormDocument&quot;, oNewForm)
508 &apos; Prevent desynchonization when using .last(), .next() etc immediately after component loading. Bug #156836
509 Wait 1
511 Finally:
512 Set OpenFormDocument = oOpen
513 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
514 Exit Function
515 Catch:
516 GoTo Finally
517 End Function &apos; SFDocuments.SF_Base.OpenFormDocument
519 REM -----------------------------------------------------------------------------
520 Public Function OpenQuery(Optional ByVal QueryName As Variant _
521 , Optional ByVal DesignMode As Variant _
522 ) As Object
523 &apos;&apos;&apos; Open the query given by its name either in normal or in design mode
524 &apos;&apos;&apos; If the query is already open, the query datasheet is made active without changing its mode
525 &apos;&apos;&apos; If still open, the datasheet will be closed together with the actual Base document.
526 &apos;&apos;&apos; Args:
527 &apos;&apos;&apos; QueryName: a valid Query name as a case-sensitive string
528 &apos;&apos;&apos; DesignMode: when True the query is opened in design mode (Default = False)
529 &apos;&apos;&apos; Returns:
530 &apos;&apos;&apos; A Datasheet class instance if the query could be opened and DesignMode = False, otherwise Nothing
531 &apos;&apos;&apos; Exceptions:
532 &apos;&apos;&apos; Query name is invalid
533 &apos;&apos;&apos; Example:
534 &apos;&apos;&apos; oDoc.OpenQuery(&quot;myQuery&quot;, DesignMode := False)
536 Dim oOpen As Object &apos; Return value
537 Dim vQueries As Variant &apos; Array of query names
538 Dim oNewQuery As Object &apos; Output of loadComponent()
539 Const cstThisSub = &quot;SFDocuments.Base.OpenQuery&quot;
540 Const cstSubArgs = &quot;QueryName, [DesignMode=False]&quot;
542 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
543 Set oOpen = Nothing
545 Check:
546 If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
547 vQueries = GetDatabase().Queries &apos; Includes _IsStillAlive()
548 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
549 If Not ScriptForge.SF_Utils._Validate(QueryName, &quot;QueryName&quot;, V_STRING, vQueries) Then GoTo Finally
550 If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
551 End If
553 Try:
554 With _Component.CurrentController
555 &apos; The connection may have been done previously by a user command. If not, do it now.
556 If Not .IsConnected Then .connect()
557 &apos; loadComponent activates the query component when already loaded
558 Set oNewQuery = .loadComponent(com.sun.star.sdb.application.DatabaseObject.QUERY, QueryName, DesignMode)
559 End With
560 &apos; When design mode, the method returns Nothing
561 If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewQuery, [Me])
563 Finally:
564 Set OpenQuery = oOpen
565 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
566 Exit Function
567 Catch:
568 GoTo Finally
569 End Function &apos; SFDocuments.SF_Base.OpenQuery
571 REM -----------------------------------------------------------------------------
572 Public Function OpenTable(Optional ByVal TableName As Variant _
573 , Optional ByVal DesignMode As Variant _
574 ) As Object
575 &apos;&apos;&apos; Open the table given by its name either in normal or in design mode
576 &apos;&apos;&apos; If the table is already open, the table datasheet is made active without changing its mode
577 &apos;&apos;&apos; If still open, the datasheet will be closed together with the actual Base document.
578 &apos;&apos;&apos; Args:
579 &apos;&apos;&apos; TableName: a valid table name as a case-sensitive string
580 &apos;&apos;&apos; DesignMode: when True the table is opened in design mode (Default = False)
581 &apos;&apos;&apos; Returns:
582 &apos;&apos;&apos; A Datasheet class instance if the table could be opened or was already open, and DesignMode = False.
583 &apos;&apos;&apos; Otherwise Nothing
584 &apos;&apos;&apos; Exceptions:
585 &apos;&apos;&apos; Table name is invalid
586 &apos;&apos;&apos; Example:
587 &apos;&apos;&apos; oDoc.OpenTable(&quot;myTable&quot;, DesignMode := False)
589 Dim oOpen As Object &apos; Return value
590 Dim vTables As Variant &apos; Array of table names
591 Dim oNewTable As Object &apos; Output of loadComponent()
592 Const cstThisSub = &quot;SFDocuments.Base.OpenTable&quot;
593 Const cstSubArgs = &quot;TableName, [DesignMode=False]&quot;
595 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
596 Set oOpen = Nothing
598 Check:
599 If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
600 vTables = GetDatabase().Tables
601 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
602 If Not ScriptForge.SF_Utils._Validate(TableName, &quot;TableName&quot;, V_STRING, vTables) Then GoTo Finally
603 If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
604 End If
606 Try:
607 With _Component.CurrentController
608 &apos; The connection may have been done previously by a user command. If not, do it now.
609 If Not .IsConnected Then .connect()
610 &apos; loadComponent activates the table component when already loaded
611 Set oNewTable = .loadComponent(com.sun.star.sdb.application.DatabaseObject.TABLE, TableName, DesignMode)
612 End With
613 &apos; When design mode, the method returns Nothing
614 If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewTable, [Me])
616 Finally:
617 Set OpenTable = oOpen
618 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
619 Exit Function
620 Catch:
621 GoTo Finally
622 End Function &apos; SFDocuments.SF_Base.OpenTable
624 REM -----------------------------------------------------------------------------
625 Public Function PrintOut(Optional ByVal FormDocument As Variant _
626 , Optional ByVal Pages As Variant _
627 , Optional ByVal Copies As Variant _
628 ) As Boolean
629 &apos;&apos;&apos; Send the content of the given form document to the printer.
630 &apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
631 &apos;&apos;&apos; The given form document must be open. It is activated by the method.
632 &apos;&apos;&apos; Args:
633 &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
634 &apos;&apos;&apos; Pages: the pages to print as a string, like in the user interface. Example: &quot;1-4;10;15-18&quot;. Default = all pages
635 &apos;&apos;&apos; Copies: the number of copies
636 &apos;&apos;&apos; Exceptions:
637 &apos;&apos;&apos; FORMDEADERROR The form is not open
638 &apos;&apos;&apos; Returns:
639 &apos;&apos;&apos; True when successful
640 &apos;&apos;&apos; Examples:
641 &apos;&apos;&apos; oDoc.PrintOut(&quot;myForm&quot;, &quot;1-4;10;15-18&quot;, Copies := 2)
642 &apos;&apos;&apos; DEPRECATED - Use preferably the PrintOut() method of the FormDocument service
644 Dim bPrint As Boolean &apos; Return value
645 Dim vFormNames As Variant &apos; Array of all document form names present in the document
646 Dim oFormDocument As Object &apos; com.sun.star.comp.sdb.Content
648 Const cstThisSub = &quot;SFDocuments.Base.PrintOut&quot;
649 Const cstSubArgs = &quot;FormDocument, [Pages=&quot;&quot;&quot;&quot;], [Copies=1]&quot;
651 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
652 bPrint = False
654 Check:
655 If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
656 If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
658 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
659 If Not _IsStillAlive() Then GoTo Finally
660 &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
661 If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
662 vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
663 If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
664 If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
665 If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
666 End If
667 If Not IsLoaded(FormDocument) Then GoTo CatchClosed
669 Try:
670 Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
671 bPrint = [_Super].PrintOut(Pages, Copies, oFormDocument.Component)
673 Finally:
674 PrintOut = bPrint
675 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
676 Exit Function
677 Catch:
678 GoTo Finally
679 CatchClosed:
680 ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
681 End Function &apos; SFDocuments.SF_Base.PrintOut
683 REM -----------------------------------------------------------------------------
684 Public Function Properties() As Variant
685 &apos;&apos;&apos; Return the list or properties of the Base class as an array
687 Properties = Array( _
688 &quot;DocumentType&quot; _
689 , &quot;IsBase&quot; _
690 , &quot;IsCalc&quot; _
691 , &quot;IsDraw &quot; _
692 , &quot;IsFormDocument&quot; _
693 , &quot;IsImpress&quot; _
694 , &quot;IsMath&quot; _
695 , &quot;IsWriter&quot; _
696 , &quot;XComponent&quot; _
699 End Function &apos; SFDocuments.SF_Base.Properties
701 REM -----------------------------------------------------------------------------
702 Public Function SetPrinter(Optional ByVal FormDocument As Variant _
703 , Optional ByVal Printer As Variant _
704 , Optional ByVal Orientation As Variant _
705 , Optional ByVal PaperFormat As Variant _
706 ) As Boolean
707 &apos;&apos;&apos; Define the printer options for a form document. The form document must be open.
708 &apos;&apos;&apos; Args:
709 &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
710 &apos;&apos;&apos; Printer: the name of the printer queue where to print to
711 &apos;&apos;&apos; When absent or space, the default printer is set
712 &apos;&apos;&apos; Orientation: either &quot;PORTRAIT&quot; or &quot;LANDSCAPE&quot;. Left unchanged when absent
713 &apos;&apos;&apos; PaperFormat: one of next values
714 &apos;&apos;&apos; &quot;A3&quot;, &quot;A4&quot;, &quot;A5&quot;, &quot;B4&quot;, &quot;B5&quot;, &quot;LETTER&quot;, &quot;LEGAL&quot;, &quot;TABLOID&quot;
715 &apos;&apos;&apos; Left unchanged when absent
716 &apos;&apos;&apos; Returns:
717 &apos;&apos;&apos; True when successful
718 &apos;&apos;&apos; Examples:
719 &apos;&apos;&apos; oDoc.SetPrinter(&quot;myForm&quot;, Orientation := &quot;PORTRAIT&quot;)
720 &apos;&apos;&apos; DEPRECATED - Use preferably the SetPrinter() method of the FormDocument service
722 Dim bPrinter As Boolean &apos; Return value
723 Dim vFormDocuments As Variant &apos; Array of form documents
724 Dim oFormDocument As Object &apos; com.sun.star.comp.sdb.Content
726 Const cstThisSub = &quot;SFDocuments.Base.SetPrinter&quot;
727 Const cstSubArgs = &quot;FormDocument, [Printer=&quot;&quot;&quot;&quot;], [Orientation=&quot;&quot;PORTRAIT&quot;&quot;|&quot;&quot;LANDSCAPE&quot;&quot;]&quot; _
728 &amp; &quot;, [PaperFormat=&quot;&quot;A3&quot;&quot;|&quot;&quot;A4&quot;&quot;|&quot;&quot;A5&quot;&quot;|&quot;&quot;B4&quot;&quot;|&quot;&quot;B5&quot;&quot;|&quot;&quot;LETTER&quot;&quot;|&quot;&quot;LEGAL&quot;&quot;|&quot;&quot;TABLOID&quot;&quot;&quot;
730 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
731 bPrinter = False
733 Check:
734 If IsMissing(Printer) Or IsEmpty(Printer) Then Printer = &quot;&quot;
735 If IsMissing(Orientation) Or IsEmpty(Orientation) Then Orientation = &quot;&quot;
736 If IsMissing(PaperFormat) Or IsEmpty(PaperFormat) Then PaperFormat = &quot;&quot;
738 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
739 If Not _IsStillAlive() Then GoTo Finally
740 &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
741 If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
742 vFormDocuments = Split(_CollectFormDocuments(_FormDocuments), cstToken)
743 If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormDocuments) Then GoTo Finally
744 End If
745 If Not IsLoaded(FormDocument) Then GoTo CatchClosed
747 Try:
748 Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
749 bPrinter = [_Super].SetPrinter(Printer, Orientation, PaperFormat, oFormDocument.Component)
751 Finally:
752 SetPrinter = bPrinter
753 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
754 Exit Function
755 Catch:
756 GoTo Finally
757 CatchClosed:
758 ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
759 End Function &apos; SFDocuments.SF_Base.SetPrinter
761 REM -----------------------------------------------------------------------------
762 Public Function SetProperty(Optional ByVal PropertyName As Variant _
763 , Optional ByRef Value As Variant _
764 ) As Boolean
765 &apos;&apos;&apos; Set a new value to the given property
766 &apos;&apos;&apos; Args:
767 &apos;&apos;&apos; PropertyName: the name of the property as a string
768 &apos;&apos;&apos; Value: its new value
769 &apos;&apos;&apos; Exceptions
770 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
772 Const cstThisSub = &quot;SFDocuments.Base.SetProperty&quot;
773 Const cstSubArgs = &quot;PropertyName, Value&quot;
775 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
776 SetProperty = False
778 Check:
779 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
780 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
781 End If
783 Try:
784 Select Case UCase(PropertyName)
785 Case Else
786 End Select
788 Finally:
789 SF_Utils._ExitFunction(cstThisSub)
790 Exit Function
791 Catch:
792 GoTo Finally
793 End Function &apos; SFDocuments.SF_Base.SetProperty
795 REM ======================================================= SUPERCLASS PROPERTIES
797 REM -----------------------------------------------------------------------------
798 &apos;Property Get CustomProperties() As Variant
799 &apos; CustomProperties = [_Super].GetProperty(&quot;CustomProperties&quot;)
800 &apos;End Property &apos; SFDocuments.SF_Base.CustomProperties
802 REM -----------------------------------------------------------------------------
803 &apos;Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
804 &apos; [_Super].CustomProperties = pvCustomProperties
805 &apos;End Property &apos; SFDocuments.SF_Base.CustomProperties
807 REM -----------------------------------------------------------------------------
808 &apos;Property Get Description() As Variant
809 &apos; Description = [_Super].GetProperty(&quot;Description&quot;)
810 &apos;End Property &apos; SFDocuments.SF_Base.Description
812 REM -----------------------------------------------------------------------------
813 &apos;Property Let Description(Optional ByVal pvDescription As Variant)
814 &apos; [_Super].Description = pvDescription
815 &apos;End Property &apos; SFDocuments.SF_Base.Description
817 REM -----------------------------------------------------------------------------
818 &apos;Property Get DocumentProperties() As Variant
819 &apos; DocumentProperties = [_Super].GetProperty(&quot;DocumentProperties&quot;)
820 &apos;End Property &apos; SFDocuments.SF_Base.DocumentProperties
822 REM -----------------------------------------------------------------------------
823 Property Get DocumentType() As String
824 DocumentType = [_Super].GetProperty(&quot;DocumentType&quot;)
825 End Property &apos; SFDocuments.SF_Base.DocumentType
827 REM -----------------------------------------------------------------------------
828 Property Get IsBase() As Boolean
829 IsBase = [_Super].GetProperty(&quot;IsBase&quot;)
830 End Property &apos; SFDocuments.SF_Base.IsBase
832 REM -----------------------------------------------------------------------------
833 Property Get IsCalc() As Boolean
834 IsCalc = [_Super].GetProperty(&quot;IsCalc&quot;)
835 End Property &apos; SFDocuments.SF_Base.IsCalc
837 REM -----------------------------------------------------------------------------
838 Property Get IsDraw() As Boolean
839 IsDraw = [_Super].GetProperty(&quot;IsDraw&quot;)
840 End Property &apos; SFDocuments.SF_Base.IsDraw
842 REM -----------------------------------------------------------------------------
843 Property Get IsFormDocument() As Boolean
844 IsFormDocument = [_Super].GetProperty(&quot;IsFormDocument&quot;)
845 End Property &apos; SFDocuments.SF_Writer.IsFormDocument
847 REM -----------------------------------------------------------------------------
848 Property Get IsImpress() As Boolean
849 IsImpress = [_Super].GetProperty(&quot;IsImpress&quot;)
850 End Property &apos; SFDocuments.SF_Base.IsImpress
852 REM -----------------------------------------------------------------------------
853 Property Get IsMath() As Boolean
854 IsMath = [_Super].GetProperty(&quot;IsMath&quot;)
855 End Property &apos; SFDocuments.SF_Base.IsMath
857 REM -----------------------------------------------------------------------------
858 Property Get IsWriter() As Boolean
859 IsWriter = [_Super].GetProperty(&quot;IsWriter&quot;)
860 End Property &apos; SFDocuments.SF_Base.IsWriter
862 REM -----------------------------------------------------------------------------
863 &apos;Property Get Keywords() As Variant
864 &apos; Keywords = [_Super].GetProperty(&quot;Keywords&quot;)
865 &apos;End Property &apos; SFDocuments.SF_Base.Keywords
867 REM -----------------------------------------------------------------------------
868 &apos;Property Let Keywords(Optional ByVal pvKeywords As Variant)
869 &apos; [_Super].Keywords = pvKeywords
870 &apos;End Property &apos; SFDocuments.SF_Base.Keywords
872 REM -----------------------------------------------------------------------------
873 &apos;Property Get Readonly() As Variant
874 &apos; Readonly = [_Super].GetProperty(&quot;Readonly&quot;)
875 &apos;End Property &apos; SFDocuments.SF_Base.Readonly
877 REM -----------------------------------------------------------------------------
878 &apos;Property Get Subject() As Variant
879 &apos; Subject = [_Super].GetProperty(&quot;Subject&quot;)
880 &apos;End Property &apos; SFDocuments.SF_Base.Subject
882 REM -----------------------------------------------------------------------------
883 &apos;Property Let Subject(Optional ByVal pvSubject As Variant)
884 &apos; [_Super].Subject = pvSubject
885 &apos;End Property &apos; SFDocuments.SF_Base.Subject
887 REM -----------------------------------------------------------------------------
888 &apos;Property Get Title() As Variant
889 &apos; Title = [_Super].GetProperty(&quot;Title&quot;)
890 &apos;End Property &apos; SFDocuments.SF_Base.Title
892 REM -----------------------------------------------------------------------------
893 &apos;Property Let Title(Optional ByVal pvTitle As Variant)
894 &apos; [_Super].Title = pvTitle
895 &apos;End Property &apos; SFDocuments.SF_Base.Title
897 REM -----------------------------------------------------------------------------
898 Property Get XComponent() As Variant
899 XComponent = [_Super].GetProperty(&quot;XComponent&quot;)
900 End Property &apos; SFDocuments.SF_Base.XComponent
902 REM ========================================================== SUPERCLASS METHODS
904 REM -----------------------------------------------------------------------------
905 Public Function Activate() As Boolean
906 Activate = [_Super].Activate()
907 End Function &apos; SFDocuments.SF_Base.Activate
909 REM -----------------------------------------------------------------------------
910 Public Function CreateMenu(Optional ByVal MenuHeader As Variant _
911 , Optional ByVal Before As Variant _
912 , Optional ByVal SubmenuChar As Variant _
913 ) As Object
914 Set CreateMenu = [_Super].CreateMenu(MenuHeader, Before, SubmenuChar)
915 End Function &apos; SFDocuments.SF_Base.CreateMenu
917 REM -----------------------------------------------------------------------------
918 Public Function RemoveMenu(Optional ByVal MenuHeader As Variant) As Boolean
919 RemoveMenu = [_Super].RemoveMenu(MenuHeader)
920 End Function &apos; SFDocuments.SF_Base.RemoveMenu
922 REM -----------------------------------------------------------------------------
923 Public Sub RunCommand(Optional ByVal Command As Variant _
924 , ParamArray Args As Variant _
926 [_Super].RunCommand(Command, Args)
927 End Sub &apos; SFDocuments.SF_Base.RunCommand
929 REM -----------------------------------------------------------------------------
930 Public Function Save() As Boolean
931 Save = [_Super].Save()
932 End Function &apos; SFDocuments.SF_Base.Save
934 REM -----------------------------------------------------------------------------
935 Public Function SaveAs(Optional ByVal FileName As Variant _
936 , Optional ByVal Overwrite As Variant _
937 , Optional ByVal Password As Variant _
938 , Optional ByVal FilterName As Variant _
939 , Optional ByVal FilterOptions As Variant _
940 ) As Boolean
941 SaveAs = [_Super].SaveAs(FileName, Overwrite, Password, FilterName, FilterOptions)
942 End Function &apos; SFDocuments.SF_Base.SaveAs
944 REM -----------------------------------------------------------------------------
945 Public Function SaveCopyAs(Optional ByVal FileName As Variant _
946 , Optional ByVal Overwrite As Variant _
947 , Optional ByVal Password As Variant _
948 , Optional ByVal FilterName As Variant _
949 , Optional ByVal FilterOptions As Variant _
950 ) As Boolean
951 SaveCopyAs = [_Super].SaveCopyAs(FileName, Overwrite, Password, FilterName, FilterOptions)
952 End Function &apos; SFDocuments.SF_Base.SaveCopyAs
954 REM -----------------------------------------------------------------------------
955 Public Function Toolbars(Optional ByVal ToolbarName As Variant) As Variant
956 Toolbars = [_Super].Toolbars(ToolbarName)
957 End Function &apos; SFDocuments.SF_Base.Toolbars
959 REM =========================================================== PRIVATE FUNCTIONS
961 REM -----------------------------------------------------------------------------
962 Private Function _CollectFormDocuments(ByRef poContainer As Object) As String
963 &apos;&apos;&apos; Returns a token-separated string of all hierarchical formdocument names
964 &apos;&apos;&apos; depending on the formdocuments container in argument
965 &apos;&apos;&apos; The function traverses recursively the whole tree below the container
966 &apos;&apos;&apos; The initial call starts from the container _Component.getFormDocuments
967 &apos;&apos;&apos; The list contains closed and open forms
969 Dim sCollectNames As String &apos; Return value
970 Dim oSubItem As Object &apos; com.sun.star.container.XNameAccess (folder) or com.sun.star.ucb.XContent (form)
971 Dim i As Long
972 Const cstFormType = &quot;application/vnd.oasis.opendocument.text&quot;
973 &apos; Identifies forms. Folders have a zero-length content type
975 On Local Error GoTo Finally
977 Try:
978 sCollectNames = &quot;&quot;
979 With poContainer
980 For i = 0 To .Count - 1
981 Set oSubItem = .getByIndex(i)
982 If oSubItem.ContentType = cstFormType Then &apos; Add the form to the list
983 sCollectNames = sCollectNames &amp; cstToken &amp; oSubItem.HierarchicalName
984 Else
985 sCollectNames = sCollectNames &amp; cstToken &amp; _CollectFormDocuments(oSubItem)
986 End If
987 Next i
988 End With
990 Finally:
991 If Len(sCollectNames) &gt; 0 Then
992 _CollectFormDocuments = Mid(sCollectNames, Len(cstToken) + 1) &apos; Skip the initial token
993 Else
994 _CollectFormDocuments = &quot;&quot;
995 End If
996 Exit Function
997 End Function &apos; SFDocuments.SF_Base._CollectFormDocuments
999 REM -----------------------------------------------------------------------------
1000 Private Function _FileIdent() As String
1001 &apos;&apos;&apos; Returns a file identification from the information that is currently available
1002 &apos;&apos;&apos; Useful e.g. for display in error messages
1004 _FileIdent = [_Super]._FileIdent()
1006 End Function &apos; SFDocuments.SF_Base._FileIdent
1008 REM -----------------------------------------------------------------------------
1009 Private Function _FindByPersistentName(ByRef poContainer As Object _
1010 , psPersistent As String _
1011 ) As Object
1012 &apos;&apos;&apos; The FormDocuments property of a Base component has strangely
1013 &apos;&apos;&apos; a getByHierarchical() method but no access to the same com.sun.star.comp.sdb.Content
1014 &apos;&apos;&apos; object via its persistent/ODF name
1015 &apos;&apos;&apos; This method returns the object having the given persistent name
1016 &apos;&apos;&apos; The function traverses recursively the whole tree below the container until found
1017 &apos;&apos;&apos; The initial call starts from the container _Component.getFormDocuments
1018 &apos;&apos;&apos; The list contains closed and open forms
1019 &apos;&apos;&apos; Args:
1020 &apos;&apos;&apos; poContainer: the actual top of the free, initially _FormDocuments
1021 &apos;&apos;&apos; psPersistent: a name like &quot;Obj...&quot;
1022 &apos;&apos;&apos; Returns:
1023 &apos;&apos;&apos; A com.sun.star.comp.sdb.Content object (object found, the process stops)
1024 &apos;&apos;&apos; or Nothing (object not found, the process continues)
1026 Dim oMainForm As Object &apos; Return value
1027 Dim oSubItem As Object &apos; com.sun.star.container.XNameAccess (folder) or com.sun.star.ucb.XContent (form)
1028 Dim i As Long
1029 Const cstFormType = &quot;application/vnd.oasis.opendocument.text&quot;
1030 &apos; Identifies forms. Folders have a zero-length content type
1032 On Local Error GoTo Finally
1034 Try:
1035 Set oMainForm = Nothing
1036 With poContainer
1037 For i = 0 To .Count - 1
1038 Set oSubItem = .getByIndex(i)
1039 If oSubItem.ContentType = cstFormType Then &apos; Examine its persistent name
1040 If oSubItem.PersistentName = psPersistent Then
1041 Set oMainForm = oSubItem
1042 Exit For
1043 End If
1044 Else
1045 Set oMainForm = _FindByPersistentName(oSubItem, psPersistent)
1046 End If
1047 Next i
1048 End With
1050 Finally:
1051 Set _FindByPersistentName = oMainForm
1052 Exit Function
1053 End Function &apos; SFDocuments.SF_Base.FindByPersistentName
1055 REM -----------------------------------------------------------------------------
1056 Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
1057 , Optional ByVal pbError As Boolean _
1058 ) As Boolean
1059 &apos;&apos;&apos; Returns True if the document has not been closed manually or incidentally since the last use
1060 &apos;&apos;&apos; If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
1061 &apos;&apos;&apos; Args:
1062 &apos;&apos;&apos; pbForUpdate: if True (default = False), check additionally if document is open for editing
1063 &apos;&apos;&apos; pbError: if True (default), raise a fatal error
1065 Dim bAlive As Boolean &apos; Return value
1067 If IsMissing(pbForUpdate) Then pbForUpdate = False
1068 If IsMissing(pbError) Then pbError = True
1070 Try:
1071 bAlive = [_Super]._IsStillAlive(pbForUpdate, pbError)
1073 Finally:
1074 _IsStillAlive = bAlive
1075 Exit Function
1076 End Function &apos; SFDocuments.SF_Base._IsStillAlive
1078 REM -----------------------------------------------------------------------------
1079 Private Function _PropertyGet(Optional ByVal psProperty As String _
1080 , Optional ByVal pvArg As Variant _
1081 ) As Variant
1082 &apos;&apos;&apos; Return the value of the named property
1083 &apos;&apos;&apos; Args:
1084 &apos;&apos;&apos; psProperty: the name of the property
1086 Dim oProperties As Object &apos; Document or Custom properties
1087 Dim vLastCell As Variant &apos; Coordinates of last used cell in a sheet
1088 Dim oSelect As Object &apos; Current selection
1089 Dim vRanges As Variant &apos; List of selected ranges
1090 Dim i As Long
1091 Dim cstThisSub As String
1092 Const cstSubArgs = &quot;&quot;
1094 _PropertyGet = False
1096 cstThisSub = &quot;SFDocuments.SF_Base.get&quot; &amp; psProperty
1097 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1098 If Not _IsStillAlive() Then GoTo Finally
1100 Select Case psProperty
1101 Case Else
1102 _PropertyGet = Null
1103 End Select
1105 Finally:
1106 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1107 Exit Function
1108 End Function &apos; SFDocuments.SF_Base._PropertyGet
1110 REM -----------------------------------------------------------------------------
1111 Private Function _Repr() As String
1112 &apos;&apos;&apos; Convert the SF_Base instance to a readable string, typically for debugging purposes (DebugPrint ...)
1113 &apos;&apos;&apos; Args:
1114 &apos;&apos;&apos; Return:
1115 &apos;&apos;&apos; &quot;[Base]: Type/File&quot;
1117 _Repr = &quot;[Base]: &quot; &amp; [_Super]._FileIdent()
1119 End Function &apos; SFDocuments.SF_Base._Repr
1121 REM ============================================ END OF SFDOCUMENTS.SF_BASE
1122 </script:module>