[Libreoffice-commits] core.git: Branch 'private/swe/libreoffice-5-2+backports' - 8 commits - desktop/qa filter/CppunitTest_filter_priority.mk filter/source framework/Library_fwe.mk framework/source include/comphelper include/framework include/tools include/vcl sfx2/inc sfx2/Library_sfx.mk sfx2/source sw/source tools/source uui/source vcl/source

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Thu Dec 7 13:54:36 UTC 2017


 desktop/qa/desktop_lib/test_desktop_lib.cxx      |   58 +++++++++++++++++++++--
 filter/CppunitTest_filter_priority.mk            |    1 
 filter/source/config/cache/typedetection.cxx     |   12 +++-
 filter/source/config/cache/typedetection.hxx     |   41 +++++++++++++++-
 framework/Library_fwe.mk                         |    2 
 framework/source/dispatch/closedispatcher.cxx    |    2 
 framework/source/loadenv/loadenv.cxx             |   36 +++++++++++---
 include/comphelper/propertysequence.hxx          |   18 +++++++
 include/tools/errinf.hxx                         |    5 +
 include/vcl/dialog.hxx                           |    2 
 sfx2/Library_sfx.mk                              |    1 
 sfx2/inc/preventduplicateinteraction.hxx         |   21 ++++----
 sfx2/source/appl/appopen.cxx                     |    6 +-
 sfx2/source/appl/preventduplicateinteraction.cxx |   25 +++++++--
 sw/source/core/frmedt/fetab.cxx                  |   20 +++----
 tools/source/ref/errinf.cxx                      |    7 +-
 uui/source/iahndl.cxx                            |   10 ++-
 vcl/source/window/dialog.cxx                     |    2 
 vcl/source/window/msgbox.cxx                     |    4 -
 19 files changed, 212 insertions(+), 61 deletions(-)

New commits:
commit 6709e2d08a7bf9f8e3956e1e16a56149e78b995c
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Tue Dec 5 15:46:22 2017 +0100

    Rename InitAnySequence -> InitAnyPropertySequence
    
    partial cherry-pick of c23cc5d7551a0ed0e3dad2d33dd00b38643456a1
    
    Change-Id: Idb266d42c5f9fb09f04b13e78c037f5df9c32079

diff --git a/include/comphelper/propertysequence.hxx b/include/comphelper/propertysequence.hxx
index 6af3bb389929..d6c00775a968 100644
--- a/include/comphelper/propertysequence.hxx
+++ b/include/comphelper/propertysequence.hxx
@@ -14,7 +14,6 @@
 #include <initializer_list>
 #include <com/sun/star/uno/Any.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
-#include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/beans/PropertyValue.hpp>
 
 namespace comphelper
@@ -40,14 +39,14 @@ namespace comphelper
     ///
     /// This is particularly useful for creation of sequences that are later
     /// unwrapped using comphelper::SequenceAsHashMap.
-    inline css::uno::Sequence< css::uno::Any > InitAnySequence(
+    inline css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(
         ::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
     {
         css::uno::Sequence<css::uno::Any> vResult{static_cast<sal_Int32>(vInit.size())};
         size_t nCount{0};
         for(const auto& aEntry : vInit)
         {
-            vResult[nCount] <<= css::beans::NamedValue(aEntry.first, aEntry.second);
+            vResult[nCount] <<= css::beans::PropertyValue(aEntry.first, -1, aEntry.second, css::beans::PropertyState_DIRECT_VALUE);
             ++nCount;
         }
         return vResult;
commit 8c3d3507a0a630925b5b0ccb8bee57790aab208d
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jul 19 08:35:26 2017 +0200

    comphelper: Allow initializer lists for Sequences of NamedValues.
    
    This is particularly useful for creation of sequences that are later
    unwrapped using comphelper::SequenceAsHashMap.
    
    Eg.
    
        uno::Sequence<uno::Any> aArguments(comphelper::InitAnySequence(
        {
            {"SomethingNamed", uno::makeAny(true)},
        }));
    
        Reference<XExporter> xExporter(aFactory->createInstanceWithArguments(..., aArguments), UNO_QUERY);
    
    and in the implementation where the arguments are consumed:
    
        comphelper::SequenceAsHashMap aArgumentsMap(rArguments);
        mbSomething = aArgumentsMap.getUnpackedValueOrDefault("SomethingNamed", false);
    
    Change-Id: Ib1135078a99ca08f50bf51184f2ec7d13f5e6b4d
    Reviewed-on: https://gerrit.libreoffice.org/40201
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/include/comphelper/propertysequence.hxx b/include/comphelper/propertysequence.hxx
index 28561a6904d7..6af3bb389929 100644
--- a/include/comphelper/propertysequence.hxx
+++ b/include/comphelper/propertysequence.hxx
@@ -14,10 +14,12 @@
 #include <initializer_list>
 #include <com/sun/star/uno/Any.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/beans/PropertyValue.hpp>
 
 namespace comphelper
 {
+    /// Init list for property sequences.
     inline css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(
         ::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
     {
@@ -33,6 +35,23 @@ namespace comphelper
         }
         return vResult;
     }
+
+    /// Init list for property sequences that wrap the NamedValues in Anys.
+    ///
+    /// This is particularly useful for creation of sequences that are later
+    /// unwrapped using comphelper::SequenceAsHashMap.
+    inline css::uno::Sequence< css::uno::Any > InitAnySequence(
+        ::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
+    {
+        css::uno::Sequence<css::uno::Any> vResult{static_cast<sal_Int32>(vInit.size())};
+        size_t nCount{0};
+        for(const auto& aEntry : vInit)
+        {
+            vResult[nCount] <<= css::beans::NamedValue(aEntry.first, aEntry.second);
+            ++nCount;
+        }
+        return vResult;
+    }
 }   // namespace comphelper
 
 
commit e438b6f7db20854463849366045d4da79adeb201
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Nov 23 14:05:26 2017 +0000

    set new document window as parent for dialogs during load
    
    and exit typedetection early and completely if application quits
    while detecting
    
    During typedetection, before loading proper, we have the hidden window as
    parent so warnings are not modal to existing windows and they are cancelled on
    exit.
    
    Once we do have a window, then reinit interaction handler to have that window
    as the parent for any further dialogs.
    
    Change-Id: I5c6711557266bf7d1eb9291f1c454cbfaf766886
    Reviewed-on: https://gerrit.libreoffice.org/45148
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/filter/CppunitTest_filter_priority.mk b/filter/CppunitTest_filter_priority.mk
index e5046ac0e3a2..d412b922e7ea 100644
--- a/filter/CppunitTest_filter_priority.mk
+++ b/filter/CppunitTest_filter_priority.mk
@@ -11,6 +11,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,filter_priority))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,filter_priority))
 $(eval $(call gb_CppunitTest_use_ure,filter_priority))
+$(eval $(call gb_CppunitTest_use_vcl,filter_priority))
 
 $(eval $(call gb_CppunitTest_use_configuration,filter_priority))
 
diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index 278115c8af6c..74b0b978f5f6 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -21,6 +21,7 @@
 #include "constant.hxx"
 
 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/util/URLTransformer.hpp>
 #include <com/sun/star/util/XURLTransformer.hpp>
 
@@ -50,7 +51,10 @@ namespace filter{
 
 TypeDetection::TypeDetection(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
    : m_xContext(rxContext)
+   , m_xTerminateListener(new TerminateDetection(this))
+   , m_bCancel(false)
 {
+    css::frame::Desktop::create(m_xContext)->addTerminateListener(m_xTerminateListener.get());
     BaseContainer::init(rxContext                                     ,
                         TypeDetection::impl_getImplementationName()   ,
                         TypeDetection::impl_getSupportedServiceNames(),
@@ -60,6 +64,7 @@ TypeDetection::TypeDetection(const css::uno::Reference< css::uno::XComponentCont
 
 TypeDetection::~TypeDetection()
 {
+    css::frame::Desktop::create(m_xContext)->removeTerminateListener(m_xTerminateListener.get());
 }
 
 
@@ -426,18 +431,17 @@ OUString SAL_CALL TypeDetection::queryTypeByDescriptor(css::uno::Sequence< css::
         if (lFlatTypes.size()>0)
             sType = impl_detectTypeFlatAndDeep(stlDescriptor, lFlatTypes, bAllowDeep, lUsedDetectors, sLastChance);
 
-
         // flat detection failed
         // pure deep detection failed
         // => ask might existing InteractionHandler
         // means: ask user for its decision
-        if (sType.isEmpty())
+        if (sType.isEmpty() && !m_bCancel)
             sType = impl_askUserForTypeAndFilterIfAllowed(stlDescriptor);
 
 
         // no real detected type - but a might valid one.
         // update descriptor and set last chance for return.
-        if (sType.isEmpty() && !sLastChance.isEmpty())
+        if (sType.isEmpty() && !sLastChance.isEmpty() && !m_bCancel)
         {
             OSL_FAIL("set first flat detected type without a registered deep detection service as \"last chance\" ... nevertheless some other deep detections said \"NO\". I TRY IT!");
             sType = sLastChance;
@@ -898,7 +902,7 @@ OUString TypeDetection::impl_detectTypeFlatAndDeep(      utl::MediaDescriptor& r
     //    obtained from the cache                 => ignore it, and continue with search
 
     for (FlatDetection::const_iterator pFlatIt  = lFlatTypes.begin();
-                                       pFlatIt != lFlatTypes.end()  ;
+                                       pFlatIt != lFlatTypes.end() && !m_bCancel;
                                      ++pFlatIt                      )
     {
         const FlatDetectionInfo& aFlatTypeInfo = *pFlatIt;
diff --git a/filter/source/config/cache/typedetection.hxx b/filter/source/config/cache/typedetection.hxx
index 548a14343925..f948e6522697 100644
--- a/filter/source/config/cache/typedetection.hxx
+++ b/filter/source/config/cache/typedetection.hxx
@@ -21,14 +21,16 @@
 
 #include "basecontainer.hxx"
 #include <com/sun/star/document/XTypeDetection.hpp>
+#include <com/sun/star/frame/XTerminateListener.hpp>
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <unotools/mediadescriptor.hxx>
+#include <cppuhelper/compbase.hxx>
 #include <cppuhelper/implbase.hxx>
 
-
 namespace filter{ namespace config {
 
+class TerminateDetection;
 
 /** @short      implements the service <type scope="com.sun.star.document">TypeDetection</type>.
  */
@@ -39,6 +41,8 @@ class TypeDetection : public ::cppu::ImplInheritanceHelper< BaseContainer
 // native interface
 
     css::uno::Reference< css::uno::XComponentContext > m_xContext;
+    rtl::Reference<TerminateDetection> m_xTerminateListener;
+    bool m_bCancel;
 
 public:
 
@@ -53,6 +57,11 @@ public:
      */
     explicit TypeDetection(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
 
+    void cancel()
+    {
+        m_bCancel = true;
+    }
+
 
     /** @short  standard dtor.
      */
@@ -365,6 +374,36 @@ public:
     static css::uno::Reference< css::uno::XInterface > impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
 };
 
+class TerminateDetection : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener>
+{
+private:
+    osl::Mutex m_aLock;
+    TypeDetection* m_pTypeDetection;
+
+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
+    {
+        m_pTypeDetection->cancel();
+    }
+
+    virtual void SAL_CALL notifyTermination(const css::lang::EventObject&) override
+    {
+    }
+
+    TerminateDetection(TypeDetection* pTypeDetection)
+        : cppu::WeakComponentImplHelper<css::frame::XTerminateListener>(m_aLock)
+        , m_pTypeDetection(pTypeDetection)
+    {
+    }
+};
+
 }}
 
 #endif // INCLUDED_FILTER_SOURCE_CONFIG_CACHE_TYPEDETECTION_HXX
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index 5e51c42bee83..5961c57596ab 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -28,6 +28,7 @@
 #include <services.h>
 #include <comphelper/interaction.hxx>
 #include <comphelper/lok.hxx>
+#include <comphelper/propertysequence.hxx>
 #include <framework/interaction.hxx>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/configuration.hxx>
@@ -55,6 +56,7 @@
 #include <com/sun/star/frame/FrameSearchFlag.hpp>
 #include <com/sun/star/frame/XDispatchProvider.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/lang/DisposedException.hpp>
 #include <com/sun/star/io/XInputStream.hpp>
@@ -1071,15 +1073,35 @@ bool LoadEnv::impl_loadContent()
     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 && !xProgress.is())
+    if (!bHidden && !bMinimized && !bPreview)
     {
-        // Note: it's an optional interface!
-        css::uno::Reference< css::task::XStatusIndicatorFactory > xProgressFactory(xTargetFrame, css::uno::UNO_QUERY);
-        if (xProgressFactory.is())
+        if (!xProgress.is())
         {
-            xProgress = xProgressFactory->createStatusIndicator();
-            if (xProgress.is())
-                m_lMediaDescriptor[utl::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress;
+            // 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;
+            }
+        }
+
+        // Now that we have a target window into which we can load, reinit the interaction handler to have this
+        // window as its parent for modal dialogs and ensure the window is visible
+        css::uno::Reference< css::task::XInteractionHandler > xInteraction = m_lMediaDescriptor.getUnpackedValueOrDefault(
+                                                                                utl::MediaDescriptor::PROP_INTERACTIONHANDLER(),
+                                                                                css::uno::Reference< css::task::XInteractionHandler >());
+        css::uno::Reference<css::lang::XInitialization> xHandler(xInteraction, css::uno::UNO_QUERY);
+        if (xHandler.is())
+        {
+            css::uno::Reference<css::awt::XWindow> xWindow = xTargetFrame->getContainerWindow();
+            uno::Sequence<uno::Any> aArguments(comphelper::InitAnyPropertySequence(
+            {
+                {"Parent", uno::Any(xWindow)}
+            }));
+            xHandler->initialize(aArguments);
+            impl_makeFrameWindowVisible(xWindow, false);
         }
     }
 
diff --git a/sfx2/inc/preventduplicateinteraction.hxx b/sfx2/inc/preventduplicateinteraction.hxx
index a7d1b097134f..f9097576e480 100644
--- a/sfx2/inc/preventduplicateinteraction.hxx
+++ b/sfx2/inc/preventduplicateinteraction.hxx
@@ -22,17 +22,128 @@
 
 #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/lang/XInitialization.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_TYPED(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.
@@ -50,7 +161,7 @@ struct ThreadHelpBase2
 };
 
 class PreventDuplicateInteraction : private ThreadHelpBase2
-                                    ,public ::cppu::WeakImplHelper< css::task::XInteractionHandler2 >
+                                  , public ::cppu::WeakImplHelper<css::lang::XInitialization, css::task::XInteractionHandler2>
 {
 
     // structs, types etc.
@@ -99,6 +210,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.*/
@@ -108,6 +221,7 @@ class PreventDuplicateInteraction : private ThreadHelpBase2
     // uno interface
     public:
 
+        virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
 
         /**
             @interface  XInteractionHandler
@@ -147,6 +261,7 @@ class PreventDuplicateInteraction : private ThreadHelpBase2
         virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType )
             throw (css::uno::RuntimeException, std::exception) override;
 
+
     // c++ interface
     public:
 
@@ -167,7 +282,7 @@ class PreventDuplicateInteraction : private ThreadHelpBase2
         /**
             @short      dtor to free used memory.
          */
-        virtual ~PreventDuplicateInteraction();
+        virtual ~PreventDuplicateInteraction() override;
 
 
         /**
diff --git a/sfx2/source/appl/preventduplicateinteraction.cxx b/sfx2/source/appl/preventduplicateinteraction.cxx
index fdbf43ac1ad0..7ef25e70e82d 100644
--- a/sfx2/source/appl/preventduplicateinteraction.cxx
+++ b/sfx2/source/appl/preventduplicateinteraction.cxx
@@ -20,6 +20,7 @@
 #include <preventduplicateinteraction.hxx>
 
 #include <osl/diagnose.h>
+#include <comphelper/processfactory.hxx>
 
 #include <com/sun/star/task/InteractionHandler.hpp>
 #include <com/sun/star/task/XInteractionAbort.hpp>
@@ -41,6 +42,7 @@ void PreventDuplicateInteraction::setHandler(const css::uno::Reference< css::tas
 {
     // SAFE ->
     ::osl::ResettableMutexGuard aLock(m_aLock);
+    m_xWarningDialogsParent.reset();
     m_xHandler = xHandler;
     aLock.clear();
     // <- SAFE
@@ -53,7 +55,11 @@ 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 );
+    //if we use the default handler, set the parent to a window belonging to this object so that the dialogs
+    //don't block unrelated windows.
+    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();
@@ -72,7 +78,7 @@ css::uno::Any SAL_CALL PreventDuplicateInteraction::queryInterface( const css::u
         if ( !xHandler.is() )
             return css::uno::Any();
     }
-    return ::cppu::WeakImplHelper< css::task::XInteractionHandler2 >::queryInterface( aType );
+    return ::cppu::WeakImplHelper<css::lang::XInitialization, css::task::XInteractionHandler2>::queryInterface(aType);
 }
 
 void SAL_CALL PreventDuplicateInteraction::handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
@@ -236,6 +242,18 @@ bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type&
     return false;
 }
 
+void SAL_CALL PreventDuplicateInteraction::initialize(const css::uno::Sequence<css::uno::Any>& rArguments)
+{
+    // If we're re-initialized to set a specific new window as a parent then drop our temporary
+    // dialog parent
+    css::uno::Reference<css::lang::XInitialization> xHandler(m_xHandler, css::uno::UNO_QUERY);
+    if (xHandler.is())
+    {
+        m_xWarningDialogsParent.reset();
+        xHandler->initialize(rArguments);
+    }
+}
+
 IMPL_STATIC_LINK_NOARG_TYPED(WarningDialogsParent, TerminateDesktop, void*, void)
 {
     css::frame::Desktop::create(comphelper::getProcessComponentContext())->terminate();
diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx
index 914d024cee0e..eff873f58ee8 100644
--- a/uui/source/iahndl.cxx
+++ b/uui/source/iahndl.cxx
@@ -1001,9 +1001,8 @@ executeMessageBox(
     WinBits nButtonMask)
 {
     SolarMutexGuard aGuard;
-    WinBits nStyle(0);
 
-    ScopedVclPtrInstance< MessBox > xBox(pParent, nButtonMask, nStyle, rTitle, rMessage);
+    ScopedVclPtrInstance< MessBox > xBox(pParent, nButtonMask, rTitle, rMessage);
 
     sal_uInt16 aResult = xBox->Execute();
     switch( aResult )
commit 11ea1b0751378e20ee5be8e708b58a5270524716
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 e317dcb6dcfd..5e51c42bee83 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -1069,32 +1069,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;
         }
     }
 
commit 0b8eae07eb1e7bd769b33e26064a0426558a744c
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Nov 22 15:15:08 2017 +0000

    move preventduplicateinteraction from framework to sfx2 consumer
    
    Change-Id: I1388a88ba20b5cde65cd1d88694775b071a0dff6
    Reviewed-on: https://gerrit.libreoffice.org/45099
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/framework/Library_fwe.mk b/framework/Library_fwe.mk
index 0559236b2bad..72cf5f098a4d 100644
--- a/framework/Library_fwe.mk
+++ b/framework/Library_fwe.mk
@@ -70,7 +70,6 @@ $(eval $(call gb_Library_add_exception_objects,fwe,\
     framework/source/fwe/helper/titlehelper \
     framework/source/fwe/helper/documentundoguard \
     framework/source/fwe/helper/undomanagerhelper \
-    framework/source/fwe/interaction/preventduplicateinteraction \
     framework/source/fwe/xml/menuconfiguration \
     framework/source/fwe/xml/menudocumenthandler \
     framework/source/fwe/xml/saxnamespacefilter \
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 9aca9d7f058c..619c33485de9 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -115,6 +115,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/appl/newhelp \
     sfx2/source/appl/opengrf \
     sfx2/source/appl/openuriexternally \
+    sfx2/source/appl/preventduplicateinteraction \
     sfx2/source/appl/sfxhelp \
     sfx2/source/appl/sfxpicklist \
     sfx2/source/appl/shellimpl \
diff --git a/include/framework/preventduplicateinteraction.hxx b/sfx2/inc/preventduplicateinteraction.hxx
similarity index 98%
rename from include/framework/preventduplicateinteraction.hxx
rename to sfx2/inc/preventduplicateinteraction.hxx
index cf6ac0058eda..a7d1b097134f 100644
--- a/include/framework/preventduplicateinteraction.hxx
+++ b/sfx2/inc/preventduplicateinteraction.hxx
@@ -20,8 +20,6 @@
 #ifndef INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
 #define INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
 
-#include <framework/fwedllapi.h>
-
 #include <vector>
 
 #include <com/sun/star/task/XInteractionHandler2.hpp>
@@ -33,7 +31,7 @@ namespace com { namespace sun { namespace star { namespace uno {
     class XComponentContext;
 } } } }
 
-namespace framework{
+namespace sfx2 {
 
 /**
     @short      Prevent us from showing the same interaction more than once during
@@ -51,7 +49,7 @@ struct ThreadHelpBase2
         mutable ::osl::Mutex m_aLock;
 };
 
-class FWE_DLLPUBLIC PreventDuplicateInteraction : private ThreadHelpBase2
+class PreventDuplicateInteraction : private ThreadHelpBase2
                                     ,public ::cppu::WeakImplHelper< css::task::XInteractionHandler2 >
 {
 
@@ -233,7 +231,7 @@ class FWE_DLLPUBLIC PreventDuplicateInteraction : private ThreadHelpBase2
                                                   PreventDuplicateInteraction::InteractionInfo* pReturn     ) const;
 };
 
-} // namespace framework
+} // namespace sfx2
 
 #endif // INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
 
diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx
index e5ff943baa32..5f8bdaa46640 100644
--- a/sfx2/source/appl/appopen.cxx
+++ b/sfx2/source/appl/appopen.cxx
@@ -56,7 +56,7 @@
 #include <svl/eitem.hxx>
 #include <sfx2/doctempl.hxx>
 #include <svtools/sfxecode.hxx>
-#include <framework/preventduplicateinteraction.hxx>
+#include <preventduplicateinteraction.hxx>
 #include <svtools/ehdl.hxx>
 #include <basic/sbxobj.hxx>
 #include <svl/urihelper.hxx>
@@ -665,7 +665,7 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
             // intercept all incoming interactions and provide useful information
             // later if the following transaction was finished.
 
-            ::framework::PreventDuplicateInteraction*                 pHandler       = new ::framework::PreventDuplicateInteraction(::comphelper::getProcessComponentContext());
+            ::sfx2::PreventDuplicateInteraction*                 pHandler       = new ::sfx2::PreventDuplicateInteraction(::comphelper::getProcessComponentContext());
             css::uno::Reference< css::task::XInteractionHandler >     xHandler       (static_cast< css::task::XInteractionHandler* >(pHandler), css::uno::UNO_QUERY);
             css::uno::Reference< css::task::XInteractionHandler >     xWrappedHandler;
 
@@ -684,7 +684,7 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
 
             // define rules for this handler
             css::uno::Type                                            aInteraction = ::cppu::UnoType<css::task::ErrorCodeRequest>::get();
-            ::framework::PreventDuplicateInteraction::InteractionInfo aRule        (aInteraction, 1);
+            ::sfx2::PreventDuplicateInteraction::InteractionInfo aRule        (aInteraction, 1);
             pHandler->addInteractionRule(aRule);
 
             if (!aDocService.isEmpty())
diff --git a/framework/source/fwe/interaction/preventduplicateinteraction.cxx b/sfx2/source/appl/preventduplicateinteraction.cxx
similarity index 96%
rename from framework/source/fwe/interaction/preventduplicateinteraction.cxx
rename to sfx2/source/appl/preventduplicateinteraction.cxx
index 818fdfe2122a..fdbf43ac1ad0 100644
--- a/framework/source/fwe/interaction/preventduplicateinteraction.cxx
+++ b/sfx2/source/appl/preventduplicateinteraction.cxx
@@ -17,7 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <framework/preventduplicateinteraction.hxx>
+#include <preventduplicateinteraction.hxx>
 
 #include <osl/diagnose.h>
 
@@ -25,7 +25,7 @@
 #include <com/sun/star/task/XInteractionAbort.hpp>
 #include <com/sun/star/task/XInteractionRetry.hpp>
 
-namespace framework{
+namespace sfx2 {
 
 PreventDuplicateInteraction::PreventDuplicateInteraction(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
     : ThreadHelpBase2()
@@ -236,6 +236,11 @@ bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type&
     return false;
 }
 
-} // namespace framework
+IMPL_STATIC_LINK_NOARG_TYPED(WarningDialogsParent, TerminateDesktop, void*, void)
+{
+    css::frame::Desktop::create(comphelper::getProcessComponentContext())->terminate();
+}
+
+} // namespace sfx2
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit b36eaa30fa712b558ecb1e1500577d1352a36d18
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Nov 3 15:27:35 2017 +0000

    Related: tdf#113160 set parent of warning dialogs during load
    
    to the new window frame being constructed that (may) contain
    the progress bar, that way such modal dialogs affect the loading
    document window and not whatever window happens to be active
    
    Change-Id: I1c7d3185e47fa316eef003b80d18b31d341b79d6
    Reviewed-on: https://gerrit.libreoffice.org/44269
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index ab15395be043..2b538c936a1b 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -238,6 +238,7 @@ void DesktopLOKTest::callbackImpl(int nType, const char* pPayload)
 
 void DesktopLOKTest::testGetStyles()
 {
+    comphelper::LibreOfficeKit::setActive();
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     boost::property_tree::ptree aTree;
     char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:StyleApply");
@@ -267,6 +268,7 @@ void DesktopLOKTest::testGetStyles()
             CPPUNIT_FAIL("Unknown style family: " + rPair.first);
         }
     }
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testGetFonts()
@@ -290,6 +292,7 @@ void DesktopLOKTest::testGetFonts()
 
 void DesktopLOKTest::testCreateView()
 {
+    comphelper::LibreOfficeKit::setActive();
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getViews(pDocument));
 
@@ -304,10 +307,12 @@ void DesktopLOKTest::testCreateView()
 
     pDocument->m_pDocumentClass->destroyView(pDocument, nId);
     CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getViews(pDocument));
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testGetPartPageRectangles()
 {
+    comphelper::LibreOfficeKit::setActive();
     // Test that we get as many page rectangles as expected: blank document is
     // one page.
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
@@ -326,10 +331,12 @@ void DesktopLOKTest::testGetPartPageRectangles()
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aRectangles.size());
 
     free(pRectangles);
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testGetFilterTypes()
 {
+    comphelper::LibreOfficeKit::setActive();
     LibLibreOffice_Impl aOffice;
     char* pJSON = aOffice.m_pOfficeClass->getFilterTypes(&aOffice);
 
@@ -340,12 +347,14 @@ void DesktopLOKTest::testGetFilterTypes()
     CPPUNIT_ASSERT(aTree.size() > 0);
     CPPUNIT_ASSERT_EQUAL(std::string("application/vnd.oasis.opendocument.text"), aTree.get_child("writer8").get_child("MediaType").get_value<std::string>());
     free(pJSON);
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testSearchCalc()
 {
-    LibLibreOffice_Impl aOffice;
     comphelper::LibreOfficeKit::setActive();
+
+    LibLibreOffice_Impl aOffice;
     LibLODocument_Impl* pDocument = loadDoc("search.ods");
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
     pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
@@ -378,8 +387,9 @@ void DesktopLOKTest::testSearchCalc()
 
 void DesktopLOKTest::testSearchAllNotificationsCalc()
 {
-    LibLibreOffice_Impl aOffice;
     comphelper::LibreOfficeKit::setActive();
+
+    LibLibreOffice_Impl aOffice;
     LibLODocument_Impl* pDocument = loadDoc("search.ods");
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
     pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
@@ -403,6 +413,8 @@ void DesktopLOKTest::testSearchAllNotificationsCalc()
 
 void DesktopLOKTest::testPaintTile()
 {
+    comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     int nCanvasWidth = 100;
     int nCanvasHeight = 300;
@@ -425,27 +437,38 @@ void DesktopLOKTest::testPaintTile()
     nTileHeight = 4000;
     aBuffer.resize(nCanvasWidth * nCanvasHeight * 4);
     pDocument->pClass->paintTile(pDocument, aBuffer.data(), nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testSaveAs()
 {
+    comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     utl::TempFile aTempFile;
     aTempFile.EnableKillingFile();
     CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "png", nullptr));
+
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testSaveAsCalc()
 {
+    comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("search.ods");
     utl::TempFile aTempFile;
     aTempFile.EnableKillingFile();
     CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "png", nullptr));
+
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testPasteWriter()
 {
     comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     OString aText("hello");
 
@@ -467,6 +490,7 @@ void DesktopLOKTest::testPasteWriter()
 void DesktopLOKTest::testPasteWriterJPEG()
 {
     comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
 
     OUString aFileURL;
@@ -530,6 +554,8 @@ void DesktopLOKTest::testRowColumnHeaders()
      * "size" defines the bottom/right boundary of a row/column in twips (size between 0 and boundary)
      * "text" has the header label in UTF-8
      */
+    comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("search.ods");
 
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
@@ -574,10 +600,14 @@ void DesktopLOKTest::testRowColumnHeaders()
         }
         nPrevious = nSize;
     }
+
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testHiddenRowHeaders()
 {
+    comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("hidden-row.ods");
 
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
@@ -607,10 +637,13 @@ void DesktopLOKTest::testHiddenRowHeaders()
 
         nPrevious = nSize;
     }
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testCellCursor()
 {
+    comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("search.ods");
 
     boost::property_tree::ptree aTree;
@@ -624,11 +657,14 @@ void DesktopLOKTest::testCellCursor()
     boost::property_tree::read_json(aStream, aTree);
 
     OString aRectangle(aTree.get<std::string>("commandValues").c_str());
-    CPPUNIT_ASSERT_EQUAL(aRectangle, OString("0, 0, 1278, 254"));
+
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testCommandResult()
 {
+    comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
 
     // the postUnoCommand() is supposed to be async, let's test it safely
@@ -659,11 +695,14 @@ void DesktopLOKTest::testCommandResult()
 
     CPPUNIT_ASSERT_EQUAL(aTree.get_child("commandName").get_value<std::string>(), std::string(".uno:Bold"));
     CPPUNIT_ASSERT_EQUAL(aTree.get_child("success").get_value<bool>(), true);
+
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 void DesktopLOKTest::testWriterComments()
 {
     comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
     uno::Reference<awt::XReschedule> xToolkit(com::sun::star::awt::Toolkit::create(comphelper::getProcessComponentContext()), uno::UNO_QUERY);
@@ -704,8 +743,10 @@ void DesktopLOKTest::testWriterComments()
 
 void DesktopLOKTest::testModifiedStatus()
 {
-    LibLibreOffice_Impl aOffice;
     comphelper::LibreOfficeKit::setActive();
+
+    // Load a document and create two views.
+    LibLibreOffice_Impl aOffice;
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
     pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
@@ -765,6 +806,7 @@ void DesktopLOKTest::testModifiedStatus()
 void DesktopLOKTest::testSheetOperations()
 {
     comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("sheets.ods");
 
     // insert the last sheet
@@ -797,6 +839,7 @@ void DesktopLOKTest::testSheetOperations()
 void DesktopLOKTest::testSheetSelections()
 {
     comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("sheets.ods", LOK_DOCTYPE_SPREADSHEET);
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
     pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
@@ -977,6 +1020,7 @@ namespace {
 void DesktopLOKTest::testContextMenuCalc()
 {
     comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("sheet_with_image.ods", LOK_DOCTYPE_SPREADSHEET);
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
     pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
@@ -1088,6 +1132,7 @@ void DesktopLOKTest::testContextMenuCalc()
 void DesktopLOKTest::testContextMenuWriter()
 {
     comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
     pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
@@ -1144,6 +1189,7 @@ void DesktopLOKTest::testContextMenuWriter()
 void DesktopLOKTest::testContextMenuImpress()
 {
     comphelper::LibreOfficeKit::setActive();
+
     LibLODocument_Impl* pDocument = loadDoc("blank_presentation.odp", LOK_DOCTYPE_PRESENTATION);
     pDocument->pClass->initializeForRendering(pDocument, nullptr);
     pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
@@ -1275,6 +1321,8 @@ static void callbackCompressionTest(const int type, const char* payload, void* d
 
 void DesktopLOKTest::testNotificationCompression()
 {
+    comphelper::LibreOfficeKit::setActive();
+
     std::vector<std::tuple<int, std::string>> notifs;
     std::unique_ptr<CallbackFlushHandler> handler(new CallbackFlushHandler(callbackCompressionTest, &notifs));
 
@@ -1351,6 +1399,8 @@ void DesktopLOKTest::testNotificationCompression()
 
     CPPUNIT_ASSERT_EQUAL((int)LOK_CALLBACK_SET_PART, (int)std::get<0>(notifs[i]));
     CPPUNIT_ASSERT_EQUAL(std::string("1"), std::get<1>(notifs[i++]));
+
+    comphelper::LibreOfficeKit::setActive(false);
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index b6f6f4c92178..e317dcb6dcfd 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -1069,17 +1069,32 @@ 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 && !xProgress.is())
+    if (!bHidden && !bMinimized && !bPreview)
     {
-        // Note: its an optional interface!
-        css::uno::Reference< css::task::XStatusIndicatorFactory > xProgressFactory(xTargetFrame, css::uno::UNO_QUERY);
-        if (xProgressFactory.is())
+        css::uno::Reference< css::task::XStatusIndicator > xProgress  = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), css::uno::Reference< css::task::XStatusIndicator >());
+        if (!xProgress.is())
         {
-            xProgress = xProgressFactory->createStatusIndicator();
-            if (xProgress.is())
-                m_lMediaDescriptor[utl::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress;
+            // 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;
+            }
         }
     }
 
diff --git a/include/tools/errinf.hxx b/include/tools/errinf.hxx
index 18822c9542cf..203745c4b5a7 100644
--- a/include/tools/errinf.hxx
+++ b/include/tools/errinf.hxx
@@ -131,7 +131,8 @@ private:
     static sal_uInt16   HandleError_Impl( sal_uIntPtr lId,
                               sal_uInt16 nFlags,
                               bool bJustCreateString,
-                              OUString & rError);
+                              OUString & rError,
+                              vcl::Window* pParent = nullptr);
 protected:
     virtual bool        CreateString( const ErrorInfo *,
                               OUString &, sal_uInt16& nMask ) const = 0;
@@ -140,7 +141,7 @@ public:
                         ErrorHandler();
     virtual             ~ErrorHandler();
 
-    static sal_uInt16   HandleError ( sal_uIntPtr lId, sal_uInt16 nMask = USHRT_MAX );
+    static sal_uInt16   HandleError ( sal_uIntPtr lId, vcl::Window* pParent = nullptr, sal_uInt16 nMask = USHRT_MAX );
     static bool         GetErrorString( sal_uIntPtr lId, OUString& rStr );
 
     static void         RegisterDisplay( BasicDisplayErrorFunc* );
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index fc6108bb6ad9..d7cdcec740b0 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -187,7 +187,7 @@ bool SwFEShell::InsertRow( sal_uInt16 nCnt, bool bBehind )
 
     if( dynamic_cast< const SwDDETable* >(pFrame->ImplFindTabFrame()->GetTable()) != nullptr )
     {
-        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
+        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
@@ -228,7 +228,7 @@ bool SwFEShell::InsertCol( sal_uInt16 nCnt, bool bBehind )
 
     if( dynamic_cast< const SwDDETable* >(pFrame->ImplFindTabFrame()->GetTable()) != nullptr )
     {
-        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
+        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
@@ -237,7 +237,7 @@ bool SwFEShell::InsertCol( sal_uInt16 nCnt, bool bBehind )
 
     if( !CheckSplitCells( *this, nCnt + 1, nsSwTableSearchType::TBLSEARCH_COL ) )
     {
-        ErrorHandler::HandleError( ERR_TBLINSCOL_ERROR,
+        ErrorHandler::HandleError( ERR_TBLINSCOL_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
@@ -283,7 +283,7 @@ bool SwFEShell::DeleteCol()
 
     if( dynamic_cast< const SwDDETable* >(pFrame->ImplFindTabFrame()->GetTable()) != nullptr )
     {
-        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
+        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
@@ -334,7 +334,7 @@ bool SwFEShell::DeleteRow(bool bCompleteTable)
 
     if( dynamic_cast< const SwDDETable* >(pFrame->ImplFindTabFrame()->GetTable()) != nullptr )
     {
-        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
+        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
@@ -453,7 +453,7 @@ sal_uInt16 SwFEShell::MergeTab()
         const SwTableNode* pTableNd = pTableCursor->GetNode().FindTableNode();
         if( dynamic_cast< const SwDDETable* >(&pTableNd->GetTable()) != nullptr )
         {
-            ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
+            ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR, GetWin(),
                             ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         }
         else
@@ -484,7 +484,7 @@ bool SwFEShell::SplitTab( bool bVert, sal_uInt16 nCnt, bool bSameHeight )
 
     if( dynamic_cast< const SwDDETable* >(pFrame->ImplFindTabFrame()->GetTable()) != nullptr  )
     {
-        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
+        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
@@ -493,7 +493,7 @@ bool SwFEShell::SplitTab( bool bVert, sal_uInt16 nCnt, bool bSameHeight )
 
     if( bVert && !CheckSplitCells( *this, nCnt + 1 ) )
     {
-        ErrorHandler::HandleError( ERR_TBLSPLIT_ERROR,
+        ErrorHandler::HandleError( ERR_TBLSPLIT_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
@@ -1276,7 +1276,7 @@ bool SwFEShell::DeleteTableSel()
 
     if( dynamic_cast< const SwDDETable* >(pFrame->ImplFindTabFrame()->GetTable()) != nullptr )
     {
-        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
+        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
@@ -2137,7 +2137,7 @@ bool SwFEShell::SetColRowWidthHeight( sal_uInt16 eType, sal_uInt16 nDiff )
     if( nsTableChgWidthHeightType::WH_FLAG_INSDEL & eType &&
         dynamic_cast< const SwDDETable* >(pFrame->ImplFindTabFrame()->GetTable()) != nullptr )
     {
-        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
+        ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR, GetWin(),
                         ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
         return false;
     }
diff --git a/tools/source/ref/errinf.cxx b/tools/source/ref/errinf.cxx
index 40e7b697c8e2..c287b0731096 100644
--- a/tools/source/ref/errinf.cxx
+++ b/tools/source/ref/errinf.cxx
@@ -237,14 +237,13 @@ void ErrorHandler::RegisterDisplay(BasicDisplayErrorFunc *aDsp)
     @return ???
 */
 sal_uInt16 ErrorHandler::HandleError_Impl(
-    sal_uIntPtr lId, sal_uInt16 nFlags, bool bJustCreateString, OUString & rError)
+    sal_uIntPtr lId, sal_uInt16 nFlags, bool bJustCreateString, OUString & rError, vcl::Window* pParent)
 {
     OUString aErr;
     OUString aAction;
     if(!lId || lId == ERRCODE_ABORT)
         return 0;
     EDcrData &rData      = TheEDcrData::get();
-    vcl::Window *pParent = nullptr;
     ErrorInfo *pInfo     = ErrorInfo::GetErrorInfo(lId);
     if (!rData.contexts.empty())
     {
@@ -332,10 +331,10 @@ bool ErrorHandler::GetErrorString(sal_uIntPtr lId, OUString& rStr)
 
     @see ErrorHandler::HandleError_Impl
 */
-sal_uInt16 ErrorHandler::HandleError(sal_uIntPtr lId, sal_uInt16 nFlags)
+sal_uInt16 ErrorHandler::HandleError(sal_uIntPtr lId, vcl::Window *pParent, sal_uInt16 nFlags)
 {
     OUString aDummy;
-    return HandleError_Impl( lId, nFlags, false, aDummy );
+    return HandleError_Impl( lId, nFlags, false, aDummy, pParent );
 }
 
 bool ErrorHandler_Impl::CreateString( const ErrorInfo* pInfo, OUString& pStr,
diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx
index 5abc43a88368..914d024cee0e 100644
--- a/uui/source/iahndl.cxx
+++ b/uui/source/iahndl.cxx
@@ -1158,7 +1158,7 @@ UUIInteractionHelper::handleGenericErrorRequest(
                 getParentProperty(), aTitle, aErrorString, WB_OK);
         }
         else
-            ErrorHandler::HandleError(nErrorCode);
+            ErrorHandler::HandleError(nErrorCode, getParentProperty());
 
         if (xApprove.is() && bWarning)
             xApprove->select();
commit 258b4b1ef60e5153c1c33444010c1385f46475d6
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Thu Dec 7 09:32:48 2017 +0100

    Resolves: tdf#113160 changing all warning dialogs to non-modal is unsafe
    
    existing code doesn't expect that so stuff crashes
    
    partial revert of...
    
    commit db6b703d391838c481fd090065f6d329edcd4efa
    Date:   Thu Aug 24 18:32:38 2017 +0200
    
        Allow non-modal Dialogs during FileImport/Load
    
    Reviewed-on: https://gerrit.libreoffice.org/44227
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    
     Conflicts:
            framework/source/dispatch/closedispatcher.cxx
            include/vcl/dialog.hxx
            include/vcl/msgbox.hxx
            uui/source/iahndl.cxx
            vcl/source/window/msgbox.cxx
    
    Change-Id: I152feb849186cf035664a700d3f94ee049cdf6d3

diff --git a/framework/source/dispatch/closedispatcher.cxx b/framework/source/dispatch/closedispatcher.cxx
index 9aa25190a544..d63938e9a77b 100644
--- a/framework/source/dispatch/closedispatcher.cxx
+++ b/framework/source/dispatch/closedispatcher.cxx
@@ -363,14 +363,6 @@ IMPL_LINK_NOARG_TYPED(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void)
         }
     }
 
-    // if we still have dialogs open, temporary suppress termination
-    if (bTerminateApp && Dialog::AreDialogsOpen())
-    {
-        Application::SetShutdownDelayed();
-        bCloseFrame = true;
-        bTerminateApp = false;
-    }
-
     // Do it now ...
     bool bSuccess = false;
     if (bCloseFrame)
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index c789f4d6e957..b6f6f4c92178 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -378,10 +378,6 @@ void LoadEnv::startLoading()
     if (!bStarted)
         bStarted = impl_loadContent();
 
-    // This may have triggered Dialogs (error cases) that may have
-    // delayed the shutdown, so give delayed shutdown a chance
-    Application::TriggerShutdownDelayed();
-
     // not started => general error
     // We can't say - what was the reason for.
     if (!bStarted)
diff --git a/include/vcl/dialog.hxx b/include/vcl/dialog.hxx
index 87588d50c85d..add141adea28 100644
--- a/include/vcl/dialog.hxx
+++ b/include/vcl/dialog.hxx
@@ -38,11 +38,8 @@ public:
         /** Use given parent or get a default one using GetDefaultParent(...) */
         Default,
 
-        /** Suppress Parent so that Parent is not blocked (kind of modal mode) */
-        NoParent,
-
-        /** Suppress Parent (no modal, see above) and additionally center on default parent */
-        NoParentCentered
+        /** No Parent */
+        NoParent
     };
 
 private:
@@ -125,7 +122,6 @@ public:
 
     void            EndDialog( long nResult = 0 );
     static void     EndAllDialogs( vcl::Window* pParent=nullptr );
-    static bool     AreDialogsOpen();
 
     void            GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder,
                                          sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const;
diff --git a/include/vcl/msgbox.hxx b/include/vcl/msgbox.hxx
index 0f526f618fe6..f3351664574c 100644
--- a/include/vcl/msgbox.hxx
+++ b/include/vcl/msgbox.hxx
@@ -47,8 +47,7 @@ protected:
 
 public:
                         MessBox( vcl::Window* pParent, WinBits nStyle,
-                                 const OUString& rTitle, const OUString& rMessage,
-                            Dialog::InitFlag eInitFlag = Dialog::InitFlag::NoParentCentered);
+                                 const OUString& rTitle, const OUString& rMessage);
     virtual             ~MessBox();
     virtual void        dispose() override;
 
diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx
index 2be63c268198..34b659fa7f33 100644
--- a/include/vcl/svapp.hxx
+++ b/include/vcl/svapp.hxx
@@ -1451,12 +1451,6 @@ public:
     // For vclbootstrapprotector:
     static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
 
-    // for delayed shutdown: set using SetShutdownDelayed, then
-    // trigger using TriggerShutdownDelayed which may actually shutdown
-    // when SetShutdownDelayed is set
-    static void SetShutdownDelayed();
-    static void TriggerShutdownDelayed();
-
 private:
     DECL_STATIC_LINK_TYPED( Application, PostEventHandler, void*, void );
 };
diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx
index b53f5b474323..5abc43a88368 100644
--- a/uui/source/iahndl.cxx
+++ b/uui/source/iahndl.cxx
@@ -998,33 +998,12 @@ executeMessageBox(
     vcl::Window * pParent,
     OUString const & rTitle,
     OUString const & rMessage,
-    WinBits nButtonMask,
-    Dialog::InitFlag eInitFlag)
+    WinBits nButtonMask)
 {
     SolarMutexGuard aGuard;
-    ScopedVclPtrInstance< MessBox > xBox(pParent, nButtonMask, rTitle, rMessage, eInitFlag);
+    WinBits nStyle(0);
 
-    if (Dialog::InitFlag::NoParentCentered == eInitFlag)
-    {
-        vcl::Window* pDefaultParent = Dialog::GetDefaultParent(nButtonMask);
-
-        if (pDefaultParent)
-        {
-            // need to 'Show' to have the following tasks do someting, does
-            // not work without and may even stumble on nullptrs/errors
-            xBox->Show();
-
-            // center on parent window
-            const Point aP(pDefaultParent->GetPosPixel());
-            const Size aS(pDefaultParent->GetSizePixel());
-            const Size aMySize(xBox->GetSizePixel());
-
-            xBox->SetPosPixel(
-                Point(
-                    aP.X() + ((aS.Width() - aMySize.Width()) >> 1),
-                    aP.Y() + ((aS.Height() - aMySize.Height()) >> 1)));
-        }
-    }
+    ScopedVclPtrInstance< MessBox > xBox(pParent, nButtonMask, nStyle, rTitle, rMessage);
 
     sal_uInt16 aResult = xBox->Execute();
     switch( aResult )
@@ -1176,7 +1155,7 @@ UUIInteractionHelper::handleGenericErrorRequest(
             aTitle += aErrTitle;
 
             executeMessageBox(
-                getParentProperty(), aTitle, aErrorString, WB_OK, Dialog::InitFlag::NoParentCentered);
+                getParentProperty(), aTitle, aErrorString, WB_OK);
         }
         else
             ErrorHandler::HandleError(nErrorCode);
@@ -1299,8 +1278,7 @@ UUIInteractionHelper::handleBrokenPackageRequest(
         " " +
         utl::ConfigManager::getProductVersion() );
 
-    switch (
-        executeMessageBox( getParentProperty(), title, aMessage, nButtonMask, Dialog::InitFlag::NoParentCentered) )
+    switch (executeMessageBox(getParentProperty(), title, aMessage, nButtonMask))
     {
     case ERRCODE_BUTTON_OK:
         OSL_ENSURE( xAbort.is(), "unexpected situation" );
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index fc6fefc7d958..6af3c7c1c7cf 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -1816,20 +1816,4 @@ void Application::setDeInitHook(Link<LinkParamNone*,void> const & hook) {
     pSVData->maAppData.mbInAppMain = true;
 }
 
-void Application::SetShutdownDelayed()
-{
-    ImplSVData * pSVData = ImplGetSVData();
-    pSVData->maAppData.mbShutdownDelayed = true;
-}
-
-void Application::TriggerShutdownDelayed()
-{
-    ImplSVData * pSVData = ImplGetSVData();
-
-    if (pSVData->maAppData.mbShutdownDelayed && !Dialog::AreDialogsOpen())
-    {
-        Application::PostUserEvent(LINK(nullptr, ImplSVAppData, ImplPrepareExitMsg));
-    }
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 95fed10ab0a6..6dbad6496184 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -406,7 +406,7 @@ void Dialog::ImplInit( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag )
     // Now, all Dialogs are per default system windows !!!
     nStyle |= WB_SYSTEMWINDOW;
 
-    if (InitFlag::NoParent == eFlag || InitFlag::NoParentCentered == eFlag)
+    if (InitFlag::NoParent == eFlag)
     {
         pParent = nullptr;
     }
@@ -1009,14 +1009,6 @@ void Dialog::EndAllDialogs( vcl::Window* pParent )
     }
 }
 
-bool Dialog::AreDialogsOpen()
-{
-    ImplSVData* pSVData = ImplGetSVData();
-    Dialog* pModDialog = pSVData->maWinData.mpLastExecuteDlg;
-
-    return (nullptr != pModDialog);
-}
-
 void Dialog::SetModalInputMode( bool bModal )
 {
     if ( bModal == mbModalMode )
diff --git a/vcl/source/window/msgbox.cxx b/vcl/source/window/msgbox.cxx
index f6fd26773624..9cd2ae08a8ce 100644
--- a/vcl/source/window/msgbox.cxx
+++ b/vcl/source/window/msgbox.cxx
@@ -138,12 +138,12 @@ void MessBox::ImplInitButtons()
 }
 
 MessBox::MessBox( vcl::Window* pParent, WinBits nStyle,
-                  const OUString& rTitle, const OUString& rMessage, Dialog::InitFlag eInitFlag) :
+                  const OUString& rTitle, const OUString& rMessage) :
     ButtonDialog( WINDOW_MESSBOX ),
     maMessText( rMessage )
 {
     ImplInitMessBoxData();
-    ImplInit( pParent, nStyle | WB_MOVEABLE | WB_HORZ | WB_CENTER, eInitFlag);
+    ImplInit( pParent, nStyle | WB_MOVEABLE | WB_HORZ | WB_CENTER);
     ImplInitButtons();
 
     if ( !rTitle.isEmpty() )
commit 64d2902a61f6aa90554bc76fe70aee78bba6b3dd
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Thu Dec 7 14:26:16 2017 +0100

    Revert "Resolves: tdf#113160 changing all warning dialogs to non-modal is unsafe"
    
    This reverts commit e0dc344395393c8a9364952a5d241c12fa8b8f54.
    
    Had to redo this because some commits before and after were missing.

diff --git a/framework/Library_fwe.mk b/framework/Library_fwe.mk
index d94cb100a975..0559236b2bad 100644
--- a/framework/Library_fwe.mk
+++ b/framework/Library_fwe.mk
@@ -46,7 +46,6 @@ $(eval $(call gb_Library_use_libraries,fwe,\
     svl \
     svt \
     tl \
-    tk \
     utl \
     vcl \
 	$(gb_UWINAPI) \
diff --git a/framework/source/dispatch/closedispatcher.cxx b/framework/source/dispatch/closedispatcher.cxx
index 96df4fe9d9e5..9aa25190a544 100644
--- a/framework/source/dispatch/closedispatcher.cxx
+++ b/framework/source/dispatch/closedispatcher.cxx
@@ -36,6 +36,8 @@
 #include <vcl/window.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/syswin.hxx>
+#include <osl/mutex.hxx>
+#include <vcl/dialog.hxx>
 #include <unotools/moduleoptions.hxx>
 #include <comphelper/processfactory.hxx>
 
@@ -361,6 +363,14 @@ IMPL_LINK_NOARG_TYPED(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void)
         }
     }
 
+    // if we still have dialogs open, temporary suppress termination
+    if (bTerminateApp && Dialog::AreDialogsOpen())
+    {
+        Application::SetShutdownDelayed();
+        bCloseFrame = true;
+        bTerminateApp = false;
+    }
+
     // Do it now ...
     bool bSuccess = false;
     if (bCloseFrame)
diff --git a/framework/source/fwe/interaction/preventduplicateinteraction.cxx b/framework/source/fwe/interaction/preventduplicateinteraction.cxx
index 9e43e1b1d44f..818fdfe2122a 100644
--- a/framework/source/fwe/interaction/preventduplicateinteraction.cxx
+++ b/framework/source/fwe/interaction/preventduplicateinteraction.cxx
@@ -19,7 +19,6 @@
 
 #include <framework/preventduplicateinteraction.hxx>
 
-#include <comphelper/processfactory.hxx>
 #include <osl/diagnose.h>
 
 #include <com/sun/star/task/InteractionHandler.hpp>
@@ -54,9 +53,7 @@ void PreventDuplicateInteraction::useDefaultUUIHandler()
     aLock.clear();
     // <- SAFE
 
-    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);
+    css::uno::Reference< css::task::XInteractionHandler > xHandler( css::task::InteractionHandler::createWithParent( m_xContext, nullptr ), css::uno::UNO_QUERY_THROW );
 
     // SAFE ->
     aLock.reset();
@@ -239,11 +236,6 @@ bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type&
     return false;
 }
 
-IMPL_STATIC_LINK_NOARG_TYPED(WarningDialogsParent, TerminateDesktop, void*, void)
-{
-    css::frame::Desktop::create(comphelper::getProcessComponentContext())->terminate();
-}
-
 } // namespace framework
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index 5e51c42bee83..c789f4d6e957 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -378,6 +378,10 @@ void LoadEnv::startLoading()
     if (!bStarted)
         bStarted = impl_loadContent();
 
+    // This may have triggered Dialogs (error cases) that may have
+    // delayed the shutdown, so give delayed shutdown a chance
+    Application::TriggerShutdownDelayed();
+
     // not started => general error
     // We can't say - what was the reason for.
     if (!bStarted)
@@ -1073,7 +1077,7 @@ bool LoadEnv::impl_loadContent()
 
     if (!bHidden && !bMinimized && !bPreview && !xProgress.is())
     {
-        // Note: it's an optional interface!
+        // Note: its an optional interface!
         css::uno::Reference< css::task::XStatusIndicatorFactory > xProgressFactory(xTargetFrame, css::uno::UNO_QUERY);
         if (xProgressFactory.is())
         {
diff --git a/include/framework/preventduplicateinteraction.hxx b/include/framework/preventduplicateinteraction.hxx
index 00c76089da2a..cf6ac0058eda 100644
--- a/include/framework/preventduplicateinteraction.hxx
+++ b/include/framework/preventduplicateinteraction.hxx
@@ -24,127 +24,17 @@
 
 #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 framework{
 
-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_TYPED(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&) throw (::css::uno::RuntimeException, ::std::exception) override
-    {
-    }
-
-    // XTerminateListener
-    virtual void SAL_CALL queryTermination(const css::lang::EventObject&) throw (::css::frame::TerminationVetoException, ::css::uno::RuntimeException, ::std::exception) override
-    {
-        closewarningdialogs();
-        Application::PostUserEvent(LINK(this, WarningDialogsParent, TerminateDesktop));
-        throw css::frame::TerminationVetoException();
-    }
-
-    virtual void SAL_CALL notifyTermination(const css::lang::EventObject&) throw (::css::uno::RuntimeException, ::std::exception) 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.
@@ -211,8 +101,6 @@ class FWE_DLLPUBLIC 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/include/vcl/dialog.hxx b/include/vcl/dialog.hxx
index 34e03fc03a99..87588d50c85d 100644
--- a/include/vcl/dialog.hxx
+++ b/include/vcl/dialog.hxx
@@ -38,8 +38,11 @@ public:
         /** Use given parent or get a default one using GetDefaultParent(...) */
         Default,
 
-        /** No Parent */
-        NoParent
+        /** Suppress Parent so that Parent is not blocked (kind of modal mode) */
+        NoParent,
+
+        /** Suppress Parent (no modal, see above) and additionally center on default parent */
+        NoParentCentered
     };
 
 private:
@@ -121,7 +124,8 @@ public:
 
 
     void            EndDialog( long nResult = 0 );
-    static void     EndAllDialogs( vcl::Window const * pParent );
+    static void     EndAllDialogs( vcl::Window* pParent=nullptr );
+    static bool     AreDialogsOpen();
 
     void            GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder,
                                          sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const;
diff --git a/include/vcl/msgbox.hxx b/include/vcl/msgbox.hxx
index f3351664574c..0f526f618fe6 100644
--- a/include/vcl/msgbox.hxx
+++ b/include/vcl/msgbox.hxx
@@ -47,7 +47,8 @@ protected:
 
 public:
                         MessBox( vcl::Window* pParent, WinBits nStyle,
-                                 const OUString& rTitle, const OUString& rMessage);
+                                 const OUString& rTitle, const OUString& rMessage,
+                            Dialog::InitFlag eInitFlag = Dialog::InitFlag::NoParentCentered);
     virtual             ~MessBox();
     virtual void        dispose() override;
 
diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx
index 34b659fa7f33..2be63c268198 100644
--- a/include/vcl/svapp.hxx
+++ b/include/vcl/svapp.hxx
@@ -1451,6 +1451,12 @@ public:
     // For vclbootstrapprotector:
     static void setDeInitHook(Link<LinkParamNone*,void> const & hook);
 
+    // for delayed shutdown: set using SetShutdownDelayed, then
+    // trigger using TriggerShutdownDelayed which may actually shutdown
+    // when SetShutdownDelayed is set
+    static void SetShutdownDelayed();
+    static void TriggerShutdownDelayed();
+
 private:
     DECL_STATIC_LINK_TYPED( Application, PostEventHandler, void*, void );
 };
diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx
index e94947ecc233..b53f5b474323 100644
--- a/uui/source/iahndl.cxx
+++ b/uui/source/iahndl.cxx
@@ -998,10 +998,33 @@ executeMessageBox(
     vcl::Window * pParent,
     OUString const & rTitle,
     OUString const & rMessage,
-    WinBits nStyle)
+    WinBits nButtonMask,
+    Dialog::InitFlag eInitFlag)
 {
     SolarMutexGuard aGuard;
-    ScopedVclPtrInstance< MessBox > xBox(pParent, nStyle, rTitle, rMessage);
+    ScopedVclPtrInstance< MessBox > xBox(pParent, nButtonMask, rTitle, rMessage, eInitFlag);
+
+    if (Dialog::InitFlag::NoParentCentered == eInitFlag)
+    {
+        vcl::Window* pDefaultParent = Dialog::GetDefaultParent(nButtonMask);
+
+        if (pDefaultParent)
+        {
+            // need to 'Show' to have the following tasks do someting, does
+            // not work without and may even stumble on nullptrs/errors
+            xBox->Show();
+
+            // center on parent window
+            const Point aP(pDefaultParent->GetPosPixel());
+            const Size aS(pDefaultParent->GetSizePixel());
+            const Size aMySize(xBox->GetSizePixel());
+
+            xBox->SetPosPixel(
+                Point(
+                    aP.X() + ((aS.Width() - aMySize.Width()) >> 1),
+                    aP.Y() + ((aS.Height() - aMySize.Height()) >> 1)));
+        }
+    }
 
     sal_uInt16 aResult = xBox->Execute();
     switch( aResult )
@@ -1152,7 +1175,8 @@ UUIInteractionHelper::handleGenericErrorRequest(
                 aTitle += " - " ;
             aTitle += aErrTitle;
 
-            executeMessageBox(getParentProperty(), aTitle, aErrorString, WB_OK);
+            executeMessageBox(
+                getParentProperty(), aTitle, aErrorString, WB_OK, Dialog::InitFlag::NoParentCentered);
         }
         else
             ErrorHandler::HandleError(nErrorCode);
@@ -1275,7 +1299,8 @@ UUIInteractionHelper::handleBrokenPackageRequest(
         " " +
         utl::ConfigManager::getProductVersion() );
 
-    switch (executeMessageBox(getParentProperty(), title, aMessage, nButtonMask))
+    switch (
+        executeMessageBox( getParentProperty(), title, aMessage, nButtonMask, Dialog::InitFlag::NoParentCentered) )
     {
     case ERRCODE_BUTTON_OK:
         OSL_ENSURE( xAbort.is(), "unexpected situation" );
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 6af3c7c1c7cf..fc6fefc7d958 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -1816,4 +1816,20 @@ void Application::setDeInitHook(Link<LinkParamNone*,void> const & hook) {
     pSVData->maAppData.mbInAppMain = true;
 }
 
+void Application::SetShutdownDelayed()
+{
+    ImplSVData * pSVData = ImplGetSVData();
+    pSVData->maAppData.mbShutdownDelayed = true;
+}
+
+void Application::TriggerShutdownDelayed()
+{
+    ImplSVData * pSVData = ImplGetSVData();
+
+    if (pSVData->maAppData.mbShutdownDelayed && !Dialog::AreDialogsOpen())
+    {
+        Application::PostUserEvent(LINK(nullptr, ImplSVAppData, ImplPrepareExitMsg));
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index d0aa084e777e..95fed10ab0a6 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -406,7 +406,7 @@ void Dialog::ImplInit( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag )
     // Now, all Dialogs are per default system windows !!!
     nStyle |= WB_SYSTEMWINDOW;
 
-    if (InitFlag::NoParent == eFlag)
+    if (InitFlag::NoParent == eFlag || InitFlag::NoParentCentered == eFlag)
     {
         pParent = nullptr;
     }
@@ -992,7 +992,7 @@ long Dialog::GetResult() const
     return mpDialogImpl->mnResult;
 }
 
-void Dialog::EndAllDialogs( vcl::Window const * pParent )
+void Dialog::EndAllDialogs( vcl::Window* pParent )
 {
     ImplSVData* pSVData = ImplGetSVData();
     Dialog* pTempModDialog;
@@ -1009,6 +1009,14 @@ void Dialog::EndAllDialogs( vcl::Window const * pParent )
     }
 }
 
+bool Dialog::AreDialogsOpen()
+{
+    ImplSVData* pSVData = ImplGetSVData();
+    Dialog* pModDialog = pSVData->maWinData.mpLastExecuteDlg;
+
+    return (nullptr != pModDialog);
+}
+
 void Dialog::SetModalInputMode( bool bModal )
 {
     if ( bModal == mbModalMode )
diff --git a/vcl/source/window/msgbox.cxx b/vcl/source/window/msgbox.cxx
index 172c9870889c..f6fd26773624 100644
--- a/vcl/source/window/msgbox.cxx
+++ b/vcl/source/window/msgbox.cxx
@@ -138,14 +138,12 @@ void MessBox::ImplInitButtons()
 }
 
 MessBox::MessBox( vcl::Window* pParent, WinBits nStyle,
-                  const OUString& rTitle, const OUString& rMessage) :
+                  const OUString& rTitle, const OUString& rMessage, Dialog::InitFlag eInitFlag) :
     ButtonDialog( WINDOW_MESSBOX ),
-    maMessText( rMessage ),
-    mbHelpBtn( false ),
-    mbCheck( false )
+    maMessText( rMessage )
 {
     ImplInitMessBoxData();
-    ImplInit( pParent, nStyle | WB_MOVEABLE | WB_HORZ | WB_CENTER);
+    ImplInit( pParent, nStyle | WB_MOVEABLE | WB_HORZ | WB_CENTER, eInitFlag);
     ImplInitButtons();
 
     if ( !rTitle.isEmpty() )


More information about the Libreoffice-commits mailing list