Resolves: tdf#121607 set parent for password dialogs

Change-Id: I02210a61d103aed4a181b0e907ea2fd141e5f587
Reviewed-on: https://gerrit.libreoffice.org/63787
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index c4abf49..8ca9302 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -386,7 +386,8 @@ public:

    static css::uno::Reference< css::sdbc::XConnection>
            GetConnection(const OUString& rDataSource,
                css::uno::Reference< css::sdbc::XDataSource>& rxSource);
                css::uno::Reference< css::sdbc::XDataSource>& rxSource,
                SwView* pView);

    static css::uno::Reference< css::sdbcx::XColumnsSupplier>
            GetColumnSupplier(css::uno::Reference< css::sdbc::XConnection> const & xConnection,
@@ -444,11 +445,11 @@ public:

    */
    static css::uno::Reference< css::sdbc::XResultSet>
            createCursor(   const OUString& _sDataSourceName,
                            const OUString& _sCommand,
                            sal_Int32 _nCommandType,
                            const css::uno::Reference< css::sdbc::XConnection>& _xConnection
                            );
            createCursor(const OUString& _sDataSourceName,
                         const OUString& _sCommand,
                         sal_Int32 _nCommandType,
                         const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
                         SwView* pView);

    void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell);
    const OUString& getEmbeddedName() const;
diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx
index 4b804eb..60759a3b 100644
--- a/sw/source/ui/dbui/dbinsdlg.cxx
+++ b/sw/source/ui/dbui/dbinsdlg.cxx
@@ -957,7 +957,7 @@ void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection,
    // we don't have a cursor, so we have to create our own RowSet
    if ( !xResultSet.is() )
    {
        xResultSet = SwDBManager::createCursor(aDBData.sDataSource,aDBData.sCommand,aDBData.nCommandType,xConnection);
        xResultSet = SwDBManager::createCursor(aDBData.sDataSource,aDBData.sCommand,aDBData.nCommandType,xConnection,pView);
        bDisposeResultSet = xResultSet.is();
    }

diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 71ee070..97063bb 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -1931,7 +1931,7 @@ sal_Int32 SwDBManager::GetColumnType( const OUString& rDBName,
}

uno::Reference< sdbc::XConnection> SwDBManager::GetConnection(const OUString& rDataSource,
                                                    uno::Reference<sdbc::XDataSource>& rxSource)
                                                              uno::Reference<sdbc::XDataSource>& rxSource, SwView *pView)
{
    uno::Reference< sdbc::XConnection> xConnection;
    uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
@@ -1941,7 +1941,8 @@ uno::Reference< sdbc::XConnection> SwDBManager::GetConnection(const OUString& rD
        if ( xComplConnection.is() )
        {
            rxSource.set(xComplConnection, uno::UNO_QUERY);
            uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(xContext, nullptr), uno::UNO_QUERY_THROW );
            weld::Window* pWindow = pView ? pView->GetFrameWeld() : nullptr;
            uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(xContext, pWindow ? pWindow->GetXWindow() : nullptr), uno::UNO_QUERY_THROW );
            xConnection = xComplConnection->connectWithCompletion( xHandler );
        }
    }
@@ -2420,7 +2421,8 @@ uno::Reference< sdbc::XConnection> const & SwDBManager::RegisterConnection(OUStr
    uno::Reference< sdbc::XDataSource> xSource;
    if(!pFound->xConnection.is())
    {
        pFound->xConnection = SwDBManager::GetConnection(rDataSource, xSource );
        SwView* pView = (m_pDoc && m_pDoc->GetDocShell()) ? m_pDoc->GetDocShell()->GetView() : nullptr;
        pFound->xConnection = SwDBManager::GetConnection(rDataSource, xSource, pView);
        try
        {
            uno::Reference<lang::XComponent> xComponent(pFound->xConnection, uno::UNO_QUERY);
@@ -3183,8 +3185,8 @@ uno::Reference<sdbc::XDataSource> SwDBManager::getDataSourceAsParent(const uno::
uno::Reference<sdbc::XResultSet> SwDBManager::createCursor(const OUString& _sDataSourceName,
                                       const OUString& _sCommand,
                                       sal_Int32 _nCommandType,
                                       const uno::Reference<sdbc::XConnection>& _xConnection
                                      )
                                       const uno::Reference<sdbc::XConnection>& _xConnection,
                                       SwView* pView)
{
    uno::Reference<sdbc::XResultSet> xResultSet;
    try
@@ -3205,7 +3207,8 @@ uno::Reference<sdbc::XResultSet> SwDBManager::createCursor(const OUString& _sDat

                if ( xRowSet.is() )
                {
                    uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(comphelper::getComponentContext(xMgr), nullptr), uno::UNO_QUERY_THROW );
                    weld::Window* pWindow = pView ? pView->GetFrameWeld() : nullptr;
                    uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(comphelper::getComponentContext(xMgr), pView ? pWindow->GetXWindow() : nullptr), uno::UNO_QUERY_THROW );
                    xRowSet->executeWithCompletion(xHandler);
                }
                xResultSet.set(xRowSet, uno::UNO_QUERY);
diff --git a/sw/source/uibase/dbui/mmconfigitem.cxx b/sw/source/uibase/dbui/mmconfigitem.cxx
index d7c4707..6e6a6a4 100644
--- a/sw/source/uibase/dbui/mmconfigitem.cxx
+++ b/sw/source/uibase/dbui/mmconfigitem.cxx
@@ -863,7 +863,7 @@ Reference< XResultSet> const & SwMailMergeConfigItem::GetResultSet() const
    if(!m_pImpl->m_xConnection.is() && !m_pImpl->m_aDBData.sDataSource.isEmpty())
    {
        m_pImpl->m_xConnection.reset(
            SwDBManager::GetConnection( m_pImpl->m_aDBData.sDataSource, m_pImpl->m_xSource ),
            SwDBManager::GetConnection(m_pImpl->m_aDBData.sDataSource, m_pImpl->m_xSource, m_pSourceView),
            SharedConnection::TakeOwnership
        );
    }
diff --git a/sw/source/uibase/shells/textsh2.cxx b/sw/source/uibase/shells/textsh2.cxx
index 7a0afc7..e5369fa 100644
--- a/sw/source/uibase/shells/textsh2.cxx
+++ b/sw/source/uibase/shells/textsh2.cxx
@@ -116,7 +116,8 @@ void SwTextShell::ExecDB(SfxRequest const &rReq)
    if ( !xConnection.is() )
    {
        Reference<XDataSource> xSource;
        xConnection = SwDBManager::GetConnection(sSourceArg, xSource);
        SwView &rSwView = GetView();
        xConnection = SwDBManager::GetConnection(sSourceArg, xSource, &rSwView);
    }
    if(!xConnection.is())
        return ;
@@ -155,7 +156,8 @@ void SwTextShell::ExecDB(SfxRequest const &rReq)
                bool bDisposeResultSet = false;
                if ( !xCursor.is() )
                {
                    xCursor = SwDBManager::createCursor(sSourceArg,sCommandArg,nCommandTypeArg,xConnection);
                    SwView &rSwView = GetView();
                    xCursor = SwDBManager::createCursor(sSourceArg,sCommandArg,nCommandTypeArg,xConnection,&rSwView);
                    bDisposeResultSet = xCursor.is();
                }

@@ -233,7 +235,8 @@ IMPL_LINK( SwBaseShell, InsertDBTextHdl, void*, p, void )

        if ( !xConnection.is()  )
        {
            xConnection = SwDBManager::GetConnection(pDBStruct->aDBData.sDataSource, xSource);
            SwView &rSwView = GetView();
            xConnection = SwDBManager::GetConnection(pDBStruct->aDBData.sDataSource, xSource, &rSwView);
            bDispose = true;
        }