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:
27 ''' For usual documents, there is only
1 form document. It is in fact the document itself.
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 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 FormDocument and its FormName or FormIndex
44 ''' Service invocations:
46 ''' REM the form is stored in a not-Base document (Calc, Writer)
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 one of the FormDocuments of a Base document
54 ''' Dim oDoc As Object, myForm As Object, mySubForm As Object
55 ''' Set oDoc = CreateScriptService(
"SFDocuments.Document
", ThisDatabaseDocument)
56 ''' oDoc.OpenFormDocument(
"thisFormDocument
")
57 ''' Set myForm = oDoc.Forms(
"thisFormDocument
",
"MainForm
")
58 ''' ' or, alternatively, when there is only
1 form
59 ''' Set myForm = oDoc.Forms(
"thisFormDocument
",
0)
60 ''' ' To access a subform: myForm and mySubForm become distinct instances of the current class
61 ''' Set mySubForm = myForm.SubForms(
"mySubForm
")
63 ''' REM the form is the subject of an event
64 ''' Sub OnEvent(ByRef poEvent As Object)
65 ''' Dim myForm As Object
66 ''' Set myForm = CreateScriptService(
"SFDocuments.FormEvent
", poEvent)
68 ''' Detailed user documentation:
69 ''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/
03/sf_form.html?DbPAR=BASIC
71 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
73 REM ================================================================== EXCEPTIONS
75 Private Const FORMDEADERROR =
"FORMDEADERROR
"
76 Private Const SUBFORMNOTFOUNDERROR =
"SUBFORMNOTFOUNDERROR
"
78 REM ============================================================= PRIVATE MEMBERS
80 Private [Me] As Object
81 Private [_Parent] As Object
82 Private ObjectType As String
' Must be Form
83 Private ServiceName As String
86 Private _Name As String
' Internal name of the form
87 Private _FormType As Integer
' One of the ISxxxFORM constants
88 Private _SheetName As String
' Name as the sheet containing the form (Calc only)
89 Private _FormDocumentName As String
' The hierarchical name of the containing form document (Base only)
90 Private _FormDocument As Object
' com.sun.star.comp.sdb.Content - the containing form document
91 ' The form topmost container
92 Private _Component As Object
' com.sun.star.lang.XComponent or com.sun.star.comp.dba.ODatabaseDocument
94 ' Events management
95 Private _CacheIndex As Long
' Index in central cache storage
97 ' Form UNO references
98 ' The entry to the interactions with the form. Validity checked by the _IsStillAlive() method
99 ' Each method or property requiring that the form is opened should first invoke that method
100 Private _Form As Object
' com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm
101 Private _Database As Object
' Database class instance
103 ' Form attributes
105 ' Cache storage for controls
106 Private _ControlNames As Variant
' Array of control names
107 Private _ControlCache As Variant
' Array of control objects sorted like ElementNames of XForm
109 REM ============================================================ MODULE CONSTANTS
111 Const ISDOCFORM =
1 ' Form is stored in a Writer document
112 Const ISCALCFORM =
2 ' Form is stored in a Calc document
113 Const ISBASEFORM =
3 ' Form is stored in a Base document
114 Const ISSUBFORM =
4 ' Form is a subform of a form or of another subform
115 Const ISUNDEFINED = -
1 ' Undefined form type
117 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
119 REM -----------------------------------------------------------------------------
120 Private Sub Class_Initialize()
122 Set [_Parent] = Nothing
123 ObjectType =
"FORM
"
124 ServiceName =
"SFDocuments.Form
"
126 _SheetName =
""
127 _FormDocumentName =
""
128 Set _FormDocument = Nothing
129 _FormType = ISUNDEFINED
132 Set _Database = Nothing
133 _ControlNames = Array()
134 _ControlCache = Array()
135 End Sub
' SFDocuments.SF_Form Constructor
137 REM -----------------------------------------------------------------------------
138 Private Sub Class_Terminate()
139 Call Class_Initialize()
140 End Sub
' SFDocuments.SF_Form Destructor
142 REM -----------------------------------------------------------------------------
143 Public Function Dispose() As Variant
144 If Not IsNull(_Database) And (_FormType = ISDOCFORM Or _FormType = ISCALCFORM) Then
145 Set _Database = _Database.Dispose()
147 SF_Register._CleanCacheEntry(_CacheIndex)
148 Call Class_Terminate()
149 Set Dispose = Nothing
150 End Function
' SFDocuments.SF_Form Explicit Destructor
152 REM ================================================================== PROPERTIES
154 REM -----------------------------------------------------------------------------
155 Property Get AllowDeletes() As Variant
156 ''' The AllowDeletes property specifies if the form allows to delete records
157 AllowDeletes = _PropertyGet(
"AllowDeletes
")
158 End Property
' SFDocuments.SF_Form.AllowDeletes (get)
160 REM -----------------------------------------------------------------------------
161 Property Let AllowDeletes(Optional ByVal pvAllowDeletes As Variant)
162 ''' Set the updatable property AllowDeletes
163 _PropertySet(
"AllowDeletes
", pvAllowDeletes)
164 End Property
' SFDocuments.SF_Form.AllowDeletes (let)
166 REM -----------------------------------------------------------------------------
167 Property Get AllowInserts() As Variant
168 ''' The AllowInserts property specifies if the form allows to add records
169 AllowInserts = _PropertyGet(
"AllowInserts
")
170 End Property
' SFDocuments.SF_Form.AllowInserts (get)
172 REM -----------------------------------------------------------------------------
173 Property Let AllowInserts(Optional ByVal pvAllowInserts As Variant)
174 ''' Set the updatable property AllowInserts
175 _PropertySet(
"AllowInserts
", pvAllowInserts)
176 End Property
' SFDocuments.SF_Form.AllowInserts (let)
178 REM -----------------------------------------------------------------------------
179 Property Get AllowUpdates() As Variant
180 ''' The AllowUpdates property specifies if the form allows to update records
181 AllowUpdates = _PropertyGet(
"AllowUpdates
")
182 End Property
' SFDocuments.SF_Form.AllowUpdates (get)
184 REM -----------------------------------------------------------------------------
185 Property Let AllowUpdates(Optional ByVal pvAllowUpdates As Variant)
186 ''' Set the updatable property AllowUpdates
187 _PropertySet(
"AllowUpdates
", pvAllowUpdates)
188 End Property
' SFDocuments.SF_Form.AllowUpdates (let)
190 REM -----------------------------------------------------------------------------
191 Property Get BaseForm() As String
192 ''' The BaseForm property specifies the hierarchical name of the Base form containing the actual form
193 BaseForm = _PropertyGet(
"BaseForm
")
194 End Property
' SFDocuments.SF_Form.BaseForm (get)
196 REM -----------------------------------------------------------------------------
197 Property Get Bookmark() As Variant
198 ''' The Bookmark property specifies uniquely the current record of the form
's underlying table, query or SQL statement.
199 Bookmark = _PropertyGet(
"Bookmark
")
200 End Property
' SFDocuments.SF_Form.Bookmark (get)
202 REM -----------------------------------------------------------------------------
203 Property Let Bookmark(Optional ByVal pvBookmark As Variant)
204 ''' Set the updatable property Bookmark
205 _PropertySet(
"Bookmark
", pvBookmark)
206 End Property
' SFDocuments.SF_Form.Bookmark (let)
208 REM -----------------------------------------------------------------------------
209 Property Get CurrentRecord() As Variant
210 ''' The CurrentRecord property identifies the current record in the recordset being viewed on a form
211 CurrentRecord = _PropertyGet(
"CurrentRecord
")
212 End Property
' SFDocuments.SF_Form.CurrentRecord (get)
214 REM -----------------------------------------------------------------------------
215 Property Let CurrentRecord(Optional ByVal pvCurrentRecord As Variant)
216 ''' Set the updatable property CurrentRecord
217 ''' If the row number is positive, the cursor moves to the given row number with respect to the beginning of the result set.
218 ''' The first row is row
1, the second is row
2, and so on.
219 ''' If the given row number is negative, the cursor moves to an absolute row position with respect to the end of the result set.
220 ''' For example, setting CurrentRecord = -
1 positions the cursor on the last row, -
2 indicates the next-to-last row, and so on
221 _PropertySet(
"CurrentRecord
", pvCurrentRecord)
222 End Property
' SFDocuments.SF_Form.CurrentRecord (let)
224 REM -----------------------------------------------------------------------------
225 Property Get Filter() As Variant
226 ''' The Filter property specifies a subset of records to be displayed.
227 Filter = _PropertyGet(
"Filter
")
228 End Property
' SFDocuments.SF_Form.Filter (get)
230 REM -----------------------------------------------------------------------------
231 Property Let Filter(Optional ByVal pvFilter As Variant)
232 ''' Set the updatable property Filter
233 _PropertySet(
"Filter
", pvFilter)
234 End Property
' SFDocuments.SF_Form.Filter (let)
236 REM -----------------------------------------------------------------------------
237 Property Get LinkChildFields() As Variant
238 ''' The LinkChildFields property specifies how records in a subform (child) are linked to records in its parent form
239 ''' It returns an array of strings
240 LinkChildFields = _PropertyGet(
"LinkChildFields
")
241 End Property
' SFDocuments.SF_Form.LinkChildFields (get)
243 REM -----------------------------------------------------------------------------
244 Property Get LinkParentFields() As Variant
245 ''' The LinkParentFields property specifies how records in a subform (Child) are linked to records in its parent form
246 ''' It returns an array of strings
247 LinkParentFields = _PropertyGet(
"LinkParentFields
")
248 End Property
' SFDocuments.SF_Form.LinkParentFields (get)
250 REM -----------------------------------------------------------------------------
251 Property Get Name() As String
252 ''' Return the name of the actual Form
253 Name = _PropertyGet(
"Name
")
254 End Property
' SFDocuments.SF_Form.Name
256 REM -----------------------------------------------------------------------------
257 Property Get OnApproveCursorMove() As Variant
258 ''' The OnApproveCursorMove property specifies the script to trigger when this event occurs
259 OnApproveCursorMove = _PropertyGet(
"OnApproveCursorMove
")
260 End Property
' SFDocuments.SF_Form.OnApproveCursorMove (get)
262 REM -----------------------------------------------------------------------------
263 Property Let OnApproveCursorMove(Optional ByVal pvOnApproveCursorMove As Variant)
264 ''' Set the updatable property OnApproveCursorMove
265 _PropertySet(
"OnApproveCursorMove
", pvOnApproveCursorMove)
266 End Property
' SFDocuments.SF_Form.OnApproveCursorMove (let)
268 REM -----------------------------------------------------------------------------
269 Property Get OnApproveReset() As Variant
270 ''' The OnApproveReset property specifies the script to trigger when this event occurs
271 OnApproveReset = _PropertyGet(
"OnApproveReset
")
272 End Property
' SFDocuments.SF_Form.OnApproveReset (get)
274 REM -----------------------------------------------------------------------------
275 Property Let OnApproveReset(Optional ByVal pvOnApproveReset As Variant)
276 ''' Set the updatable property OnApproveReset
277 _PropertySet(
"OnApproveReset
", pvOnApproveReset)
278 End Property
' SFDocuments.SF_Form.OnApproveReset (let)
280 REM -----------------------------------------------------------------------------
281 Property Get OnApproveRowChange() As Variant
282 ''' The OnApproveRowChange property specifies the script to trigger when this event occurs
283 OnApproveRowChange = _PropertyGet(
"OnApproveRowChange
")
284 End Property
' SFDocuments.SF_Form.OnApproveRowChange (get)
286 REM -----------------------------------------------------------------------------
287 Property Let OnApproveRowChange(Optional ByVal pvOnApproveRowChange As Variant)
288 ''' Set the updatable property OnApproveRowChange
289 _PropertySet(
"OnApproveRowChange
", pvOnApproveRowChange)
290 End Property
' SFDocuments.SF_Form.OnApproveRowChange (let)
292 REM -----------------------------------------------------------------------------
293 Property Get OnApproveSubmit() As Variant
294 ''' The OnApproveSubmit property specifies the script to trigger when this event occurs
295 OnApproveSubmit = _PropertyGet(
"OnApproveSubmit
")
296 End Property
' SFDocuments.SF_Form.OnApproveSubmit (get)
298 REM -----------------------------------------------------------------------------
299 Property Let OnApproveSubmit(Optional ByVal pvOnApproveSubmit As Variant)
300 ''' Set the updatable property OnApproveSubmit
301 _PropertySet(
"OnApproveSubmit
", pvOnApproveSubmit)
302 End Property
' SFDocuments.SF_Form.OnApproveSubmit (let)
304 REM -----------------------------------------------------------------------------
305 Property Get OnConfirmDelete() As Variant
306 ''' The OnConfirmDelete property specifies the script to trigger when this event occurs
307 OnConfirmDelete = _PropertyGet(
"OnConfirmDelete
")
308 End Property
' SFDocuments.SF_Form.OnConfirmDelete (get)
310 REM -----------------------------------------------------------------------------
311 Property Let OnConfirmDelete(Optional ByVal pvOnConfirmDelete As Variant)
312 ''' Set the updatable property OnConfirmDelete
313 _PropertySet(
"OnConfirmDelete
", pvOnConfirmDelete)
314 End Property
' SFDocuments.SF_Form.OnConfirmDelete (let)
316 REM -----------------------------------------------------------------------------
317 Property Get OnCursorMoved() As Variant
318 ''' The OnCursorMoved property specifies the script to trigger when this event occurs
319 OnCursorMoved = _PropertyGet(
"OnCursorMoved
")
320 End Property
' SFDocuments.SF_Form.OnCursorMoved (get)
322 REM -----------------------------------------------------------------------------
323 Property Let OnCursorMoved(Optional ByVal pvOnCursorMoved As Variant)
324 ''' Set the updatable property OnCursorMoved
325 _PropertySet(
"OnCursorMoved
", pvOnCursorMoved)
326 End Property
' SFDocuments.SF_Form.OnCursorMoved (let)
328 REM -----------------------------------------------------------------------------
329 Property Get OnErrorOccurred() As Variant
330 ''' The OnErrorOccurred property specifies the script to trigger when this event occurs
331 OnErrorOccurred = _PropertyGet(
"OnErrorOccurred
")
332 End Property
' SFDocuments.SF_Form.OnErrorOccurred (get)
334 REM -----------------------------------------------------------------------------
335 Property Let OnErrorOccurred(Optional ByVal pvOnErrorOccurred As Variant)
336 ''' Set the updatable property OnErrorOccurred
337 _PropertySet(
"OnErrorOccurred
", pvOnErrorOccurred)
338 End Property
' SFDocuments.SF_Form.OnErrorOccurred (let)
340 REM -----------------------------------------------------------------------------
341 Property Get OnLoaded() As Variant
342 ''' The OnLoaded property specifies the script to trigger when this event occurs
343 OnLoaded = _PropertyGet(
"OnLoaded
")
344 End Property
' SFDocuments.SF_Form.OnLoaded (get)
346 REM -----------------------------------------------------------------------------
347 Property Let OnLoaded(Optional ByVal pvOnLoaded As Variant)
348 ''' Set the updatable property OnLoaded
349 _PropertySet(
"OnLoaded
", pvOnLoaded)
350 End Property
' SFDocuments.SF_Form.OnLoaded (let)
352 REM -----------------------------------------------------------------------------
353 Property Get OnReloaded() As Variant
354 ''' The OnReloaded property specifies the script to trigger when this event occurs
355 OnReloaded = _PropertyGet(
"OnReloaded
")
356 End Property
' SFDocuments.SF_Form.OnReloaded (get)
358 REM -----------------------------------------------------------------------------
359 Property Let OnReloaded(Optional ByVal pvOnReloaded As Variant)
360 ''' Set the updatable property OnReloaded
361 _PropertySet(
"OnReloaded
", pvOnReloaded)
362 End Property
' SFDocuments.SF_Form.OnReloaded (let)
364 REM -----------------------------------------------------------------------------
365 Property Get OnReloading() As Variant
366 ''' The OnReloading property specifies the script to trigger when this event occurs
367 OnReloading = _PropertyGet(
"OnReloading
")
368 End Property
' SFDocuments.SF_Form.OnReloading (get)
370 REM -----------------------------------------------------------------------------
371 Property Let OnReloading(Optional ByVal pvOnReloading As Variant)
372 ''' Set the updatable property OnReloading
373 _PropertySet(
"OnReloading
", pvOnReloading)
374 End Property
' SFDocuments.SF_Form.OnReloading (let)
376 REM -----------------------------------------------------------------------------
377 Property Get OnResetted() As Variant
378 ''' The OnResetted property specifies the script to trigger when this event occurs
379 OnResetted = _PropertyGet(
"OnResetted
")
380 End Property
' SFDocuments.SF_Form.OnResetted (get)
382 REM -----------------------------------------------------------------------------
383 Property Let OnResetted(Optional ByVal pvOnResetted As Variant)
384 ''' Set the updatable property OnResetted
385 _PropertySet(
"OnResetted
", pvOnResetted)
386 End Property
' SFDocuments.SF_Form.OnResetted (let)
388 REM -----------------------------------------------------------------------------
389 Property Get OnRowChanged() As Variant
390 ''' The OnRowChanged property specifies the script to trigger when this event occurs
391 OnRowChanged = _PropertyGet(
"OnRowChanged
")
392 End Property
' SFDocuments.SF_Form.OnRowChanged (get)
394 REM -----------------------------------------------------------------------------
395 Property Let OnRowChanged(Optional ByVal pvOnRowChanged As Variant)
396 ''' Set the updatable property OnRowChanged
397 _PropertySet(
"OnRowChanged
", pvOnRowChanged)
398 End Property
' SFDocuments.SF_Form.OnRowChanged (let)
400 REM -----------------------------------------------------------------------------
401 Property Get OnUnloaded() As Variant
402 ''' The OnUnloaded property specifies the script to trigger when this event occurs
403 OnUnloaded = _PropertyGet(
"OnUnloaded
")
404 End Property
' SFDocuments.SF_Form.OnUnloaded (get)
406 REM -----------------------------------------------------------------------------
407 Property Let OnUnloaded(Optional ByVal pvOnUnloaded As Variant)
408 ''' Set the updatable property OnUnloaded
409 _PropertySet(
"OnUnloaded
", pvOnUnloaded)
410 End Property
' SFDocuments.SF_Form.OnUnloaded (let)
412 REM -----------------------------------------------------------------------------
413 Property Get OnUnloading() As Variant
414 ''' The OnUnloading property specifies the script to trigger when this event occurs
415 OnUnloading = _PropertyGet(
"OnUnloading
")
416 End Property
' SFDocuments.SF_Form.OnUnloading (get)
418 REM -----------------------------------------------------------------------------
419 Property Let OnUnloading(Optional ByVal pvOnUnloading As Variant)
420 ''' Set the updatable property OnUnloading
421 _PropertySet(
"OnUnloading
", pvOnUnloading)
422 End Property
' SFDocuments.SF_Form.OnUnloading (let)
424 REM -----------------------------------------------------------------------------
425 Property Get OrderBy() As Variant
426 ''' The OrderBy property specifies in which order the records should be displayed.
427 OrderBy = _PropertyGet(
"OrderBy
")
428 End Property
' SFDocuments.SF_Form.OrderBy (get)
430 REM -----------------------------------------------------------------------------
431 Property Let OrderBy(Optional ByVal pvOrderBy As Variant)
432 ''' Set the updatable property OrderBy
433 _PropertySet(
"OrderBy
", pvOrderBy)
434 End Property
' SFDocuments.SF_Form.OrderBy (let)
436 REM -----------------------------------------------------------------------------
437 Property Get Parent() As Object
438 ''' Return the Parent of the actual Form
439 Parent = _PropertyGet(
"Parent
")
440 End Property
' SFDocuments.SF_Form.Parent
442 REM -----------------------------------------------------------------------------
443 Property Get RecordSource() As Variant
444 ''' The RecordSource property specifies the source of the data,
445 ''' a table name, a query name or a SQL statement
446 RecordSource = _PropertyGet(
"RecordSource
")
447 End Property
' SFDocuments.SF_Form.RecordSource (get)
449 REM -----------------------------------------------------------------------------
450 Property Let RecordSource(Optional ByVal pvRecordSource As Variant)
451 ''' Set the updatable property RecordSource
452 _PropertySet(
"RecordSource
", pvRecordSource)
453 End Property
' SFDocuments.SF_Form.RecordSource (let)
455 REM -----------------------------------------------------------------------------
456 Property Get XForm() As Object
457 ''' The XForm property returns the XForm UNO object of the Form
458 XForm = _PropertyGet(
"XForm
")
459 End Property
' SFDocuments.SF_Form.XForm (get)
461 REM ===================================================================== METHODS
463 REM -----------------------------------------------------------------------------
464 Public Function Activate() As Boolean
465 ''' Set the focus on the current Form instance
466 ''' Probably called from after an event occurrence or to focus on an open Base form document
467 ''' If the parent document is ...
468 ''' Calc Activate the corresponding sheet
469 ''' Writer Activate the parent document
470 ''' Base Activate the parent form document
471 ''' Args:
472 ''' Returns:
473 ''' True if focusing is successful
474 ''' Example:
475 ''' myForm.Activate()
477 Dim bActivate As Boolean
' Return value
478 Dim oContainer As Object
' com.sun.star.awt.XWindow
479 Const cstThisSub =
"SFDocuments.Form.Activate
"
480 Const cstSubArgs =
""
482 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
486 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
487 If Not _IsStillAlive() Then GoTo Finally
490 Select Case _FormType
491 Case ISDOCFORM : bActivate = [_Parent].Activate()
492 Case ISCALCFORM : bActivate = [_Parent].Activate(_SheetName)
494 Set oContainer = _FormDocument.Component.CurrentController.Frame.ContainerWindow
496 If .isVisible() = False Then .setVisible(True)
499 .toFront()
' Force window change in Linux
500 Wait
1 ' Bypass desynchro issue in Linux
507 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
511 End Function
' SFDocuments.SF_Form.Activate
513 REM -----------------------------------------------------------------------------
514 Public Function CloseFormDocument() As Boolean
515 ''' Close the form document containing the actual form instance
516 ''' The form instance is disposed
517 ''' The method does nothing if the actual form is not located in a Base form document
518 ''' Args:
519 ''' Returns:
520 ''' True if closure is successful
521 ''' Example:
522 ''' myForm.CloseFormDocument()
524 Dim bClose As Boolean
' Return value
525 Dim oContainer As Object
' com.sun.star.awt.XWindow
526 Const cstThisSub =
"SFDocuments.Form.CloseFormDocument
"
527 Const cstSubArgs =
""
529 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
533 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
534 If Not _IsStillAlive() Then GoTo Finally
537 Select Case _FormType
538 Case ISDOCFORM, ISCALCFORM, ISSUBFORM
540 _FormDocument.close()
546 CloseFormDocument = bClose
547 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
551 End Function
' SFDocuments.SF_Form.CloseFormDocument
553 REM -----------------------------------------------------------------------------
554 Public Function Controls(Optional ByVal ControlName As Variant) As Variant
555 ''' Return either
556 ''' - the list of the controls contained in the Form
557 ''' - a Form control object based on its name
558 ''' Args:
559 ''' ControlName: a valid control name as a case-sensitive string. If absent the list is returned
560 ''' Returns:
561 ''' A zero-base array of strings if ControlName is absent
562 ''' An instance of the SF_FormControl class if ControlName exists
563 ''' Exceptions:
564 ''' ControlName is invalid
565 ''' Example:
566 ''' Dim myForm As Object, myList As Variant, myControl As Object
567 ''' Set myForm = myDoc.Forms(
"myForm
")
568 ''' myList = myForm.Controls()
569 ''' Set myControl = myForm.Controls(
"myTextBox
")
571 Dim oControl As Object
' The new control class instance
572 Dim lIndexOfNames As Long
' Index in ElementNames array. Used to access _ControlCache
573 Dim vControl As Variant
' Alias of _ControlCache entry
575 Const cstThisSub =
"SFDocuments.Form.Controls
"
576 Const cstSubArgs =
"[ControlName]
"
578 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
581 If IsMissing(ControlName) Or IsEmpty(ControlName) Then ControlName =
""
582 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
583 If Not _IsStillAlive() Then GoTo Finally
584 If Not ScriptForge.SF_Utils._Validate(ControlName,
"ControlName
", V_STRING) Then GoTo Finally
588 ' Collect all control names if not yet done
589 If UBound(_ControlNames)
< 0 Then
590 _ControlNames = _Form.getElementNames()
591 ' Remove all subforms from the list
592 For i =
0 To UBound(_ControlNames)
593 ' Subforms have no ClassId property
594 If Not ScriptForge.SF_Session.HasUnoProperty(_Form.getByName(_ControlNames(i)),
"ClassId
") Then _ControlNames(i) =
""
596 _ControlNames = ScriptForge.SF_Array.TrimArray(_ControlNames)
597 ' Size the cache accordingly
598 If UBound(_ControlNames)
>=
0 Then
599 ReDim _ControlCache(
0 To UBound(_ControlNames))
603 ' Return the list of controls or a FormControl instance
604 If Len(ControlName) =
0 Then
605 Controls = _ControlNames
609 If Not _Form.hasByName(ControlName) Then GoTo CatchNotFound
610 lIndexOfNames = ScriptForge.SF_Array.IndexOf(_ControlNames, ControlName, CaseSensitive := True)
611 ' Reuse cache when relevant
612 vControl = _ControlCache(lIndexOfNames)
614 If IsEmpty(vControl) Then
615 ' Create the new form control class instance
616 Set oControl = New SF_FormControl
620 Set .[_Parent] = [Me]
621 Set ._ParentForm = [Me]
622 ._IndexOfNames = lIndexOfNames
624 ' Get model and view of the current control
625 Set ._ControlModel = _Form.getByName(ControlName)
629 Set oControl = vControl
632 Set Controls = oControl
636 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
641 ScriptForge.SF_Utils._Validate(ControlName,
"ControlName
", V_STRING, _Form.getElementNames())
643 End Function
' SFDocuments.SF_Form.Controls
645 REM -----------------------------------------------------------------------------
646 Public Function GetDatabase(Optional ByVal User As Variant _
647 , Optional ByVal Password As Variant _
649 ''' Returns a Database instance (service = SFDatabases.Database) giving access
650 ''' to the execution of SQL commands on the database defined and/or stored in
651 ''' the actual Base document
652 ''' Each main form has its own database connection, except within Base documents where
653 ''' they all share the same connection
654 ''' Args:
655 ''' User, Password: the login parameters as strings. Defaults =
""
656 ''' Returns:
657 ''' A SFDatabases.Database instance or Nothing
658 ''' Example:
659 ''' Dim myDb As Object
660 ''' Set myDb = oForm.GetDatabase()
662 Dim FSO As Object
' Alias for SF_FileSystem
663 Dim sDataSource As String
' Database file name in FileNaming format
664 Dim sUser As String
' Alias for User
665 Dim sPassword As String
' Alias for Password
666 Const cstThisSub =
"SFDocuments.Form.GetDatabase
"
667 Const cstSubArgs =
"[User=
""""], [Password=
""""]
"
669 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
670 Set GetDatabase = Nothing
673 If IsMissing(User) Or IsEmpty(User) Then User =
""
674 If IsMissing(Password) Or IsEmpty(Password) Then Password =
""
675 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
676 If Not [_Parent]._IsStillAlive(True) Then GoTo Finally
677 If Not ScriptForge.SF_Utils._Validate(User,
"User
", V_STRING) Then GoTo Finally
678 If Not ScriptForge.SF_Utils._Validate(Password,
"Password
", V_STRING) Then GoTo Finally
682 ' Adjust connection arguments
683 If Len(User) =
0 Then
684 If ScriptForge.SF_Session.HasUnoProperty(_Form,
"User
") Then sUser = _Form.User Else sUser =
""
688 If Len(sUser) + Len(Password) =
0 Then
689 If ScriptForge.SF_Session.HasUnoProperty(_Form,
"Password
") Then sPassword = _Form.Password Else sPassword = Password
692 ' Connect to database, avoiding multiple requests
693 If IsNull(_Database) Then
' 1st connection request from the current form instance
694 If _FormType = ISBASEFORM Then
695 ' Fetch the shared connection
696 Set _Database = [_Parent].GetDatabase(User, Password)
697 ElseIf _FormType = ISSUBFORM Then
698 Set _Database = [_Parent].GetDatabase()
' Recursive call, climb the tree
699 ElseIf Len(_Form.DataSourceName) =
0 Then
' There is no database linked with the form
700 ' Return Nothing
702 ' Check if DataSourceName is a file or a registered name and create database instance accordingly
703 Set FSO = ScriptForge.SF_FileSystem
704 sDataSource = FSO._ConvertFromUrl(_Form.DataSourceName)
705 If FSO.FileExists(sDataSource) Then
706 Set _Database = ScriptForge.SF_Services.CreateScriptService(
"SFDatabases.Database
" _
707 , sDataSource, , , sUser, sPassword)
709 Set _Database = ScriptForge.SF_Services.CreateScriptService(
"SFDatabases.Database
" _
710 , , _Form.DataSourceName, , sUser, sPassword)
712 If IsNull(_Database) Then GoTo CatchConnect
718 Set GetDatabase = _Database
719 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
724 ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR,
"User
", User,
"Password
", Password, [_Super]._FileIdent())
726 End Function
' SFDocuments.SF_Form.GetDatabase
728 REM -----------------------------------------------------------------------------
729 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
730 ''' Return the actual value of the given property
731 ''' Args:
732 ''' PropertyName: the name of the property as a string
733 ''' Returns:
734 ''' The actual value of the property
735 ''' Exceptions:
736 ''' ARGUMENTERROR The property does not exist
737 ''' Examples:
738 ''' oDlg.GetProperty(
"Caption
")
740 Const cstThisSub =
"SFDocuments.Form.GetProperty
"
741 Const cstSubArgs =
""
743 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
747 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
748 If Not ScriptForge.SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
752 GetProperty = _PropertyGet(PropertyName)
755 SF_Utils._ExitFunction(cstThisSub)
759 End Function
' SFDocuments.SF_Form.GetProperty
761 REM -----------------------------------------------------------------------------
762 Public Function Methods() As Variant
763 ''' Return the list of public methods of the Form service as an array
766 "Activate
" _
767 ,
"CloseForm
" _
768 ,
"Controls
" _
769 ,
"GetDatabase
" _
770 ,
"MoveFirst
" _
771 ,
"MoveLast
" _
772 ,
"MoveNew
" _
773 ,
"MoveNext
" _
774 ,
"MovePrevious
" _
775 ,
"Requery
" _
776 ,
"SubForms
" _
779 End Function
' SFDocuments.SF_Form.Methods
781 REM -----------------------------------------------------------------------------
782 Public Function MoveFirst() As Boolean
783 ''' The cursor is (re)positioned on the first row
784 ''' Args:
785 ''' Returns:
786 ''' True if cursor move is successful
787 ''' Example:
788 ''' myForm.MoveFirst()
790 Dim bMoveFirst As Boolean
' Return value
791 Const cstThisSub =
"SFDocuments.Form.MoveFirst
"
792 Const cstSubArgs =
""
794 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
798 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
799 If Not _IsStillAlive() Then GoTo Finally
803 bMoveFirst = .first()
807 MoveFirst = bMoveFirst
808 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
812 End Function
' SFDocuments.SF_Form.MoveFirst
814 REM -----------------------------------------------------------------------------
815 Public Function MoveLast() As Boolean
816 ''' The cursor is (re)positioned on the last row
817 ''' Args:
818 ''' Returns:
819 ''' True if cursor move is successful
820 ''' Example:
821 ''' myForm.MoveLast()
823 Dim bMoveLast As Boolean
' Return value
824 Const cstThisSub =
"SFDocuments.Form.MoveLast
"
825 Const cstSubArgs =
""
827 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
831 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
832 If Not _IsStillAlive() Then GoTo Finally
841 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
845 End Function
' SFDocuments.SF_Form.MoveLast
847 REM -----------------------------------------------------------------------------
848 Public Function MoveNew() As Boolean
849 ''' The cursor is (re)positioned in the new record area
850 ''' Args:
851 ''' Returns:
852 ''' True if cursor move is successful
853 ''' Example:
854 ''' myForm.MoveNew()
856 Dim bMoveNew As Boolean
' Return value
857 Const cstThisSub =
"SFDocuments.Form.MoveNew
"
858 Const cstSubArgs =
""
860 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
864 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
865 If Not _IsStillAlive() Then GoTo Finally
869 .last()
' To simulate the behaviour in the UI
876 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
880 End Function
' SFDocuments.SF_Form.MoveNew
882 REM -----------------------------------------------------------------------------
883 Public Function MoveNext(Optional ByVal Offset As Variant) As Boolean
884 ''' The cursor is (re)positioned on the next row
885 ''' Args:
886 ''' Offset: The number of records to go forward (default =
1)
887 ''' Returns:
888 ''' True if cursor move is successful
889 ''' Example:
890 ''' myForm.MoveNext()
892 Dim bMoveNext As Boolean
' Return value
893 Dim lOffset As Long
' Alias of Offset
894 Const cstThisSub =
"SFDocuments.Form.MoveNext
"
895 Const cstSubArgs =
""
897 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
901 If IsMissing(Offset) Or IsEmpty(Offset) Then Offset =
1
902 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
903 If Not _IsStillAlive() Then GoTo Finally
904 If Not ScriptForge.SF_Utils._Validate(Offset,
"Offset
", ScriptForge.V_NUMERIC) Then GoTo Finally
907 lOffset = CLng(Offset)
' To be sure to have the right argument type
909 If lOffset =
1 Then bMoveNext = .next() Else bMoveNext = .relative(lOffset)
914 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
918 End Function
' SFDocuments.SF_Form.MoveNext
920 REM -----------------------------------------------------------------------------
921 Public Function MovePrevious(Optional ByVal Offset As Variant) As Boolean
922 ''' The cursor is (re)positioned on the previous row
923 ''' Args:
924 ''' Offset: The number of records to go backward (default =
1)
925 ''' Returns:
926 ''' True if cursor move is successful
927 ''' Example:
928 ''' myForm.MovePrevious()
930 Dim bMovePrevious As Boolean
' Return value
931 Dim lOffset As Long
' Alias of Offset
932 Const cstThisSub =
"SFDocuments.Form.MovePrevious
"
933 Const cstSubArgs =
""
935 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
936 bMovePrevious = False
939 If IsMissing(Offset) Or IsEmpty(Offset) Then Offset =
1
940 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
941 If Not _IsStillAlive() Then GoTo Finally
942 If Not ScriptForge.SF_Utils._Validate(Offset,
"Offset
", ScriptForge.V_NUMERIC) Then GoTo Finally
945 lOffset = CLng(Offset)
' To be sure to have the right argument type
947 If lOffset =
1 Then bMovePrevious = .previous() Else bMovePrevious = .relative(-lOffset)
951 MovePrevious = bMovePrevious
952 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
956 End Function
' SFDocuments.SF_Form.MovePrevious
958 REM -----------------------------------------------------------------------------
959 Public Function Properties() As Variant
960 ''' Return the list or properties of the Form class as an array
962 Properties = Array( _
963 "AllowDeletes
" _
964 ,
"AllowInserts
" _
965 ,
"AllowUpdates
" _
966 ,
"BaseForm
" _
967 ,
"Bookmark
" _
968 ,
"CurrentRecord
" _
969 ,
"Filter
" _
970 ,
"LinkChildFields
" _
971 ,
"LinkParentFields
" _
973 ,
"OnApproveCursorMove
" _
974 ,
"OnApproveParameter
" _
975 ,
"OnApproveReset
" _
976 ,
"OnApproveRowChange
" _
977 ,
"OnApproveSubmit
" _
978 ,
"OnConfirmDelete
" _
979 ,
"OnCursorMoved
" _
980 ,
"OnErrorOccurred
" _
981 ,
"OnLoaded
" _
982 ,
"OnReloaded
" _
983 ,
"OnReloading
" _
984 ,
"OnResetted
" _
985 ,
"OnRowChanged
" _
986 ,
"OnUnloaded
" _
987 ,
"OnUnloading
" _
988 ,
"OrderBy
" _
989 ,
"Parent
" _
990 ,
"RecordSource
" _
991 ,
"XForm
" _
994 End Function
' SFDocuments.SF_Form.Properties
996 REM -----------------------------------------------------------------------------
997 Public Function Requery() As Boolean
998 ''' Reload from the database the actual data into the form
999 ''' The cursor is (re)positioned on the first row
1000 ''' Args:
1001 ''' Returns:
1002 ''' True if requery is successful
1003 ''' Example:
1004 ''' myForm.Requery()
1006 Dim bRequery As Boolean
' Return value
1007 Const cstThisSub =
"SFDocuments.Form.Requery
"
1008 Const cstSubArgs =
""
1010 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1014 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1015 If Not _IsStillAlive() Then GoTo Finally
1019 If .isLoaded() Then .reload() Else .load()
1025 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1029 End Function
' SFDocuments.SF_Form.Requery
1031 REM -----------------------------------------------------------------------------
1032 Public Function SetProperty(Optional ByVal PropertyName As Variant _
1033 , Optional ByRef Value As Variant _
1035 ''' Set a new value to the given property
1036 ''' Args:
1037 ''' PropertyName: the name of the property as a string
1038 ''' Value: its new value
1039 ''' Exceptions
1040 ''' ARGUMENTERROR The property does not exist
1042 Const cstThisSub =
"SFDocuments.Form.SetProperty
"
1043 Const cstSubArgs =
"PropertyName, Value
"
1045 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1049 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1050 If Not SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
1054 SetProperty = _PropertySet(PropertyName, Value)
1057 SF_Utils._ExitFunction(cstThisSub)
1061 End Function
' SFDocuments.SF_Form.SetProperty
1063 REM -----------------------------------------------------------------------------
1064 Public Function Subforms(Optional ByVal Subform As Variant) As Variant
1065 ''' Return either
1066 ''' - the list of the subforms contained in the actual form or subform instance
1067 ''' - a SFDocuments.Form object based on its name or its index in the alphabetic list of subforms
1068 ''' Args:
1069 ''' Subform: a subform stored in the parent form given by its name or its index
1070 ''' When absent, the list of available subforms is returned
1071 ''' To get the first (unique ?) subform stored in the parent form, set Subform =
0
1072 ''' Exceptions:
1073 ''' SUBFORMNOTFOUNDERROR Subform not found
1074 ''' Returns:
1075 ''' A zero-based array of strings if Subform is absent
1076 ''' An instance of the SF_Form class if Subform exists
1077 ''' Example:
1078 ''' Dim myForm As Object, myList As Variant, mySubform As Object
1079 ''' myList = myForm.Subforms()
1080 ''' Set mySubform = myForm.Subforms(
"mySubform
")
1082 Dim oSubform As Object
' The new Form class instance
1083 Dim oXSubform As Object
' com.sun.star.form.XForm
1084 Dim vSubformNames As Variant
' Array of subform names
1086 Const cstDrawPage =
0 ' Only
1 drawpage in a Writer document
1088 Const cstThisSub =
"SFDocuments.Form.Subforms
"
1089 Const cstSubArgs =
"[Subform=
""""]
"
1091 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1094 If IsMissing(Subform) Or IsEmpty(Subform) Then Subform =
""
1095 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1096 If Not _IsStillAlive() Then GoTo Finally
1097 If Not ScriptForge.SF_Utils._Validate(Subform,
"Subform
", Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
1101 ' Collect all control names and retain only the subforms
1102 vSubformNames = _Form.getElementNames()
1103 For i =
0 To UBound(vSubformNames)
1104 Set oSubform = _Form.getByName(vSubformNames(i))
1105 ' Subforms are the only control types having no ClassId property
1106 If ScriptForge.SF_Session.HasUnoProperty(oSubform,
"ClassId
") Then vSubformNames(i) =
""
1108 vSubformNames = ScriptForge.SF_Array.TrimArray(vSubformNames)
1110 If Len(Subform) =
0 Then
' Return the list of valid subform names
1111 Subforms = vSubformNames
1113 If VarType(Subform) = V_STRING Then
' Find the form by name
1114 If Not ScriptForge.SF_Array.Contains(vSubformNames, Subform, CaseSensitive := True) Then GoTo CatchNotFound
1115 Set oXSubform = _Form.getByName(Subform)
1116 Else
' Find the form by index
1117 If Subform
< 0 Or Subform
> UBound(vSubformNames) Then GoTo CatchNotFound
1118 Set oXSubform = _Form.getByName(vSubformNames(Subform))
1120 ' Create the new Form class instance
1121 Set oSubform = SF_Register._NewForm(oXSubform)
1123 Set .[_Parent] = [Me]
1124 ._FormType = ISSUBFORM
1125 Set ._Component = _Component
1126 Set ._FormDocument = _FormDocument
1127 ._SheetName = _SheetName
1128 ._FormDocumentName = _FormDocumentName
1129 Set ._Database = _Database
1132 Set Subforms = oSubform
1136 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1141 ScriptForge.SF_Exception.RaiseFatal(SUBFORMNOTFOUNDERROR, Subform, _Name)
1143 End Function
' SFDocuments.SF_Form.Subforms
1145 REM =========================================================== PRIVATE FUNCTIONS
1147 REM -----------------------------------------------------------------------------
1148 Public Function _GetEventName(ByVal psProperty As String) As String
1149 ''' Return the LO internal event name derived from the SF property name
1150 ''' The SF property name is not case sensitive, while the LO name is case-sensitive
1151 ' Corrects the typo on ErrorOccur(r?)ed, if necessary
1153 Dim vProperties As Variant
' Array of class properties
1154 Dim sProperty As String
' Correctly cased property name
1156 vProperties = Properties()
1157 sProperty = vProperties(ScriptForge.SF_Array.IndexOf(vProperties, psProperty, SortOrder :=
"ASC
"))
1159 _GetEventName = LCase(Mid(sProperty,
3,
1))
& Right(sProperty, Len(sProperty) -
3)
1161 End Function
' SFDocuments.SF_Form._GetEventName
1163 REM -----------------------------------------------------------------------------
1164 Private Function _GetListener(ByVal psEventName As String) As String
1165 ''' Getting/Setting macros triggered by events requires a Listener-EventName pair
1166 ''' Return the X...Listener corresponding with the event name in argument
1168 Select Case UCase(psEventName)
1169 Case UCase(
"OnApproveCursorMove
")
1170 _GetListener =
"XRowSetApproveListener
"
1171 Case UCase(
"OnApproveParameter
")
1172 _GetListener =
"XDatabaseParameterListener
"
1173 Case UCase(
"OnApproveReset
"), UCase(
"OnResetted
")
1174 _GetListener =
"XResetListener
"
1175 Case UCase(
"OnApproveRowChange
")
1176 _GetListener =
"XRowSetApproveListener
"
1177 Case UCase(
"OnApproveSubmit
")
1178 _GetListener =
"XSubmitListener
"
1179 Case UCase(
"OnConfirmDelete
")
1180 _GetListener =
"XConfirmDeleteListener
"
1181 Case UCase(
"OnCursorMoved
"), UCase(
"OnRowChanged
")
1182 _GetListener =
"XRowSetListener
"
1183 Case UCase(
"OnErrorOccurred
")
1184 _GetListener =
"XSQLErrorListener
"
1185 Case UCase(
"OnLoaded
"), UCase(
"OnReloaded
"), UCase(
"OnReloading
"), UCase(
"OnUnloaded
"), UCase(
"OnUnloading
")
1186 _GetListener =
"XLoadListener
"
1189 End Function
' SFDocuments.SF_Form._GetListener
1191 REM -----------------------------------------------------------------------------
1192 Private Sub _GetParents()
1193 ''' When the current instance is created top-down, the parents are completely defined
1194 ''' and nothing should be done in this method
1195 ''' When the a class instance is created in a (form/control) event, it is the opposite
1196 ''' The current method rebuilds the missing members in the instance from the bottom
1197 ''' Members potentially to collect are:
1198 ''' - _FormType
1199 ''' - [_Parent], the immediate parent: a form or a document instance
1200 ''' + Only when the _FormType is a main form
1201 ''' - _SheetName (Calc only)
1202 ''' - _FormDocumentName (Base only)
1203 ''' - _FormDocument, the topmost form collection
1204 ''' - _Component, the containing document
1205 ''' They must be identified only starting from the _Form UNO object
1207 ''' The method is called from the _Initialize() method at instance creation
1209 Dim oParent As Object
' Successive bottom-up parents
1210 Dim sType As String
' UNO object type
1211 Dim sPersistentName As String
' The Obj... name of a Base form
1212 Dim iLevel As Integer
' When =
1 =
> first parent
1213 Dim oSession As Object : Set oSession = ScriptForge.SF_Session
1215 On Local Error GoTo Finally
' Being probably called from events, this method should avoid failures
1216 ' When the form type is known, the upper part of the branch is not scanned
1217 If _FormType
<> ISUNDEFINED Then GoTo Finally
1220 ' The whole branch is scanned bottom-up
1221 If oSession.HasUnoProperty(_Form,
"Parent
") Then Set oParent = _Form.Parent Else Set oParent = Nothing
1222 _FormType = ISUNDEFINED
1225 Do While Not IsNull(oParent)
1226 sType = SF_Session.UnoObjectType(oParent)
1228 ' Collect at each level the needed info
1229 Case
"com.sun.star.comp.forms.ODatabaseForm
" ' The parent _Form of a subform
1231 _FormType = ISSUBFORM
1232 Set [_Parent] = SF_Register._NewForm(oParent)
1233 ' Everything is in the parent, copy items and stop scan
1234 [_Parent]._Initialize()
' Current method is called recursively here
1236 _SheetName = ._SheetName
1237 _FormDocumentName = ._FormDocumentName
1238 Set _FormDocument = ._FormDocument
1239 Set _Component = ._Component
1243 Case
"com.sun.star.form.OFormsCollection
" ' The collection of forms inside a drawpage
1244 Case
"SwXTextDocument
" ' The parent document: a Writer document or a Base form document
1245 If oParent.Identifier =
"com.sun.star.sdb.FormDesign
" Then
1246 sPersistentName = ScriptForge._GetPropertyValue(oParent.Args,
"HierarchicalDocumentName
")
1247 ElseIf oParent.Identifier =
"com.sun.star.text.TextDocument
" Then
1248 _FormType = ISDOCFORM
1249 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(
"SFDocuments.Document
", oParent)
1250 Set _Component = [_Parent]._Component
1252 Case
"ScModelObj
" ' The parent document: a Calc document
1253 _FormType = ISCALCFORM
1254 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(
"SFDocuments.Document
", oParent)
1255 Set _Component = oParent
1256 ' The triggered form event is presumed to be located in the (drawpage of the) active sheet
1257 _SheetName = [_Parent].XSpreadsheet(
"~
")
1258 Case
"com.sun.star.comp.dba.ODatabaseDocument
" ' The Base document
1259 _FormType = ISBASEFORM
1260 Set [_Parent] = ScriptForge.SF_Services.CreateScriptService(
"SFDocuments.Document
", oParent)
1261 Set _Component = oParent
1262 If IsNull([_Parent]._FormDocuments) Then Set [_Parent]._FormDocuments = _Component.getFormDocuments()
1263 Set _FormDocument = [_Parent]._FindByPersistentName([_Parent]._FormDocuments, sPersistentName)
1264 _FormDocumentName = _FormDocument.HierarchicalName
1267 If oSession.HasUnoProperty(oParent,
"Parent
") Then Set oParent = oParent.Parent Else Set oParent = Nothing
1273 End Sub
' SFDocuments.SF_Form._GetParents
1275 REM -----------------------------------------------------------------------------
1276 Public Sub _Initialize()
1277 ''' Achieve the creation of a SF_Form instance
1278 ''' - complete the missing private members
1279 ''' - store the new instance in the cache
1282 _CacheIndex = SF_Register._AddFormToCache(_Form, [Me])
1284 End Sub
' SFDocuments.SF_Form._Initialize
1286 REM -----------------------------------------------------------------------------
1287 Private Function _IsStillAlive(Optional ByVal pbError As Boolean) As Boolean
1288 ''' Return True if the Form is still open
1289 ''' If dead the actual instance is disposed
1290 ''' and the execution is cancelled when pbError = True (default)
1291 ''' Args:
1292 ''' pbError: if True (default), raise a fatal error
1294 Dim bAlive As Boolean
' Return value
1295 Dim sName As String
' Alias of _Name
1296 Dim sId As String
' Alias of FileIdent
1299 On Local Error GoTo Catch
' Anticipate DisposedException errors or alike
1300 If IsMissing(pbError) Then pbError = True
1303 ' At main form termination, all database connections are lost
1304 bAlive = Not IsNull(_Form)
1305 If Not bAlive Then GoTo Catch
1308 _IsStillAlive = bAlive
1313 ' Keep error message elements before disposing the instance
1314 sName = _SheetName
& _FormDocumentName
' At least one of them is a zero-length string
1315 sName = Iif(Len(sName)
> 0,
"[
" & sName
& "].
",
"")
& _Name
1316 If Not IsNull(_Component) Then sId = _Component.Location Else sId =
""
1317 ' Dispose the actual forms instance
1319 ' Display error message
1320 If pbError Then ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, sName, sId)
1322 End Function
' SFDocuments.SF_Form._IsStillAlive
1324 REM -----------------------------------------------------------------------------
1325 Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
1326 ''' Return the value of the named property
1327 ''' Args:
1328 ''' psProperty: the name of the property
1330 Static oSession As Object
' Alias of SF_Session
1331 Dim vBookmark As Variant
' Form bookmark
1332 Dim cstThisSub As String
1333 Const cstSubArgs =
""
1335 cstThisSub =
"SFDocuments.Form.get
" & psProperty
1336 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1338 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1339 _PropertyGet = Empty
1340 If Not _IsStillAlive() Then GoTo Finally
1342 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"Session
")
1343 Select Case UCase(psProperty)
1344 Case UCase(
"AllowDeletes
")
1345 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowDeletes
1346 Case UCase(
"AllowInserts
")
1347 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowInserts
1348 Case UCase(
"AllowUpdates
")
1349 If Not IsNull(_Form) Then _PropertyGet = _Form.AllowUpdates
1350 Case UCase(
"BaseForm
")
1351 _PropertyGet = _FormDocumentName
1352 Case UCase(
"Bookmark
")
1353 If IsNull(_Form) Then
1356 On Local Error Resume Next
' Disable error handler because bookmarking does not always react well in events ...
1357 If _Form.IsBookmarkable Then vBookmark = _Form.getBookmark() Else vBookmark = Nothing
1358 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error Goto Catch Else On Local Error Goto
0
1359 If IsNull(vBookmark) Then Goto Catch
1360 _PropertyGet = vBookmark
1362 Case UCase(
"CurrentRecord
")
1363 If IsNull(_Form) Then _PropertyGet =
0 Else _PropertyGet = _Form.Row
1364 Case UCase(
"Filter
")
1365 If IsNull(_Form) Then _PropertyGet =
"" Else _PropertyGet = _Form.Filter
1366 Case UCase(
"LinkChildFields
")
1367 If IsNull(_Form) Or _FormType
<> ISSUBFORM Then _PropertyGet = Array() Else _PropertyGet = _Form.DetailFields
1368 Case UCase(
"LinkParentFields
")
1369 If IsNull(_Form) Or _FormType
<> ISSUBFORM Then _PropertyGet = Array() Else _PropertyGet = _Form.MasterFields
1370 Case UCase(
"Name
")
1371 _PropertyGet = _Name
1372 Case UCase(
"OnApproveCursorMove
"), UCase(
"OnApproveParameter
"), UCase(
"OnApproveReset
"), UCase(
"OnApproveRowChange
") _
1373 , UCase(
"OnApproveSubmit
"), UCase(
"OnConfirmDelete
"), UCase(
"OnCursorMoved
"), UCase(
"OnErrorOccurred
") _
1374 , UCase(
"OnLoaded
"), UCase(
"OnReloaded
"), UCase(
"OnReloading
"), UCase(
"OnResetted
"), UCase(
"OnRowChanged
") _
1375 , UCase(
"OnUnloaded
"), UCase(
"OnUnloading
")
1376 If IsNull(_Form) Then _PropertyGet =
"" Else _PropertyGet = SF_Register._GetEventScriptCode(_Form, psProperty, _Name)
1377 Case UCase(
"OrderBy
")
1378 If IsNull(_Form) Then _PropertyGet =
"" Else _PropertyGet = _Form.Order
1379 Case UCase(
"Parent
")
1380 _PropertyGet = [_Parent]
1381 Case UCase(
"RecordSource
")
1382 If IsNull(_Form) Then _PropertyGet =
"" Else _PropertyGet = _Form.Command
1383 Case UCase(
"XForm
")
1384 Set _PropertyGet = _Form
1390 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1394 End Function
' SFDocuments.SF_Form._PropertyGet
1396 REM -----------------------------------------------------------------------------
1397 Private Function _PropertySet(Optional ByVal psProperty As String _
1398 , Optional ByVal pvValue As Variant _
1400 ''' Set the new value of the named property
1401 ''' Args:
1402 ''' psProperty: the name of the property
1403 ''' pvValue: the new value of the given property
1404 ''' Returns:
1405 ''' True if successful
1407 Dim bSet As Boolean
' Return value
1408 Dim oDatabase As Object
' Database class instance
1409 Dim lCommandType As Long
' Record source type:
0 = Table,
1 = Query,
2 = SELECT
1410 Dim sCommand As String
' Record source
1411 Static oSession As Object
' Alias of SF_Session
1412 Dim cstThisSub As String
1413 Const cstSubArgs =
"Value
"
1415 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1418 cstThisSub =
"SFDocuments.Form.set
" & psProperty
1419 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1420 If Not _IsStillAlive() Then GoTo Finally
1422 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"Session
")
1424 Select Case UCase(psProperty)
1425 Case UCase(
"AllowDeletes
")
1426 If Not ScriptForge.SF_Utils._Validate(pvValue,
"AllowDeletes
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1427 If Not IsNull(_Form) Then
1428 _Form.AllowDeletes = pvValue
1431 Case UCase(
"AllowInserts
")
1432 If Not ScriptForge.SF_Utils._Validate(pvValue,
"AllowInserts
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1433 If Not IsNull(_Form) Then
1434 _Form.AllowInserts = pvValue
1437 Case UCase(
"AllowUpdates
")
1438 If Not ScriptForge.SF_Utils._Validate(pvValue,
"AllowUpdates
", ScriptForge.V_BOOLEAN) Then GoTo Finally
1439 If Not IsNull(_Form) Then
1440 _Form.AllowUpdates = pvValue
1443 Case UCase(
"Bookmark
")
1444 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Bookmark
", Array(ScriptForge.V_NUMERIC, ScriptForge.V_OBJECT)) Then GoTo Finally
1445 If Not IsNull(pvValue) And Not IsNull(_Form) Then bSet = _Form.moveToBookmark(pvValue)
1446 Case UCase(
"CurrentRecord
")
1447 If Not ScriptForge.SF_Utils._Validate(pvValue,
"CurrentRecord
", ScriptForge.V_NUMERIC) Then GoTo Finally
1448 If Not IsNull(_Form) Then bSet = _Form.absolute(pvValue)
1449 Case UCase(
"Filter
")
1450 If Not ScriptForge.SF_Utils._Validate(pvValue,
"Filter
", V_STRING) Then GoTo Finally
1451 If Not IsNull(_Form) Then
1453 If Len(pvValue)
> 0 Then
1454 Set oDatabase = GetDatabase()
1455 If Not IsNull(oDatabase) Then .Filter = oDatabase._ReplaceSquareBrackets(pvValue) Else .Filter = pvValue
1457 .Filter =
""
1463 Case UCase(
"OnApproveCursorMove
"), UCase(
"OnApproveParameter
"), UCase(
"OnApproveReset
"), UCase(
"OnApproveRowChange
") _
1464 , UCase(
"OnApproveSubmit
"), UCase(
"OnConfirmDelete
"), UCase(
"OnCursorMoved
"), UCase(
"OnErrorOccurred
") _
1465 , UCase(
"OnLoaded
"), UCase(
"OnReloaded
"), UCase(
"OnReloading
"), UCase(
"OnResetted
"), UCase(
"OnRowChanged
") _
1466 , UCase(
"OnUnloaded
"), UCase(
"OnUnloading
")
1467 If Not ScriptForge.SF_Utils._Validate(pvValue, psProperty, V_STRING) Then Goto Finally
1468 If Not IsNull(_Form) Then
1469 bSet = SF_Register._RegisterEventScript(_Form _
1471 , _GetListener(psProperty) _
1476 Case UCase(
"OrderBy
")
1477 If Not ScriptForge.SF_Utils._Validate(pvValue,
"OrderBy
", V_STRING) Then GoTo Finally
1478 If Not IsNull(_Form) Then
1480 If Len(pvValue)
> 0 Then
1481 Set oDatabase = GetDatabase()
1482 If Not IsNull(oDatabase) Then .Order = oDatabase._ReplaceSquareBrackets(pvValue) Else .Order = pvValue
1484 .Order =
""
1489 Case UCase(
"RecordSource
")
1490 If Not ScriptForge.SF_Utils._Validate(pvValue,
"RecordSource
", V_STRING) Then GoTo Finally
1491 If Not IsNull(_Form) And Len(pvValue)
> 0 Then
1492 Set oDatabase = GetDatabase()
1493 If Not IsNull(oDatabase) Then
1495 If ScriptForge.SF_Array.Contains(.Tables, pvValue, CaseSensitive := True) Then
1497 lCommandType = com.sun.star.sdb.CommandType.TABLE
1498 ElseIf ScriptForge.SF_Array.Contains(.Queries, pvValue, CaseSensitive := True) Then
1500 lCommandType = com.sun.star.sdb.CommandType.QUERY
1501 ElseIf ScriptForge.SF_String.StartsWith(pvValue,
"SELECT
", CaseSensitive := False) Then
1502 sCommand = .ReplaceSquareBrackets(pvValue)
1503 lCommandType = com.sun.star.sdb.CommandType.COMMAND
1505 _Form.Command = sCommand
1506 _Form.CommandType = lCommandType
1516 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1520 End Function
' SFDocuments.SF_Form._PropertySet
1522 REM -----------------------------------------------------------------------------
1523 Private Function _Repr() As String
1524 ''' Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
1525 ''' Args:
1526 ''' Return:
1527 ''' "[Form]: Name
"
1529 Dim sParent As String
' To recognize the parent
1531 sParent = _SheetName
& _FormDocumentName
' At least one of them is a zero-length string
1532 _Repr =
"[Form]:
" & Iif(Len(sParent)
> 0, sParent
& "...
",
"")
& _Name
1534 End Function
' SFDocuments.SF_Form._Repr
1536 REM ============================================ END OF SFDOCUMENTS.SF_FORM