Resolves: tdf#124698 bubble down parent for modal dialog
Change-Id: If03c6ff8043bb39f2efdf4cde19d8277886bf36f
Reviewed-on: https://gerrit.libreoffice.org/70658
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/sfx2/linkmgr.hxx b/include/sfx2/linkmgr.hxx
index 2646d2d..7f3bf02 100644
--- a/include/sfx2/linkmgr.hxx
+++ b/include/sfx2/linkmgr.hxx
@@ -158,7 +158,8 @@ public:
static bool GetGraphicFromAny(const OUString& rMimeType,
const css::uno::Any & rValue,
const OUString& rReferer,
Graphic& rGrf);
Graphic& rGrf,
weld::Window* pParentWin);
private:
LinkManager( const LinkManager& ) = delete;
diff --git a/include/unotools/ucbstreamhelper.hxx b/include/unotools/ucbstreamhelper.hxx
index fd0a8cd..0d7d867 100644
--- a/include/unotools/ucbstreamhelper.hxx
+++ b/include/unotools/ucbstreamhelper.hxx
@@ -19,6 +19,8 @@
#ifndef INCLUDED_UNOTOOLS_UCBSTREAMHELPER_HXX
#define INCLUDED_UNOTOOLS_UCBSTREAMHELPER_HXX
#include <com/sun/star/awt/XWindow.hpp>
#include <unotools/unotoolsdllapi.h>
#include <tools/stream.hxx>
@@ -45,9 +47,9 @@ namespace utl
class UNOTOOLS_DLLPUBLIC UcbStreamHelper
{
public:
static std::unique_ptr<SvStream> CreateStream( const OUString& rFileName, StreamMode eOpenMode );
static std::unique_ptr<SvStream> CreateStream( const OUString& rFileName, StreamMode eOpenMode,
bool bFileExists );
static std::unique_ptr<SvStream> CreateStream(const OUString& rFileName, StreamMode eOpenMode, css::uno::Reference<css::awt::XWindow> xParentWin = nullptr);
static std::unique_ptr<SvStream> CreateStream(const OUString& rFileName, StreamMode eOpenMode,
bool bFileExists, css::uno::Reference<css::awt::XWindow> xParentWin = nullptr);
static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream );
static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XStream >& xStream );
static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream, bool bCloseStream );
diff --git a/include/vcl/GraphicLoader.hxx b/include/vcl/GraphicLoader.hxx
index 9b96ec1..5cca83a 100644
--- a/include/vcl/GraphicLoader.hxx
+++ b/include/vcl/GraphicLoader.hxx
@@ -12,11 +12,16 @@
#include <vcl/graph.hxx>
namespace weld
{
class Window;
}
namespace vcl
{
namespace graphic
{
Graphic VCL_DLLPUBLIC loadFromURL(OUString const& rURL);
Graphic VCL_DLLPUBLIC loadFromURL(OUString const& rURL, weld::Window* pParentWin = nullptr);
}
} // end vcl::graphic
diff --git a/sfx2/source/appl/linkmgr2.cxx b/sfx2/source/appl/linkmgr2.cxx
index 459ded0..9654175 100644
--- a/sfx2/source/appl/linkmgr2.cxx
+++ b/sfx2/source/appl/linkmgr2.cxx
@@ -502,7 +502,8 @@ SotClipboardFormatId LinkManager::RegisterStatusInfoId()
bool LinkManager::GetGraphicFromAny(const OUString& rMimeType,
const css::uno::Any & rValue,
const OUString& rReferer,
Graphic& rGraphic )
Graphic& rGraphic,
weld::Window* pParentWin)
{
bool bRet = false;
@@ -513,7 +514,7 @@ bool LinkManager::GetGraphicFromAny(const OUString& rMimeType,
{
OUString sURL = rValue.get<OUString>();
if (!SvtSecurityOptions().isUntrustedReferer(rReferer))
rGraphic = vcl::graphic::loadFromURL(sURL);
rGraphic = vcl::graphic::loadFromURL(sURL, pParentWin);
if (!rGraphic)
rGraphic.SetDefaultType();
rGraphic.setOriginURL(sURL);
diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx
index c8eb04b..7360157 100644
--- a/svx/source/svdraw/svdograf.cxx
+++ b/svx/source/svdraw/svdograf.cxx
@@ -103,7 +103,7 @@ SdrGraphicLink::SdrGraphicLink(SdrGrafObj& rObj)
sfx2::LinkManager::GetDisplayNames( this, nullptr, &rGrafObj.aFileName, nullptr, &rGrafObj.aFilterName );
Graphic aGraphic;
if (sfx2::LinkManager::GetGraphicFromAny(rMimeType, rValue, getReferer(), aGraphic))
if (sfx2::LinkManager::GetGraphicFromAny(rMimeType, rValue, getReferer(), aGraphic, nullptr))
{
rGrafObj.ImpSetLinkedGraphic(aGraphic);
}
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 1cd8d8c..9f92d20 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -489,6 +489,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
sw/source/core/unocore/unotbl \
sw/source/core/unocore/unotext \
sw/source/core/unocore/unotextmarkup \
sw/source/core/view/dialoghelp \
sw/source/core/view/pagepreviewlayout \
sw/source/core/view/printdata \
sw/source/core/view/vdraw \
diff --git a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
index 018ca3e0..65f0319 100644
--- a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
+++ b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
@@ -29,6 +29,7 @@
#include <sfx2/linkmgr.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/frame.hxx>
#include <dialoghelp.hxx>
#include <linkenum.hxx>
#include <com/sun/star/document/UpdateDocMode.hpp>
#include <swtypes.hxx>
@@ -237,11 +238,8 @@ void DocumentLinksAdministrationManager::UpdateLinks()
{
rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
SfxMedium* pMedium = m_rDoc.GetDocShell()->GetMedium();
SfxFrame* pFrame = pMedium ? pMedium->GetLoadTargetFrame() : nullptr;
weld::Window* pDlgParent = pFrame ? pFrame->GetWindow().GetFrameWeld() : nullptr;
GetLinkManager().UpdateAllLinks( bAskUpdate, false, pDlgParent );
weld::Window* pDlgParent = GetFrameWeld(m_rDoc.GetDocShell());
GetLinkManager().UpdateAllLinks(bAskUpdate, false, pDlgParent);
}
else
{
diff --git a/sw/source/core/docnode/swbaslnk.cxx b/sw/source/core/docnode/swbaslnk.cxx
index 7d0edf5..8957ac4 100644
--- a/sw/source/core/docnode/swbaslnk.cxx
+++ b/sw/source/core/docnode/swbaslnk.cxx
@@ -53,6 +53,7 @@
#include <cntfrm.hxx>
#include <htmltbl.hxx>
#include <calbck.hxx>
#include <dialoghelp.hxx>
#include <memory>
using namespace com::sun::star;
@@ -149,7 +150,10 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem )
sReferer = sh->GetMedium()->GetName();
}
if( sfx2::LinkManager::GetGraphicFromAny(rMimeType, rValue, sReferer, aGrf) &&
// tdf#124698 if any auth dialog is needed, find what the parent window should be
weld::Window* pDlgParent = GetFrameWeld(pDoc);
if( sfx2::LinkManager::GetGraphicFromAny(rMimeType, rValue, sReferer, aGrf, pDlgParent) &&
( GraphicType::Default != aGrf.GetType() ||
GraphicType::Default != rGrfObj.GetType() ) )
{
diff --git a/sw/source/core/inc/dialoghelp.hxx b/sw/source/core/inc/dialoghelp.hxx
new file mode 100644
index 0000000..ce9c072
--- /dev/null
+++ b/sw/source/core/inc/dialoghelp.hxx
@@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SW_SOURCE_CORE_INC_DIALOGHELP_HXX
#define INCLUDED_SW_SOURCE_CORE_INC_DIALOGHELP_HXX
class SwDoc;
class SwDocShell;
class SfxFrame;
class SfxMedium;
namespace weld
{
class Window;
}
weld::Window* GetFrameWeld(SfxFrame* pFrame);
weld::Window* GetFrameWeld(SfxMedium* pMedium);
weld::Window* GetFrameWeld(SwDocShell* pDocSh);
weld::Window* GetFrameWeld(SwDoc* pDoc);
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sw/source/core/view/dialoghelp.cxx b/sw/source/core/view/dialoghelp.cxx
new file mode 100644
index 0000000..0ee7658
--- /dev/null
+++ b/sw/source/core/view/dialoghelp.cxx
@@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sfx2/docfile.hxx>
#include <sfx2/frame.hxx>
#include <vcl/weld.hxx>
#include <vcl/window.hxx>
#include <dialoghelp.hxx>
#include <doc.hxx>
#include <docsh.hxx>
#include <view.hxx>
weld::Window* GetFrameWeld(SfxFrame* pFrame)
{
return pFrame ? pFrame->GetWindow().GetFrameWeld() : nullptr;
}
weld::Window* GetFrameWeld(SfxMedium* pMedium)
{
return GetFrameWeld(pMedium ? pMedium->GetLoadTargetFrame() : nullptr);
}
weld::Window* GetFrameWeld(SwDocShell* pDocShell)
{
if (!pDocShell)
return nullptr;
weld::Window* pRet = GetFrameWeld(pDocShell->GetMedium());
if (!pRet)
{
if (SwView* pView = pDocShell->GetView())
pRet = pView->GetFrameWeld();
}
return pRet;
}
weld::Window* GetFrameWeld(SwDoc* pDoc)
{
return GetFrameWeld(pDoc ? pDoc->GetDocShell() : nullptr);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/unotools/source/ucbhelper/ucbstreamhelper.cxx b/unotools/source/ucbhelper/ucbstreamhelper.cxx
index 94d8845..33c6529 100644
--- a/unotools/source/ucbhelper/ucbstreamhelper.cxx
+++ b/unotools/source/ucbhelper/ucbstreamhelper.cxx
@@ -138,24 +138,24 @@ static std::unique_ptr<SvStream> lcl_CreateStream( const OUString& rFileName, St
return pStream;
}
std::unique_ptr<SvStream> UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode )
std::unique_ptr<SvStream> UcbStreamHelper::CreateStream(const OUString& rFileName, StreamMode eOpenMode, css::uno::Reference<css::awt::XWindow> xParentWin)
{
// related tdf#99312
// create a specialized interaction handler to manages Web certificates and Web credentials when needed
Reference< XInteractionHandler > xIH(
css::task::InteractionHandler::createWithParent( comphelper::getProcessComponentContext(), nullptr ) );
css::task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), xParentWin));
Reference<XInteractionHandler> xIHScoped(new comphelper::SimpleFileAccessInteraction(xIH));
return lcl_CreateStream( rFileName, eOpenMode, xIHScoped, true /* bEnsureFileExists */ );
}
std::unique_ptr<SvStream> UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode,
bool bFileExists )
std::unique_ptr<SvStream> UcbStreamHelper::CreateStream(const OUString& rFileName, StreamMode eOpenMode,
bool bFileExists, css::uno::Reference<css::awt::XWindow> xParentWin)
{
// related tdf#99312
// create a specialized interaction handler to manages Web certificates and Web credentials when needed
Reference< XInteractionHandler > xIH(
css::task::InteractionHandler::createWithParent( comphelper::getProcessComponentContext(), nullptr ) );
css::task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), xParentWin));
Reference<XInteractionHandler> xIHScoped(new comphelper::SimpleFileAccessInteraction(xIH));
return lcl_CreateStream( rFileName, eOpenMode, xIHScoped,!bFileExists );
}
diff --git a/vcl/source/graphic/GraphicLoader.cxx b/vcl/source/graphic/GraphicLoader.cxx
index 770cb21..8343b51 100644
--- a/vcl/source/graphic/GraphicLoader.cxx
+++ b/vcl/source/graphic/GraphicLoader.cxx
@@ -12,6 +12,7 @@
#include <unotools/ucbstreamhelper.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/weld.hxx>
#include <vcl/wmf.hxx>
using namespace css;
@@ -20,12 +21,12 @@ namespace vcl
{
namespace graphic
{
Graphic loadFromURL(OUString const& rURL)
Graphic loadFromURL(OUString const& rURL, weld::Window* pParentWin)
{
Graphic aGraphic;
std::unique_ptr<SvStream> pInputStream
= utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ);
std::unique_ptr<SvStream> pInputStream = utl::UcbStreamHelper::CreateStream(
rURL, StreamMode::READ, pParentWin ? pParentWin->GetXWindow() : nullptr);
if (pInputStream)
{