summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2020-09-12 17:22:23 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2020-09-13 12:49:46 +0200
commit0c88fd43aebc57ebe8e4e49b74c1b6bef067ad89 (patch)
tree16173deb89a3b34d040a36ce2a25590d6bc0e849
parent35377971467be9b2ba30bab3e9b0983be11b4196 (diff)
Unify the code used to get object shell for components
and their parents across the codebase. Change-Id: Ifb37fb940d285f81c1724a912204533e8c3b0044 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102546 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--chart2/source/controller/drawinglayer/DrawViewWrapper.cxx30
-rw-r--r--include/sfx2/objsh.hxx4
-rw-r--r--sfx2/source/doc/objembed.cxx32
-rw-r--r--sfx2/source/doc/objitem.cxx19
-rw-r--r--sfx2/source/doc/objxtor.cxx37
-rw-r--r--sfx2/source/doc/ownsubfilterservice.cxx7
-rw-r--r--sfx2/source/doc/printhelper.cxx10
-rw-r--r--sfx2/source/statbar/stbitem.cxx15
-rw-r--r--sfx2/source/toolbox/tbxitem.cxx16
-rw-r--r--sfx2/source/view/frame.cxx14
-rw-r--r--starmath/source/unomodel.cxx11
11 files changed, 39 insertions, 156 deletions
diff --git a/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx b/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx
index d60b259dad62..4d9598430d08 100644
--- a/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx
+++ b/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx
@@ -32,7 +32,6 @@
#include <svx/svdoutl.hxx>
#include <svx/svxids.hrc>
#include <svx/unoshape.hxx>
-#include <tools/globname.hxx>
#include <editeng/fhgtitem.hxx>
#include <com/sun/star/container/XChild.hpp>
@@ -58,38 +57,11 @@ namespace
return nHitTolerance;
}
-// this code is copied from sfx2/source/doc/objembed.cxx
-SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
-{
- SfxObjectShell* pResult = nullptr;
-
- try
- {
- uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
- if ( xChildModel.is() )
- {
- uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
- if ( xParentTunnel.is() )
- {
- SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
- pResult = reinterpret_cast< SfxObjectShell * >(
- xParentTunnel->getSomething( aSfxIdent.GetByteSequence() ) );
- }
- }
- }
- catch( const uno::Exception& )
- {
- // TODO: error handling
- }
-
- return pResult;
-}
-
// this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
// get the reference device (e.g. printer) from the parent document
OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
{
- SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
+ SfxObjectShell* pParent = SfxObjectShell::GetParentShell(xModel);
if ( pParent )
return pParent->GetDocumentRefDev();
return nullptr;
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 6a5da58e3ae0..8da1f2bb7f82 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -583,7 +583,8 @@ public:
static SfxObjectShell* CreateObjectByFactoryName( const OUString& rURL, SfxObjectCreateMode = SfxObjectCreateMode::STANDARD );
static css::uno::Reference< css::lang::XComponent >
CreateAndLoadComponent( const SfxItemSet& rSet );
- static SfxObjectShell* GetShellFromComponent( const css::uno::Reference< css::lang::XComponent >& xComp );
+ static SfxObjectShell* GetShellFromComponent(const css::uno::Reference< css::uno::XInterface >& xComp);
+ static SfxObjectShell* GetParentShell(const css::uno::Reference<css::uno::XInterface>& xChild);
static OUString GetServiceNameFromFactory( const OUString& rFact );
bool IsInPlaceActive() const;
bool IsUIActive() const;
@@ -759,7 +760,6 @@ public:
SAL_DLLPRIVATE void SetProgress_Impl( SfxProgress *pProgress );
SAL_DLLPRIVATE void PostActivateEvent_Impl( SfxViewFrame const * );
SAL_DLLPRIVATE void SetActivateEvent_Impl(SfxEventHintId );
- SAL_DLLPRIVATE SfxObjectShell* GetParentShellByModel_Impl();
// configuration items
SAL_DLLPRIVATE SignatureState ImplGetSignatureState( bool bScriptingContent = false );
diff --git a/sfx2/source/doc/objembed.cxx b/sfx2/source/doc/objembed.cxx
index f6b4f5345055..cb1cd95663de 100644
--- a/sfx2/source/doc/objembed.cxx
+++ b/sfx2/source/doc/objembed.cxx
@@ -26,7 +26,6 @@
#include <sfx2/event.hxx>
#include <comphelper/fileformat.h>
-#include <tools/globname.hxx>
#include <tools/fract.hxx>
#include <vcl/transfer.hxx>
#include <vcl/outdev.hxx>
@@ -35,36 +34,9 @@
using namespace ::com::sun::star;
-// TODO/LATER: this workaround must be replaced by API in future if possible
-SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
-{
- SfxObjectShell* pResult = nullptr;
-
- try {
- uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
- if ( xChildModel.is() )
- {
- uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
- if ( xParentTunnel.is() )
- {
- SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
- pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
- aSfxIdent.GetByteSequence() ) );
- }
- }
- }
- catch( uno::Exception& )
- {
- // TODO: error handling
- }
-
- return pResult;
-}
-
-
Printer* SfxObjectShell::GetDocumentPrinter()
{
- SfxObjectShell* pParent = GetParentShellByModel_Impl();
+ SfxObjectShell* pParent = GetParentShell(GetModel());
if ( pParent )
return pParent->GetDocumentPrinter();
return nullptr;
@@ -73,7 +45,7 @@ Printer* SfxObjectShell::GetDocumentPrinter()
OutputDevice* SfxObjectShell::GetDocumentRefDev()
{
- SfxObjectShell* pParent = GetParentShellByModel_Impl();
+ SfxObjectShell* pParent = GetParentShell(GetModel());
if ( pParent )
return pParent->GetDocumentRefDev();
return nullptr;
diff --git a/sfx2/source/doc/objitem.cxx b/sfx2/source/doc/objitem.cxx
index 9f4e6126041b..911ec9a33303 100644
--- a/sfx2/source/doc/objitem.cxx
+++ b/sfx2/source/doc/objitem.cxx
@@ -23,8 +23,6 @@
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/frame/XModel.hpp>
-#include <tools/globname.hxx>
-
SfxPoolItem* SfxObjectShellItem::CreateDefault() { return new SfxObjectShellItem; }
@@ -64,22 +62,7 @@ bool SfxObjectShellItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMembe
if ( rVal >>= xModel )
{
- if ( xModel.is() )
- {
- css::uno::Reference< css::lang::XUnoTunnel > xTunnel( xModel, css::uno::UNO_QUERY );
- if ( xTunnel.is() )
- {
- css::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
- sal_Int64 nHandle = xTunnel->getSomething( aSeq );
- if ( nHandle )
- {
- pObjSh = reinterpret_cast< SfxObjectShell* >(sal::static_int_cast<sal_IntPtr>( nHandle ));
- return true;
- }
- }
- }
-
- pObjSh = nullptr;
+ pObjSh = SfxObjectShell::GetShellFromComponent(xModel);
return true;
}
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index 7dd8276eb20c..35c43e821248 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -991,17 +991,10 @@ SfxObjectShell* SfxObjectShell::CreateObject( const OUString& rServiceName, SfxO
if ( !rServiceName.isEmpty() )
{
uno::Reference < frame::XModel > xDoc( ::comphelper::getProcessServiceFactory()->createInstance( rServiceName ), UNO_QUERY );
- if ( xDoc.is() )
+ if (SfxObjectShell* pRet = SfxObjectShell::GetShellFromComponent(xDoc))
{
- uno::Reference < lang::XUnoTunnel > xObj( xDoc, UNO_QUERY );
- uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
- sal_Int64 nHandle = xObj->getSomething( aSeq );
- if ( nHandle )
- {
- SfxObjectShell* pRet = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
- pRet->SetCreateMode_Impl( eCreateMode );
- return pRet;
- }
+ pRet->SetCreateMode_Impl(eCreateMode);
+ return pRet;
}
}
@@ -1036,17 +1029,15 @@ Reference<lang::XComponent> SfxObjectShell::CreateAndLoadComponent( const SfxIte
return xComp;
}
-SfxObjectShell* SfxObjectShell::GetShellFromComponent( const Reference<lang::XComponent>& xComp )
+SfxObjectShell* SfxObjectShell::GetShellFromComponent(const Reference<uno::XInterface>& xComp)
{
try
{
Reference<lang::XUnoTunnel> xTunnel(xComp, UNO_QUERY_THROW);
Sequence <sal_Int8> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
sal_Int64 nHandle = xTunnel->getSomething( aSeq );
- if (!nHandle)
- return nullptr;
-
- return reinterpret_cast< SfxObjectShell* >(sal::static_int_cast< sal_IntPtr >( nHandle ));
+ if (nHandle)
+ return reinterpret_cast<SfxObjectShell*>(sal::static_int_cast<sal_IntPtr>(nHandle));
}
catch (const Exception&)
{
@@ -1055,6 +1046,22 @@ SfxObjectShell* SfxObjectShell::GetShellFromComponent( const Reference<lang::XCo
return nullptr;
}
+SfxObjectShell* SfxObjectShell::GetParentShell(const css::uno::Reference<css::uno::XInterface>& xChild)
+{
+ SfxObjectShell* pResult = nullptr;
+
+ try
+ {
+ if (css::uno::Reference<css::container::XChild> xChildModel{ xChild, css::uno::UNO_QUERY })
+ pResult = GetShellFromComponent(xChildModel->getParent());
+ }
+ catch (const Exception&)
+ {
+ }
+
+ return pResult;
+}
+
void SfxObjectShell::SetInitialized_Impl( const bool i_fromInitNew )
{
pImpl->bInitialized = true;
diff --git a/sfx2/source/doc/ownsubfilterservice.cxx b/sfx2/source/doc/ownsubfilterservice.cxx
index af6a903e5460..7e1048da06b4 100644
--- a/sfx2/source/doc/ownsubfilterservice.cxx
+++ b/sfx2/source/doc/ownsubfilterservice.cxx
@@ -29,7 +29,6 @@
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <sfx2/objsh.hxx>
-#include <tools/globname.hxx>
using namespace css;
@@ -69,11 +68,7 @@ OwnSubFilterService::OwnSubFilterService(const css::uno::Sequence< css::uno::Any
if ( ( aArguments[1] >>= m_xStream ) && m_xStream.is()
&& ( aArguments[0] >>= m_xModel ) && m_xModel.is() )
{
- css::uno::Reference < css::lang::XUnoTunnel > xObj( m_xModel, uno::UNO_QUERY_THROW );
- css::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
- sal_Int64 nHandle = xObj->getSomething( aSeq );
- if ( nHandle )
- m_pObjectShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ m_pObjectShell = SfxObjectShell::GetShellFromComponent(m_xModel);
}
if ( !m_pObjectShell )
diff --git a/sfx2/source/doc/printhelper.cxx b/sfx2/source/doc/printhelper.cxx
index 821c78f8b897..e0c2cc75ad77 100644
--- a/sfx2/source/doc/printhelper.cxx
+++ b/sfx2/source/doc/printhelper.cxx
@@ -37,7 +37,6 @@
#include <unotools/tempfile.hxx>
#include <osl/file.hxx>
#include <osl/thread.hxx>
-#include <tools/globname.hxx>
#include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx>
#include <cppuhelper/interfacecontainer.hxx>
@@ -155,14 +154,9 @@ void SAL_CALL SfxPrintHelper::initialize( const css::uno::Sequence< css::uno::An
css::uno::Reference < css::frame::XModel > xModel;
aArguments[0] >>= xModel;
- uno::Reference < lang::XUnoTunnel > xObj( xModel, uno::UNO_QUERY );
- uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
- sal_Int64 nHandle = xObj->getSomething( aSeq );
- if ( nHandle )
- {
- m_pData->m_pObjectShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
+ m_pData->m_pObjectShell = SfxObjectShell::GetShellFromComponent(xModel);
+ if (m_pData->m_pObjectShell)
m_pData->StartListening(*m_pData->m_pObjectShell);
- }
}
SfxPrintHelper::~SfxPrintHelper()
diff --git a/sfx2/source/statbar/stbitem.cxx b/sfx2/source/statbar/stbitem.cxx
index 5695bfb296ee..58dea92b8026 100644
--- a/sfx2/source/statbar/stbitem.cxx
+++ b/sfx2/source/statbar/stbitem.cxx
@@ -46,7 +46,6 @@
#include <svl/intitem.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <toolkit/helper/convert.hxx>
-#include <tools/globname.hxx>
#include <ctrlfactoryimpl.hxx>
using namespace ::com::sun::star;
@@ -80,7 +79,6 @@ svt::StatusbarController* SfxStatusBarControllerFactory(
uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
xTrans->parseStrict( aTargetURL );
- SfxObjectShell* pObjShell = nullptr;
uno::Reference < frame::XController > xController;
uno::Reference < frame::XModel > xModel;
if ( rFrame.is() )
@@ -90,18 +88,7 @@ svt::StatusbarController* SfxStatusBarControllerFactory(
xModel = xController->getModel();
}
- if ( xModel.is() )
- {
- // Get tunnel from model to retrieve the SfxObjectShell pointer from it
- css::uno::Reference < css::lang::XUnoTunnel > xObj( xModel, uno::UNO_QUERY );
- css::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
- if ( xObj.is() )
- {
- sal_Int64 nHandle = xObj->getSomething( aSeq );
- if ( nHandle )
- pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
- }
- }
+ SfxObjectShell* pObjShell = SfxObjectShell::GetShellFromComponent(xModel);
SfxModule* pModule = pObjShell ? pObjShell->GetModule() : nullptr;
SfxSlotPool* pSlotPool = nullptr;
diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx
index 0559ac6464f9..1240100e9daa 100644
--- a/sfx2/source/toolbox/tbxitem.cxx
+++ b/sfx2/source/toolbox/tbxitem.cxx
@@ -47,7 +47,6 @@
#include <vcl/taskpanelist.hxx>
#include <vcl/event.hxx>
#include <toolkit/helper/vclunohelper.hxx>
-#include <tools/globname.hxx>
#include <vcl/InterimItemWindow.hxx>
#include <sfx2/tbxctrl.hxx>
@@ -84,7 +83,6 @@ svt::ToolboxController* SfxToolBoxControllerFactory( const Reference< XFrame >&
if ( !aTargetURL.Arguments.isEmpty() )
return nullptr;
- SfxObjectShell* pObjShell = nullptr;
Reference < XController > xController;
Reference < XModel > xModel;
if ( rFrame.is() )
@@ -94,19 +92,7 @@ svt::ToolboxController* SfxToolBoxControllerFactory( const Reference< XFrame >&
xModel = xController->getModel();
}
- if ( xModel.is() )
- {
- // Get tunnel from model to retrieve the SfxObjectShell pointer from it
- css::uno::Reference < css::lang::XUnoTunnel > xObj( xModel, UNO_QUERY );
- if ( xObj.is() )
- {
- css::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
- sal_Int64 nHandle = xObj->getSomething( aSeq );
- if ( nHandle )
- pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
- }
- }
-
+ SfxObjectShell* pObjShell = SfxObjectShell::GetShellFromComponent(xModel);
SfxModule* pModule = pObjShell ? pObjShell->GetModule() : nullptr;
SfxSlotPool* pSlotPool = nullptr;
diff --git a/sfx2/source/view/frame.cxx b/sfx2/source/view/frame.cxx
index c7aa11f97b08..8997b9367317 100644
--- a/sfx2/source/view/frame.cxx
+++ b/sfx2/source/view/frame.cxx
@@ -30,7 +30,6 @@
#include <vcl/menu.hxx>
#include <svl/intitem.hxx>
#include <svl/stritem.hxx>
-#include <tools/globname.hxx>
#include <tools/svborder.hxx>
#include <osl/diagnose.h>
@@ -691,15 +690,10 @@ void SfxFrame::Resize()
SfxInPlaceClient* pClient = GetCurrentViewFrame()->GetViewShell() ? GetCurrentViewFrame()->GetViewShell()->GetUIActiveIPClient_Impl() : nullptr;
if ( pClient )
{
- uno::Reference < lang::XUnoTunnel > xObj( pClient->GetObject()->getComponent(), uno::UNO_QUERY );
- uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
- sal_Int64 nHandle = (xObj.is()? xObj->getSomething( aSeq ): 0);
- if ( nHandle )
- {
- SfxObjectShell* pDoc = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
- SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDoc );
- pWork = pFrame ? pFrame->GetFrame().GetWorkWindow_Impl() : nullptr;
- }
+ SfxObjectShell* pDoc
+ = SfxObjectShell::GetShellFromComponent(pClient->GetObject()->getComponent());
+ SfxViewFrame* pFrame = SfxViewFrame::GetFirst(pDoc);
+ pWork = pFrame ? pFrame->GetFrame().GetWorkWindow_Impl() : nullptr;
}
if ( pWork )
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index 17d52ce7b4d6..bb46211914e3 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -1063,15 +1063,8 @@ void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xPare
{
SolarMutexGuard aGuard;
SfxBaseModel::setParent( xParent );
- uno::Reference< lang::XUnoTunnel > xParentTunnel( xParent, uno::UNO_QUERY );
- if ( xParentTunnel.is() )
- {
- SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
- SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell *>(xParentTunnel->getSomething(
- aSfxIdent.GetByteSequence() ) );
- if ( pDoc )
- GetObjectShell()->OnDocumentPrinterChanged( pDoc->GetDocumentPrinter() );
- }
+ if (SfxObjectShell* pDoc = SfxObjectShell::GetShellFromComponent(xParent))
+ GetObjectShell()->OnDocumentPrinterChanged(pDoc->GetDocumentPrinter());
}
void SmModel::writeFormulaOoxml(