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                  &apos;  
SFDialogs.SF_Dialog.EndExecute
 REM 
-----------------------------------------------------------------------------
 Public Function Execute(Optional ByVal Modal As Variant) As Long
 &apos;&apos;&apos;     Display the dialog and wait for its termination by the 
user
+&apos;&apos;&apos;     When the window Close button is clicked:
+&apos;&apos;&apos;             - a modal dialog is stopped as if a Cancel 
button was pressed
+&apos;&apos;&apos;             - a non-modal dialog is made hidden
+&apos;&apos;&apos;     Termination and disposal of the dialog instance are 
roles of user scripts
 &apos;&apos;&apos;     Args:
 &apos;&apos;&apos;             Modal: False when non-modal dialog. Default = 
True
 &apos;&apos;&apos;     Returns:
@@ -1944,6 +1949,7 @@ Public Function Execute(Optional ByVal Modal As Variant) 
As Long
 &apos;&apos;&apos;                     Select Case lReturn
 
 Dim lExecute As Long                   &apos;  Return value
+Dim oListener As Object                        &apos;  
com.sun.star.awt.XTopWindowListener
 Const cstThisSub = &quot;SFDialogs.Dialog.Execute&quot;
 Const cstSubArgs = &quot;[Modal=True]&quot;
 
@@ -1976,6 +1982,9 @@ Try:
                &apos;  To make visible an on-the-fly designed dialog when 
macro triggered from Python
                _DialogModel.DesktopAsParent = Not ( _BuiltFromScratch And 
_BuiltInPython )
                _DialogControl.setVisible(True)
+               &apos;  Watch the window Close button
+               Set oListener = CreateUnoListener(&quot;_SFNONMODAL_&quot;, 
&quot;com.sun.star.awt.XTopWindowListener&quot;)
+               _DialogControl.addTopWindowListener(oListener)
                lExecute = 0
        End If
 
@@ -3119,4 +3128,4 @@ Private Function _Repr() As String
 End Function   &apos;  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
 &apos;&apos;&apos;                                     
 &apos;&apos;&apos;                     The described events are processed thru 
UNO listeners
 &apos;&apos;&apos;
-&apos;&apos;&apos;                     &quot;On&quot; events defined by code, 
prefix = _SFFOCUS_, _SFKEY_, _SFMOUSE_, _SFMOVE_, _SFITEM_, _SFADJUST_, _SFTEXT_
-&apos;&apos;&apos;                     -----------
+&apos;&apos;&apos;                     &quot;On&quot; events defined by code, 
prefix = _SFACTION_, _SFADJUST_, _SFFOCUS_, _SFKEY_, _SFMOUSE_,
+&apos;&apos;&apos;                     -----------                             
                                _SFMOVE_, _SFITEM_, _SFADJUST_, _SFTEXT_
 &apos;&apos;&apos;                             All event types applicable on 
dialogs and control types &lt;&gt; TreeControl
 &apos;&apos;&apos;                             The events MUST NOT be preset 
in the Basic IDE
 &apos;&apos;&apos;
+&apos;&apos;&apos;                     Closure of non-modal dialogs, prefix = 
_SFNONMODAL_
+&apos;&apos;&apos;                     --------------------
+&apos;&apos;&apos;                             Before LibreOffice 24.2 the 
window Close button was inoperant
+&apos;&apos;&apos;                             Now a 
com.sun.star.awt.XTopWindowListener listener is set on the dialog closure
+&apos;&apos;&apos;                             by the dialog.Execute(Modal := 
False) method
+&apos;&apos;&apos;
 
&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
 
 REM ================================================================= 
DEFINITIONS
@@ -393,6 +399,59 @@ REM 
----------------------------------------------------------------------------
 Public Sub _SFTEXT_disposing()
 End Sub
 
+REM ================================== PUBLIC METHODS (NON-MODAL DIALOGS 
CLOSURE)
+
+&apos;&apos;&apos;     Next events are watched by a 
com.sun.star.awt.XTopWindowListener set
+&apos;&apos;&apos;     when a non-modal dialog is executed.
+&apos;&apos;&apos;     The use of the window Close button triggers the clean 
termination
+&apos;&apos;&apos;     of the dialog.
+
+REM 
-----------------------------------------------------------------------------
+Sub _SFNONMODAL_disposing&apos;(Optional ByRef poEvent As Object)
+End Sub
+
+REM 
-----------------------------------------------------------------------------
+Sub _SFNONMODAL_windowOpened&apos;(Optional ByRef poEvent As Object)
+End Sub
+
+REM 
-----------------------------------------------------------------------------
+Sub _SFNONMODAL_windowClosing(Optional ByRef poEvent As Object)
+&apos;&apos;&apos;     Identify and hide the closing dialog
+
+Dim oDialog As Object                  &apos;  The dialog class instance
+
+       On Local Error GoTo Finally                     &apos;  Never abort here
+
+       If Not IsNull(poEvent) Then
+               Set oDialog = 
CreateScriptService(&quot;SFDialogs.DialogEvent&quot;, 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 
-----------------------------------------------------------------------------

Reply via email to