diff options
Diffstat (limited to 'wizards/source/sfdocuments/SF_Form.xba')
-rw-r--r-- | wizards/source/sfdocuments/SF_Form.xba | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/wizards/source/sfdocuments/SF_Form.xba b/wizards/source/sfdocuments/SF_Form.xba index 9b259034e56d..5e1f011c8a1d 100644 --- a/wizards/source/sfdocuments/SF_Form.xba +++ b/wizards/source/sfdocuments/SF_Form.xba @@ -60,6 +60,11 @@ Option Explicit ''' ' To access a subform: myForm and mySubForm become distinct instances of the current class ''' Set mySubForm = myForm.SubForms("mySubForm") ''' +''' REM the form is the subject of an event +''' Sub OnEvent(ByRef poEvent As Object) +''' Dim myForm As Object +''' Set myForm = CreateScriptService("SFDocuments.FormEvent", poEvent) +''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' REM ================================================================== EXCEPTIONS @@ -83,7 +88,7 @@ Private _FormDocument As Object ' com.sun.star.comp.sdb.Content - the con ' The form topmost container Private _Component As Object ' com.sun.star.lang.XComponent or com.sun.star.comp.dba.ODatabaseDocument -' EVents management +' Events management Private _CacheIndex As Long ' Index in central cache storage ' Form UNO references @@ -94,7 +99,8 @@ Private _Database As Object ' Database class instance ' Form attributes -' Persistent storage for controls +' Cache storage for controls +Private _ControlNames As Variant ' Array of control names Private _ControlCache As Variant ' Array of control objects sorted like ElementNames of XForm REM ============================================================ MODULE CONSTANTS @@ -111,7 +117,7 @@ REM ---------------------------------------------------------------------------- Private Sub Class_Initialize() Set [Me] = Nothing Set [_Parent] = Nothing - ObjectType = "Form" + ObjectType = "FORM" ServiceName = "SFDocuments.Form" _Name = "" _SheetName = "" @@ -121,6 +127,7 @@ Private Sub Class_Initialize() _CacheIndex = -1 Set _Form = Nothing Set _Database = Nothing + _ControlNames = Array() _ControlCache = Array() End Sub ' SFDocuments.SF_Form Constructor @@ -554,13 +561,14 @@ Public Function Controls(Optional ByVal ControlName As Variant) As Variant ''' ControlName is invalid ''' Example: ''' Dim myForm As Object, myList As Variant, myControl As Object -''' Set myForm = CreateScriptService("SFDocuments.Form", Container, Library, FormName) +''' Set myForm = myDoc.Forms("myForm") ''' myList = myForm.Controls() ''' Set myControl = myForm.Controls("myTextBox") Dim oControl As Object ' The new control class instance Dim lIndexOfNames As Long ' Index in ElementNames array. Used to access _ControlCache Dim vControl As Variant ' Alias of _ControlCache entry +Dim i As Long Const cstThisSub = "SFDocuments.Form.Controls" Const cstSubArgs = "[ControlName]" @@ -574,8 +582,51 @@ Check: End If Try: + ' Collect all control names if not yet done + If UBound(_ControlNames) < 0 Then + _ControlNames = _Form.getElementNames() + ' Remove all subforms from the list + For i = 0 To UBound(_ControlNames) + ' Subforms have no ClassId property + If Not ScriptForge.SF_Session.HasUnoProperty(_Form.getByName(_ControlNames(i)), "ClassId") Then _ControlNames(i) = "" + Next i + _ControlNames = ScriptForge.SF_Array.TrimArray(_ControlNames) + ' Size the cache accordingly + If UBound(_ControlNames) >= 0 Then + ReDim _ControlCache(0 To UBound(_ControlNames)) + End If + End If + + ' Return the list of controls or a FormControl instance If Len(ControlName) = 0 Then + Controls = _ControlNames + Else + + If Not _Form.hasByName(ControlName) Then GoTo CatchNotFound + lIndexOfNames = ScriptForge.SF_Array.IndexOf(_ControlNames, ControlName, CaseSensitive := True) + ' Reuse cache when relevant + vControl = _ControlCache(lIndexOfNames) + + If IsEmpty(vControl) Then + ' Create the new form control class instance + Set oControl = New SF_FormControl + With oControl + ._Name = ControlName + Set .[Me] = oControl + Set .[_Parent] = [Me] + Set ._ParentForm = [Me] + ._IndexOfNames = lIndexOfNames + ._FormName = _Name + ' Get model and view of the current control + Set ._ControlModel = _Form.getByName(ControlName) + ._Initialize() + End With + Else + Set oControl = vControl + End If + + Set Controls = oControl End If Finally: @@ -584,7 +635,7 @@ Finally: Catch: GoTo Finally CatchNotFound: - ScriptForge.SF_Utils._Validate(ControlName, "ControlName", V_STRING, _FormModel.getElementNames()) + ScriptForge.SF_Utils._Validate(ControlName, "ControlName", V_STRING, _Form.getElementNames()) GoTo Finally End Function ' SFDocuments.SF_Form.Controls |