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_Form" 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 =======================================================================================================================
14 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
15 ''' SF_Form
16 ''' =======
17 ''' Management of forms defined in LibreOffice documents. Supported types are Base, Calc and Writer documents.
18 ''' It includes the management of subforms
19 ''' Each instance of the current class represents a single form or a single subform
21 ''' A form may optionally be (understand
"is often
") linked to a data source manageable with the SFDatabases.Database service
22 ''' The current service offers a rapid access to that service
24 ''' Definitions:
26 ''' FormDocument: BASE DOCUMENTS ONLY
27 ''' For usual documents, there is only
1 forms container. It is either the document itself or one of its sheets (Calc)
28 ''' A Base document may contain an unlimited number of form documents.
29 ''' In the Base terminology they are called
"forms
" or
"Base forms
". This could create some confusion.
30 ''' They can be organized in folders. Their name is then always the full path of folders + form
31 ''' with the slash (
"/
") as path separator
32 ''' A FormDocument is a set of Forms. Form names are visible in the user interface thanks to the form navigator
33 ''' Often there is only
1 Form present in a FormDocument. Having more, however, might improve
34 ''' the user experience significantly
36 ''' Form: WHERE IT IS ABOUT IN THE CURRENT
"Form
" SERVICE
37 ''' Is an abstract set of Controls in an OPEN Document or FormDocument
38 ''' Each form is usually linked to one single dataset (table, query or Select statement),
39 ''' located in any database (provided the user may access it)
40 ''' A usual document may contain several forms. Each of which may have its own data source (database + dataset)
41 ''' A Base form document may contain several forms. Each of which may address its own dataset. The database however is unique
42 ''' A form is defined by its owning Document or FormDocument and its FormName or FormIndex
44 ''' Service invocations:
46 ''' REM the form is stored in a Writer document
47 ''' Dim oDoc As Object, myForm As Object
48 ''' Set oDoc = CreateScriptService(
"SFDocuments.Document
", ThisComponent)
49 ''' Set myForm = oDoc.Forms(
"Form1
")
50 ''' ' or, alternatively, when there is only
1 form
51 ''' Set myForm = oDoc.Forms(
0)
53 ''' REM the form is stored in a Calc document
54 ''' Dim oCalc As Object, myForm As Object
55 ''' Set oCalc = CreateScriptService(
"SFDocuments.Document
", ThisComponent)
56 ''' Set myForm = oCalc.Forms(
"Sheet1
",
"Form1
")
57 ''' ' or, alternatively, when there is only
1 form
58 ''' Set myForm = oCalc.Forms(
"Sheet1
",
0)
60 ''' REM the form is stored in one of the FormDocuments of a Base document
61 ''' Dim oBase As Object, myFormDoc As Object, myForm As Object, mySubForm As Object
62 ''' Set oBase = CreateScriptService(
"SFDocuments.Document
", ThisDatabaseDocument)
63 ''' Set oFormDoc = oBase.OpenFormDocument(
"thisFormDocument
")
64 ''' Set myForm = oFormDoc.Forms(
"MainForm
")
65 ''' ' or, alternatively, when there is only
1 form
66 ''' Set myForm = oFormDoc.Forms(
0)
67 ''' ' To access a subform: myForm and mySubForm become distinct instances of the current class
68 ''' Set mySubForm = myForm.SubForms(
"mySubForm
")
70 ''' REM the form is the subject of an event
71 ''' Sub OnEvent(ByRef poEvent As Object)
72 ''' Dim myForm As Object
73 ''' Set myForm = CreateScriptService(
"SFDocuments.FormEvent
", poEvent)
75 ''' Detailed user documentation:
76 ''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/
03/sf_form.html?DbPAR=BASIC
78 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
80 REM ================================================================== EXCEPTIONS
82 Private Const FORMDEADERROR =
"FORMDEADERROR
"
83 Private Const SUBFORMNOTFOUNDERROR =
"SUBFORMNOTFOUNDERROR
"
85 REM ============================================================= PRIVATE MEMBERS
87 Private [Me] As Object
88 Private [_Parent] As Object
89 Private ObjectType As String
' Must be Form
90 Private ServiceName As String
93 Private _Name As String
' Internal name of the form
94 Private _FormType As Integer
' One of the ISxxxFORM constants
95 Private _SheetName As String
' Name as the sheet containing the form (Calc only)
96 Private _FormDocumentName As String
' The hierarchical name of the containing form document (Base only)
97 Private _FormDocument As Object
' com.sun.star.comp.sdb.Content - the form document container
98 ' The form topmost containers
99 Private _Component As Object
' com.sun.star.lang.XComponent
100 Private _BaseComponent As Object
' com.sun.star.comp.dba.ODatabaseDocument
102 ' Events management
103 Private _CacheIndex As Long
' Index in central cache storage
105 ' Form UNO references
106 ' The entry to the interactions with the form. Validity checked by the _IsStillAlive() method
107 ' Each method or property requiring that the form is opened should first invoke that method
108 Private _Form As Object
' com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm
110 ' Form attributes
111 Private _Database As Object
' Database class instance
113 ' Cache storage for controls
114 Private _ControlNames As Variant
' Array of control names
115 Private _ControlCache As Variant
' Array of control objects sorted like ElementNames of XForm
117 REM ============================================================ MODULE CONSTANTS
119 Const ISDOCFORM =
1 ' Form is stored in a Writer document
120 Const ISCALCFORM =
2 ' Form is stored in a Calc document
121 Const ISBASEFORM =
3 ' Form is stored in a Base form document
122 Const ISSUBFORM =
4 ' Form is a subform of a form or of another subform
123 Const ISUNDEFINED = -
1 ' Undefined form type
125 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
127 REM -----------------------------------------------------------------------------
128 Private Sub Class_Initialize()
130 Set [_Parent] = Nothing
131 ObjectType =
"FORM
"
132 ServiceName =
"SFDocuments.Form
"
134 _SheetName =
""
135 _FormDocumentName =
""
136 Set _FormDocument = Nothing
137 Set _Component = Nothing
138 Set _BaseComponent = Nothing
139 _FormType = ISUNDEFINED
142 Set _Database = Nothing
143 _ControlNames = Array()
144 _ControlCache = Array()
145 End Sub
' SFDocuments.SF_Form Constructor
147 REM -----------------------------------------------------------------------------
148 Private Sub Class_Terminate()
149 Call Class_Initialize()
150 End Sub
' SFDocuments.SF_Form Destructor
152 REM -----------------------------------------------------------------------------
153 Public Function Dispose() As Variant
154 If Not IsNull(_Database) And (_FormType = ISDOCFORM Or _FormType = ISCALCFORM) Then
155 Set _Database = _Database.Dispose()
157 SF_Register._CleanCacheEntry(_CacheIndex)
158 Call Class_Terminate()
159 Set Dispose = Nothing
160 End Function
' SFDocuments.SF_Form Explicit Destructor
162 REM ================================================================== PROPERTIES
164 REM -----------------------------------------------------------------------------
165 Property Get AllowDeletes() As Variant
166 ''' The AllowDeletes property specifies if the form allows to delete records
167 AllowDeletes = _PropertyGet(
"AllowDeletes
")
168 End Property
' SFDocuments.SF_Form.AllowDeletes (get)
170 REM -----------------------------------------------------------------------------
171 Property Let AllowDeletes(Optional ByVal pvAllowDeletes As Variant)
172 ''' Set the updatable property AllowDeletes
173 _PropertySet(
"AllowDeletes
", pvAllowDeletes)
174 End Property
' SFDocuments.SF_Form.AllowDeletes (let)
176 REM -----------------------------------------------------------------------------
177 Property Get AllowInserts() As Variant
178 ''' The AllowInserts property specifies if the form allows to add records
179 AllowInserts = _PropertyGet(
"AllowInserts
")
180 End Property
' SFDocuments.SF_Form.AllowInserts (get)
182 REM -----------------------------------------------------------------------------
183 Property Let AllowInserts(Optional ByVal pvAllowInserts As Variant)
184 ''' Set the updatable property AllowInserts
185 _PropertySet(
"AllowInserts
", pvAllowInserts)
186 End Property
' SFDocuments.SF_Form.AllowInserts (let)
188 REM -----------------------------------------------------------------------------
189 Property Get AllowUpdates() As Variant
190 ''' The AllowUpdates property specifies if the form allows to update records
191 AllowUpdates = _PropertyGet(
"AllowUpdates
")
192 End Property
' SFDocuments.SF_Form.AllowUpdates (get)
194 REM -----------------------------------------------------------------------------
195 Property Let AllowUpdates(Optional ByVal pvAllowUpdates As Variant)
196 ''' Set the updatable property AllowUpdates
197 _PropertySet(
"AllowUpdates
", pvAllowUpdates)
198 End Property
' SFDocuments.SF_Form.AllowUpdates (let)
200 REM -----------------------------------------------------------------------------
201 Property Get BaseForm() As String
202 ''' The BaseForm property specifies the hierarchical name of the Base form containing the actual form
203 BaseForm = _PropertyGet(
"BaseForm
")
204 End Property
' SFDocuments.SF_Form.BaseForm (get)
206 REM -----------------------------------------------------------------------------
207 Property Get Bookmark() As Variant
208 ''' The Bookmark property specifies uniquely the current record of the form
's underlying table, query or SQL statement.
209 Bookmark = _PropertyGet(
"Bookmark
")
210 End Property
' SFDocuments.SF_Form.Bookmark (get)
212 REM -----------------------------------------------------------------------------
213 Property Let Bookmark(Optional ByVal pvBookmark As Variant)
214 ''' Set the updatable property Bookmark
215 _PropertySet(
"Bookmark
", pvBookmark)
216 End Property
' SFDocuments.SF_Form.Bookmark (let)
218 REM -----------------------------------------------------------------------------
219 Property Get CurrentRecord() As Variant
220 ''' The CurrentRecord property identifies the current record in the recordset being viewed on a form
221 CurrentRecord = _PropertyGet(
"CurrentRecord
")
222 End Property
' SFDocuments.SF_Form.CurrentRecord (get)
224 REM -----------------------------------------------------------------------------
225 Property Let CurrentRecord(Optional ByVal pvCurrentRecord As Variant)
226 ''' Set the updatable property CurrentRecord
227 ''' If the row number is positive, the cursor moves to the given row number with respect to the beginning of the result set.
228 ''' The first row is row
1, the second is row
2, and so on.
229 ''' If the given row number is negative, the cursor moves to an absolute row position with respect to the end of the result set.
230 ''' For example, setting CurrentRecord = -
1 positions the cursor on the last row, -
2 indicates the next-to-last row, and so on
231 _PropertySet(
"CurrentRecord
", pvCurrentRecord)
232 End Property
' SFDocuments.SF_Form.CurrentRecord (let)
234 REM -----------------------------------------------------------------------------
235 Property Get Filter() As Variant
236 ''' The Filter property specifies a subset of records to be displayed.
237 Filter = _PropertyGet(
"Filter
")
238 End Property
' SFDocuments.SF_Form.Filter (get)
240 REM -----------------------------------------------------------------------------
241 Property Let Filter(Optional ByVal pvFilter As Variant)
242 ''' Set the updatable property Filter
243 _PropertySet(
"Filter
", pvFilter)
244 End Property
' SFDocuments.SF_Form.Filter (let)
246 REM -----------------------------------------------------------------------------
247 Property Get LinkChildFields() As Variant
248 ''' The LinkChildFields property specifies how records in a subform (child) are linked to records in its parent form
249 ''' It returns an array of strings
250 LinkChildFields = _PropertyGet(
"LinkChildFields
")
251 End Property
' SFDocuments.SF_Form.LinkChildFields (get)
253 REM -----------------------------------------------------------------------------
254 Property Get LinkParentFields() As Variant
255 ''' The LinkParentFields property specifies how records in a subform (Child) are linked to records in its parent form
256 ''' It returns an array of strings
257 LinkParentFields = _PropertyGet(
"LinkParentFields
")
258 End Property
' SFDocuments.SF_Form.LinkParentFields (get)
260 REM -----------------------------------------------------------------------------
261 Property Get Name() As String
262 ''' Return the name of the actual Form
263 Name = _PropertyGet(
"Name
")
264 End Property
' SFDocuments.SF_Form.Name
266 REM -----------------------------------------------------------------------------
267 Property Get OnApproveCursorMove() As Variant
268 ''' The OnApproveCursorMove property specifies the script to trigger when this event occurs
269 OnApproveCursorMove = _PropertyGet(
"OnApproveCursorMove
")
270 End Property
' SFDocuments.SF_Form.OnApproveCursorMove (get)
272 REM -----------------------------------------------------------------------------
273 Property Let OnApproveCursorMove(Optional ByVal pvOnApproveCursorMove As Variant)
274 ''' Set the updatable property OnApproveCursorMove
275 _PropertySet(
"OnApproveCursorMove
", pvOnApproveCursorMove)
276 End Property
' SFDocuments.SF_Form.OnApproveCursorMove (let)
278 REM -----------------------------------------------------------------------------
279 Property Get OnApproveReset() As Variant
280 ''' The OnApproveReset property specifies the script to trigger when this event occurs
281 OnApproveReset = _PropertyGet(
"OnApproveReset
")
282 End Property
' SFDocuments.SF_Form.OnApproveReset (get)
284 REM -----------------------------------------------------------------------------
285 Property Let OnApproveReset(Optional ByVal pvOnApproveReset As Variant)
286 ''' Set the updatable property OnApproveReset
287 _PropertySet(
"OnApproveReset
", pvOnApproveReset)
288 End Property
' SFDocuments.SF_Form.OnApproveReset (let)
290 REM -----------------------------------------------------------------------------
291 Property Get OnApproveRowChange() As Variant
292 ''' The OnApproveRowChange property specifies the script to trigger when this event occurs
293 OnApproveRowChange = _PropertyGet(
"OnApproveRowChange
")
294 End Property
' SFDocuments.SF_Form.OnApproveRowChange (get)
296 REM -----------------------------------------------------------------------------
297 Property Let OnApproveRowChange(Optional ByVal pvOnApproveRowChange As Variant)
298 ''' Set the updatable property OnApproveRowChange
299 _PropertySet(
"OnApproveRowChange
", pvOnApproveRowChange)
300 End Property
' SFDocuments.SF_Form.OnApproveRowChange (let)
302 REM -----------------------------------------------------------------------------
303 Property Get OnApproveSubmit() As Variant
304 ''' The OnApproveSubmit property specifies the script to trigger when this event occurs
305 OnApproveSubmit = _PropertyGet(
"OnApproveSubmit
")
306 End Property
' SFDocuments.SF_Form.OnApproveSubmit (get)
308 REM -----------------------------------------------------------------------------
309 Property Let OnApproveSubmit(Optional ByVal pvOnApproveSubmit As Variant)
310 ''' Set the updatable property OnApproveSubmit
311 _PropertySet(
"OnApproveSubmit
", pvOnApproveSubmit)
312 End Property
' SFDocuments.SF_Form.OnApproveSubmit (let)
314 REM -----------------------------------------------------------------------------
315 Property Get OnConfirmDelete() As Variant
316 ''' The OnConfirmDelete property specifies the script to trigger when this event occurs
317 OnConfirmDelete = _PropertyGet(
"OnConfirmDelete
")
318 End Property
' SFDocuments.SF_Form.OnConfirmDelete (get)
320 REM -----------------------------------------------------------------------------
321 Property Let OnConfirmDelete(Optional ByVal pvOnConfirmDelete As Variant)
322 ''' Set the updatable property OnConfirmDelete
323 _PropertySet(
"OnConfirmDelete
", pvOnConfirmDelete)
324 End Property
' SFDocuments.SF_Form.OnConfirmDelete (let)
326 REM -----------------------------------------------------------------------------
327 Property Get OnCursorMoved() As Variant
328 ''' The OnCursorMoved property specifies the script to trigger when this event occurs
329 OnCursorMoved = _PropertyGet(
"OnCursorMoved
")
330 End Property
' SFDocuments.SF_Form.OnCursorMoved (get)
332 REM -----------------------------------------------------------------------------
333 Property Let OnCursorMoved(Optional ByVal pvOnCursorMoved As Variant)
334 ''' Set the updatable property OnCursorMoved
335 _PropertySet(
"OnCursorMoved
", pvOnCursorMoved)
336 End Property
' SFDocuments.SF_Form.OnCursorMoved (let)
338 REM -----------------------------------------------------------------------------
339 Property Get OnErrorOccurred() As Variant
340 ''' The OnErrorOccurred property specifies the script to trigger when this event occurs
341 OnErrorOccurred = _PropertyGet(
"OnErrorOccurred
")
342 End Property
' SFDocuments.SF_Form.OnErrorOccurred (get)
344 REM -----------------------------------------------------------------------------
345 Property Let OnErrorOccurred(Optional ByVal pvOnErrorOccurred As Variant)
346 ''' Set the updatable property OnErrorOccurred
347 _PropertySet(
"OnErrorOccurred
", pvOnErrorOccurred)
348 End Property
' SFDocuments.SF_Form.OnErrorOccurred (let)
350 REM -----------------------------------------------------------------------------
351 Property Get OnLoaded() As Variant
352 ''' The OnLoaded property specifies the script to trigger when this event occurs
353 OnLoaded = _PropertyGet(
"OnLoaded
")
354 End Property
' SFDocuments.SF_Form.OnLoaded (get)
356 REM -----------------------------------------------------------------------------
357 Property Let OnLoaded(Optional ByVal pvOnLoaded As Variant)
358 ''' Set the updatable property OnLoaded
359 _PropertySet(
"OnLoaded
", pvOnLoaded)
360 End Property
' SFDocuments.SF_Form.OnLoaded (let)
362 REM -----------------------------------------------------------------------------
363 Property Get OnReloaded() As Variant
364 ''' The OnReloaded property specifies the script to trigger when this event occurs
365 OnReloaded = _PropertyGet(
"OnReloaded
")
366 End Property
' SFDocuments.SF_Form.OnReloaded (get)
368 REM -----------------------------------------------------------------------------
369 Property Let OnReloaded(Optional ByVal pvOnReloaded As Variant)
370 ''' Set the updatable property OnReloaded
371 _PropertySet(
"OnReloaded
", pvOnReloaded)
372 End Property
' SFDocuments.SF_Form.OnReloaded (let)
374 REM -----------------------------------------------------------------------------
375 Property Get OnReloading() As Variant
376 ''' The OnReloading property specifies the script to trigger when this event occurs
377 OnReloading = _PropertyGet(
"OnReloading
")
378 End Property
' SFDocuments.SF_Form.OnReloading (get)
380 REM -----------------------------------------------------------------------------
381 Property Let OnReloading(Optional ByVal pvOnReloading As Variant)
382 ''' Set the updatable property OnReloading
383 _PropertySet(
"OnReloading
", pvOnReloading)
384 End Property
' SFDocuments.SF_Form.OnReloading (let)
386 REM -----------------------------------------------------------------------------
387 Property Get OnResetted() As Variant
388 ''' The OnResetted property specifies the script to trigger when this event occurs
389 OnResetted = _PropertyGet(
"OnResetted
")
390 End Property
' SFDocuments.SF_Form.OnResetted (get)
392 REM -----------------------------------------------------------------------------
393 Property Let OnResetted(Optional ByVal pvOnResetted As Variant)
394 ''' Set the updatable property OnResetted
395 _PropertySet(
"OnResetted
", pvOnResetted)
396 End Property
' SFDocuments.SF_Form.OnResetted (let)
398 REM -----------------------------------------------------------------------------
399 Property Get OnRowChanged() As Variant
400 ''' The OnRowChanged property specifies the script to trigger when this event occurs
401 OnRowChanged = _PropertyGet(
"OnRowChanged
")
402 End Property
' SFDocuments.SF_Form.OnRowChanged (get)
404 REM -----------------------------------------------------------------------------
405 Property Let OnRowChanged(Optional ByVal pvOnRowChanged As Variant)
406 ''' Set the updatable property OnRowChanged
407 _PropertySet(
"OnRowChanged
", pvOnRowChanged)
408 End Property
' SFDocuments.SF_Form.OnRowChanged (let)
410 REM -----------------------------------------------------------------------------
411 Property Get OnUnloaded() As Variant
412 ''' The OnUnloaded property specifies the script to trigger when this event occurs
413 OnUnloaded = _PropertyGet(
"OnUnloaded
")
414 End Property
' SFDocuments.SF_Form.OnUnloaded (get)
416 REM -----------------------------------------------------------------------------
417 Property Let OnUnloaded(Optional ByVal pvOnUnloaded As Variant)
418 ''' Set the updatable property OnUnloaded
419 _PropertySet(
"OnUnloaded
", pvOnUnloaded)
420 End Property
' SFDocuments.SF_Form.OnUnloaded (let)
422 REM -----------------------------------------------------------------------------
423 Property Get OnUnloading() As Variant
424 ''' The OnUnloading property specifies the script to trigger when this event occurs
425 OnUnloading = _PropertyGet(
"OnUnloading
")
426 End Property
' SFDocuments.SF_Form.OnUnloading (get)
428 REM -----------------------------------------------------------------------------
429 Property Let OnUnloading(Optional ByVal pvOnUnloading As Variant)
430 ''' Set the updatable property OnUnloading
431 _PropertySet(
"OnUnloading
", pvOnUnloading)
432 End Property
' SFDocuments.SF_Form.OnUnloading (let)
434 REM -----------------------------------------------------------------------------
435 Property Get OrderBy() As Variant
436 ''' The OrderBy property specifies in which order the records should be displayed.
437 OrderBy = _PropertyGet(
"OrderBy
")
438 End Property
' SFDocuments.SF_Form.OrderBy (get)
440 REM -----------------------------------------------------------------------------
441 Property Let OrderBy(Optional ByVal pvOrderBy As Variant)
442 ''' Set the updatable property OrderBy
443 _PropertySet(
"OrderBy
", pvOrderBy)
444 End Property
' SFDocuments.SF_Form.OrderBy (let)
446 REM -----------------------------------------------------------------------------
447 Property Get Parent() As Object
448 ''' Return the Parent of the actual Form
449 Parent = _PropertyGet(
"Parent
")
450 End Property
' SFDocuments.SF_Form.Parent
452 REM -----------------------------------------------------------------------------
453 Property Get RecordSource() As Variant
454 ''' The RecordSource property specifies the source of the data,
455 ''' a table name, a query name or a SQL statement
456 RecordSource = _PropertyGet(
"RecordSource
")
457 End Property
' SFDocuments.SF_Form.RecordSource (get)
459 REM -----------------------------------------------------------------------------
460 Property Let RecordSource(Optional ByVal pvRecordSource As Variant)
461 ''' Set the updatable property RecordSource
462 _PropertySet(
"RecordSource
", pvRecordSource)
463 End Property
' SFDocuments.SF_Form.RecordSource (let)
465 REM -----------------------------------------------------------------------------
466 Property Get XForm() As Object
467 ''' The XForm property returns the XForm UNO object of the Form
468 XForm = _PropertyGet(
"XForm
")
469 End Property
' SFDocuments.SF_Form.XForm (get)
471 REM ===================================================================== METHODS
473 REM -----------------------------------------------------------------------------
474 Public Function Activate() As Boolean
475 ''' Set the focus on the current Form instance
476 ''' Probably called from after an event occurrence or to focus on an open Base form document
477 ''' If the parent document is ...
478 ''' Calc Activate the corresponding sheet
479 ''' Writer Activate the parent document
480 ''' Base Activate the parent form document
481 ''' Args:
482 ''' Returns:
483 ''' True if focusing is successful
484 ''' Example:
485 ''' myForm.Activate()
487 Dim bActivate As Boolean
' Return value
488 Dim oContainer As Object
' com.sun.star.awt.XWindow
489 Const cstThisSub =
"SFDocuments.Form.Activate
"
490 Const cstSubArgs =
""
492 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
496 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
497 If Not _IsStillAlive() Then GoTo Finally
500 Select Case _FormType
501 Case ISDOCFORM : bActivate = [_Parent].Activate()
502 Case ISCALCFORM : bActivate = [_Parent].Activate(_SheetName)
504 Set oContainer = _FormDocument.Component.CurrentController.Frame.ContainerWindow
506 If .isVisible() = False Then .setVisible(True)
509 .toFront()
' Force window change in Linux
510 Wait
1 ' Bypass desynchro issue in Linux
517 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
521 End Function
' SFDocuments.SF_Form.Activate
523 REM -----------------------------------------------------------------------------
524 Public Function CloseFormDocument() As Boolean
525 ''' Close the form document containing the actual form instance
526 ''' The form instance is disposed
527 ''' The method does nothing if the actual form is not located in a Base form document
528 ''' Args:
529 ''' Returns:
530 ''' True if closure is successful
531 ''' Example:
532 ''' myForm.CloseFormDocument()
534 Dim bClose As Boolean
' Return value
535 Dim oContainer As Object
' com.sun.star.awt.XWindow
536 Const cstThisSub =
"SFDocuments.Form.CloseFormDocument
"
537 Const cstSubArgs =
""
539 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
543 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
544 If Not _IsStillAlive() Then GoTo Finally
547 Select Case _FormType
548 Case ISDOCFORM, ISCALCFORM
549 Case ISBASEFORM, ISSUBFORM
550 If Not IsNull(_FormDocument) Then
551 _FormDocument.close()
559 CloseFormDocument = bClose
560 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
564 End Function
' SFDocuments.SF_Form.CloseFormDocument
566 REM -----------------------------------------------------------------------------
567 Public Function Controls(Optional ByVal ControlName As Variant) As Variant
568 ''' Return either
569 ''' - the list of the controls contained in the Form
570 ''' - a Form control object based on its name
571 ''' Args:
572 ''' ControlName: a valid control name as a case-sensitive string. If absent the list is returned
573 ''' Returns:
574 ''' A zero-base array of strings if ControlName is absent
575 ''' An instance of the SF_FormControl class if ControlName exists
576 ''' Exceptions:
577 ''' ControlName is invalid
578 ''' Example:
579 ''' Dim myForm As Object, myList As Variant, myControl As Object
580 ''' Set myForm = myDoc.Forms(
"myForm
")
581 ''' myList = myForm.Controls()
582 ''' Set myControl = myForm.Controls(
"myTextBox
")
584 Dim oControl As Object
' The new control class instance
585 Dim lIndexOfNames As Long
' Index in ElementNames array. Used to access _ControlCache
586 Dim vControl As Variant
' Alias of _ControlCache entry
588 Const cstThisSub =
"SFDocuments.Form.Controls
"
589 Const cstSubArgs =
"[ControlName]
"
591 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
594 If IsMissing(ControlName) Or IsEmpty(ControlName) Then ControlName =
""
595 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
596 If Not _IsStillAlive() Then GoTo Finally
597 If Not ScriptForge.SF_Utils._Validate(ControlName,
"ControlName
", V_STRING) Then GoTo Finally
601 ' Collect all control names if not yet done
602 If UBound(_ControlNames)
< 0 Then
603 _ControlNames = _Form.getElementNames()
604 ' Remove all subforms from the list
605 For i =
0 To UBound(_ControlNames)
606 ' Subforms have no ClassId property
607 If Not ScriptForge.SF_Session.HasUnoProperty(_Form.getByName(_ControlNames(i)),
"ClassId
") Then _ControlNames(i) =
""
609 _ControlNames = ScriptForge.SF_Array.TrimArray(_ControlNames)
610 ' Size the cache accordingly
611 If UBound(_ControlNames)
>=
0 Then
612 ReDim _ControlCache(
0 To UBound(_ControlNames))
616 ' Return the list of controls or a FormControl instance
617 If Len(ControlName) =
0 Then
618 Controls = _ControlNames
622 If Not _Form.hasByName(ControlName) Then GoTo CatchNotFound
623 lIndexOfNames = ScriptForge.SF_Array.IndexOf(_ControlNames, ControlName, CaseSensitive := True)
624 ' Reuse cache when relevant
625 vControl = _ControlCache(lIndexOfNames)
627 If IsEmpty(vControl) Then
628 ' Create the new form control class instance
629 Set oControl = New SF_FormControl
633 Set .[_Parent] = [Me]
634 Set ._ParentForm = [Me]
635 ._IndexOfNames = lIndexOfNames
637 ' Get model and view of the current control
638 Set ._ControlModel = _Form.getByName(ControlName)
642 Set oControl = vControl
645 Set Controls = oControl
649 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
654 ScriptForge.SF_Utils._Validate(ControlName,
"ControlName
", V_STRING, _Form.getElementNames())
656 End Function
' SFDocuments.SF_Form.Controls
658 REM -----------------------------------------------------------------------------
659 Public Function GetDatabase(Optional ByVal User As Variant _
660 , Optional ByVal Password As Variant _
662 ''' Returns a Database instance (service = SFDatabases.Database) giving access
663 ''' to the execution of SQL commands on the database defined and/or stored in
664 ''' the actual Base document
665 ''' Each main form has its own database connection, except within Base documents where
666 ''' they all share the same connection
667 ''' Args:
668 ''' User, Password: the login parameters as strings. Defaults =
""
669 ''' Returns:
670 ''' A SFDatabases.Database instance or Nothing
671 ''' Example:
672 ''' Dim myDb As Object
673 ''' Set myDb = oForm.GetDatabase()
675 Dim FSO As Object
' Alias for SF_FileSystem
676 Dim sDataSource As String
' Database file name in FileNaming format
677 Dim sUser As String
' Alias for User
678 Dim sPassword As String
' Alias for Password
679 Const cstThisSub =
"SFDocuments.Form.GetDatabase
"
680 Const cstSubArgs =
"[User=
""""], [Password=
""""]
"
682 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
683 Set GetDatabase = Nothing
686 If IsMissing(User) Or IsEmpty(User) Then User =
""
687 If IsMissing(Password) Or IsEmpty(Password) Then Password =
""
688 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
689 If Not [_Parent]._IsStillAlive(False) Then GoTo Finally
690 If Not ScriptForge.SF_Utils._Validate(User,
"User
", V_STRING) Then GoTo Finally
691 If Not ScriptForge.SF_Utils._Validate(Password,
"Password
", V_STRING) Then GoTo Finally
695 ' Adjust connection arguments
696 If Len(User) =
0 Then
697 If ScriptForge.SF_Session.HasUnoProperty(_Form,
"User
") Then sUser = _Form.User Else sUser =
""
701 If Len(sUser) + Len(Password) =
0 Then
702 If ScriptForge.SF_Session.HasUnoProperty(_Form,
"Password
") Then sPassword = _Form.Password Else sPassword = Password
705 ' Connect to database, avoiding multiple requests
706 If IsNull(_Database) Then
' 1st connection request from the current form instance
707 If _FormType = ISBASEFORM And Not IsNull(_BaseComponent) Then
708 ' Fetch the shared connection
709 Set _Database = [_Parent].GetDatabase(User, Password)
710 ElseIf _FormType = ISSUBFORM Then
711 Set _Database = [_Parent].GetDatabase()
' Recursive call, climb the tree
712 ElseIf Len(_Form.DataSourceName) =
0 Then
' There is no database linked with the form
713 ' Return Nothing
715 ' Check if DataSourceName is a file or a registered name and create database instance accordingly
716 Set FSO = ScriptForge.SF_FileSystem
717 sDataSource = FSO._ConvertFromUrl(_Form.DataSourceName)
718 If FSO.FileExists(sDataSource) Then
719 Set _Database = ScriptForge.SF_Services.CreateScriptService(
"SFDatabases.Database
" _
720 , sDataSource, , , sUser, sPassword)
722 Set _Database = ScriptForge.SF_Services.CreateScriptService(
"SFDatabases.Database
" _
723 , , _Form.DataSourceName, , sUser, sPassword)
725 If IsNull(_Database) Then GoTo CatchConnect
731 Set GetDatabase = _Database
732 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
737 ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR,
"User
", User,
"Password
", Password, [_Super]._FileIdent())
739 End Function
' SFDocuments.SF_Form.GetDatabase
741 REM -----------------------------------------------------------------------------
742 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
743 ''' Return the actual value of the given property
744 ''' Args:
745 ''' PropertyName: the name of the property as a string
746 ''' Returns:
747 ''' The actual value of the property
748 ''' Exceptions:
749 ''' ARGUMENTERROR The property does not exist
750 ''' Examples:
751 ''' oDlg.GetProperty(
"Caption
")
753 Const cstThisSub =
"SFDocuments.Form.GetProperty
"
754 Const cstSubArgs =
""
756 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
760 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
761 If Not ScriptForge.SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
765 GetProperty = _PropertyGet(PropertyName)
768 SF_Utils._ExitFunction(cstThisSub)
772 End Function
' SFDocuments.SF_Form.GetProperty
774 REM -----------------------------------------------------------------------------
775 Public Function Methods() As Variant
776 ''' Return the list of public methods of the Form service as an array
779 "Activate
" _
780 ,
"CloseForm
" _
781 ,
"Controls
" _
782 ,
"GetDatabase
" _
783 ,
"MoveFirst
" _
784 ,
"MoveLast
" _
785 ,
"MoveNew
" _
786 ,
"MoveNext
" _
787 ,
"MovePrevious
" _
788 ,
"Requery
" _
789 ,
"SubForms
" _
792 End Function
' SFDocuments.SF_Form.Methods
794 REM -----------------------------------------------------------------------------
795 Public Function MoveFirst() As Boolean
796 ''' The cursor is (re)positioned on the first row
797 ''' Args:
798 ''' Returns:
799 ''' True if cursor move is successful
800 ''' Example:
801 ''' myForm.MoveFirst()
803 Dim bMoveFirst As Boolean
' Return value
804 Const cstThisSub =
"SFDocuments.Form.MoveFirst
"
805 Const cstSubArgs =
""
807 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
811 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
812 If Not _IsStillAlive() Then GoTo Finally
816 bMoveFirst = .first()
820 MoveFirst = bMoveFirst
821 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
825 End Function
' SFDocuments.SF_Form.MoveFirst
827 REM -----------------------------------------------------------------------------
828 Public Function MoveLast() As Boolean
829 ''' The cursor is (re)positioned on the last row
830 ''' Args:
831 ''' Returns:
832 ''' True if cursor move is successful
833 ''' Example:
834 ''' myForm.MoveLast()
836 Dim bMoveLast As Boolean
' Return value
837 Const cstThisSub =
"SFDocuments.Form.MoveLast
"
838 Const cstSubArgs =
""
840 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
844 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
845 If Not _IsStillAlive() Then GoTo Finally
854 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
858 End Function
' SFDocuments.SF_Form.MoveLast
860 REM -----------------------------------------------------------------------------
861 Public Function MoveNew() As Boolean
862 ''' The cursor is (re)positioned in the new record area
863 ''' Args:
864 ''' Returns:
865 ''' True if cursor move is successful
866 ''' Example:
867 ''' myForm.MoveNew()
869 Dim bMoveNew As Boolean
' Return value
870 Const cstThisSub =
"SFDocuments.Form.MoveNew
"
871 Const cstSubArgs =
""
873 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
877 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
878 If Not _IsStillAlive() Then GoTo Finally
882 .last()
' To simulate the behaviour in the UI
889 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
893 End Function
' SFDocuments.SF_Form.MoveNew
895 REM -----------------------------------------------------------------------------
896 Public Function MoveNext(Optional ByVal Offset As Variant) As Boolean
897 ''' The cursor is (re)positioned on the next row
898 ''' Args:
899 ''' Offset: The number of records to go forward (default =
1)
900 ''' Returns:
901 ''' True if cursor move is successful
902 ''' Example:
903 ''' myForm.MoveNext()
905 Dim bMoveNext As Boolean
' Return value
906 Dim lOffset As Long
' Alias of Offset
907 Const cstThisSub =
"SFDocuments.Form.MoveNext
"
908 Const cstSubArgs =
""
910 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
914 If IsMissing(Offset) Or IsEmpty(Offset) Then Offset =
1
915 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
916 If Not _IsStillAlive() Then GoTo Finally
917 If Not ScriptForge.SF_Utils._Validate(Offset,
"Offset
", ScriptForge.V_NUMERIC) Then GoTo Finally
920 lOffset = CLng(Offset)
' To be sure to have the right argument type
922 If lOffset =
1 Then bMoveNext = .next() Else bMoveNext = .relative(lOffset)
927 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
931 End Function
' SFDocuments.SF_Form.MoveNext
933 REM -----------------------------------------------------------------------------
934 Public Function MovePrevious(Optional ByVal Offset As Variant) As Boolean
935 ''' The cursor is (re)positioned on the previous row
936 ''' Args:
937 ''' Offset: The number of records to go backward (default =
1)
938 ''' Returns:
939 ''' True if cursor move is successful
940 ''' Example:
941 ''' myForm.MovePrevious()
943 Dim bMovePrevious As Boolean
' Return value
944 Dim lOffset As Long
' Alias of Offset
945 Const cstThisSub =
"SFDocuments.Form.MovePrevious
"
946 Const cstSubArgs =
""
948 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
949 bMovePrevious = False
952 If IsMissing(Offset) Or IsEmpty(Offset) Then Offset =
1
953 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
954 If Not _IsStillAlive() Then GoTo Finally
955 If Not ScriptForge.SF_Utils._Validate(Offset,
"Offset
", ScriptForge.V_NUMERIC) Then GoTo Finally
958 lOffset = CLng(Offset)
' To be sure to have the right argument type
960 If lOffset =
1 Then bMovePrevious = .previous() Else bMovePrevious = .relative(-lOffset)
964 MovePrevious = bMovePrevious
965 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
969 End Function
' SFDocuments.SF_Form.MovePrevious
971 REM -----------------------------------------------------------------------------
972 Public Function Properties() As Variant
973 ''' Return the list or properties of the Form class as an array
975 Properties = Array( _
976 "AllowDeletes
" _
977 ,
"AllowInserts
" _
978 ,
"AllowUpdates
" _
979 ,
"BaseForm
" _
980 ,
"Bookmark
" _
981 ,
"CurrentRecord
" _
982 ,
"Filter
" _
983 ,
"LinkChildFields
" _
984 ,
"LinkParentFields
" _
986 ,
"OnApproveCursorMove
" _
987 ,
"OnApproveParameter
" _
988 ,
"OnApproveReset
" _
989 ,
"OnApproveRowChange
" _
990 ,
"OnApproveSubmit
" _
991 ,
"OnConfirmDelete
" _
992 ,
"OnCursorMoved
" _
993 ,
"OnErrorOccurred
" _
994 ,
"OnLoaded
" _
995 ,
"OnReloaded
" _
996 ,
"OnReloading
" _
997 ,
"OnResetted
" _
998 ,
"OnRowChanged
" _
999 ,
"OnUnloaded
" _
1000 ,
"OnUnloading
" _
1001 ,
"OrderBy
" _
1002 ,
"Parent
" _
1003 ,
"RecordSource
" _
1004 ,
"XForm
" _
1007 End Function
' SFDocuments.SF_Form.Properties
1009 REM -----------------------------------------------------------------------------
1010 Public Function Requery() As Boolean
1011 ''' Reload from the database the actual data into the form
1012 ''' The cursor is (re)positioned on the first row
1013 ''' Args:
1014 ''' Returns:
1015 ''' True if requery is successful
1016 ''' Example:
1017 ''' myForm.Requery()
1019 Dim bRequery As Boolean
' Return value
1020 Const cstThisSub =
"SFDocuments.Form.Requery
"
1021 Const cstSubArgs =
""
1023 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1027 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1028 If Not _IsStillAlive() Then GoTo Finally
1032 If .isLoaded() Then .reload() Else .load()
1038 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1042 End Function
' SFDocuments.SF_Form.Requery
1044 REM -----------------------------------------------------------------------------
1045 Public Function SetProperty(Optional ByVal PropertyName As Variant _
1046 , Optional ByRef Value As Variant _
1048 ''' Set a new value to the given property
1049 ''' Args:
1050 ''' PropertyName: the name of the property as a string
1051 ''' Value: its new value
1052 ''' Exceptions
1053 ''' ARGUMENTERROR The property does not exist
1055 Const cstThisSub =
"SFDocuments.Form.SetProperty
"
1056 Const cstSubArgs =
"PropertyName, Value
"
1058 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1062 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1063 If Not SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
1067 SetProperty = _PropertySet(PropertyName, Value)
1070 SF_Utils._ExitFunction(cstThisSub)
1074 End Function
' SFDocuments.SF_Form.SetProperty
1076 REM -----------------------------------------------------------------------------
1077 Public Function Subforms(Optional ByVal Subform As Variant) As Variant
1078 ''' Return either
1079 ''' - the list of the subforms contained in the actual form or subform instance
1080 ''' - a SFDocuments.Form object based on its name or its index in the alphabetic list of subforms
1081 ''' Args:
1082 ''' Subform: a subform stored in the parent form given by its name or its index
1083 ''' When absent, the list of available subforms is returned
1084 ''' To get the first (unique ?) subform stored in the parent form, set Subform =
0
1085 ''' Exceptions:
1086 ''' SUBFORMNOTFOUNDERROR Subform not found
1087 ''' Returns:
1088 ''' A zero-based array of strings if Subform is absent
1089 ''' An instance of the SF_Form class if Subform exists
1090 ''' Example:
1091 ''' Dim myForm As Object, myList As Variant, mySubform As Object
1092 ''' myList = myForm.Subforms()
1093 ''' Set mySubform = myForm.Subforms(
"mySubform
")
1095 Dim oSubform As Object
' The new Form class instance
1096 Dim oXSubform As Object
' com.sun.star.form.XForm
1097 Dim vSubformNames As Variant
' Array of subform names
1099 Const cstDrawPage =
0 ' Only
1 drawpage in a Writer document
1101 Const cstThisSub =
"SFDocuments.Form.Subforms
"
1102 Const cstSubArgs =
"[Subform=
""""]
"
1104 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1107 If IsMissing(Subform) Or IsEmpty(Subform) Then Subform =
""
1108 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1109 If Not _IsStillAlive() Then GoTo Finally
1110 If Not ScriptForge.SF_Utils._Validate(Subform,
"Subform
", Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
1114 ' Collect all control names and retain only the subforms
1115 vSubformNames = _Form.getElementNames()
1116 For i =
0 To UBound(vSubformNames)
1117 Set oSubform = _Form.getByName(vSubformNames(i))
1118 ' Subforms are the only control types having no ClassId property
1119 If ScriptForge.SF_Session.HasUnoProperty(oSubform,
"ClassId
") Then vSubformNames(i) =
""
1121 vSubformNames = ScriptForge.SF_Array.TrimArray(vSubformNames)
1123 If Len(Subform) =
0 Then
' Return the list of valid subform names
1124 Subforms = vSubformNames
1126 If VarType(Subform) = V_STRING Then
' Find the form by name
1127 If Not ScriptForge.SF_Array.Contains(vSubformNames, Subform, CaseSensitive := True) Then GoTo CatchNotFound
1128 Set oXSubform = _Form.getByName(Subform)
1129 Else
' Find the form by index
1130 If Subform
< 0 Or Subform
> UBound(vSubformNames) Then GoTo CatchNotFound
1131 Set oXSubform = _Form.getByName(vSubformNames(Subform))
1133 ' Create the new Form class instance
1134 Set oSubform = SF_Register._NewForm(oXSubform)
1136 Set .[_Parent] = [Me]
1137 ._FormType = ISSUBFORM
1138 Set ._Component = _Component
1139 Set ._BaseComponent = _BaseComponent
1140 Set ._FormDocument = _FormDocument
1141 ._SheetName = _SheetName
1142 ._FormDocumentName = _FormDocumentName
1143 Set ._Database = _Database
1146 Set Subforms = oSubform
1150 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1155 ScriptForge.SF_Exception.RaiseFatal(SUBFORMNOTFOUNDERROR, Subform, _Name)
1157 End Function
' SFDocuments.SF_Form.Subforms
1159 REM =========================================================== PRIVATE FUNCTIONS
1161 REM -----------------------------------------------------------------------------
1162 Public Function _GetEventName(ByVal psProperty As String) As String
1163 ''' Return the LO internal event name derived from the SF property name
1164 ''' The SF property name is not case sensitive, while the LO name is case-sensitive
1165 ' Corrects the typo on ErrorOccur(r?)ed, if necessary
1167 Dim vProperties As Variant
' Array of class properties
1168 Dim sProperty As String
' Correctly cased property name
1170 vProperties = Properties()
1171 sProperty = vProperties(ScriptForge.SF_Array.IndexOf(vProperties, psProperty, SortOrder :=
"ASC
"))
1173 _GetEventName = LCase(Mid(sProperty,
3,
1))
& Right(sProperty, Len(sProperty) -
3)
1175 End Function
' SFDocuments.SF_Form._GetEventName
1177 REM -----------------------------------------------------------------------------
1178 Private Function _GetListener(ByVal psEventName As String) As String
1179 ''' Getting/Setting macros triggered by events requires a Listener-EventName pair
1180 ''' Return the X...Listener corresponding with the event name in argument
1182 Select Case UCase(psEventName)
1183 Case UCase(
"OnApproveCursorMove
")
1184 _GetListener =
"XRowSetApproveListener
"
1185 Case UCase(
"OnApproveParameter
")
1186 _GetListener =
"XDatabaseParameterListener
"
1187 Case UCase(
"OnApproveReset
"), UCase(
"OnResetted
")
1188 _GetListener =
"XResetListener
"
1189 Case UCase(
"OnApproveRowChange
")
1190 _GetListener =
"XRowSetApproveListener
"
1191 Case UCase(
"OnApproveSubmit
")
1192 _GetListener =
"XSubmitListener
"
1193 Case UCase(
"OnConfirmDelete
")
1194 _GetListener =
"XConfirmDeleteListener
"
1195 Case UCase(
"OnCursorMoved
"), UCase(
"OnRowChanged
")
1196 _GetListener =
"XRowSetListener
"
1197 Case UCase(
"OnErrorOccurred
")
1198 _GetListener =
"XSQLErrorListener
"
1199 Case UCase(
"OnLoaded
"), UCase(
"OnReloaded
"), UCase(
"OnReloading
"), UCase(
"OnUnloaded
"), UCase(
"OnUnloading
")
1200 _GetListener =
"XLoadListener
"
1203 End Function
' SFDocuments.SF_Form._GetListener
1205 REM -----------------------------------------------------------------------------
1206 Private Sub _GetParents()
1207 ''' When the current instance is created top-down, the parents are completely defined
1208 ''' and nothing should be done in this method
1209 ''' When the a class instance is created in a (form/control) event, it is the opposite
1210 ''' The current method rebuilds the missing members in the instance from the bottom
1211 ''' Members potentially to collect are:
1212 ''' - _FormType
1213 ''' - [_Parent], the immediate parent: a form or a document instance
1214 ''' + Only when the _FormType is a main form
1215 ''' - _SheetName (Calc only)
1216 ''' - _FormDocumentName (Base only)
1217 ''' - _FormDocument, the topmost form collection
1218 ''' - _Component, the containing document
1219 ''' They must be identified only starting from the _Form UNO object
1221 ''' The method is called from the _Initialize() method at instance creation
1223 Dim oParent As Object
' Successive bottom-up parents
1224 Dim sType As String
' UNO object type
1225 Dim iLevel As Integer
' When =
1 =
> first parent
1226 Dim oBase As Object
' Empty Base instance
1227 Dim oSession As Object : Set oSession = ScriptForge.SF_Session
1229 On Local Error GoTo Finally
' Being probably called from events, this method should avoid failures
1230 ' When the form type is known, the upper part of the branch is not scanned
1231 If _FormType
<> ISUNDEFINED Then GoTo Finally
1234 ' The whole branch is scanned bottom-up
1235 If oSession.HasUnoProperty(_Form,
"Parent
") Then Set oParent = _Form.Parent Else Set oParent = Nothing
1236 _FormType = ISUNDEFINED
1239 Do While Not IsNull(oParent)
1240 sType = SF_Session.UnoObjectType(oParent)
1242 ' Collect at each level the needed info
1243 Case
"com.sun.star.comp.forms.ODatabaseForm
" ' The parent _Form of a subform
1245 _FormType = ISSUBFORM
1246 Set [_Parent] = SF_Register._NewForm(oParent)
1247 ' Everything is in the parent, copy items and stop scan
1248 [_Parent]._Initialize()
' Current method is called recursively here
1250 _SheetName = ._SheetName
1251 _FormDocumentName = ._FormDocumentName
1252 Set _FormDocument = ._FormDocument
1253 Set _Component = ._Component
1257 Case
"com.sun.star.form.OFormsCollection
" ' The collection of forms inside a drawpage
1258 Case
"SwXTextDocument
" ' The parent document: a Writer document or a Base form document
1259 If oParent.Identifier =
"com.sun.star.sdb.FormDesign
" Then
1260 _FormType = ISBASEFORM
1261 ' Make a new SF_FormDocument instance
1262 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(
"SFDocuments.FormDocument
", oParent)
1263 Set _FormDocument = [_Parent]._FormDocument
1264 ElseIf oParent.Identifier =
"com.sun.star.text.TextDocument
" Then
1265 _FormType = ISDOCFORM
1266 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(
"SFDocuments.Document
", oParent)
1268 Set _Component = oParent
1269 Case
"ScModelObj
" ' The parent document: a Calc document
1270 _FormType = ISCALCFORM
1271 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(
"SFDocuments.Document
", oParent)
1272 Set _Component = oParent
1273 ' The triggered form event is presumed to be located in the (drawpage of the) active sheet
1274 _SheetName = [_Parent].XSpreadsheet(
"~
")
1275 Case
"com.sun.star.comp.dba.ODatabaseDocument
" ' The Base document
1278 If oSession.HasUnoProperty(oParent,
"Parent
") Then Set oParent = oParent.Parent Else Set oParent = Nothing
1284 End Sub
' SFDocuments.SF_Form._GetParents
1286 REM -----------------------------------------------------------------------------
1287 Public Sub _Initialize()
1288 ''' Achieve the creation of a SF_Form instance
1289 ''' - complete the missing private members
1290 ''' - store the new instance in the cache
1293 _CacheIndex = SF_Register._AddFormToCache(_Form, [Me])
1295 End Sub
' SFDocuments.SF_Form._Initialize
1297 REM -----------------------------------------------------------------------------
1298 Private Function _IsStillAlive(Optional ByVal pbError As Boolean) As Boolean
1299 ''' Return True if the Form is still open
1300 ''' If dead the actual instance is disposed
1301 ''' and the execution is cancelled when pbError = True (default)
1302 ''' Args:
1303 ''' pbError: if True (default), raise a fatal error
1305 Dim bAlive As Boolean
' Return value
1306 Dim sName As String
' Alias of _Name
1307 Dim sId As String
' Alias of FileIdent
1310 On Local Error GoTo Catch
' Anticipate DisposedException errors or alike
1311 If IsMissing(pbError) Then pbError = True
1314 ' At main form termination, all database connections are lost
1315 bAlive = Not IsNull(_Form)
1316 If Not bAlive Then GoTo Catch
1319 _IsStillAlive = bAlive
1324 ' Keep error message elements before disposing the instance
1325 sName = _SheetName
& _FormDocumentName
' At least one of them is a zero-length string
1326 sName = Iif(Len(sName)
> 0,
"[
" & sName
& "].
",
"")
& _Name
1327 If Not IsNull(_Component) Then sId = _Component.Location Else sId =
""
1328 ' Dispose the actual forms instance
1330 ' Display error message
1331 If pbError Then ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, sName, sId)
1333 End Function
' SFDocuments.SF_Form._IsStillAlive
1335 REM -----------------------------------------------------------------------------
1336 Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
1337 ''' Return the value of the named property
1338 ''' Args:
1339 ''' psProperty: the name of the property
1341 Static oSession As Object
' Alias of SF_Session
1342 Dim vBookmark As Variant
' Form bookmark
1343 Dim cstThisSub As String
1344 Const cstSubArgs =
""
1346 cstThisSub =
"SFDocuments.Form.get
" & psProperty
1347 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1349 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1350 _PropertyGet = Empty
1351 If Not _IsStillAlive() Then GoTo Finally
1353 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"Session
")
1354 Select Case UCase(psProperty)
1355 Case UCase(
"AllowDeletes
")
1356 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowDeletes
1357 Case UCase(
"AllowInserts
")
1358 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowInserts
1359 Case UCase(
"AllowUpdates
")
1360 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowUpdates
1361 Case UCase(
"BaseForm
")
1362 _PropertyGet = _FormDocumentName
1363 Case UCase(
"Bookmark
")
1364 If IsNull(_Form) Then
1367 On Local Error Resume Next
' Disable error handler because bookmarking does not always react well in events ...
1368 If _Form.IsBookmarkable Then vBookmark = _Form.getBookmark() Else vBookmark = Nothing
1369 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error Goto Catch Else On Local Error Goto
0
1370 If IsNull(vBookmark) Then Goto Catch
1371 _PropertyGet = vBookmark
1373 Case UCase(
"CurrentRecord
")
1374 If IsNull(_Form) Then _PropertyGet =
0 Else _PropertyGet = _Form.Row
1375 Case UCase(
"Filter
")
1376 If IsNull(_Form) Then _PropertyGet =
"" Else _PropertyGet = _Form.Filter
1377 Case UCase(
"LinkChildFields
")
1378 If IsNull(_Form) Or _FormType
<> ISSUBFORM Then _PropertyGet = Array() Else _PropertyGet = _Form.DetailFields
1379 Case UCase(
"LinkParentFields
")
1380 If IsNull(_Form) Or _FormType
<> ISSUBFORM Then _PropertyGet = Array() Else _PropertyGet = _Form.MasterFields
1381 Case UCase(
"Name
")
1382 _PropertyGet = _Name
1383 Case UCase(
"OnApproveCursorMove
"), UCase(
"OnApproveParameter
"), UCase(
"OnApproveReset
"), UCase(
"OnApproveRowChange
") _
1384 , UCase(
"OnApproveSubmit
"), UCase(
"OnConfirmDelete
"), UCase(
"OnCursorMoved
"), UCase(
"OnErrorOccurred
") _
1385 , UCase(
"OnLoaded
"), UCase(
"OnReloaded
"), UCase(
"OnReloading
"), UCase(
"OnResetted
"), UCase(
"OnRowChanged
") _
1386 , UCase(
"OnUnloaded
"), UCase(
"OnUnloading
")
1387 If IsNull(_Form) Then _PropertyGet =
"" Else _PropertyGet = SF_Register._GetEventScriptCode(_Form, psProperty, _Name)
1388 Case UCase(
"OrderBy
")
1389 If IsNull(_Form) Then _PropertyGet =
"" Else _PropertyGet = _Form.Order
1390 Case UCase(
"Parent
")
1391 _PropertyGet = [_Parent]
1392 Case UCase(
"RecordSource
")
1393 If IsNull(_Form) Then _PropertyGet =
"" Else _PropertyGet = _Form.Command
1394 Case UCase(
"XForm
")
1395 Set _PropertyGet = _Form
1401 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1405 End Function
' SFDocuments.SF_Form._PropertyGet
1407 REM -----------------------------------------------------------------------------
1408 Private Function _PropertySet(Optional ByVal psProperty As String _
1409 , Optional ByVal pvValue As Variant _
1411 ''' Set the new value of the named property
1412 ''' Args:
1413 ''' psProperty: the name of the property
1414 ''' pvValue: the new value of the given property
1415 ''' Returns:
1416 ''' True if successful
1418 Dim bSet As Boolean
' Return value
1419 Dim oDatabase As Object
' Database class instance
1420 Dim lCommandType As Long
' Record source type:
0 = Table,
1 = Query,
2 = SELECT
1421 Dim sCommand As String
' Record source
1422 Static oSession As Object
' Alias of SF_Session
1423 Dim cstThisSub As String
1424 Const cstSubArgs =
"Value
"
1426 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1429 cstThisSub =
"SFDocuments.Form.set
" & psProperty
1430 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1431 If Not _IsStillAlive() Then GoTo Finally
1433 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"Session
")
1435 Select Case UCase(psProperty)
1436 Case UCase(
"AllowDeletes
")
1437 If Not ScriptForge.SF_Utils._Validate(pvValue,
"AllowDeletes
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1438 If Not IsNull(_Form) Then
1439 _Form.AllowDeletes = pvValue
1442 Case UCase(
"AllowInserts
")
1443 If Not ScriptForge.SF_Utils._Validate(pvValue,
"AllowInserts
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1444 If Not IsNull(_Form) Then
1445 _Form.AllowInserts = pvValue
1448 Case UCase(
"AllowUpdates
")
1449 If Not ScriptForge.SF_Utils._Validate(pvValue,
"AllowUpdates
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1450 If Not IsNull(_Form) Then
1451 _Form.AllowUpdates = pvValue
1454 Case UCase(
"Bookmark
")
1455 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Bookmark
", Array(ScriptForge.V_NUMERIC, ScriptForge.V_OBJECT)) Then GoTo Finally
1456 If Not IsNull(pvValue) And Not IsNull(_Form) Then bSet = _Form.moveToBookmark(pvValue)
1457 Case UCase(
"CurrentRecord
")
1458 If Not ScriptForge.SF_Utils._Validate(pvValue,
"CurrentRecord
", ScriptForge.V_NUMERIC) Then GoTo Finally
1459 If Not IsNull(_Form) Then bSet = _Form.absolute(pvValue)
1460 Case UCase(
"Filter
")
1461 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Filter
", V_STRING) Then GoTo Finally
1462 If Not IsNull(_Form) Then
1464 If Len(pvValue)
> 0 Then
1465 Set oDatabase = GetDatabase()
1466 If Not IsNull(oDatabase) Then .Filter = oDatabase._ReplaceSquareBrackets(pvValue) Else .Filter = pvValue
1468 .Filter =
""
1474 Case UCase(
"OnApproveCursorMove
"), UCase(
"OnApproveParameter
"), UCase(
"OnApproveReset
"), UCase(
"OnApproveRowChange
") _
1475 , UCase(
"OnApproveSubmit
"), UCase(
"OnConfirmDelete
"), UCase(
"OnCursorMoved
"), UCase(
"OnErrorOccurred
") _
1476 , UCase(
"OnLoaded
"), UCase(
"OnReloaded
"), UCase(
"OnReloading
"), UCase(
"OnResetted
"), UCase(
"OnRowChanged
") _
1477 , UCase(
"OnUnloaded
"), UCase(
"OnUnloading
")
1478 If Not ScriptForge.SF_Utils._Validate(pvValue, psProperty, V_STRING) Then Goto Finally
1479 If Not IsNull(_Form) Then
1480 bSet = SF_Register._RegisterEventScript(_Form _
1482 , _GetListener(psProperty) _
1487 Case UCase(
"OrderBy
")
1488 If Not ScriptForge.SF_Utils._Validate(pvValue,
"OrderBy
", V_STRING) Then GoTo Finally
1489 If Not IsNull(_Form) Then
1491 If Len(pvValue)
> 0 Then
1492 Set oDatabase = GetDatabase()
1493 If Not IsNull(oDatabase) Then .Order = oDatabase._ReplaceSquareBrackets(pvValue) Else .Order = pvValue
1495 .Order =
""
1500 Case UCase(
"RecordSource
")
1501 If Not ScriptForge.SF_Utils._Validate(pvValue,
"RecordSource
", V_STRING) Then GoTo Finally
1502 If Not IsNull(_Form) And Len(pvValue)
> 0 Then
1503 Set oDatabase = GetDatabase()
1504 If Not IsNull(oDatabase) Then
1506 If ScriptForge.SF_Array.Contains(.Tables, pvValue, CaseSensitive := True) Then
1508 lCommandType = com.sun.star.sdb.CommandType.TABLE
1509 ElseIf ScriptForge.SF_Array.Contains(.Queries, pvValue, CaseSensitive := True) Then
1511 lCommandType = com.sun.star.sdb.CommandType.QUERY
1512 ElseIf ScriptForge.SF_String.StartsWith(pvValue,
"SELECT
", CaseSensitive := False) Then
1513 sCommand = .ReplaceSquareBrackets(pvValue)
1514 lCommandType = com.sun.star.sdb.CommandType.COMMAND
1516 _Form.Command = sCommand
1517 _Form.CommandType = lCommandType
1527 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1531 End Function
' SFDocuments.SF_Form._PropertySet
1533 REM -----------------------------------------------------------------------------
1534 Private Function _Repr() As String
1535 ''' Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
1536 ''' Args:
1537 ''' Return:
1538 ''' "[Form]: Name
"
1540 Dim sParent As String
' To recognize the parent
1542 sParent = _SheetName
& _FormDocumentName
' At least one of them is a zero-length string
1543 _Repr =
"[Form]:
" & Iif(Len(sParent)
> 0, sParent
& "...
",
"")
& _Name
1545 End Function
' SFDocuments.SF_Form._Repr
1547 REM ============================================ END OF SFDOCUMENTS.SF_FORM