Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / wizards / source / sfdocuments / SF_FormDocument.xba
blob29c2bfff8b1cd77d64a325cff7f487be8a8d7508
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_FormDocument" 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_FormDocument
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; managing and manipulating 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, SF_Base, ...
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_FormDocument module is focused on :
30 &apos;&apos;&apos; The orchestration of Base form documents (aka Base Forms, but this is confusing)
31 &apos;&apos;&apos; and the identification of and the access to their controls.
32 &apos;&apos;&apos; Form documents are always contained in a Base document.
33 &apos;&apos;&apos; They should not be confused with Writer documents containing forms,
34 &apos;&apos;&apos; even if it is easy to convert the former to the latter.
35 &apos;&apos;&apos;
36 &apos;&apos;&apos; The current module is closely related to
37 &apos;&apos;&apos; the &quot;Base&quot; service of the current library
38 &apos;&apos;&apos; the &quot;Database&quot; service of the SFDatabases library
39 &apos;&apos;&apos;
40 &apos;&apos;&apos; A form document may be opened either:
41 &apos;&apos;&apos; via code or user interface from the Base file welcome page
42 &apos;&apos;&apos; via code only, without having its Base container opened first
43 &apos;&apos;&apos; The Base document remains hidden but the user might be prompted about the macro execution mode
44 &apos;&apos;&apos; In any mode, a form document can be opened only in 1 single copy
45 &apos;&apos;&apos;
46 &apos;&apos;&apos; Service invocation examples:
47 &apos;&apos;&apos; 1) From the Base service
48 &apos;&apos;&apos; Dim oBase As Object, oFormDoc As Object
49 &apos;&apos;&apos; &apos; oBase is presumed to represent an open Base document
50 &apos;&apos;&apos; Set oFormDoc = oBade.OpenFormDocument(&quot;Folder1/Form1&quot;)
51 &apos;&apos;&apos; 2) Directly without making the Base document visible
52 &apos;&apos;&apos; Dim oDatabase As Object, oFormDoc As Object
53 &apos;&apos;&apos; Set oDatabase = CreateScriptService(&quot;SFDatabases.Database&quot;, &quot;.../myFile.odb&quot;, ReadOnly := False)
54 &apos;&apos;&apos; &apos; The substring &quot;SFDatabases.&quot; in the service name is optional
55 &apos;&apos;&apos; Set oFormDoc = oDatabase.OpenFormDocument(&quot;Folder1/Form1&quot;)
56 &apos;&apos;&apos;
57 &apos;&apos;&apos; Definitions:
58 &apos;&apos;&apos; None
59 &apos;&apos;&apos;
60 &apos;&apos;&apos; Detailed user documentation:
61 &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_formdocument.html?DbPAR=BASIC
62 &apos;&apos;&apos;
63 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
65 REM ================================================================== EXCEPTIONS
67 Private Const BASEFORMNOTFOUNDERROR = &quot;BASEFORMNOTFOUNDERROR&quot;
69 REM ============================================================= PRIVATE MEMBERS
71 Private [Me] As Object
72 Private [_Parent] As Object &apos; Unused
73 Private [_Super] As Object &apos; Document superclass, which the current instance is a subclass of
74 Private ObjectType As String &apos; Must be FormDocument
75 Private ServiceName As String
77 &apos; Components
78 Private _Component As Object &apos; com.sun.star.lang.XComponent
79 Private _BaseComponent As Object &apos; com.sun.star.comp.dba.ODatabaseDocument
80 Private _FormDocument As Object &apos; com.sun.star.comp.sdb.Content
82 &apos; Form document description
83 Private _PersistentName As String &apos; Typically Objxx
84 Private _HierarchicalName As String
85 Private _DataSource As Object &apos; com.sun.star.sdbc.XDataSource
86 Private _User As String &apos; Credentials
87 Private _Password As String
89 REM ============================================================ MODULE CONSTANTS
91 Const ISBASEFORM = 3 &apos; Form is stored in a Form document
93 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
95 REM -----------------------------------------------------------------------------
96 Private Sub Class_Initialize()
97 Set [Me] = Nothing
98 Set [_Parent] = Nothing
99 Set [_Super] = Nothing
100 ObjectType = &quot;FormDocument&quot;
101 ServiceName = &quot;SFDocuments.FormDocument&quot;
102 Set _Component = Nothing
103 Set _BaseComponent = Nothing
104 Set _FormDocument = Nothing
105 Set _DataSource = Nothing
106 _PersistentName = &quot;&quot;
107 _HierarchicalName = &quot;&quot;
108 End Sub &apos; SFDocuments.SF_FormDocument Constructor
110 REM -----------------------------------------------------------------------------
111 Private Sub Class_Terminate()
112 Call Class_Initialize()
113 End Sub &apos; SFDocuments.SF_FormDocument Destructor
115 REM -----------------------------------------------------------------------------
116 Public Function Dispose() As Variant
117 If Not IsNull([_Super]) Then Set [_Super] = [_Super].Dispose()
118 Call Class_Terminate()
119 Set Dispose = Nothing
120 End Function &apos; SFDocuments.SF_FormDocument Explicit Destructor
122 REM ================================================================== PROPERTIES
124 REM ===================================================================== METHODS
126 REM -----------------------------------------------------------------------------
127 Public Function CloseDocument() As Boolean
128 &apos;&apos;&apos; Close the form document and dispose the actual instance
129 &apos;&apos;&apos; Args:
130 &apos;&apos;&apos; Returns:
131 &apos;&apos;&apos; True if closure is successful
132 &apos;&apos;&apos; Example:
133 &apos;&apos;&apos; myFormDoc.CloseDocument()
135 Dim bClose As Boolean &apos; Return value
136 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
137 Const cstThisSub = &quot;SFDocuments.FormDocument.CloseDocument&quot;
138 Const cstSubArgs = &quot;&quot;
140 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
141 bClose = False
143 Check:
144 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
145 If Not _IsStillAlive() Then GoTo Finally
146 End If
147 Try:
148 _FormDocument.close()
149 Dispose()
150 bClose = True
152 Finally:
153 CloseDocument = bClose
154 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
155 Exit Function
156 Catch:
157 GoTo Finally
158 End Function &apos; SFDocuments.SF_FormDocument.CloseDocument
160 REM -----------------------------------------------------------------------------
161 Public Function Forms(Optional ByVal Form As Variant) As Variant
162 &apos;&apos;&apos; Return either
163 &apos;&apos;&apos; - the list of the Forms contained in the form document
164 &apos;&apos;&apos; - a SFDocuments.Form object based on its name or its index
165 &apos;&apos;&apos; Args:
166 &apos;&apos;&apos; Form: a form stored in the document given by its name or its index
167 &apos;&apos;&apos; When absent, the list of available forms is returned
168 &apos;&apos;&apos; To get the first (unique ?) form stored in the form document, set Form = 0
169 &apos;&apos;&apos; Exceptions:
170 &apos;&apos;&apos; BASEFORMNOTFOUNDERROR Form not found
171 &apos;&apos;&apos; Returns:
172 &apos;&apos;&apos; A zero-based array of strings if Form is absent
173 &apos;&apos;&apos; An instance of the SF_Form class if Form exists
174 &apos;&apos;&apos; Example:
175 &apos;&apos;&apos; Dim myForm As Object, myList As Variant
176 &apos;&apos;&apos; myList = oDoc.Forms()
177 &apos;&apos;&apos; Set myForm = oDoc.Forms(&quot;myForm&quot;)
179 Dim oForm As Object &apos; The new Form class instance
180 Dim oMainForm As Object &apos; com.sun.star.comp.sdb.Content
181 Dim oXForm As Object &apos; com.sun.star.form.XForm
182 Dim vFormNames As Variant &apos; Array of form names
183 Dim oForms As Object &apos; Forms collection
184 Const cstDrawPage = 0 &apos; Only 1 drawpage in a FormDocument document
186 Const cstThisSub = &quot;SFDocuments.FormDocument.Forms&quot;
187 Const cstSubArgs = &quot;[Form=&quot;&quot;&quot;&quot;]&quot;
189 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
191 Check:
192 If IsMissing(Form) Or IsEmpty(Form) Then Form = &quot;&quot;
193 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
194 If Not _IsStillAlive() Then GoTo Finally
195 If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
196 End If
198 Try:
199 &apos; Start from the document component and go down to forms
200 Set oForms = _Component.DrawPages(cstDrawPage).Forms
201 vFormNames = oForms.getElementNames()
203 If Len(Form) = 0 Then &apos; Return the list of valid form names
204 Forms = vFormNames
205 Else
206 If VarType(Form) = V_STRING Then &apos; Find the form by name
207 If Not ScriptForge.SF_Array.Contains(vFormNames, Form, CaseSensitive := True) Then GoTo CatchNotFound
208 Set oXForm = oForms.getByName(Form)
209 Else &apos; Find the form by index
210 If Form &lt; 0 Or Form &gt;= oForms.Count Then GoTo CatchNotFound
211 Set oXForm = oForms.getByIndex(Form)
212 End If
213 &apos; Create the new Form class instance
214 Set oForm = SF_Register._NewForm(oXForm)
215 With oForm
216 Set .[_Parent] = [Me]
217 ._FormType = ISBASEFORM
218 Set ._Component = _Component
219 Set ._BaseComponent = _BaseComponent
220 ._FormDocumentName = _HierarchicalName
221 ._FormDocument = _FormDocument
222 ._Initialize()
223 End With
224 Set Forms = oForm
225 End If
227 Finally:
228 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
229 Exit Function
230 Catch:
231 GoTo Finally
232 CatchNotFound:
233 ScriptForge.SF_Exception.RaiseFatal(BASEFORMNOTFOUNDERROR, Form, _FileIdent())
234 End Function &apos; SFDocuments.SF_FormDocument.Forms
236 REM -----------------------------------------------------------------------------
237 Public Function GetDatabase(Optional ByVal User As Variant _
238 , Optional ByVal Password As Variant _
239 ) As Object
240 &apos;&apos;&apos; Returns a Database instance (service = SFDatabases.Database) giving access
241 &apos;&apos;&apos; to the execution of SQL commands on the database defined and/or stored in
242 &apos;&apos;&apos; the actual form document
243 &apos;&apos;&apos; Args:
244 &apos;&apos;&apos; User, Password: the login parameters as strings. Defaults = &quot;&quot;
245 &apos;&apos;&apos; Returns:
246 &apos;&apos;&apos; A SFDatabases.Database instance or Nothing
247 &apos;&apos;&apos; Example:
248 &apos;&apos;&apos; Dim myDb As Object
249 &apos;&apos;&apos; Set myDb = oFormDoc.GetDatabase()
251 Dim oDatabase As Object &apos; Return value
252 Const cstThisSub = &quot;SFDocuments.FormDocument.GetDatabase&quot;
253 Const cstSubArgs = &quot;[User=&quot;&quot;&quot;&quot;], [Password=&quot;&quot;&quot;&quot;]&quot;
255 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
256 Set oDatabase = Nothing
258 Check:
259 If IsMissing(User) Or IsEmpty(User) Then User = &quot;&quot;
260 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
261 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
262 If Not _IsStillAlive(False) Then GoTo Finally
263 If Not ScriptForge.SF_Utils._Validate(User, &quot;User&quot;, V_STRING) Then GoTo Finally
264 If Not ScriptForge.SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
265 End If
267 Try:
268 If IsNull(_DataSource) Then GoTo CatchConnect
269 Set oDatabase = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.DatabaseFromDocument&quot; _
270 , _DataSource, Iif(User = &quot;&quot;, _User, User), Iif(Password = &quot;&quot;, _Password, &quot;&quot;))
271 If IsNull(oDatabase) Then GoTo CatchConnect
272 oDatabase._Location = _DataSource.Name
274 Finally:
275 Set GetDatabase = oDatabase
276 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
277 Exit Function
278 Catch:
279 GoTo Finally
280 CatchConnect:
281 ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR, &quot;User&quot;, User, &quot;Password&quot;, Password, [_Super]._FileIdent())
282 GoTo Finally
283 End Function &apos; SFDocuments.SF_FormDocument.GetDatabase
285 REM -----------------------------------------------------------------------------
286 Public Function GetProperty(Optional ByVal PropertyName As Variant _
287 , Optional ObjectName As Variant _
288 ) As Variant
289 &apos;&apos;&apos; Return the actual value of the given property
290 &apos;&apos;&apos; Args:
291 &apos;&apos;&apos; PropertyName: the name of the property as a string
292 &apos;&apos;&apos; ObjectName: a sheet or range name
293 &apos;&apos;&apos; Returns:
294 &apos;&apos;&apos; The actual value of the property
295 &apos;&apos;&apos; Exceptions:
296 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
298 Const cstThisSub = &quot;SFDocuments.FormDocument.GetProperty&quot;
299 Const cstSubArgs = &quot;&quot;
301 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
302 GetProperty = Null
304 Check:
305 If IsMissing(ObjectName) Or IsEmpty(ObjectName) Then ObjectName = &quot;&quot;
306 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
307 If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
308 If Not ScriptForge.SF_Utils._Validate(ObjectName, &quot;ObjectName&quot;, V_STRING) Then GoTo Catch
309 End If
311 Try:
312 &apos; Superclass or subclass property ?
313 If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
314 GetProperty = [_Super].GetProperty(PropertyName)
315 ElseIf Len(ObjectName) = 0 Then
316 GetProperty = _PropertyGet(PropertyName)
317 Else
318 GetProperty = _PropertyGet(PropertyName, ObjectName)
319 End If
321 Finally:
322 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
323 Exit Function
324 Catch:
325 GoTo Finally
326 End Function &apos; SFDocuments.SF_FormDocument.GetProperty
328 REM -----------------------------------------------------------------------------
329 Public Function Methods() As Variant
330 &apos;&apos;&apos; Return the list of public methods of the FormDocument service as an array
332 Methods = Array( _
333 &quot;CloseDocument&quot; _
334 , &quot;Forms&quot; _
335 , &quot;PrintOut&quot; _
338 End Function &apos; SFDocuments.SF_FormDocument.Methods
340 REM -----------------------------------------------------------------------------
341 Public Function PrintOut(Optional ByVal Pages As Variant _
342 , Optional ByVal Copies As Variant _
343 , Optional ByVal PrintBackground As Variant _
344 , Optional ByVal PrintBlankPages As Variant _
345 , Optional ByVal PrintEvenPages As Variant _
346 , Optional ByVal PrintOddPages As Variant _
347 , Optional ByVal PrintImages As Variant _
348 ) As Boolean
349 &apos;&apos;&apos; Send the content of the document to the printer.
350 &apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
351 &apos;&apos;&apos; Args:
352 &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
353 &apos;&apos;&apos; Copies: the number of copies
354 &apos;&apos;&apos; PrintBackground: print the background image when True (default)
355 &apos;&apos;&apos; PrintBlankPages: when False (default), omit empty pages
356 &apos;&apos;&apos; PrintEvenPages: print the left pages when True (default)
357 &apos;&apos;&apos; PrintOddPages: print the right pages when True (default)
358 &apos;&apos;&apos; PrintImages: print the graphic objects when True (default)
359 &apos;&apos;&apos; Returns:
360 &apos;&apos;&apos; True when successful
361 &apos;&apos;&apos; Examples:
362 &apos;&apos;&apos; oDoc.PrintOut(&quot;1-4;10;15-18&quot;, Copies := 2, PrintImages := False)
364 Dim bPrint As Boolean &apos; Return value
365 Dim vPrintOptions As Variant &apos; com.sun.star.text.DocumentSettings
367 Const cstThisSub = &quot;SFDocuments.FormDocument.PrintOut&quot;
368 Const cstSubArgs = &quot;[Pages=&quot;&quot;&quot;&quot;], [Copies=1], [PrintBackground=True], [PrintBlankPages=False], [PrintEvenPages=True]&quot; _
369 &amp; &quot;, [PrintOddPages=True], [PrintImages=True]&quot;
371 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
372 bPrint = False
374 Check:
375 If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
376 If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
377 If IsMissing(PrintBackground) Or IsEmpty(PrintBackground) Then PrintBackground = True
378 If IsMissing(PrintBlankPages) Or IsEmpty(PrintBlankPages) Then PrintBlankPages = False
379 If IsMissing(PrintEvenPages) Or IsEmpty(PrintEvenPages) Then PrintEvenPages = True
380 If IsMissing(PrintOddPages) Or IsEmpty(PrintOddPages) Then PrintOddPages = True
381 If IsMissing(PrintImages) Or IsEmpty(PrintImages) Then PrintImages = True
383 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
384 If Not _IsStillAlive() Then GoTo Finally
385 If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
386 If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
387 If Not ScriptForge.SF_Utils._Validate(PrintBackground, &quot;PrintBackground&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
388 If Not ScriptForge.SF_Utils._Validate(PrintBlankPages, &quot;PrintBlankPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
389 If Not ScriptForge.SF_Utils._Validate(PrintEvenPages, &quot;PrintEvenPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
390 If Not ScriptForge.SF_Utils._Validate(PrintOddPages, &quot;PrintOddPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
391 If Not ScriptForge.SF_Utils._Validate(PrintImages, &quot;PrintImages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
392 End If
394 Try:
395 vPrintOptions = _Component.createInstance(&quot;com.sun.star.text.DocumentSettings&quot;)
396 With vPrintOptions
397 .PrintPageBackground = PrintBackground
398 .PrintEmptyPages = PrintBlankPages
399 .PrintLeftPages = PrintEvenPages
400 .PrintRightPages = PrintOddPages
401 .PrintGraphics = PrintImages
402 .PrintDrawings = PrintImages
403 End With
405 bPrint = [_Super].PrintOut(Pages, Copies, _Component)
407 Finally:
408 PrintOut = bPrint
409 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
410 Exit Function
411 Catch:
412 GoTo Finally
413 End Function &apos; SFDocuments.SF_FormDocument.PrintOut
415 REM -----------------------------------------------------------------------------
416 Public Function Properties() As Variant
417 &apos;&apos;&apos; Return the list or properties of the FormDocument class as an array
419 Properties = Array( _
420 &quot;DocumentType&quot; _
421 , &quot;IsBase&quot; _
422 , &quot;IsCalc&quot; _
423 , &quot;IsDraw&quot; _
424 , &quot;IsFormDocument&quot; _
425 , &quot;IsImpress&quot; _
426 , &quot;IsMath&quot; _
427 , &quot;Readonly&quot; _
428 , &quot;XComponent&quot; _
431 End Function &apos; SFDocuments.SF_FormDocument.Properties
433 REM ======================================================= SUPERCLASS PROPERTIES
435 REM -----------------------------------------------------------------------------
436 Property Get IsBase() As Boolean
437 IsBase = [_Super].GetProperty(&quot;IsBase&quot;)
438 End Property &apos; SFDocuments.SF_FormDocument.IsBase
440 REM -----------------------------------------------------------------------------
441 Property Get IsCalc() As Boolean
442 IsCalc = [_Super].GetProperty(&quot;IsCalc&quot;)
443 End Property &apos; SFDocuments.SF_FormDocument.IsCalc
445 REM -----------------------------------------------------------------------------
446 Property Get IsDraw() As Boolean
447 IsDraw = [_Super].GetProperty(&quot;IsDraw&quot;)
448 End Property &apos; SFDocuments.SF_FormDocument.IsDraw
450 REM -----------------------------------------------------------------------------
451 Property Get IsFormDocument() As Boolean
452 IsFormDocument = [_Super].GetProperty(&quot;IsFormDocument&quot;)
453 End Property &apos; SFDocuments.SF_Writer.IsFormDocument
455 REM -----------------------------------------------------------------------------
456 Property Get IsImpress() As Boolean
457 IsImpress = [_Super].GetProperty(&quot;IsImpress&quot;)
458 End Property &apos; SFDocuments.SF_FormDocument.IsImpress
460 REM -----------------------------------------------------------------------------
461 Property Get IsMath() As Boolean
462 IsMath = [_Super].GetProperty(&quot;IsMath&quot;)
463 End Property &apos; SFDocuments.SF_FormDocument.IsMath
465 REM -----------------------------------------------------------------------------
466 Property Get Readonly() As Variant
467 Readonly = [_Super].GetProperty(&quot;Readonly&quot;)
468 End Property &apos; SFDocuments.SF_FormDocument.Readonly
470 REM -----------------------------------------------------------------------------
471 Property Get XComponent() As Variant
472 XComponent = [_Super].GetProperty(&quot;XComponent&quot;)
473 End Property &apos; SFDocuments.SF_FormDocument.XComponent
475 REM ========================================================== SUPERCLASS METHODS
477 REM -----------------------------------------------------------------------------
478 Public Function Activate() As Boolean
479 Activate = [_Super].Activate()
480 End Function &apos; SFDocuments.SF_FormDocument.Activate
482 REM -----------------------------------------------------------------------------
483 Public Function CreateMenu(Optional ByVal MenuHeader As Variant _
484 , Optional ByVal Before As Variant _
485 , Optional ByVal SubmenuChar As Variant _
486 ) As Object
487 Set CreateMenu = [_Super].CreateMenu(MenuHeader, Before, SubmenuChar)
488 End Function &apos; SFDocuments.SF_FormDocument.CreateMenu
490 REM -----------------------------------------------------------------------------
491 Public Sub Echo(Optional ByVal EchoOn As Variant _
492 , Optional ByVal Hourglass As Variant _
494 [_Super].Echo(EchoOn, Hourglass)
495 End Sub &apos; SFDocuments.SF_FormDocument.Echo
497 REM -----------------------------------------------------------------------------
498 Public Function ExportAsPDF(Optional ByVal FileName As Variant _
499 , Optional ByVal Overwrite As Variant _
500 , Optional ByVal Pages As Variant _
501 , Optional ByVal Password As Variant _
502 , Optional ByVal Watermark As Variant _
503 ) As Boolean
504 ExportAsPDF = [_Super].ExportAsPDF(FileName, Overwrite, Pages, Password, Watermark)
505 End Function &apos; SFDocuments.SF_FormDocument.ExportAsPDF
507 REM -----------------------------------------------------------------------------
508 Public Function RemoveMenu(Optional ByVal MenuHeader As Variant) As Boolean
509 RemoveMenu = [_Super].RemoveMenu(MenuHeader)
510 End Function &apos; SFDocuments.SF_FormDocument.RemoveMenu
512 REM -----------------------------------------------------------------------------
513 Public Sub RunCommand(Optional ByVal Command As Variant _
514 , ParamArray Args As Variant _
516 [_Super].RunCommand(Command, Args)
517 End Sub &apos; SFDocuments.SF_FormDocument.RunCommand
519 REM -----------------------------------------------------------------------------
520 Public Function SaveCopyAs(Optional ByVal FileName As Variant _
521 , Optional ByVal Overwrite As Variant _
522 , Optional ByVal Password As Variant _
523 , Optional ByVal FilterName As Variant _
524 , Optional ByVal FilterOptions As Variant _
525 ) As Boolean
526 SaveCopyAs = [_Super].SaveCopyAs(FileName, Overwrite, Password, FilterName, FilterOptions)
527 End Function &apos; SFDocuments.SF_FormDocument.SaveCopyAs
529 REM -----------------------------------------------------------------------------
530 Public Function SetPrinter(Optional ByVal Printer As Variant _
531 , Optional ByVal Orientation As Variant _
532 , Optional ByVal PaperFormat As Variant _
533 ) As Boolean
534 SetPrinter = [_Super].SetPrinter(Printer, Orientation, PaperFormat)
535 End Function &apos; SFDocuments.SF_FormDocument.SetPrinter
537 REM -----------------------------------------------------------------------------
538 Public Function Toolbars(Optional ByVal ToolbarName As Variant) As Variant
539 Toolbars = [_Super].Toolbars(ToolbarName)
540 End Function &apos; SFDocuments.SF_FormDocument.Toolbars
542 REM =========================================================== PRIVATE FUNCTIONS
544 REM -----------------------------------------------------------------------------
545 Private Function _FileIdent() As String
546 &apos;&apos;&apos; Returns a file identification from the information that is currently available
547 &apos;&apos;&apos; Useful e.g. for display in error messages
549 _FileIdent = [_Super]._FileIdent()
551 End Function &apos; SFDocuments.SF_FormDocument._FileIdent
553 REM -----------------------------------------------------------------------------
554 Public Sub _Initialize()
555 &apos;&apos;&apos; Achieve the creation of a SF_Form instance
556 &apos;&apos;&apos; - the database file
557 &apos;&apos;&apos; - the database connection
558 &apos;&apos;&apos; the internal and external names
560 Dim oBase As Object &apos; A temporary Base instance
562 On Local Error GoTo Catch
564 Try:
565 &apos; Base file where form document is stored
566 Set _BaseComponent = _Component.Parent
568 &apos; Connection arguments
569 Set _DataSource = _BaseComponent.DataSource
570 With _DataSource
571 _User = .User
572 _Password = .Password
573 End With
575 &apos; External and internal names
576 _PersistentName = ScriptForge.SF_Utils._GetPropertyValue(_Component.Args, &quot;HierarchicalDocumentName&quot;)
577 Set oBase = New SF_Base &apos; Only to be able to call the _FindByPersistentName() method
578 With oBase
579 Set _FormDocument = ._FindByPersistentName(_BaseComponent.getFormDocuments(), _PersistentName)
580 _HierarchicalName = _FormDocument.HierarchicalName
581 Set oBase = .Dispose()
582 End With
584 Finally:
585 Exit Sub
586 Catch:
587 On Local Error GoTo 0
588 GoTo Finally
589 End Sub &apos; SFDocuments.SF_FormDocument._Initialize
591 REM -----------------------------------------------------------------------------
592 Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
593 , Optional ByVal pbError As Boolean _
594 ) As Boolean
595 &apos;&apos;&apos; Returns True if the document has not been closed manually or incidentally since the last use
596 &apos;&apos;&apos; If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
597 &apos;&apos;&apos; Args:
598 &apos;&apos;&apos; pbForUpdate: if True (default = False), check additionally if document is open for editing
599 &apos;&apos;&apos; pbError: if True (default), raise a fatal error
601 Dim bAlive As Boolean &apos; Return value
603 If IsMissing(pbForUpdate) Then pbForUpdate = False
604 If IsMissing(pbError) Then pbError = True
606 Try:
607 bAlive = [_Super]._IsStillAlive(pbForUpdate, pbError)
609 Finally:
610 _IsStillAlive = bAlive
611 Exit Function
612 End Function &apos; SFDocuments.SF_FormDocument._IsStillAlive
614 REM -----------------------------------------------------------------------------
615 Private Function _PropertyGet(Optional ByVal psProperty As String _
616 , Optional ByVal pvArg As Variant _
617 ) As Variant
618 &apos;&apos;&apos; Return the value of the named property
619 &apos;&apos;&apos; Args:
620 &apos;&apos;&apos; psProperty: the name of the property
622 Dim cstThisSub As String
623 Const cstSubArgs = &quot;&quot;
625 _PropertyGet = False
627 cstThisSub = &quot;SFDocuments.FormDocument.get&quot; &amp; psProperty
628 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
629 If Not _IsStillAlive() Then GoTo Finally
631 Select Case psProperty
632 Case Else
633 _PropertyGet = Null
634 End Select
636 Finally:
637 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
638 Exit Function
639 End Function &apos; SFDocuments.SF_FormDocument._PropertyGet
641 REM -----------------------------------------------------------------------------
642 Private Function _Repr() As String
643 &apos;&apos;&apos; Convert the SF_FormDocument instance to a readable string, typically for debugging purposes (DebugPrint ...)
644 &apos;&apos;&apos; Args:
645 &apos;&apos;&apos; Return:
646 &apos;&apos;&apos; &quot;[DOCUMENT]: Type/File&quot;
648 _Repr = &quot;[FormDocument]: &quot; &amp; [_Super]._FileIdent()
650 End Function &apos; SFDocuments.SF_FormDocument._Repr
652 REM ============================================ END OF SFDOCUMENTS.SF_FORMDOCUMENT
653 </script:module>