summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2020-12-20 12:52:28 +0100
committerJean-Pierre Ledure <jp@ledure.be>2020-12-20 14:14:56 +0100
commitff07da5d888648e0343aabe1f533790029470165 (patch)
treee84e4902fe53120a3f5258020cbb7131dd3eaff6 /wizards
parentc90118762d1f0fe7abaadf45f13550b2d2838502 (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.xba2
-rw-r--r--wizards/source/sfdialogs/SF_Register.xba8
-rw-r--r--wizards/source/sfdocuments/SF_Base.xba6
-rw-r--r--wizards/source/sfdocuments/SF_Calc.xba1
-rw-r--r--wizards/source/sfdocuments/SF_Document.xba1
-rw-r--r--wizards/source/sfdocuments/SF_Form.xba12
-rw-r--r--wizards/source/sfdocuments/SF_Register.xba107
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 &apos; File name of Python helper functions (sto
Private Interface As Object &apos; ScriptForge own L10N service
Private OSName As String &apos; WIN, LINUX, MACOS
Private SFDialogs As Variant &apos; Persistent storage for the SFDialogs library
+Private SFForms As Variant &apos; 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 = &quot;&quot;
SFDialogs = Empty
+ SFForms = Empty
End Sub &apos; 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 &apos; SFDialogs.SF_Dialog._AddDialogToCache
+End Function &apos; SFDialogs.SF_Register._AddDialogToCache
REM -----------------------------------------------------------------------------
Private Sub _CleanCacheEntry(ByVal plIndex As Long)
@@ -131,7 +131,7 @@ Dim vCache As New _DialogCache &apos; Cleaned entry
Finally:
Exit Sub
-End Sub &apos; SFDialogs.SF_Dialog._CleanCacheEntry
+End Sub &apos; 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 &apos; SFDialogs.SF_Documents._EventManager
+End Function &apos; 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 &apos; SFDialogs.SF_Documents._FindDialogInCache
+End Function &apos; 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 &apos; Bypass desynchro issue in Linux
End With
Else &apos; 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 &apos; Index in DrawPages collection
Private _SheetName As String &apos; Name as the sheet containing the form (Calc only)
Private _FormDocumentName As String &apos; The hierarchical name of the containing form document (Base only)
Private _FormType As Integer &apos; One of the ISxxxFORM constants
+Private _CacheIndex As Long &apos; Index in central cache storage
&apos; Form UNO references
&apos; The forms container found in a Base document
@@ -114,6 +115,7 @@ Private Sub Class_Initialize()
_SheetName = &quot;&quot;
_FormDocumentName = &quot;&quot;
_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 &apos; SFDocuments.SF_Form Explicit Destructor
@@ -541,6 +544,15 @@ Private Function _GetListener(ByVal psEventName As String) As String
End Function &apos; SFDocuments.SF_Form._GetListener
REM -----------------------------------------------------------------------------
+Public Sub _Initialize()
+&apos;&apos;&apos; Achieve the creation of a SF_Form instance
+&apos;&apos;&apos; - store the new instance in the cache
+
+ _CacheIndex = SF_Register._AddFormToCache(_Form, [Me])
+
+End Sub &apos; SFDocuments.SF_Form._Initialize
+
+REM -----------------------------------------------------------------------------
Private Function _IsStillAlive(Optional ByVal pbError As Boolean) As Boolean
&apos;&apos;&apos; Return True if the Form is still open
&apos;&apos;&apos; 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
+
+&apos;&apos;&apos; Event management of forms requires to being able to rebuild a Form object
+&apos;&apos;&apos; from its com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm UNO instance
+&apos;&apos;&apos; 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 &apos; SFDocuments.SF_Register.RegisterScriptServices
REM =========================================================== PRIVATE FUNCTIONS
REM -----------------------------------------------------------------------------
+Private Function _AddFormToCache(ByRef pvUnoForm As Object _
+ , ByRef pvBasicForm As Object _
+ ) As Long
+&apos;&apos;&apos; Add a new entry in the cache array with the references of the actual Form
+&apos;&apos;&apos; If relevant, the last entry of the cache is reused.
+&apos;&apos;&apos; The cache is located in the global _SF_ variable
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; pvUnoForm: com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm
+&apos;&apos;&apos; pvBasicForm: its corresponding Basic object
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; The index of the new or modified entry
+
+Dim vCache As New _FormCache &apos; Entry to be added
+Dim lIndex As Long &apos; UBound of _SF_.SFForms
+Dim vCacheArray As Variant &apos; Alias of _SF_.SFForms
+
+Try:
+ vCacheArray = _SF_.SFForms
+
+ If IsEmpty(vCacheArray) Then vCacheArray = Array()
+ lIndex = UBound(vCacheArray)
+ If lIndex &lt; LBound(vCacheArray) Then
+ ReDim vCacheArray(0 To 0)
+ lIndex = 0
+ ElseIf Not vCacheArray(lIndex).Terminated Then &apos; 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 &apos; SFDocuments.SF_Register._AddFormToCache
+
+REM -----------------------------------------------------------------------------
+Private Sub _CleanCacheEntry(ByVal plIndex As Long)
+&apos;&apos;&apos; Clean the plIndex-th entry in the Forms cache
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; plIndex: must fit within the actual boundaries of the cache, otherwise the request is ignored
+
+Dim vCache As New _FormCache &apos; Cleaned entry
+
+ With _SF_
+ If Not IsArray(.SFForms) Then Exit Sub
+ If plIndex &lt; LBound(.SFForms) Or plIndex &gt; 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 &apos; SFDocuments.SF_Register._CleanCacheEntry
+
+REM -----------------------------------------------------------------------------
Public Function _EventManager(Optional ByRef pvArgs As Variant) As Object
&apos;&apos;&apos; Returns a Document or Calc object corresponding with the active component
&apos;&apos;&apos; which triggered the event in argument
@@ -92,7 +172,32 @@ Try:
Finally:
Set _EventManager = oSource
Exit Function
-End Function &apos; SFDocuments.SF_Documents._EventManager
+End Function &apos; SFDocuments.SF_Register._EventManager
+
+REM -----------------------------------------------------------------------------
+Private Function _FindFormInCache(ByRef poForm As Object) As Object
+&apos;&apos;&apos; Find the Form based on its XUnoForm
+&apos;&apos;&apos; The Form must not be terminated
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; The corresponding Basic Form part or Nothing
+
+Dim oBasicForm As Object &apos; Return value
+Dim oCache As _FormCache &apos; 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 &apos; SFDocuments.SF_Register._FindFormInCache
REM -----------------------------------------------------------------------------
Public Function _NewDocument(Optional ByVal pvArgs As Variant) As Object