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