diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2020-12-20 12:52:28 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2020-12-20 14:14:56 +0100 |
commit | ff07da5d888648e0343aabe1f533790029470165 (patch) | |
tree | e84e4902fe53120a3f5258020cbb7131dd3eaff6 /wizards | |
parent | c90118762d1f0fe7abaadf45f13550b2d2838502 (diff) |
ScriptForge - (SF_Form) manage cache entries for form instances
Event management of forms requires to being able
to rebuild a Form object from its
com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm
UNO instance
For that purpose, the active forms are buffered
in a global array of _FormCache types
Change-Id: I004934f4b9d24ec035cc4adc798df1a2ac01d227
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108047
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/scriptforge/SF_Root.xba | 2 | ||||
-rw-r--r-- | wizards/source/sfdialogs/SF_Register.xba | 8 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Base.xba | 6 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Calc.xba | 1 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Document.xba | 1 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Form.xba | 12 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Register.xba | 107 |
7 files changed, 131 insertions, 6 deletions
diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba index 07ec5acfca8d..22a4a8aba2b2 100644 --- a/wizards/source/scriptforge/SF_Root.xba +++ b/wizards/source/scriptforge/SF_Root.xba @@ -72,6 +72,7 @@ Private PythonHelper As String ' File name of Python helper functions (sto Private Interface As Object ' ScriptForge own L10N service Private OSName As String ' WIN, LINUX, MACOS Private SFDialogs As Variant ' Persistent storage for the SFDialogs library +Private SFForms As Variant ' Persistent storage for the SF_Form class in the SFDocuments library REM ====================================================== CONSTRUCTOR/DESTRUCTOR @@ -118,6 +119,7 @@ Private Sub Class_Initialize() Set TreeDataModel = Nothing OSName = "" SFDialogs = Empty + SFForms = Empty End Sub ' ScriptForge.SF_Root Constructor REM ----------------------------------------------------------------------------- diff --git a/wizards/source/sfdialogs/SF_Register.xba b/wizards/source/sfdialogs/SF_Register.xba index e8348d7e53ec..0bda31d48ebe 100644 --- a/wizards/source/sfdialogs/SF_Register.xba +++ b/wizards/source/sfdialogs/SF_Register.xba @@ -107,7 +107,7 @@ Try: Finally: _AddDialogToCache = lIndex Exit Function -End Function ' SFDialogs.SF_Dialog._AddDialogToCache +End Function ' SFDialogs.SF_Register._AddDialogToCache REM ----------------------------------------------------------------------------- Private Sub _CleanCacheEntry(ByVal plIndex As Long) @@ -131,7 +131,7 @@ Dim vCache As New _DialogCache ' Cleaned entry Finally: Exit Sub -End Sub ' SFDialogs.SF_Dialog._CleanCacheEntry +End Sub ' SFDialogs.SF_Register._CleanCacheEntry REM ----------------------------------------------------------------------------- Public Function _EventManager(Optional ByRef pvArgs As Variant) As Object @@ -190,7 +190,7 @@ Try: Finally: Set _EventManager = oSource Exit Function -End Function ' SFDialogs.SF_Documents._EventManager +End Function ' SFDialogs.SF_Register._EventManager REM ----------------------------------------------------------------------------- Private Function _FindDialogInCache(ByRef poDialog As Object) As Object @@ -215,7 +215,7 @@ Try: Finally: Set _FindDialogInCache = oBasicDialog Exit Function -End Function ' SFDialogs.SF_Documents._FindDialogInCache +End Function ' SFDialogs.SF_Register._FindDialogInCache REM ----------------------------------------------------------------------------- Public Function _NewDialog(Optional ByVal pvArgs As Variant) As Object diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba index 92101c6f41d8..31c12b016a50 100644 --- a/wizards/source/sfdocuments/SF_Base.xba +++ b/wizards/source/sfdocuments/SF_Base.xba @@ -242,6 +242,7 @@ Try: Set ._MainForm = oMainForm ._FormType = ISBASEFORM Set ._Form = oXForm + ._Initialize() End With Set Forms = oForm End If @@ -453,7 +454,10 @@ Try: Wait 1 ' Bypass desynchro issue in Linux End With Else ' Open - _Component.CurrentController.loadComponent(com.sun.star.sdb.application.DatabaseObject.FORM, FormDocument, DesignMode) + With _Component.CurrentController + If Not .IsConnected Then .connect() + .loadComponent(com.sun.star.sdb.application.DatabaseObject.FORM, FormDocument, DesignMode) + End With bOpen = True End If diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index 48f35fed98f0..8bbcf29019ac 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -918,6 +918,7 @@ Try: Set ._MainForm = Nothing ._FormType = ISCALCFORM Set ._Form = oXForm + ._Initialize() End With Set Forms = oForm End If diff --git a/wizards/source/sfdocuments/SF_Document.xba b/wizards/source/sfdocuments/SF_Document.xba index d7dc14e5e9ed..b028d140c74f 100644 --- a/wizards/source/sfdocuments/SF_Document.xba +++ b/wizards/source/sfdocuments/SF_Document.xba @@ -521,6 +521,7 @@ Try: Set ._MainForm = Nothing ._FormType = ISDOCFORM Set ._Form = oXForm + ._Initialize() End With Set Forms = oForm End If diff --git a/wizards/source/sfdocuments/SF_Form.xba b/wizards/source/sfdocuments/SF_Form.xba index ee905e729581..ca4be09e56df 100644 --- a/wizards/source/sfdocuments/SF_Form.xba +++ b/wizards/source/sfdocuments/SF_Form.xba @@ -79,6 +79,7 @@ Private _DrawPage As Long ' Index in DrawPages collection Private _SheetName As String ' Name as the sheet containing the form (Calc only) Private _FormDocumentName As String ' The hierarchical name of the containing form document (Base only) Private _FormType As Integer ' One of the ISxxxFORM constants +Private _CacheIndex As Long ' Index in central cache storage ' Form UNO references ' The forms container found in a Base document @@ -114,6 +115,7 @@ Private Sub Class_Initialize() _SheetName = "" _FormDocumentName = "" _FormType = 0 + _CacheIndex = -1 Set _MainForm = Nothing Set _Form = Nothing Set _Database = Nothing @@ -130,6 +132,7 @@ Public Function Dispose() As Variant If Not IsNull(_Database) And (_FormType = ISDOCFORM Or _FormType = ISCALCFORM) Then Set _Database = _Database.Dispose() End If + SF_Register._CleanCacheEntry(_CacheIndex) Call Class_Terminate() Set Dispose = Nothing End Function ' SFDocuments.SF_Form Explicit Destructor @@ -541,6 +544,15 @@ Private Function _GetListener(ByVal psEventName As String) As String End Function ' SFDocuments.SF_Form._GetListener REM ----------------------------------------------------------------------------- +Public Sub _Initialize() +''' Achieve the creation of a SF_Form instance +''' - store the new instance in the cache + + _CacheIndex = SF_Register._AddFormToCache(_Form, [Me]) + +End Sub ' SFDocuments.SF_Form._Initialize + +REM ----------------------------------------------------------------------------- Private Function _IsStillAlive(Optional ByVal pbError As Boolean) As Boolean ''' Return True if the Form is still open ''' If dead the actual instance is disposed diff --git a/wizards/source/sfdocuments/SF_Register.xba b/wizards/source/sfdocuments/SF_Register.xba index d003eee71c31..2dccc12c972d 100644 --- a/wizards/source/sfdocuments/SF_Register.xba +++ b/wizards/source/sfdocuments/SF_Register.xba @@ -24,6 +24,18 @@ Option Explicit REM ================================================================== EXCEPTIONS +REM ================================================================= DEFINITIONS + +''' Event management of forms requires to being able to rebuild a Form object +''' from its com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm UNO instance +''' For that purpose, the active forms are buffered in a global array of _FormCache types + +Type _FormCache + Terminated As Boolean + XUnoForm As Object + BasicForm As Object +End Type + REM ============================================================== PUBLIC METHODS REM ----------------------------------------------------------------------------- @@ -54,6 +66,74 @@ End Sub ' SFDocuments.SF_Register.RegisterScriptServices REM =========================================================== PRIVATE FUNCTIONS REM ----------------------------------------------------------------------------- +Private Function _AddFormToCache(ByRef pvUnoForm As Object _ + , ByRef pvBasicForm As Object _ + ) As Long +''' Add a new entry in the cache array with the references of the actual Form +''' If relevant, the last entry of the cache is reused. +''' The cache is located in the global _SF_ variable +''' Args: +''' pvUnoForm: com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm +''' pvBasicForm: its corresponding Basic object +''' Returns: +''' The index of the new or modified entry + +Dim vCache As New _FormCache ' Entry to be added +Dim lIndex As Long ' UBound of _SF_.SFForms +Dim vCacheArray As Variant ' Alias of _SF_.SFForms + +Try: + vCacheArray = _SF_.SFForms + + If IsEmpty(vCacheArray) Then vCacheArray = Array() + lIndex = UBound(vCacheArray) + If lIndex < LBound(vCacheArray) Then + ReDim vCacheArray(0 To 0) + lIndex = 0 + ElseIf Not vCacheArray(lIndex).Terminated Then ' Often last entry can be reused + lIndex = lIndex + 1 + ReDim Preserve vCacheArray(0 To lIndex) + End If + + With vCache + .Terminated = False + Set .XUnoForm = pvUnoForm + Set .BasicForm = pvBasicForm + End With + Set vCacheArray(lIndex) = vCache + + _SF_.SFForms = vCacheArray + +Finally: + _AddFormToCache = lIndex + Exit Function +End Function ' SFDocuments.SF_Register._AddFormToCache + +REM ----------------------------------------------------------------------------- +Private Sub _CleanCacheEntry(ByVal plIndex As Long) +''' Clean the plIndex-th entry in the Forms cache +''' Args: +''' plIndex: must fit within the actual boundaries of the cache, otherwise the request is ignored + +Dim vCache As New _FormCache ' Cleaned entry + + With _SF_ + If Not IsArray(.SFForms) Then Exit Sub + If plIndex < LBound(.SFForms) Or plIndex > UBound(.SFForms) Then Exit Sub + + With vCache + .Terminated = True + Set .XUnoForm = Nothing + Set .BasicForm = Nothing + End With + .SFForms(plIndex) = vCache + End With + +Finally: + Exit Sub +End Sub ' SFDocuments.SF_Register._CleanCacheEntry + +REM ----------------------------------------------------------------------------- Public Function _EventManager(Optional ByRef pvArgs As Variant) As Object ''' Returns a Document or Calc object corresponding with the active component ''' which triggered the event in argument @@ -92,7 +172,32 @@ Try: Finally: Set _EventManager = oSource Exit Function -End Function ' SFDocuments.SF_Documents._EventManager +End Function ' SFDocuments.SF_Register._EventManager + +REM ----------------------------------------------------------------------------- +Private Function _FindFormInCache(ByRef poForm As Object) As Object +''' Find the Form based on its XUnoForm +''' The Form must not be terminated +''' Returns: +''' The corresponding Basic Form part or Nothing + +Dim oBasicForm As Object ' Return value +Dim oCache As _FormCache ' Entry in the cache + + Set oBasicForm = Nothing + +Try: + For Each oCache In _SF_.SFForms + If EqualUnoObjects(poForm, oCache.XUnoForm) And Not oCache.Terminated Then + Set oBasicForm = oCache.BasicForm + Exit For + End If + Next oCache + +Finally: + Set _FindFormInCache = oBasicForm + Exit Function +End Function ' SFDocuments.SF_Register._FindFormInCache REM ----------------------------------------------------------------------------- Public Function _NewDocument(Optional ByVal pvArgs As Variant) As Object |