diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-05-11 13:44:44 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-05-11 16:56:52 +0200 |
commit | 318d5bf2a3d70300268c778074919fa908a0dcee (patch) | |
tree | d8266cb00cde559ee9e391fdc70f1abf0c8f19ef /forms | |
parent | 0c50447a94d092d1c19edb1bdebf9bf6dde3ae0f (diff) |
factor out finding the matching SfxObjectShell
Change-Id: I8d73e55e8fe836f495a44a0e24ac085f15bfcf4b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93965
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'forms')
-rw-r--r-- | forms/source/component/clickableimage.cxx | 90 | ||||
-rw-r--r-- | forms/source/component/clickableimage.hxx | 5 |
2 files changed, 51 insertions, 44 deletions
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<css::uno::XInterface> xIfc( *this ); + while( !xModel.is() && xIfc.is() ) + { + Reference<XChild> 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<css::uno::XInterface> xIfc( *this ); - while( !xModel.is() && xIfc.is() ) - { - Reference<XChild> 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 <com/sun/star/graphic/XGraphicObject.hpp> #include <cppuhelper/implbase3.hxx> - 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 ); }; |