vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx   |    9 +++-
 vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx |    5 ++
 vcl/unx/gtk/fpicker/SalGtkPicker.cxx       |   56 +++++++++++++++++++++++++----
 vcl/unx/gtk/fpicker/SalGtkPicker.hxx       |   10 +++--
 4 files changed, 67 insertions(+), 13 deletions(-)

New commits:
commit 6748074004a173876cfd54bff67e24865ba41acb
Author: Caolán McNamara <caol...@redhat.com>
Date:   Tue Aug 15 16:07:47 2017 +0100

    Resolves: tdf#111760 cancel file dialog on terminate
    
    schedule cancel dialog in query termination, take ownership of the desktop 
and
    re-schedule terminate to be re-attempted after the dialog is cancelled
    
    Change-Id: I5c061b47959baba138c6c23aaae365f28e9cf167
    Reviewed-on: https://gerrit.libreoffice.org/41181
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx 
b/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx
index 222ce648f435..f487bed1670e 100644
--- a/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx
+++ b/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx
@@ -26,6 +26,7 @@
 #include <config_gio.h>
 
 #include <com/sun/star/awt/Toolkit.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
@@ -886,10 +887,14 @@ sal_Int16 SAL_CALL SalGtkFilePicker::execute()
         awt::Toolkit::create(m_xContext),
         UNO_QUERY_THROW );
 
+    uno::Reference< frame::XDesktop > xDesktop(
+        frame::Desktop::create(m_xContext),
+        UNO_QUERY_THROW );
+
     GtkWindow *pParent = RunDialog::GetTransientFor();
     if (pParent)
         gtk_window_set_transient_for(GTK_WINDOW(m_pDialog), pParent);
-    RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit);
+    RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit, xDesktop);
     uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog);
     while( GTK_RESPONSE_NO == btn )
     {
@@ -982,7 +987,7 @@ sal_Int16 SAL_CALL SalGtkFilePicker::execute()
                             if (pParent)
                                 gtk_window_set_transient_for(GTK_WINDOW(dlg), 
pParent);
 #endif
-                            RunDialog* pAnotherDialog = new RunDialog(dlg, 
xToolkit);
+                            RunDialog* pAnotherDialog = new RunDialog(dlg, 
xToolkit, xDesktop);
                             uno::Reference < awt::XTopWindowListener > 
xAnotherLifeCycle(pAnotherDialog);
                             btn = pAnotherDialog->run();
 
diff --git a/vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx 
b/vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx
index 98d109f50878..015f0dfdb269 100644
--- a/vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx
+++ b/vcl/unx/gtk/fpicker/SalGtkFolderPicker.cxx
@@ -26,6 +26,7 @@
 #include <config_gio.h>
 
 #include <com/sun/star/awt/Toolkit.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
@@ -136,10 +137,12 @@ sal_Int16 SAL_CALL SalGtkFolderPicker::execute()
         awt::Toolkit::create(m_xContext),
         uno::UNO_QUERY);
 
+    uno::Reference<frame::XDesktop> 
xDesktop(frame::Desktop::create(m_xContext), uno::UNO_QUERY);
+
     GtkWindow *pParent = RunDialog::GetTransientFor();
     if (pParent)
         gtk_window_set_transient_for(GTK_WINDOW(m_pDialog), pParent);
-    RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit);
+    RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit, xDesktop);
     uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog);
     gint nStatus = pRunDialog->run();
     switch( nStatus )
diff --git a/vcl/unx/gtk/fpicker/SalGtkPicker.cxx 
b/vcl/unx/gtk/fpicker/SalGtkPicker.cxx
index e025583aa73d..6c7433b3c5f2 100644
--- a/vcl/unx/gtk/fpicker/SalGtkPicker.cxx
+++ b/vcl/unx/gtk/fpicker/SalGtkPicker.cxx
@@ -23,6 +23,7 @@
 #undef _LINUX_SOURCE_COMPAT
 #endif
 
+#include <com/sun/star/frame/TerminationVetoException.hpp>
 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
 #include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
@@ -119,9 +120,13 @@ GtkWindow* RunDialog::GetTransientFor()
     return pParent;
 }
 
-RunDialog::RunDialog( GtkWidget *pDialog, uno::Reference< 
awt::XExtendedToolkit > const & rToolkit ) :
-    cppu::WeakComponentImplHelper< awt::XTopWindowListener, 
frame::XTerminateListener >( maLock ),
-    mpDialog(pDialog), mxToolkit(rToolkit)
+RunDialog::RunDialog(GtkWidget *pDialog, const 
uno::Reference<awt::XExtendedToolkit>& rToolkit,
+                                         const 
uno::Reference<frame::XDesktop>& rDesktop)
+    : cppu::WeakComponentImplHelper<awt::XTopWindowListener, 
frame::XTerminateListener>(maLock)
+    , mpDialog(pDialog)
+    , mbTerminateDesktop(false)
+    , mxToolkit(rToolkit)
+    , mxDesktop(rDesktop)
 {
 }
 
@@ -153,13 +158,17 @@ void SAL_CALL RunDialog::windowOpened(const 
css::lang::EventObject& e)
 
 void SAL_CALL RunDialog::queryTermination( const css::lang::EventObject& )
 {
+    SolarMutexGuard g;
+
+    g_timeout_add_full(G_PRIORITY_HIGH_IDLE, 0, 
reinterpret_cast<GSourceFunc>(canceldialog), this, nullptr);
+
+    mbTerminateDesktop = true;
+
+    throw css::frame::TerminationVetoException();
 }
 
 void SAL_CALL RunDialog::notifyTermination( const css::lang::EventObject& )
 {
-    SolarMutexGuard g;
-
-    g_timeout_add_full(G_PRIORITY_HIGH_IDLE, 0, 
reinterpret_cast<GSourceFunc>(canceldialog), this, nullptr);
 }
 
 void RunDialog::cancel()
@@ -168,19 +177,52 @@ void RunDialog::cancel()
     gtk_widget_hide( mpDialog );
 }
 
+namespace
+{
+    class ExecuteInfo
+    {
+    private:
+        css::uno::Reference<css::frame::XDesktop> mxDesktop;
+    public:
+        ExecuteInfo(const css::uno::Reference<css::frame::XDesktop>& rDesktop)
+            : mxDesktop(rDesktop)
+        {
+        }
+        void terminate()
+        {
+            mxDesktop->terminate();
+        }
+    };
+}
+
 gint RunDialog::run()
 {
     if (mxToolkit.is())
         mxToolkit->addTopWindowListener(this);
 
-    gint nStatus = gtk_dialog_run( GTK_DIALOG( mpDialog ) );
+    mxDesktop->addTerminateListener(this);
+    gint nStatus = gtk_dialog_run(GTK_DIALOG(mpDialog));
+    mxDesktop->removeTerminateListener(this);
 
     if (mxToolkit.is())
         mxToolkit->removeTopWindowListener(this);
 
+    if (mbTerminateDesktop)
+    {
+        ExecuteInfo* pExecuteInfo = new ExecuteInfo(mxDesktop);
+        Application::PostUserEvent(LINK(nullptr, RunDialog, TerminateDesktop), 
pExecuteInfo);
+    }
+
     return nStatus;
 }
 
+IMPL_STATIC_LINK(RunDialog, TerminateDesktop, void*, p, void)
+{
+    ExecuteInfo* pExecuteInfo = static_cast<ExecuteInfo*>(p);
+    pExecuteInfo->terminate();
+    delete pExecuteInfo;
+}
+
 SalGtkPicker::SalGtkPicker( const uno::Reference<uno::XComponentContext>& 
xContext )
     : m_pDialog( nullptr ), m_xContext( xContext )
 {
diff --git a/vcl/unx/gtk/fpicker/SalGtkPicker.hxx 
b/vcl/unx/gtk/fpicker/SalGtkPicker.hxx
index c90504f3aec7..6af2459562eb 100644
--- a/vcl/unx/gtk/fpicker/SalGtkPicker.hxx
+++ b/vcl/unx/gtk/fpicker/SalGtkPicker.hxx
@@ -25,6 +25,7 @@
 
 #include <com/sun/star/awt/XTopWindowListener.hpp>
 #include <com/sun/star/awt/XExtendedToolkit.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
 #include <com/sun/star/frame/XTerminateListener.hpp>
 
 #include <gtk/gtk.h>
@@ -79,7 +80,10 @@ class RunDialog :
 private:
     osl::Mutex maLock;
     GtkWidget *mpDialog;
-    css::uno::Reference< css::awt::XExtendedToolkit>  mxToolkit;
+    bool mbTerminateDesktop;
+    css::uno::Reference<css::awt::XExtendedToolkit> mxToolkit;
+    css::uno::Reference<css::frame::XDesktop> mxDesktop;
+    DECL_STATIC_LINK(RunDialog, TerminateDesktop, void*, void);
 public:
 
     // XTopWindowListener
@@ -98,8 +102,8 @@ public:
     virtual void SAL_CALL notifyTermination( const css::lang::EventObject& 
aEvent ) override;
 public:
     RunDialog(GtkWidget *pDialog,
-        css::uno::Reference< css::awt::XExtendedToolkit > const &rToolkit
-        );
+        const css::uno::Reference<css::awt::XExtendedToolkit>& rToolkit,
+        const css::uno::Reference<css::frame::XDesktop>& rDesktop);
     virtual ~RunDialog() override;
     gint run();
     void cancel();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to