ScriptForge Don't watch close button of stored dialogs

Dialogs can either be stored in a library
or created from scratch.

When run in non-modal mode, the closing of
a stored dialog with the Close top-right cross
is done by LO correctly.

When the dialog is created from scratch,
a coded XTopWindowListener should do the job.

So far, the listener was activated for all dialogs.

Additionally the Console is a stored dialog.
When closed and relaunched, the processing
will now handle the window Close and
the built-in Close buttons identically, at
least apparently.

Change-Id: I29e0881989816fbf7e3e8bd12f59517bde4b3047
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184662
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
This commit is contained in:
Jean-Pierre Ledure
2025-04-26 15:50:03 +02:00
parent 44f182a0e0
commit e803595fc4
3 changed files with 44 additions and 40 deletions
+22 -24
View File
@@ -364,28 +364,25 @@ Try:
With _SF_
bConsoleActive = False
If Not IsNull(.ConsoleDialog) Then bConsoleActive = .ConsoleDialog._IsStillAlive(False) &apos; False to not raise an error
If bConsoleActive And Modal = False Then
&apos; Bring to front
.ConsoleDialog.Activate()
Else
&apos; Initialize dialog and fill with actual data
&apos; The dual modes (modal and non-modal) require to have 2 close buttons o/w only 1 is visible
&apos; - a usual OK button
&apos; - a Default button triggering the Close action
Set .ConsoleDialog = CreateScriptService(&quot;SFDialogs.Dialog&quot;, &quot;GlobalScope&quot;, &quot;ScriptForge&quot;, &quot;dlgConsole&quot;, _Context)
&apos; Setup labels and visibility
Set oModalBtn = .ConsoleDialog.Controls(&quot;CloseModalButton&quot;)
Set oNonModalBtn = .ConsoleDialog.Controls(&quot;CloseNonModalButton&quot;)
oModalBtn.Visible = Modal
oNonModalBtn.Visible = CBool(Not Modal)
&apos; Load console lines
_ConsoleRefresh()
.ConsoleDialog.Execute(Modal)
&apos; Terminate the modal dialog
If Modal Then
Set .ConsoleControl = .ConsoleControl.Dispose()
.ConsoleDialog.Terminate()
End If
If bConsoleActive And Modal = False Then _CloseConsole()
&apos; Initialize dialog and fill with actual data
&apos; The dual modes (modal and non-modal) require to have 2 close buttons o/w only 1 is visible
&apos; - a usual OK button
&apos; - a Default button triggering the Close action
Set .ConsoleDialog = CreateScriptService(&quot;SFDialogs.Dialog&quot;, &quot;GlobalScope&quot;, &quot;ScriptForge&quot;, &quot;dlgConsole&quot;, _Context)
&apos; Setup labels and visibility
Set oModalBtn = .ConsoleDialog.Controls(&quot;CloseModalButton&quot;)
Set oNonModalBtn = .ConsoleDialog.Controls(&quot;CloseNonModalButton&quot;)
oModalBtn.Visible = Modal
oNonModalBtn.Visible = CBool(Not Modal)
&apos; Load console lines
_ConsoleRefresh()
.ConsoleDialog.Execute(Modal)
&apos; Terminate the modal dialog
If Modal Then
Set .ConsoleControl = .ConsoleControl.Dispose()
.ConsoleDialog.Terminate()
End If
End With
@@ -1306,8 +1303,9 @@ Try:
With _SF_
If Not IsNull(.ConsoleDialog) Then
If .ConsoleDialog._IsStillAlive(False) Then &apos; False to not raise an error
Set .ConsoleControl = .ConsoleControl.Dispose()
Set .ConsoleDialog = .ConsoleDialog.Dispose()
.ConsoleDialog.Terminate()
Set .ConsoleControl = Nothing
Set .ConsoleDialog = Nothing
End If
End If
End With
+10 -10
View File
@@ -1,10 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="ScriptForge" library:readonly="false" library:passwordprotected="false">
<library:element library:name="SF_Exception"/>
<library:element library:name="SF_Dictionary"/>
<library:element library:name="SF_Session"/>
<library:element library:name="SF_Timer"/>
<library:element library:name="SF_FileSystem"/>
<library:element library:name="SF_Root"/>
<library:element library:name="__License"/>
<library:element library:name="SF_Utils"/>
<library:element library:name="_ModuleModel"/>
<library:element library:name="_CodingConventions"/>
<library:element library:name="SF_Services"/>
<library:element library:name="SF_UI"/>
<library:element library:name="SF_Exception"/>
<library:element library:name="SF_Dictionary"/>
<library:element library:name="SF_TextStream"/>
<library:element library:name="SF_Array"/>
<library:element library:name="SF_Region"/>
@@ -12,12 +20,4 @@
<library:element library:name="SF_PythonHelper"/>
<library:element library:name="SF_Platform"/>
<library:element library:name="SF_String"/>
<library:element library:name="SF_Session"/>
<library:element library:name="_ModuleModel"/>
<library:element library:name="_CodingConventions"/>
<library:element library:name="SF_Utils"/>
<library:element library:name="__License"/>
<library:element library:name="SF_Root"/>
<library:element library:name="SF_Timer"/>
<library:element library:name="SF_FileSystem"/>
</library:library>
+12 -6
View File
@@ -143,7 +143,9 @@ Private _MouseCounter As Integer &apos; Counts the number of events set on the
Private _MouseMotionListener As Object &apos; com.sun.star.awt.XMouseMotionListener
Private _OnMouseDragged As String &apos; Script to invoke when mouse is dragged from the dialog
Private _OnMouseMoved As String &apos; Script to invoke when mouse is moved across the dialog
Private _MouseMotionCounter As Integer &apos; Counts the number of events set on the listener
Private _MouseMotionCounter As Integer &apos; Counts the number of events set on the listener
&apos; ---
Private _TopWindowListener As Object &apos; com.sun.star.awt.XTopWindowListener
&apos; Persistent storage for controls
Private _ControlCache As Variant &apos; Array of control objects sorted like ElementNames of the Dialog model
@@ -2050,7 +2052,6 @@ 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;
@@ -2083,10 +2084,12 @@ 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;SFDialogs.SF_DialogListener._SFNONMODAL_&quot; _
, &quot;com.sun.star.awt.XTopWindowListener&quot;)
_DialogControl.addTopWindowListener(oListener)
&apos; Watch the window Close button - not to be done for stored dialogs
If _BuiltFromScratch Then
Set _TopWindowListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFNONMODAL_&quot; _
, &quot;com.sun.star.awt.XTopWindowListener&quot;)
_DialogControl.addTopWindowListener(_TopWindowListener)
End If
lExecute = 0
End If
@@ -3329,6 +3332,9 @@ Try:
Set _MouseListener = Nothing
Set _MouseMotionListener = Nothing
&apos; Clean close listener for non-modal dialog
If Not IsNull(_TopWindowListener) Then _DialogControl.removeTopWindowListener(_TopWindowListener)
Finally:
Exit Sub
End Sub &apos; SFDialogs.SF_Dialog._RemoveAllListeners