wizards/source/sfdialogs/SF_Dialog.xba | 11 +++- wizards/source/sfdialogs/SF_DialogListener.xba | 63 ++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 3 deletions(-)
New commits: commit 5111caa82918ce02f12abfd02cd61ab9942a3392 Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Fri Aug 9 18:03:01 2024 +0200 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Sat Aug 10 11:18:07 2024 +0200 ScriptForge (SFDialogs) Closure of non-modal dialogs Before LibreOffice 24.2 the window Close button was inoperant. Now a com.sun.star.awt.XTopWindowListener listener is set on the dialog closure by the dialog.Execute(Modal := False) method. In summary, when the window Close button is clicked: - a modal dialog is stopped as if a Cancel button was pressed - a non-modal dialog is made hidden Termination and disposal of the dialog instance remain roles for user scripts. This change requires minor changes in the help documentation. Change-Id: Ia4a3e39422b4050fc48f5552fadecfd984e46524 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171703 Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> Tested-by: Jenkins diff --git a/wizards/source/sfdialogs/SF_Dialog.xba b/wizards/source/sfdialogs/SF_Dialog.xba index bbbeddd111d1..3951a1ea2658 100644 --- a/wizards/source/sfdialogs/SF_Dialog.xba +++ b/wizards/source/sfdialogs/SF_Dialog.xba @@ -470,6 +470,7 @@ Check: End If Try: If Not IsNull(_DialogControl) Then + _DialogControl.setVisible(True) _DialogControl.setFocus() bActivate = True End If @@ -1931,6 +1932,10 @@ End Sub ' SFDialogs.SF_Dialog.EndExecute REM ----------------------------------------------------------------------------- Public Function Execute(Optional ByVal Modal As Variant) As Long ''' Display the dialog and wait for its termination by the user +''' When the window Close button is clicked: +''' - a modal dialog is stopped as if a Cancel button was pressed +''' - a non-modal dialog is made hidden +''' Termination and disposal of the dialog instance are roles of user scripts ''' Args: ''' Modal: False when non-modal dialog. Default = True ''' Returns: @@ -1944,6 +1949,7 @@ Public Function Execute(Optional ByVal Modal As Variant) As Long ''' Select Case lReturn Dim lExecute As Long ' Return value +Dim oListener As Object ' com.sun.star.awt.XTopWindowListener Const cstThisSub = "SFDialogs.Dialog.Execute" Const cstSubArgs = "[Modal=True]" @@ -1976,6 +1982,9 @@ Try: ' To make visible an on-the-fly designed dialog when macro triggered from Python _DialogModel.DesktopAsParent = Not ( _BuiltFromScratch And _BuiltInPython ) _DialogControl.setVisible(True) + ' Watch the window Close button + Set oListener = CreateUnoListener("_SFNONMODAL_", "com.sun.star.awt.XTopWindowListener") + _DialogControl.addTopWindowListener(oListener) lExecute = 0 End If @@ -3119,4 +3128,4 @@ Private Function _Repr() As String End Function ' SFDialogs.SF_Dialog._Repr REM ============================================ END OF SFDIALOGS.SF_DIALOG -</script:module> +</script:module> \ No newline at end of file diff --git a/wizards/source/sfdialogs/SF_DialogListener.xba b/wizards/source/sfdialogs/SF_DialogListener.xba index 54dc8754529c..60c5e9a34499 100644 --- a/wizards/source/sfdialogs/SF_DialogListener.xba +++ b/wizards/source/sfdialogs/SF_DialogListener.xba @@ -31,11 +31,17 @@ Option Explicit ''' ''' The described events are processed thru UNO listeners ''' -''' "On" events defined by code, prefix = _SFFOCUS_, _SFKEY_, _SFMOUSE_, _SFMOVE_, _SFITEM_, _SFADJUST_, _SFTEXT_ -''' ----------- +''' "On" events defined by code, prefix = _SFACTION_, _SFADJUST_, _SFFOCUS_, _SFKEY_, _SFMOUSE_, +''' ----------- _SFMOVE_, _SFITEM_, _SFADJUST_, _SFTEXT_ ''' All event types applicable on dialogs and control types <> TreeControl ''' The events MUST NOT be preset in the Basic IDE ''' +''' Closure of non-modal dialogs, prefix = _SFNONMODAL_ +''' -------------------- +''' Before LibreOffice 24.2 the window Close button was inoperant +''' Now a com.sun.star.awt.XTopWindowListener listener is set on the dialog closure +''' by the dialog.Execute(Modal := False) method +''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' REM ================================================================= DEFINITIONS @@ -393,6 +399,59 @@ REM ---------------------------------------------------------------------------- Public Sub _SFTEXT_disposing() End Sub +REM ================================== PUBLIC METHODS (NON-MODAL DIALOGS CLOSURE) + +''' Next events are watched by a com.sun.star.awt.XTopWindowListener set +''' when a non-modal dialog is executed. +''' The use of the window Close button triggers the clean termination +''' of the dialog. + +REM ----------------------------------------------------------------------------- +Sub _SFNONMODAL_disposing'(Optional ByRef poEvent As Object) +End Sub + +REM ----------------------------------------------------------------------------- +Sub _SFNONMODAL_windowOpened'(Optional ByRef poEvent As Object) +End Sub + +REM ----------------------------------------------------------------------------- +Sub _SFNONMODAL_windowClosing(Optional ByRef poEvent As Object) +''' Identify and hide the closing dialog + +Dim oDialog As Object ' The dialog class instance + + On Local Error GoTo Finally ' Never abort here + + If Not IsNull(poEvent) Then + Set oDialog = CreateScriptService("SFDialogs.DialogEvent", poEvent) + If Not IsNull(oDialog) Then oDialog.Visible = False + End If + +Finally: + On Local Error GoTo 0 + Exit Sub +End Sub + +REM ----------------------------------------------------------------------------- +Sub _SFNONMODAL_windowClosed() +End Sub + +REM ----------------------------------------------------------------------------- +Sub _SFNONMODAL_windowMinimized() +End Sub + +REM ----------------------------------------------------------------------------- +Sub _SFNONMODAL_windowNormalized() +End Sub + +REM ----------------------------------------------------------------------------- +Sub _SFNONMODAL_windowActivated() +End Sub + +REM ----------------------------------------------------------------------------- +Sub _SFNONMODAL_windowDeactivated() +End Sub + REM ============================================================= PRIVATE METHODS REM -----------------------------------------------------------------------------