[Libreoffice-commits] core.git: framework/source sfx2/inc sfx2/source

Caolán McNamara caolanm at redhat.com
Thu Nov 23 14:14:16 UTC 2017


 framework/source/loadenv/loadenv.cxx             |   31 +-----
 sfx2/inc/preventduplicateinteraction.hxx         |  112 +++++++++++++++++++++++
 sfx2/source/appl/preventduplicateinteraction.cxx |   10 +-
 3 files changed, 129 insertions(+), 24 deletions(-)

New commits:
commit c46f0c9f6eb07db061d2f99c61c9ea05644a78ec
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Nov 21 16:25:55 2017 +0000

    Related: tdf#113160 set a temporary dialog parent during type detection
    
    to get warning dialogs that don't block the existing windows but whose
    lifecycle can be controlled to avoid crashes during exit
    
    Change-Id: I57965301c3d8a031acb33e83bf7715fe132385d0
    Reviewed-on: https://gerrit.libreoffice.org/45044
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index b76f13ef8c66..3bfd87e3244c 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -1042,32 +1042,17 @@ bool LoadEnv::impl_loadContent()
     bool bHidden    = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_HIDDEN(), false);
     bool bMinimized = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_MINIMIZED(), false);
     bool bPreview   = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_PREVIEW(), false);
+    css::uno::Reference< css::task::XStatusIndicator > xProgress  = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference< css::task::XStatusIndicator >());
 
-    if (!bHidden && !bMinimized && !bPreview)
+    if (!bHidden && !bMinimized && !bPreview && !xProgress.is())
     {
-        css::uno::Reference< css::task::XStatusIndicator > xProgress  = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference< css::task::XStatusIndicator >());
-        if (!xProgress.is())
+        // Note: it's an optional interface!
+        css::uno::Reference< css::task::XStatusIndicatorFactory > xProgressFactory(xTargetFrame, css::uno::UNO_QUERY);
+        if (xProgressFactory.is())
         {
-            // Note: it's an optional interface!
-            css::uno::Reference< css::task::XStatusIndicatorFactory > xProgressFactory(xTargetFrame, css::uno::UNO_QUERY);
-            if (xProgressFactory.is())
-            {
-                xProgress = xProgressFactory->createStatusIndicator();
-                if (xProgress.is())
-                    m_lMediaDescriptor[utl::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress;
-            }
-        }
-        if (!comphelper::LibreOfficeKit::isActive())
-        {
-            //now that we have a window, set things up so that warnings dialogs are relative to that window
-            css::uno::Reference<css::task::XInteractionHandler> xInteractionHandler(
-                task::InteractionHandler::createWithParent(m_xContext, xTargetFrame->getContainerWindow()),
-                css::uno::UNO_QUERY);
-            if (xInteractionHandler.is())
-            {
-                m_lMediaDescriptor[utl::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteractionHandler;
-                m_lMediaDescriptor[utl::MediaDescriptor::PROP_AUTHENTICATIONHANDLER()] <<= xInteractionHandler;
-            }
+            xProgress = xProgressFactory->createStatusIndicator();
+            if (xProgress.is())
+                m_lMediaDescriptor[utl::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress;
         }
     }
 
diff --git a/sfx2/inc/preventduplicateinteraction.hxx b/sfx2/inc/preventduplicateinteraction.hxx
index f7bec486a2cf..9e31a5bcc829 100644
--- a/sfx2/inc/preventduplicateinteraction.hxx
+++ b/sfx2/inc/preventduplicateinteraction.hxx
@@ -22,17 +22,127 @@
 
 #include <vector>
 
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/TerminationVetoException.hpp>
+#include <com/sun/star/frame/XTerminateListener2.hpp>
 #include <com/sun/star/task/XInteractionHandler2.hpp>
 #include <com/sun/star/task/XInteractionRequest.hpp>
 
+#include <cppuhelper/compbase.hxx>
 #include <cppuhelper/implbase.hxx>
 
+#include <sfx2/app.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <vcl/dialog.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/wrkwin.hxx>
+
 namespace com { namespace sun { namespace star { namespace uno {
     class XComponentContext;
 } } } }
 
 namespace sfx2 {
 
+inline void closedialogs(SystemWindow& rTopLevel, bool bCloseRoot)
+{
+    for (vcl::Window *pChild = rTopLevel.GetWindow(GetWindowType::FirstTopWindowChild); pChild; pChild = rTopLevel.GetWindow(GetWindowType::NextTopWindowSibling))
+        closedialogs(dynamic_cast<SystemWindow&>(*pChild), true);
+    if (bCloseRoot)
+        rTopLevel.Close();
+}
+
+// This is intended to be the parent for any warning dialogs launched
+// during the load of a document so that those dialogs are modal to
+// this window and don't block any existing windows.
+//
+// If there are dialog children open on exit then veto termination,
+// close the topmost dialog and retry termination.
+class WarningDialogsParent :
+    public cppu::WeakComponentImplHelper<css::frame::XTerminateListener>
+{
+private:
+    osl::Mutex m_aLock;
+    VclPtr<WorkWindow> m_xWin;
+    css::uno::Reference<css::awt::XWindow> m_xInterface;
+
+private:
+
+    DECL_STATIC_LINK(WarningDialogsParent, TerminateDesktop, void*, void);
+
+    void closewarningdialogs()
+    {
+        if (!m_xWin)
+            return;
+        SolarMutexGuard aSolarGuard;
+        closedialogs(dynamic_cast<SystemWindow&>(*m_xWin), false);
+    }
+
+public:
+
+    using cppu::WeakComponentImplHelperBase::disposing;
+    virtual void SAL_CALL disposing(const css::lang::EventObject&) override
+    {
+    }
+
+    // XTerminateListener
+    virtual void SAL_CALL queryTermination(const css::lang::EventObject&) override
+    {
+        closewarningdialogs();
+        Application::PostUserEvent(LINK(this, WarningDialogsParent, TerminateDesktop));
+        throw css::frame::TerminationVetoException();
+    }
+
+    virtual void SAL_CALL notifyTermination(const css::lang::EventObject&) override
+    {
+    }
+
+public:
+    WarningDialogsParent()
+        : cppu::WeakComponentImplHelper<css::frame::XTerminateListener>(m_aLock)
+    {
+        SolarMutexGuard aSolarGuard;
+        m_xWin = VclPtr<WorkWindow>::Create(nullptr, WB_STDWORK);
+        m_xWin->SetText("dialog parent for warning dialogs during load");
+        m_xInterface = VCLUnoHelper::GetInterface(m_xWin);
+    }
+
+    virtual ~WarningDialogsParent() override
+    {
+        closewarningdialogs();
+        m_xWin.disposeAndClear();
+    }
+
+    const css::uno::Reference<css::awt::XWindow>& GetDialogParent() const
+    {
+        return m_xInterface;
+    }
+};
+
+class WarningDialogsParentScope
+{
+private:
+    css::uno::Reference<css::frame::XDesktop> m_xDesktop;
+    rtl::Reference<WarningDialogsParent> m_xListener;
+
+public:
+    WarningDialogsParentScope(const css::uno::Reference<css::uno::XComponentContext>& rContext)
+        : m_xDesktop(css::frame::Desktop::create(rContext), css::uno::UNO_QUERY_THROW)
+        , m_xListener(new WarningDialogsParent)
+    {
+        m_xDesktop->addTerminateListener(m_xListener.get());
+    }
+
+    const css::uno::Reference<css::awt::XWindow>& GetDialogParent() const
+    {
+        return m_xListener->GetDialogParent();
+    }
+
+    ~WarningDialogsParentScope()
+    {
+        m_xDesktop->removeTerminateListener(m_xListener.get());
+    }
+};
+
 /**
     @short      Prevent us from showing the same interaction more than once during
                 the same transaction.
@@ -99,6 +209,8 @@ class PreventDuplicateInteraction : private ThreadHelpBase2
             if it's not blocked. */
         css::uno::Reference< css::task::XInteractionHandler > m_xHandler;
 
+        std::unique_ptr<WarningDialogsParentScope> m_xWarningDialogsParent;
+
         /** This list describe which and how incoming interactions must be handled.
             Further it contains all collected information after this interaction
             object was used.*/
diff --git a/sfx2/source/appl/preventduplicateinteraction.cxx b/sfx2/source/appl/preventduplicateinteraction.cxx
index bf7eeab13a16..009754cae517 100644
--- a/sfx2/source/appl/preventduplicateinteraction.cxx
+++ b/sfx2/source/appl/preventduplicateinteraction.cxx
@@ -19,6 +19,7 @@
 
 #include <preventduplicateinteraction.hxx>
 
+#include <comphelper/processfactory.hxx>
 #include <osl/diagnose.h>
 
 #include <com/sun/star/task/InteractionHandler.hpp>
@@ -53,7 +54,9 @@ void PreventDuplicateInteraction::useDefaultUUIHandler()
     aLock.clear();
     // <- SAFE
 
-    css::uno::Reference< css::task::XInteractionHandler > xHandler( css::task::InteractionHandler::createWithParent( m_xContext, nullptr ), css::uno::UNO_QUERY_THROW );
+    m_xWarningDialogsParent.reset(new WarningDialogsParentScope(m_xContext));
+    css::uno::Reference<css::task::XInteractionHandler> xHandler(css::task::InteractionHandler::createWithParent(
+        m_xContext, m_xWarningDialogsParent->GetDialogParent()), css::uno::UNO_QUERY_THROW);
 
     // SAFE ->
     aLock.reset();
@@ -227,6 +230,11 @@ bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type&
     return false;
 }
 
+IMPL_STATIC_LINK_NOARG(WarningDialogsParent, TerminateDesktop, void*, void)
+{
+    css::frame::Desktop::create(comphelper::getProcessComponentContext())->terminate();
+}
+
 } // namespace sfx2
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list