From 318d5bf2a3d70300268c778074919fa908a0dcee Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 11 May 2020 13:44:44 +0100 Subject: factor out finding the matching SfxObjectShell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8d73e55e8fe836f495a44a0e24ac085f15bfcf4b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93965 Tested-by: Caolán McNamara Reviewed-by: Caolán McNamara --- forms/source/component/clickableimage.cxx | 90 ++++++++++++++++--------------- forms/source/component/clickableimage.hxx | 5 +- 2 files changed, 51 insertions(+), 44 deletions(-) (limited to 'forms/source') diff --git a/forms/source/component/clickableimage.cxx b/forms/source/component/clickableimage.cxx index e606ea2f549e..a78b1908fc65 100644 --- a/forms/source/component/clickableimage.cxx +++ b/forms/source/component/clickableimage.cxx @@ -684,6 +684,52 @@ namespace frm } } + SfxObjectShell* OClickableImageBaseModel::GetObjectShell() + { + // Find the XModel to get to the Object shell or at least the + // Referer. + // There's only a Model if we load HTML documents and the URL is + // changed in a document that is already loaded. There's no way + // we can get to the Model during loading. + Reference< XModel > xModel; + css::uno::Reference xIfc( *this ); + while( !xModel.is() && xIfc.is() ) + { + Reference xChild( xIfc, UNO_QUERY ); + xIfc = xChild->getParent(); + xModel.set(xIfc, css::uno::UNO_QUERY); + } + + // Search for the Object shell by iterating over all Object shells + // and comparing their XModel to ours. + // As an optimization, we try the current Object shell first. + SfxObjectShell *pObjSh = nullptr; + + if( xModel.is() ) + { + SfxObjectShell *pTestObjSh = SfxObjectShell::Current(); + if( pTestObjSh ) + { + Reference< XModel > xTestModel = pTestObjSh->GetModel(); + if( xTestModel == xModel ) + pObjSh = pTestObjSh; + } + if( !pObjSh ) + { + pTestObjSh = SfxObjectShell::GetFirst(); + while( !pObjSh && pTestObjSh ) + { + Reference< XModel > xTestModel = pTestObjSh->GetModel(); + if( xTestModel == xModel ) + pObjSh = pTestObjSh; + else + pTestObjSh = SfxObjectShell::GetNext( *pTestObjSh ); + } + } + } + + return pObjSh; + } void OClickableImageBaseModel::SetURL( const OUString& rURL ) { @@ -701,50 +747,10 @@ namespace frm return; if (!rURL.isEmpty() && !::svt::GraphicAccess::isSupportedURL( rURL ) ) - { + { m_pMedium.reset(new SfxMedium(rURL, StreamMode::STD_READ)); - // Find the XModel to get to the Object shell or at least the - // Referer. - // There's only a Model if we load HTML documents and the URL is - // changed in a document that is already loaded. There's no way - // we can get to the Model during loading. - Reference< XModel > xModel; - css::uno::Reference xIfc( *this ); - while( !xModel.is() && xIfc.is() ) - { - Reference xChild( xIfc, UNO_QUERY ); - xIfc = xChild->getParent(); - xModel.set(xIfc, css::uno::UNO_QUERY); - } - - // Search for the Object shell by iterating over all Object shells - // and comparing their XModel to ours. - // As an optimization, we try the current Object shell first. - SfxObjectShell *pObjSh = nullptr; - - if( xModel.is() ) - { - SfxObjectShell *pTestObjSh = SfxObjectShell::Current(); - if( pTestObjSh ) - { - Reference< XModel > xTestModel = pTestObjSh->GetModel(); - if( xTestModel == xModel ) - pObjSh = pTestObjSh; - } - if( !pObjSh ) - { - pTestObjSh = SfxObjectShell::GetFirst(); - while( !pObjSh && pTestObjSh ) - { - Reference< XModel > xTestModel = pTestObjSh->GetModel(); - if( xTestModel == xModel ) - pObjSh = pTestObjSh; - else - pTestObjSh = SfxObjectShell::GetNext( *pTestObjSh ); - } - } - } + SfxObjectShell *pObjSh = GetObjectShell(); #ifdef USE_REGISTER_TRANSFER if( pObjSh ) diff --git a/forms/source/component/clickableimage.hxx b/forms/source/component/clickableimage.hxx index d4a5065e0383..ad823c4209ac 100644 --- a/forms/source/component/clickableimage.hxx +++ b/forms/source/component/clickableimage.hxx @@ -35,9 +35,8 @@ #include #include - class SfxMedium; - +class SfxObjectShell; namespace frm { @@ -148,6 +147,8 @@ namespace frm // to be called from within the cloning-ctor of your derived class void implInitializeImageURL( ); + SfxObjectShell* GetObjectShell(); + DECL_LINK( OnImageImportDone, ::Graphic*, void ); }; -- cgit v1.2.3