diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2020-12-17 17:20:45 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2020-12-17 18:39:46 +0100 |
commit | 554949d5cacaff2d0080b3e4f6124f8c5b045d6e (patch) | |
tree | 8c335dad14fe42d91634ce73830146f0ddb2e0f5 /wizards | |
parent | 668525eeeb4a84bafb90b1d920e68a1cc3e8dfaf (diff) |
ScriptForge - (SFDocuments) new Activate() method in SF_Form class
Activate
- the parent document if Writer
- the parent sheet if Calc
- the parent form document if Base
Change-Id: Idf2af0184111467d0a94fb27709fd6bb289c6414
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107888
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/sfdocuments/SF_Base.xba | 6 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Calc.xba | 6 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Form.xba | 58 |
3 files changed, 50 insertions, 20 deletions
diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba index 8ab19d5cf103..d0900849255f 100644 --- a/wizards/source/sfdocuments/SF_Base.xba +++ b/wizards/source/sfdocuments/SF_Base.xba @@ -67,7 +67,7 @@ Private _FormDocuments As Object REM ============================================================ MODULE CONSTANTS -Const ISBASEFORM = 2 ' Form is stored in a Base document +Const ISBASEFORM = 3 ' Form is stored in a Base document Const cstToken = "//" ' Form names accept special characters but not slashes REM ====================================================== CONSTRUCTOR/DESTRUCTOR @@ -238,7 +238,7 @@ Try: Set .[Me] = oForm Set .[_Parent] = [Me] ._DrawPage = cstDrawPage - ._UsualName = FormDocument & " : " & ._Name + ._FormDocumentName = FormDocument Set ._MainForm = oMainForm ._FormType = ISBASEFORM Set ._Form = oXForm @@ -710,4 +710,4 @@ Private Function _Repr() As String End Function ' SFDocuments.SF_Base._Repr REM ============================================ END OF SFDOCUMENTS.SF_BASE -</script:module> +</script:module>
\ No newline at end of file diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index 86825961630c..aeb19ffed9c7 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -869,8 +869,8 @@ Public Function Forms(Optional ByVal SheetName As Variant _ ''' An instance of the SF_Form class if Form exists ''' Example: ''' Dim myForm As Object, myList As Variant -''' myList = oDoc.Forms() -''' Set myForm = oDoc.Forms("myForm") +''' myList = oDoc.Forms("ThisSheet") +''' Set myForm = oDoc.Forms("ThisSheet", 0) Dim oForm As Object ' The new Form class instance Dim oMainForm As Object ' com.sun.star.comp.sdb.Content @@ -914,7 +914,7 @@ Try: Set .[Me] = oForm Set .[_Parent] = [Me] ._DrawPage = cstDrawPage - ._UsualName = SheetName & " : " & ._Name + ._SheetName = SheetName Set ._MainForm = Nothing ._FormType = ISCALCFORM Set ._Form = oXForm diff --git a/wizards/source/sfdocuments/SF_Form.xba b/wizards/source/sfdocuments/SF_Form.xba index ef83da999582..0b9303fae9b6 100644 --- a/wizards/source/sfdocuments/SF_Form.xba +++ b/wizards/source/sfdocuments/SF_Form.xba @@ -76,14 +76,15 @@ Private ServiceName As String ' Form location Private _Name As String ' Internal name of the form Private _DrawPage As Long ' Index in DrawPages collection -Private _UsualName As String ' Name as known by user +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 ' Form UNO references ' The forms container found in a Base document ' Vital for Base forms and subforms Private _MainForm As Object ' com.sun.star.comp.sdb.Content -' The entry to the interactions with the form. Set by the _IsStillAlive() method +' The entry to the interactions with the form. Validity checked by the _IsStillAlive() method ' Each method or property requiring that the form is opened should first invoke that method Private _Form As Object ' com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm Private _Database As Object ' Database class instance @@ -110,6 +111,8 @@ Private Sub Class_Initialize() ServiceName = "SFDocuments.Form" _Name = "" _DrawPage = -1 + _SheetName = "" + _FormDocumentName = "" _FormType = 0 Set _MainForm = Nothing Set _Form = Nothing @@ -124,6 +127,9 @@ End Sub ' SFDocuments.SF_Form Destructor REM ----------------------------------------------------------------------------- Public Function Dispose() As Variant + If Not IsNull(_Database) And (_FormType = ISDOCFORM Or _FormType = ISCALCFORM) Then + Set _Database = _Database.Dispose() + End If Call Class_Terminate() Set Dispose = Nothing End Function ' SFDocuments.SF_Form Explicit Destructor @@ -201,16 +207,19 @@ REM ===================================================================== METHOD REM ----------------------------------------------------------------------------- Public Function Activate() As Boolean ''' Set the focus on the current Form instance -''' Probably called from after an event occurrence or to focus on an open fForm +''' Probably called from after an event occurrence or to focus on an open Base form document +''' If the parent document is ... +''' Calc Activate the corresponding sheet +''' Writer Activate the parent document +''' Base Activate the parent form document ''' Args: ''' Returns: ''' True if focusing is successful ''' Example: -''' Dim oDlg As Object -''' Set oDlg = CreateScriptService(,, "myForm") ' Form stored in current document's standard library -''' oDlg.Activate() +''' myForm.Activate() Dim bActivate As Boolean ' Return value +Dim oContainer As Object ' com.sun.star.awt.XWindow Const cstThisSub = "SFDocuments.Form.Activate" Const cstSubArgs = "" @@ -222,6 +231,20 @@ Check: If Not _IsStillAlive() Then GoTo Finally End If Try: + Select Case _FormType + Case ISDOCFORM : bActivate = [_Parent].Activate() + Case ISCALCFORM : bActivate = [_Parent].Activate(_SheetName) + Case ISBASEFORM + Set oContainer = _MainForm.Component.CurrentController.Frame.ContainerWindow + With oContainer + If .isVisible() = False Then .setVisible(True) + .IsMinimized = False + .setFocus() + .toFront() ' Force window change in Linux + Wait 1 ' Bypass desynchro issue in Linux + End With + bActivate = True + End Select Finally: Activate = bActivate @@ -520,12 +543,14 @@ End Function ' SFDocuments.SF_Form._GetListener 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 partially (part related to open forms) disposed +''' If dead the actual instance is disposed ''' and the execution is cancelled when pbError = True (default) ''' Args: ''' pbError: if True (default), raise a fatal error Dim bAlive As Boolean ' Return value +Dim sName As String ' Alias of _Name +Dim sId As String ' Alias of FileIdent Check: On Local Error GoTo Catch ' Anticipate DisposedException errors or alike @@ -551,12 +576,14 @@ Finally: Catch: bAlive = False On Error GoTo 0 - ' Dispose the properties related to *open* forms - Set _Form = Nothing - If Not IsNull(_Database) And _FormType = ISDOCFORM Then Set _Database = _Database.Dispose() - Set _ControlCache = Nothing + ' Keep error message elements before disposing the instance + sName = _SheetName & _FormDocumentName ' At least one of them is a zero-length string + sName = Iif(Len(sName) > 0, "[" & sName & "].", "") & _Name + sId = [_Parent]._FileIdent() + ' Dispose the actual forms instance + Dispose() ' Display error message - If pbError Then ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, _Name, [_Parent]._FileIdent()) + If pbError Then ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, sName, sId) GoTo Finally End Function ' SFDocuments.SF_Form._IsStillAlive @@ -644,9 +671,12 @@ Private Function _Repr() As String ''' Return: ''' "[Form]: Name" - _Repr = "[Form]: " & _UsualName +Dim sParent As String ' To recognize the parent + + sParent = _SheetName & _FormDocumentName ' At least one of them is a zero-length string + _Repr = "[Form]: " & Iif(Len(sParent) > 0, sParent & "...", "") & _Name End Function ' SFDocuments.SF_Form._Repr REM ============================================ END OF SFDOCUMENTS.SF_FORM -</script:module> +</script:module>
\ No newline at end of file |