diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-11-21 16:25:55 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-11-23 15:13:46 +0100 |
commit | c46f0c9f6eb07db061d2f99c61c9ea05644a78ec (patch) | |
tree | 84346fccf04a608ff88c5c1d23d323592d66fb8c /sfx2 | |
parent | e0bd8f36964b84d7649b7705c3df98256d3ce627 (diff) |
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@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/preventduplicateinteraction.hxx | 112 | ||||
-rw-r--r-- | sfx2/source/appl/preventduplicateinteraction.cxx | 10 |
2 files changed, 121 insertions, 1 deletions
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: */ |