summaryrefslogtreecommitdiffstats
path: root/wizards/source/sfdocuments/SF_Base.xba
blob: b6497b9b4f1274289bcb89bee058c66ba51563aa (plain)
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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
<?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_Base" 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

&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
&apos;&apos;&apos;	SF_Base
&apos;&apos;&apos;	=======
&apos;&apos;&apos;
&apos;&apos;&apos;		The SFDocuments library gathers a number of methods and properties making easy
&apos;&apos;&apos;		the management and several manipulations of LibreOffice documents
&apos;&apos;&apos;
&apos;&apos;&apos;		Some methods are generic for all types of documents: they are combined in the SF_Document module.
&apos;&apos;&apos;		Specific properties and methods are implemented in the concerned subclass(es) SF_Calc, SF_Writer, ...
&apos;&apos;&apos;
&apos;&apos;&apos;		To workaround the absence of class inheritance in LibreOffice Basic, some redundancy is necessary
&apos;&apos;&apos;		Each subclass MUST implement also the generic methods and properties, even if they only call
&apos;&apos;&apos;		the parent methods and properties.
&apos;&apos;&apos;		They should also duplicate some generic private members as a subset of their own set of members
&apos;&apos;&apos;
&apos;&apos;&apos;		The SF_Base module is provided mainly to block parent properties that are NOT applicable to Base documents
&apos;&apos;&apos;		In addition, it provides methods to identify form documents and access their internal forms
&apos;&apos;&apos;			(read more elsewhere (the &quot;SFDocuments.Form&quot; service) about this subject)
&apos;&apos;&apos;
&apos;&apos;&apos;		The current module is closely related to the &quot;UI&quot; service of the ScriptForge library
&apos;&apos;&apos;
&apos;&apos;&apos;		Service invocation examples:
&apos;&apos;&apos;		1) From the UI service
&apos;&apos;&apos;			Dim ui As Object, oDoc As Object
&apos;&apos;&apos;			Set ui = CreateScriptService(&quot;UI&quot;)
&apos;&apos;&apos;			Set oDoc = ui.CreateBaseDocument(&quot;C:\Me\MyFile.odb&quot;, ...)
&apos;&apos;&apos;				&apos; or Set oDoc = ui.OpenDocument(&quot;C:\Me\MyFile.odb&quot;)
&apos;&apos;&apos;		2) Directly if the document is already opened
&apos;&apos;&apos;			Dim oDoc As Object
&apos;&apos;&apos;			Set oDoc = CreateScriptService(&quot;SFDocuments.Base&quot;, &quot;MyFile.odb&quot;)
&apos;&apos;&apos;			&apos; The substring &quot;SFDocuments.&quot; in the service name is optional
&apos;&apos;&apos;
&apos;&apos;&apos;		Detailed user documentation:
&apos;&apos;&apos;			https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_base.html?DbPAR=BASIC
&apos;&apos;&apos;
&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;

REM ================================================================== EXCEPTIONS

Private Const DBCONNECTERROR			=	&quot;DBCONNECTERROR&quot;
Private Const FORMDEADERROR				=	&quot;FORMDEADERROR&quot;
Private Const BASEFORMNOTFOUNDERROR		=	&quot;BASEFORMNOTFOUNDERROR&quot;

REM ============================================================= PRIVATE MEMBERS

Private [Me]					As Object
Private [_Parent]				As Object
Private [_Super]				As Object		&apos;	Document superclass, which the current instance is a subclass of
Private ObjectType				As String		&apos;	Must be BASE
Private ServiceName				As String

&apos;	UNO references
Private _Component				As Object		&apos;	com.sun.star.comp.dba.ODatabaseDocument
Private _DataSource				As Object		&apos;	com.sun.star.comp.dba.ODatabaseSource
Private _Database				As Object		&apos;	SFDatabases.Database service instance
Private _FormDocuments			As Object

REM ============================================================ MODULE CONSTANTS

Const ISBASEFORM = 3				&apos;	Form is stored in a Base document
Const cstToken = &quot;//&quot;				&apos;	Form names accept special characters but not slashes

REM ====================================================== CONSTRUCTOR/DESTRUCTOR

REM -----------------------------------------------------------------------------
Private Sub Class_Initialize()
	Set [Me] = Nothing
	Set [_Parent] = Nothing
	Set [_Super] = Nothing
	ObjectType = &quot;BASE&quot;
	ServiceName = &quot;SFDocuments.Base&quot;
	Set _Component = Nothing
	Set _DataSource = Nothing
	Set _Database = Nothing
	Set _FormDocuments = Nothing
End Sub		&apos;	SFDocuments.SF_Base Constructor

REM -----------------------------------------------------------------------------
Private Sub Class_Terminate()
	Call Class_Initialize()
End Sub		&apos;	SFDocuments.SF_Base Destructor

REM -----------------------------------------------------------------------------
Public Function Dispose() As Variant
	If Not IsNull([_Super]) Then Set [_Super] = [_Super].Dispose()
	Call Class_Terminate()
	Set Dispose = Nothing
End Function	&apos;	SFDocuments.SF_Base Explicit Destructor

REM ================================================================== PROPERTIES

REM ===================================================================== METHODS

REM -----------------------------------------------------------------------------
Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
&apos;&apos;&apos;	The closure of a Base document requires the closures of
&apos;&apos;&apos;		1) the connection =&gt; done in the CloseDatabase() method
&apos;&apos;&apos;		2) the data source
&apos;&apos;&apos;		3) the document itself =&gt; done in the superclass

Const cstThisSub = &quot;SFDocuments.Base.CloseDocument&quot;
Const cstSubArgs = &quot;[SaveAsk=True]&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch

Check:
	If IsMissing(SaveAsk) Or IsEmpty(SaveAsk) Then SaveAsk = True
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not _IsStillAlive(True) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(SaveAsk, &quot;SaveAsk&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
	End If

Try:
	If Not IsNull(_Database) Then _Database.CloseDatabase()
	If Not IsNull(_DataSource) Then _DataSource.dispose()
	CloseDocument = [_Super].CloseDocument(SaveAsk)

Finally:
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function   &apos;   SFDocuments.SF_Base.CloseDocument

REM -----------------------------------------------------------------------------
Public Function CloseFormDocument(Optional ByVal FormDocument As Variant) As Boolean
&apos;&apos;&apos;	Close the given form document
&apos;&apos;&apos;	Nothing happens if the form document is not open
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FormDocument: a valid document form name as a case-sensitive string
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if closure is successful
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;			oDoc.CloseFormDocument(&quot;Folder1/myFormDocument&quot;)
&apos;&apos;&apos;	DEPRECATED - Use preferably the CloseDocument() method of the FormDocument service

Dim bClose As Boolean				&apos;	Return value
Dim oMainForm As Object				&apos;	com.sun.star.comp.sdb.Content
Dim vFormNames As Variant			&apos;	Array of all document form names present in the document

Const cstThisSub = &quot;SFDocuments.Base.CloseFormDocument&quot;
Const cstSubArgs = &quot;FormDocument&quot;

	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
		&apos;	Build list of available FormDocuments recursively with _CollectFormDocuments
		If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
		vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
		If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
	End If
	If Not IsLoaded(FormDocument) Then GoTo Finally

Try:
	Set oMainForm = _FormDocuments.getByHierarchicalName(FormDocument)
	bClose = oMainForm.close()

Finally:
	CloseFormDocument = bClose
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.CloseFormDocument

REM -----------------------------------------------------------------------------
Public Function FormDocuments() As Variant
&apos;&apos;&apos;	Return the list of the FormDocuments contained in the Base document
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A zero-base array of strings
&apos;&apos;&apos;		Each entry is the full path name of a form document. The path separator is the slash (&quot;/&quot;)
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;			Dim myForm As Object, myList As Variant
&apos;&apos;&apos;				myList = oDoc.FormDocuments()

Dim vFormNames As Variant			&apos;	Array of all form names present in the document
Const cstThisSub = &quot;SFDocuments.Base.FormDocuments&quot;
Const cstSubArgs = &quot;&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch

Check:
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not _IsStillAlive() Then GoTo Finally
	End If

Try:
	&apos;	Build list of available FormDocuments recursively with _CollectFormDocuments
	If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
	vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
		
Finally:
	FormDocuments = vFormNames
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.FormDocuments

REM -----------------------------------------------------------------------------
Public Function Forms(Optional ByVal FormDocument As Variant _
							, Optional ByVal Form As Variant _
							) As Variant
&apos;&apos;&apos;	Return either
&apos;&apos;&apos;		- the list of the Forms contained in the form document
&apos;&apos;&apos;		- a SFDocuments.Form object based on its name or its index
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FormDocument: a valid document form name as a case-sensitive string
&apos;&apos;&apos;		Form: a form stored in the Base document given by its name or its index
&apos;&apos;&apos;			When absent, the list of available forms is returned
&apos;&apos;&apos;			To get the first (unique ?) form stored in the form document, set Form = 0
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A zero-based array of strings if Form is absent
&apos;&apos;&apos;		An instance of the SF_Form class if Form exists
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		FORMDEADERROR			The form is not open
&apos;&apos;&apos;		BASEFORMNOTFOUNDERROR	FormDocument OK but Form not found
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;			Dim myForm As Object, myList As Variant
&apos;&apos;&apos;				myList = oDoc.Forms(&quot;Folder1/myFormDocument&quot;)
&apos;&apos;&apos;				Set myForm = oDoc.Forms(&quot;Folder1/myFormDocument&quot;, 0)
&apos;&apos;&apos;	DEPRECATED - Use preferably the Forms() method of the FormDocument service

Dim oForm As Object					&apos;	The new Form class instance
Dim oFormDocument As Object			&apos;	com.sun.star.comp.sdb.Content
Dim oXForm As Object				&apos;	com.sun.star.form.XForm
Dim vFormDocuments As Variant		&apos;	Array of form documents
Dim vFormNames As Variant			&apos;	Array of form names
Dim oForms As Object				&apos;	Forms collection
Const cstDrawPage = 0				&apos;	Only 1 drawpage in a Base document

Const cstThisSub = &quot;SFDocuments.Base.Forms&quot;
Const cstSubArgs = &quot;FormDocument, [Form=&quot;&quot;&quot;&quot;]&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch

Check:
	If IsMissing(Form) Or IsEmpty(Form) Then Form = &quot;&quot;
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not _IsStillAlive() Then GoTo Finally
		&apos;	Build list of available FormDocuments recursively with _CollectFormDocuments
		If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
		vFormDocuments = Split(_CollectFormDocuments(_FormDocuments), cstToken)
		If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormDocuments) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
	End If
	If Not IsLoaded(FormDocument) Then GoTo CatchClosed

Try:
	&apos;	Start from the form document and go down to forms
	Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
	Set oForms = oFormDocument.Component.DrawPages(cstDrawPage).Forms
	vFormNames = oForms.getElementNames()

	If Len(Form) = 0 Then	&apos;	Return the list of valid form names
		Forms = vFormNames
	Else
		If VarType(Form) = V_STRING Then	&apos;	Find the form by name
			If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, V_STRING, vFormNames) Then GoTo Finally
			Set oXForm = oForms.getByName(Form)
		Else								&apos;	Find the form by index
			If Form &lt; 0 Or Form &gt;= oForms.Count Then GoTo CatchNotFound
			Set oXForm = oForms.getByIndex(Form)
		End If
		&apos;	Create the new Form class instance
		Set oForm = New SF_Form
		With oForm
			._Name = oXForm.Name
			Set .[Me] = oForm
			Set .[_Parent] = [Me]
			Set ._Component = oFormDocument.Component
			Set ._BaseComponent = _Component
			._FormDocumentName = FormDocument
			Set ._FormDocument = oFormDocument
			._FormType = ISBASEFORM
			Set ._Form = oXForm
			._Initialize()
		End With
		Set Forms = oForm
	End If

Finally:
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchClosed:
	ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
CatchNotFound:
	ScriptForge.SF_Exception.RaiseFatal(BASEFORMNOTFOUNDERROR, Form, FormDocument, _FileIdent())
End Function	&apos;	SFDocuments.SF_Base.Forms

REM -----------------------------------------------------------------------------
Public Function GetDatabase(Optional ByVal User As Variant _
								, Optional ByVal Password As Variant _
								) As Object
&apos;&apos;&apos;	Returns a Database instance (service = SFDatabases.Database) giving access
&apos;&apos;&apos;	to the execution of SQL commands on the database defined and/or stored in
&apos;&apos;&apos;	the actual Base document
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		User, Password: the login parameters as strings. Defaults = &quot;&quot;
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A SFDatabases.Database instance or Nothing
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim myDb As Object
&apos;&apos;&apos;			Set myDb = oDoc.GetDatabase()

Const cstThisSub = &quot;SFDocuments.Base.GetDatabase&quot;
Const cstSubArgs = &quot;[User=&quot;&quot;&quot;&quot;], [Password=&quot;&quot;&quot;&quot;]&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Set GetDatabase = Nothing

Check:
	If IsMissing(User) Or IsEmpty(User) Then User = &quot;&quot;
	If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not _IsStillAlive(True) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(User, &quot;User&quot;, V_STRING) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
	End If

Try:
	If IsNull(_Database) Then		&apos;	1st connection from the current document instance
		If IsNull(_DataSource) Then GoTo CatchConnect
		Set _Database = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.DatabaseFromDocument&quot; _
							, _DataSource, User, Password)
		If IsNull(_Database) Then GoTo CatchConnect
		_Database._Location = [_Super]._WindowFileName
	EndIf

Finally:
	Set GetDatabase = _Database
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchConnect:
	ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR, &quot;User&quot;, User, &quot;Password&quot;, Password, [_Super]._FileIdent())
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.GetDatabase

REM -----------------------------------------------------------------------------
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
&apos;&apos;&apos;	Return the actual value of the given property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		PropertyName: the name of the property as a string
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The actual value of the property
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		ARGUMENTERROR		The property does not exist

Const cstThisSub = &quot;SFDocuments.Base.GetProperty&quot;
Const cstSubArgs = &quot;&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	GetProperty = Null

Check:
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
	End If

Try:
	&apos;	Superclass or subclass property ?
	If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
		GetProperty = [_Super].GetProperty(PropertyName)
	Else
		GetProperty = _PropertyGet(PropertyName)
	End If

Finally:
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.GetProperty

REM -----------------------------------------------------------------------------
Public Function IsLoaded(Optional ByVal FormDocument As Variant) As Boolean
&apos;&apos;&apos;	Return True if the given FormDocument is open for the user
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FormDocument: a valid document form name as a case-sensitive string
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if the form document is currently open, otherwise False
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		Form name is invalid
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		MsgBox oDoc.IsLoaded(&quot;Folder1/myFormDocument&quot;)

Dim bLoaded As Boolean				&apos;	Return value
Dim vFormNames As Variant			&apos;	Array of all document form names present in the document
Dim oMainForm As Object				&apos;	com.sun.star.comp.sdb.Content
Const cstThisSub = &quot;SFDocuments.Base.IsLoaded&quot;
Const cstSubArgs = &quot;FormDocument&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bLoaded = False

Check:
	If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not _IsStillAlive() Then GoTo Finally
		&apos;	Build list of available FormDocuments recursively with _CollectFormDocuments
		vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
		If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
	End If

Try:
	Set oMainForm = _FormDocuments.getByHierarchicalName(FormDocument)
	&apos;	A document form that has never been opened has no component
	&apos;	If ever opened and closed afterwards, it keeps the Component but loses its Controller
	bLoaded = Not IsNull(oMainForm.Component)
	If bLoaded Then bLoaded = Not IsNull(oMainForm.Component.CurrentController)

Finally:
	IsLoaded = bLoaded
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.IsLoaded

REM -----------------------------------------------------------------------------
Public Function Methods() As Variant
&apos;&apos;&apos;	Return the list of public methods of the Base class as an array

	Methods = Array( _
					&quot;CloseFormDocument&quot; _
					, &quot;FormDocuments&quot; _
					, &quot;Forms&quot; _
					, &quot;GetDatabase&quot; _
					, &quot;IsLoaded&quot; _
					, &quot;OpenFormDocument&quot; _
					, &quot;PrintOut&quot; _
					, &quot;SetPrinter&quot; _
					)

End Function	&apos;	SFDocuments.SF_Base.Methods

REM -----------------------------------------------------------------------------
Public Function OpenFormDocument(Optional ByVal FormDocument As Variant _
									, Optional ByVal DesignMode As Variant _
									) As Object
&apos;&apos;&apos;	Open the FormDocument given by its hierarchical name either in normal or in design mode
&apos;&apos;&apos;	If the form document is already open, the form document is made active without changing its mode
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FormDocument: a valid form document name as a case-sensitive string
&apos;&apos;&apos;			When hierarchical, the hierarchy must be rendered with forward slashes (&quot;/&quot;)
&apos;&apos;&apos;		DesignMode: when True the form document is opened in design mode (Default = False)
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A FormDocument instance or Nothing
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		Form name is invalid
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Set oForm = oDoc.OpenFormDocument(&quot;Folder1/myFormDocument&quot;)

Dim oOpen As Object					&apos;	Return value
Dim vFormNames As Variant			&apos;	Array of all document form names present in the document
Dim oNewForm As Object				&apos;	Output of loadComponent()
Const cstThisSub = &quot;SFDocuments.Base.OpenFormDocument&quot;
Const cstSubArgs = &quot;FormDocument, [DesignMode=False]&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Set oOpen = Nothing

Check:
	If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not _IsStillAlive() Then GoTo Finally
		&apos;	Build list of available FormDocuments recursively with _CollectFormDocuments
		If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
		vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
		If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
	End If

Try:
	With _Component.CurrentController
		If Not .IsConnected Then .connect()
		&apos;	loadComponent activates the form when already loaded
		Set oNewForm = .loadComponent(com.sun.star.sdb.application.DatabaseObject.FORM, FormDocument, DesignMode)
		&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
		With oNewForm.CurrentController
			If .isFormDesignMode() &lt;&gt; DesignMode Then .setFormDesignMode(DesignMode)
		End With
	End With

	Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDocuments.FormDocument&quot;, oNewForm)

	&apos;	Prevent desynchronization when using .last(), .next() etc immediately after component loading. Bug #156836
	Wait 1

Finally:
	Set OpenFormDocument = oOpen
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.OpenFormDocument

REM -----------------------------------------------------------------------------
Public Function OpenQuery(Optional ByVal QueryName As Variant _
									, Optional ByVal DesignMode As Variant _
									) As Object
&apos;&apos;&apos;	Open the query given by its name either in normal or in design mode
&apos;&apos;&apos;	If the query is already open, the query datasheet is made active without changing its mode
&apos;&apos;&apos;	If still open, the datasheet will be closed together with the actual Base document.
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		QueryName: a valid Query name as a case-sensitive string
&apos;&apos;&apos;		DesignMode: when True the query is opened in design mode (Default = False)
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A Datasheet class instance if the query could be opened and DesignMode = False, otherwise Nothing
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		Query name is invalid
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		oDoc.OpenQuery(&quot;myQuery&quot;, DesignMode := False)

Dim oOpen As Object					&apos;	Return value
Dim vQueries As Variant				&apos;	Array of query names
Dim oNewQuery As Object				&apos;	Output of loadComponent()
Const cstThisSub = &quot;SFDocuments.Base.OpenQuery&quot;
Const cstSubArgs = &quot;QueryName, [DesignMode=False]&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Set oOpen = Nothing

Check:
	If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
	vQueries = GetDatabase().Queries	&apos;	Includes _IsStillAlive()
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not ScriptForge.SF_Utils._Validate(QueryName, &quot;QueryName&quot;, V_STRING, vQueries) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
	End If

Try:
	With _Component.CurrentController
		&apos;	The connection may have been done previously by a user command. If not, do it now.
		If Not .IsConnected Then .connect()
		&apos;	loadComponent activates the query component when already loaded
		Set oNewQuery = .loadComponent(com.sun.star.sdb.application.DatabaseObject.QUERY, QueryName, DesignMode)
	End With
	&apos;	When design mode, the method returns Nothing
	If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewQuery, [Me])

Finally:
	Set OpenQuery = oOpen
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.OpenQuery

REM -----------------------------------------------------------------------------
Public Function OpenTable(Optional ByVal TableName As Variant _
									, Optional ByVal DesignMode As Variant _
									) As Object
&apos;&apos;&apos;	Open the table given by its name either in normal or in design mode
&apos;&apos;&apos;	If the table is already open, the table datasheet is made active without changing its mode
&apos;&apos;&apos;	If still open, the datasheet will be closed together with the actual Base document.
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		TableName: a valid table name as a case-sensitive string
&apos;&apos;&apos;		DesignMode: when True the table is opened in design mode (Default = False)
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A Datasheet class instance if the table could be opened or was already open, and DesignMode = False.
&apos;&apos;&apos;		Otherwise Nothing
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		Table name is invalid
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		oDoc.OpenTable(&quot;myTable&quot;, DesignMode := False)

Dim oOpen As Object					&apos;	Return value
Dim vTables As Variant				&apos;	Array of table names
Dim oNewTable As Object				&apos;	Output of loadComponent()
Const cstThisSub = &quot;SFDocuments.Base.OpenTable&quot;
Const cstSubArgs = &quot;TableName, [DesignMode=False]&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Set oOpen = Nothing

Check:
	If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
	vTables = GetDatabase().Tables
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not ScriptForge.SF_Utils._Validate(TableName, &quot;TableName&quot;, V_STRING, vTables) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
	End If

Try:
	With _Component.CurrentController
		&apos;	The connection may have been done previously by a user command. If not, do it now.
		If Not .IsConnected Then .connect()
		&apos;	loadComponent activates the table component when already loaded
		Set oNewTable = .loadComponent(com.sun.star.sdb.application.DatabaseObject.TABLE, TableName, DesignMode)
	End With
	&apos;	When design mode, the method returns Nothing
	If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewTable, [Me])

Finally:
	Set OpenTable = oOpen
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.OpenTable

REM -----------------------------------------------------------------------------
Public Function PrintOut(Optional ByVal FormDocument As Variant _
							, Optional ByVal Pages As Variant _
							, Optional ByVal Copies As Variant _
							) As Boolean
&apos;&apos;&apos; Send the content of the given form document to the printer.
&apos;&apos;&apos;	The printer might be defined previously by default, by the user or by the SetPrinter() method
&apos;&apos;&apos;	The given form document must be open. It is activated by the method.
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FormDocument: a valid document form name as a case-sensitive string
&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
&apos;&apos;&apos;		Copies: the number of copies
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		FORMDEADERROR			The form is not open
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True when successful
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		oDoc.PrintOut(&quot;myForm&quot;, &quot;1-4;10;15-18&quot;, Copies := 2)
&apos;&apos;&apos;	DEPRECATED - Use preferably the PrintOut() method of the FormDocument service

Dim bPrint As Boolean				&apos;	Return value
Dim vFormNames As Variant			&apos;	Array of all document form names present in the document
Dim oFormDocument As Object			&apos;	com.sun.star.comp.sdb.Content

Const cstThisSub = &quot;SFDocuments.Base.PrintOut&quot;
Const cstSubArgs = &quot;FormDocument, [Pages=&quot;&quot;&quot;&quot;], [Copies=1]&quot;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bPrint = False

Check:
	If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
	If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
	
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not _IsStillAlive() Then GoTo Finally
		&apos;	Build list of available FormDocuments recursively with _CollectFormDocuments
		If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
		vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
		If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
		If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
	End If
	If Not IsLoaded(FormDocument) Then GoTo CatchClosed

Try:
	Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
	bPrint = [_Super].PrintOut(Pages, Copies, oFormDocument.Component)

Finally:
	PrintOut = bPrint
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchClosed:
	ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
End Function   &apos;   SFDocuments.SF_Base.PrintOut

REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
&apos;&apos;&apos;	Return the list or properties of the Base class as an array

	Properties = Array( _
					&quot;DocumentType&quot; _
					, &quot;FileSystem&quot; _
					, &quot;IsBase&quot; _
					, &quot;IsCalc&quot; _
					, &quot;IsDraw &quot; _
					, &quot;IsFormDocument&quot; _
					, &quot;IsImpress&quot; _
					, &quot;IsMath&quot; _
					, &quot;IsWriter&quot; _
					, &quot;XComponent&quot; _
					)

End Function	&apos;	SFDocuments.SF_Base.Properties

REM -----------------------------------------------------------------------------
Public Function SetPrinter(Optional ByVal FormDocument As Variant _
							, Optional ByVal Printer As Variant _
							, Optional ByVal Orientation As Variant _
							, Optional ByVal PaperFormat As Variant _
							) As Boolean
&apos;&apos;&apos; Define the printer options for a form document. The form document must be open.
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FormDocument: a valid document form name as a case-sensitive string
&apos;&apos;&apos;		Printer: the name of the printer queue where to print to
&apos;&apos;&apos;			When absent or space, the default printer is set
&apos;&apos;&apos;		Orientation: either &quot;PORTRAIT&quot; or &quot;LANDSCAPE&quot;. Left unchanged when absent
&apos;&apos;&apos;		PaperFormat: one of next values
&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;
&apos;&apos;&apos;			Left unchanged when absent
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True when successful
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		oDoc.SetPrinter(&quot;myForm&quot;, Orientation := &quot;PORTRAIT&quot;)
&apos;&apos;&apos;	DEPRECATED - Use preferably the SetPrinter() method of the FormDocument service

Dim bPrinter As Boolean				&apos;	Return value
Dim vFormDocuments As Variant		&apos;	Array of form documents
Dim oFormDocument As Object			&apos;	com.sun.star.comp.sdb.Content

Const cstThisSub = &quot;SFDocuments.Base.SetPrinter&quot;
Const cstSubArgs = &quot;FormDocument, [Printer=&quot;&quot;&quot;&quot;], [Orientation=&quot;&quot;PORTRAIT&quot;&quot;|&quot;&quot;LANDSCAPE&quot;&quot;]&quot; _
						&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;

	If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bPrinter = False

Check:
	If IsMissing(Printer) Or IsEmpty(Printer) Then Printer = &quot;&quot;
	If IsMissing(Orientation) Or IsEmpty(Orientation) Then Orientation = &quot;&quot;
	If IsMissing(PaperFormat) Or IsEmpty(PaperFormat) Then PaperFormat = &quot;&quot;
	
	If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not _IsStillAlive() Then GoTo Finally
		&apos;	Build list of available FormDocuments recursively with _CollectFormDocuments
		If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
		vFormDocuments = Split(_CollectFormDocuments(_FormDocuments), cstToken)
		If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormDocuments) Then GoTo Finally
	End If
	If Not IsLoaded(FormDocument) Then GoTo CatchClosed

Try:
	Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
	bPrinter = [_Super].SetPrinter(Printer, Orientation, PaperFormat, oFormDocument.Component)

Finally:
	SetPrinter = bPrinter
	ScriptForge.SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchClosed:
	ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
End Function   &apos;   SFDocuments.SF_Base.SetPrinter

REM -----------------------------------------------------------------------------
Public Function SetProperty(Optional ByVal PropertyName As Variant _
								, Optional ByRef Value As Variant _
								) As Boolean
&apos;&apos;&apos;	Set a new value to the given property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		PropertyName: the name of the property as a string
&apos;&apos;&apos;		Value: its new value
&apos;&apos;&apos;	Exceptions
&apos;&apos;&apos;		ARGUMENTERROR		The property does not exist

Const cstThisSub = &quot;SFDocuments.Base.SetProperty&quot;
Const cstSubArgs = &quot;PropertyName, Value&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	SetProperty = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
	End If

Try:
	Select Case UCase(PropertyName)
		Case Else
	End Select

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	SFDocuments.SF_Base.SetProperty

REM ======================================================= SUPERCLASS PROPERTIES

REM -----------------------------------------------------------------------------
&apos;Property Get CustomProperties() As Variant
&apos;	CustomProperties = [_Super].GetProperty(&quot;CustomProperties&quot;)
&apos;End Property	&apos;	SFDocuments.SF_Base.CustomProperties

REM -----------------------------------------------------------------------------
&apos;Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
&apos;	[_Super].CustomProperties = pvCustomProperties
&apos;End Property	&apos;	SFDocuments.SF_Base.CustomProperties

REM -----------------------------------------------------------------------------
&apos;Property Get Description() As Variant
&apos;	Description = [_Super].GetProperty(&quot;Description&quot;)
&apos;End Property	&apos;	SFDocuments.SF_Base.Description

REM -----------------------------------------------------------------------------
&apos;Property Let Description(Optional ByVal pvDescription As Variant)
&apos;	[_Super].Description = pvDescription
&apos;End Property	&apos;	SFDocuments.SF_Base.Description

REM -----------------------------------------------------------------------------
&apos;Property Get DocumentProperties() As Variant
&apos;	DocumentProperties = [_Super].GetProperty(&quot;DocumentProperties&quot;)
&apos;End Property	&apos;	SFDocuments.SF_Base.DocumentProperties

REM -----------------------------------------------------------------------------
Property Get DocumentType() As String
	DocumentType = [_Super].GetProperty(&quot;DocumentType&quot;)
End Property	&apos;	SFDocuments.SF_Base.DocumentType

REM -----------------------------------------------------------------------------
Property Get FileSystem() As String
	FileSystem = [_Super].GetProperty(&quot;FileSystem&quot;)
End Property	&apos;	SFDocuments.SF_Base.FileSystem

REM -----------------------------------------------------------------------------
Property Get IsBase() As Boolean
	IsBase = [_Super].GetProperty(&quot;IsBase&quot;)
End Property	&apos;	SFDocuments.SF_Base.IsBase

REM -----------------------------------------------------------------------------
Property Get IsCalc() As Boolean
	IsCalc = [_Super].GetProperty(&quot;IsCalc&quot;)
End Property	&apos;	SFDocuments.SF_Base.IsCalc

REM -----------------------------------------------------------------------------
Property Get IsDraw() As Boolean
	IsDraw = [_Super].GetProperty(&quot;IsDraw&quot;)
End Property	&apos;	SFDocuments.SF_Base.IsDraw

REM -----------------------------------------------------------------------------
Property Get IsFormDocument() As Boolean
	IsFormDocument = [_Super].GetProperty(&quot;IsFormDocument&quot;)
End Property	&apos;	SFDocuments.SF_Writer.IsFormDocument

REM -----------------------------------------------------------------------------
Property Get IsImpress() As Boolean
	IsImpress = [_Super].GetProperty(&quot;IsImpress&quot;)
End Property	&apos;	SFDocuments.SF_Base.IsImpress

REM -----------------------------------------------------------------------------
Property Get IsMath() As Boolean
	IsMath = [_Super].GetProperty(&quot;IsMath&quot;)
End Property	&apos;	SFDocuments.SF_Base.IsMath

REM -----------------------------------------------------------------------------
Property Get IsWriter() As Boolean
	IsWriter = [_Super].GetProperty(&quot;IsWriter&quot;)
End Property	&apos;	SFDocuments.SF_Base.IsWriter

REM -----------------------------------------------------------------------------
&apos;Property Get Keywords() As Variant
&apos;	Keywords = [_Super].GetProperty(&quot;Keywords&quot;)
&apos;End Property	&apos;	SFDocuments.SF_Base.Keywords

REM -----------------------------------------------------------------------------
&apos;Property Let Keywords(Optional ByVal pvKeywords As Variant)
&apos;	[_Super].Keywords = pvKeywords
&apos;End Property	&apos;	SFDocuments.SF_Base.Keywords

REM -----------------------------------------------------------------------------
&apos;Property Get Readonly() As Variant
&apos;	Readonly = [_Super].GetProperty(&quot;Readonly&quot;)
&apos;End Property	&apos;	SFDocuments.SF_Base.Readonly

REM -----------------------------------------------------------------------------
&apos;Property Get Subject() As Variant
&apos;	Subject = [_Super].GetProperty(&quot;Subject&quot;)
&apos;End Property	&apos;	SFDocuments.SF_Base.Subject

REM -----------------------------------------------------------------------------
&apos;Property Let Subject(Optional ByVal pvSubject As Variant)
&apos;	[_Super].Subject = pvSubject
&apos;End Property	&apos;	SFDocuments.SF_Base.Subject

REM -----------------------------------------------------------------------------
&apos;Property Get Title() As Variant
&apos;	Title = [_Super].GetProperty(&quot;Title&quot;)
&apos;End Property	&apos;	SFDocuments.SF_Base.Title

REM -----------------------------------------------------------------------------
&apos;Property Let Title(Optional ByVal pvTitle As Variant)
&apos;	[_Super].Title = pvTitle
&apos;End Property	&apos;	SFDocuments.SF_Base.Title

REM -----------------------------------------------------------------------------
Property Get XComponent() As Variant
	XComponent = [_Super].GetProperty(&quot;XComponent&quot;)
End Property	&apos;	SFDocuments.SF_Base.XComponent

REM ========================================================== SUPERCLASS METHODS

REM -----------------------------------------------------------------------------
Public Function Activate() As Boolean
	Activate = [_Super].Activate()
End Function    &apos;   SFDocuments.SF_Base.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	&apos;	SFDocuments.SF_Base.CreateMenu

REM -----------------------------------------------------------------------------
Public Function RemoveMenu(Optional ByVal MenuHeader As Variant) As Boolean
	RemoveMenu = [_Super].RemoveMenu(MenuHeader)
End Function	&apos;	SFDocuments.SF_Base.RemoveMenu

REM -----------------------------------------------------------------------------
Public Sub RunCommand(Optional ByVal Command As Variant _
									, ParamArray Args As Variant _
									)
	[_Super].RunCommand(Command, Args)
End Sub		  &apos;   SFDocuments.SF_Base.RunCommand

REM -----------------------------------------------------------------------------
Public Function Save() As Boolean
	Save = [_Super].Save()
End Function   &apos;   SFDocuments.SF_Base.Save

REM -----------------------------------------------------------------------------
Public Function SaveAs(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
	SaveAs = [_Super].SaveAs(FileName, Overwrite, Password, FilterName, FilterOptions)
End Function   &apos;   SFDocuments.SF_Base.SaveAs

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   &apos;   SFDocuments.SF_Base.SaveCopyAs

REM -----------------------------------------------------------------------------
Public Function Toolbars(Optional ByVal ToolbarName As Variant) As Variant
	Toolbars = [_Super].Toolbars(ToolbarName)
End Function	&apos;	SFDocuments.SF_Base.Toolbars

REM =========================================================== PRIVATE FUNCTIONS

REM -----------------------------------------------------------------------------
Private Function _CollectFormDocuments(ByRef poContainer As Object) As String
&apos;&apos;&apos;	Returns a token-separated string of all hierarchical formdocument names
&apos;&apos;&apos;	depending on the formdocuments container in argument
&apos;&apos;&apos;	The function traverses recursively the whole tree below the container
&apos;&apos;&apos;	The initial call starts from the container _Component.getFormDocuments
&apos;&apos;&apos;	The list contains closed and open forms

Dim sCollectNames As String			&apos;	Return value
Dim oSubItem As Object				&apos;	com.sun.star.container.XNameAccess (folder) or com.sun.star.ucb.XContent (form)
Dim i As Long
Const cstFormType = &quot;application/vnd.oasis.opendocument.text&quot;
									&apos;	Identifies forms. Folders have a zero-length content type

	On Local Error GoTo Finally

Try:
	sCollectNames = &quot;&quot;
	With poContainer
		For i = 0 To .Count - 1
			Set oSubItem = .getByIndex(i)
			If oSubItem.ContentType = cstFormType Then		&apos;	Add the form to the list
				sCollectNames = sCollectNames &amp; cstToken &amp; oSubItem.HierarchicalName
			Else
				sCollectNames = sCollectNames &amp; cstToken &amp; _CollectFormDocuments(oSubItem)
			End If
		Next i
	End With

Finally:
	If Len(sCollectNames) &gt; 0 Then
		_CollectFormDocuments = Mid(sCollectNames, Len(cstToken) + 1)	&apos;	Skip the initial token
	Else
		_CollectFormDocuments = &quot;&quot;
	End If
	Exit Function
End Function	&apos;	SFDocuments.SF_Base._CollectFormDocuments

REM -----------------------------------------------------------------------------
Private Function _FileIdent() As String
&apos;&apos;&apos;	Returns a file identification from the information that is currently available
&apos;&apos;&apos;	Useful e.g. for display in error messages

	_FileIdent = [_Super]._FileIdent()

End Function	&apos;	SFDocuments.SF_Base._FileIdent

REM -----------------------------------------------------------------------------
Private Function _FindByPersistentName(ByRef poContainer As Object _
										, psPersistent As String _
										) As Object
&apos;&apos;&apos;	The FormDocuments property of a Base component has strangely
&apos;&apos;&apos;	a getByHierarchical() method but no access to the same com.sun.star.comp.sdb.Content
&apos;&apos;&apos;	object via its persistent/ODF name
&apos;&apos;&apos;	This method returns the object having the given persistent name
&apos;&apos;&apos;	The function traverses recursively the whole tree below the container until found
&apos;&apos;&apos;	The initial call starts from the container _Component.getFormDocuments
&apos;&apos;&apos;	The list contains closed and open forms
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		poContainer: the actual top of the free, initially _FormDocuments
&apos;&apos;&apos;		psPersistent: a name like &quot;Obj...&quot;
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A com.sun.star.comp.sdb.Content object (object found, the process stops)
&apos;&apos;&apos;		or Nothing (object not found, the process continues)

Dim oMainForm As Object				&apos;	Return value
Dim oSubItem As Object				&apos;	com.sun.star.container.XNameAccess (folder) or com.sun.star.ucb.XContent (form)
Dim i As Long
Const cstFormType = &quot;application/vnd.oasis.opendocument.text&quot;
									&apos;	Identifies forms. Folders have a zero-length content type

	On Local Error GoTo Finally

Try:
	Set oMainForm = Nothing
	With poContainer
		For i = 0 To .Count - 1
			Set oSubItem = .getByIndex(i)
			If oSubItem.ContentType = cstFormType Then		&apos;	Examine its persistent name
				If oSubItem.PersistentName = psPersistent Then
					Set oMainForm = oSubItem
					Exit For
				End If
			Else
				Set oMainForm = _FindByPersistentName(oSubItem, psPersistent)
			End If
		Next i
	End With

Finally:
	Set _FindByPersistentName = oMainForm
	Exit Function
End Function	&apos;	SFDocuments.SF_Base.FindByPersistentName

REM -----------------------------------------------------------------------------
Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
									, Optional ByVal pbError As Boolean _
									) As Boolean
&apos;&apos;&apos;	Returns True if the document has not been closed manually or incidentally since the last use
&apos;&apos;&apos;	If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		pbForUpdate: if True (default = False), check additionally if document is open for editing
&apos;&apos;&apos;		pbError: if True (default), raise a fatal error

Dim bAlive As Boolean			&apos;	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	&apos;	SFDocuments.SF_Base._IsStillAlive

REM -----------------------------------------------------------------------------
Private Function _PropertyGet(Optional ByVal psProperty As String _
								, Optional ByVal pvArg As Variant _
								) As Variant
&apos;&apos;&apos;	Return the value of the named property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		psProperty: the name of the property

Dim oProperties As Object			&apos;	Document or Custom properties
Dim vLastCell As Variant			&apos;	Coordinates of last used cell in a sheet
Dim oSelect As Object				&apos;	Current selection
Dim vRanges As Variant				&apos;	List of selected ranges
Dim i As Long
Dim cstThisSub As String
Const cstSubArgs = &quot;&quot;

	_PropertyGet = False

	cstThisSub = &quot;SFDocuments.SF_Base.get&quot; &amp; 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	&apos;	SFDocuments.SF_Base._PropertyGet

REM -----------------------------------------------------------------------------
Private Function _Repr() As String
&apos;&apos;&apos;	Convert the SF_Base instance to a readable string, typically for debugging purposes (DebugPrint ...)
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;	Return:
&apos;&apos;&apos;		&quot;[Base]: Type/File&quot;

	_Repr = &quot;[Base]: &quot; &amp; [_Super]._FileIdent()

End Function	&apos;	SFDocuments.SF_Base._Repr

REM ============================================ END OF SFDOCUMENTS.SF_BASE
</script:module>