summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-09-29 17:20:22 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-09-29 18:18:28 +0200
commitc2ca6fabd1afc3fc07001721c2069d3c8db7000a (patch)
tree350741d6d19564bcaf00506bd7d22b4c644e0fdc /sc
parentf05d7abf93bbcf443cb0b5759ca19992e2fa85a3 (diff)
Use comphelper::getComponentContext
...and some further clean up. Change-Id: Id294c0f38fe0041646fc86cacbd2e19734c746a9
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/dpobject.cxx8
-rw-r--r--sc/source/core/tool/addincol.cxx18
-rw-r--r--sc/source/ui/docshell/docsh.cxx50
-rw-r--r--sc/source/ui/miscdlgs/solverutil.cxx33
-rw-r--r--sc/source/ui/vba/excelvbahelper.cxx6
-rw-r--r--sc/source/ui/vba/vbahelper.cxx15
-rw-r--r--sc/source/ui/vba/vbaworksheet.cxx6
7 files changed, 54 insertions, 82 deletions
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index a9462b6465e1..8c5e0c4a0274 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2628,9 +2628,6 @@ uno::Sequence<rtl::OUString> ScDPObject::GetRegisteredSources()
return aSeq;
}
-// use getContext from addincol.cxx
-uno::Reference<uno::XComponentContext> getContext(uno::Reference<lang::XMultiServiceFactory> xMSF);
-
uno::Reference<sheet::XDimensionsSupplier> ScDPObject::CreateSource( const ScDPServiceDesc& rDesc )
{
rtl::OUString aImplName = rDesc.aServiceName;
@@ -2664,9 +2661,10 @@ uno::Reference<sheet::XDimensionsSupplier> ScDPObject::CreateSource( const ScDPS
// passing the context to the component (see ScUnoAddInCollection::Initialize)
uno::Reference<uno::XInterface> xInterface;
- uno::Reference<uno::XComponentContext> xCtx = getContext(xManager);
+ uno::Reference<uno::XComponentContext> xCtx(
+ comphelper::getComponentContext(xManager));
uno::Reference<lang::XSingleComponentFactory> xCFac( xIntFac, uno::UNO_QUERY );
- if (xCtx.is() && xCFac.is())
+ if (xCFac.is())
xInterface = xCFac->createInstanceWithContext(xCtx);
if (!xInterface.is())
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index 33c92320c7b7..ac3b81272a76 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -281,19 +281,6 @@ void ScUnoAddInCollection::Clear()
bInitialized = false;
}
-uno::Reference<uno::XComponentContext> getContext(uno::Reference<lang::XMultiServiceFactory> xMSF)
-{
- uno::Reference<uno::XComponentContext> xCtx;
- try {
- uno::Reference<beans::XPropertySet> xPropset(xMSF, uno::UNO_QUERY);
- xPropset->getPropertyValue(
- ::rtl::OUString("DefaultContext")) >>= xCtx;
- }
- catch ( uno::Exception & ) {
- }
- return xCtx;
-}
-
void ScUnoAddInCollection::Initialize()
{
OSL_ENSURE( !bInitialized, "Initialize twice?" );
@@ -321,9 +308,10 @@ void ScUnoAddInCollection::Initialize()
// passing the context to the component
uno::Reference<uno::XInterface> xInterface;
- uno::Reference<uno::XComponentContext> xCtx = getContext(xManager);
+ uno::Reference<uno::XComponentContext> xCtx(
+ comphelper::getComponentContext(xManager));
uno::Reference<lang::XSingleComponentFactory> xCFac( xIntFac, uno::UNO_QUERY );
- if (xCtx.is() && xCFac.is())
+ if (xCFac.is())
{
xInterface = xCFac->createInstanceWithContext(xCtx);
if (xInterface.is())
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 211473104ebf..645911d8e5a5 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -683,36 +683,34 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
try
{
- uno::Reference< uno::XComponentContext > xContext;
- uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
- uno::Reference< beans::XPropertySet > xProp( xServiceManager, uno::UNO_QUERY_THROW );
- xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ) >>= xContext;
- if ( xContext.is() )
+ uno::Reference< uno::XComponentContext > xContext(
+ comphelper::getProcessComponentContext() );
+ uno::Reference< lang::XMultiServiceFactory > xServiceManager(
+ xContext->getServiceManager(),
+ uno::UNO_QUERY_THROW );
+ uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xServiceManager, uno::UNO_QUERY_THROW );
+ uno::Reference< container::XEnumeration> xEnum = xEnumAccess->createContentEnumeration(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocumentJob" ) ) );
+ if ( xEnum.is() )
{
- uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xServiceManager, uno::UNO_QUERY_THROW );
- uno::Reference< container::XEnumeration> xEnum = xEnumAccess->createContentEnumeration(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocumentJob" ) ) );
- if ( xEnum.is() )
+ while ( xEnum->hasMoreElements() )
{
- while ( xEnum->hasMoreElements() )
+ uno::Any aAny = xEnum->nextElement();
+ uno::Reference< lang::XSingleComponentFactory > xFactory;
+ aAny >>= xFactory;
+ if ( xFactory.is() )
{
- uno::Any aAny = xEnum->nextElement();
- uno::Reference< lang::XSingleComponentFactory > xFactory;
- aAny >>= xFactory;
- if ( xFactory.is() )
- {
- uno::Reference< task::XJob > xJob( xFactory->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW );
- uno::Sequence< beans::NamedValue > aArgsForJob(1);
- ScViewData* pViewData = GetViewData();
- SfxViewShell* pViewShell = ( pViewData ? pViewData->GetViewShell() : NULL );
- SfxViewFrame* pViewFrame = ( pViewShell ? pViewShell->GetViewFrame() : NULL );
- SfxFrame* pFrame = ( pViewFrame ? &pViewFrame->GetFrame() : NULL );
- uno::Reference< frame::XController > xController = ( pFrame ? pFrame->GetController() : 0 );
- uno::Reference< sheet::XSpreadsheetView > xSpreadsheetView( xController, uno::UNO_QUERY_THROW );
- aArgsForJob[0] = beans::NamedValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "SpreadsheetView" )),
+ uno::Reference< task::XJob > xJob( xFactory->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW );
+ uno::Sequence< beans::NamedValue > aArgsForJob(1);
+ ScViewData* pViewData = GetViewData();
+ SfxViewShell* pViewShell = ( pViewData ? pViewData->GetViewShell() : NULL );
+ SfxViewFrame* pViewFrame = ( pViewShell ? pViewShell->GetViewFrame() : NULL );
+ SfxFrame* pFrame = ( pViewFrame ? &pViewFrame->GetFrame() : NULL );
+ uno::Reference< frame::XController > xController = ( pFrame ? pFrame->GetController() : 0 );
+ uno::Reference< sheet::XSpreadsheetView > xSpreadsheetView( xController, uno::UNO_QUERY_THROW );
+ aArgsForJob[0] = beans::NamedValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "SpreadsheetView" )),
uno::makeAny( xSpreadsheetView ) );
- xJob->execute( aArgsForJob );
- }
+ xJob->execute( aArgsForJob );
}
}
}
diff --git a/sc/source/ui/miscdlgs/solverutil.cxx b/sc/source/ui/miscdlgs/solverutil.cxx
index 356eef7440e2..8ed768e1f760 100644
--- a/sc/source/ui/miscdlgs/solverutil.cxx
+++ b/sc/source/ui/miscdlgs/solverutil.cxx
@@ -29,6 +29,7 @@
#include "solverutil.hxx"
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
@@ -84,19 +85,13 @@ void ScSolverUtil::GetImplementations( uno::Sequence<rtl::OUString>& rImplNames,
rImplNames.realloc(0); // clear
rDescriptions.realloc(0);
- uno::Reference<uno::XComponentContext> xCtx;
- uno::Reference<lang::XMultiServiceFactory> xMSF = comphelper::getProcessServiceFactory();
- uno::Reference<beans::XPropertySet> xPropset(xMSF, uno::UNO_QUERY);
- try
- {
- xPropset->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xCtx;
- }
- catch ( uno::Exception & )
- {
- }
+ uno::Reference<uno::XComponentContext> xCtx(
+ comphelper::getProcessComponentContext() );
+ uno::Reference<lang::XMultiServiceFactory> xMSF(
+ xCtx->getServiceManager(), uno::UNO_QUERY_THROW );
uno::Reference<container::XContentEnumerationAccess> xEnAc( xMSF, uno::UNO_QUERY );
- if ( xCtx.is() && xEnAc.is() )
+ if ( xEnAc.is() )
{
uno::Reference<container::XEnumeration> xEnum =
xEnAc->createContentEnumeration( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SCSOLVER_SERVICE)) );
@@ -140,19 +135,13 @@ uno::Reference<sheet::XSolver> ScSolverUtil::GetSolver( const rtl::OUString& rIm
{
uno::Reference<sheet::XSolver> xSolver;
- uno::Reference<uno::XComponentContext> xCtx;
- uno::Reference<lang::XMultiServiceFactory> xMSF = comphelper::getProcessServiceFactory();
- uno::Reference<beans::XPropertySet> xPropset(xMSF, uno::UNO_QUERY);
- try
- {
- xPropset->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xCtx;
- }
- catch ( uno::Exception & )
- {
- }
+ uno::Reference<uno::XComponentContext> xCtx(
+ comphelper::getProcessComponentContext() );
+ uno::Reference<lang::XMultiServiceFactory> xMSF(
+ xCtx->getServiceManager(), uno::UNO_QUERY_THROW );
uno::Reference<container::XContentEnumerationAccess> xEnAc( xMSF, uno::UNO_QUERY );
- if ( xCtx.is() && xEnAc.is() )
+ if ( xEnAc.is() )
{
uno::Reference<container::XEnumeration> xEnum =
xEnAc->createContentEnumeration( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SCSOLVER_SERVICE)) );
diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx
index cfbb7e79b64b..ec54e24a5051 100644
--- a/sc/source/ui/vba/excelvbahelper.cxx
+++ b/sc/source/ui/vba/excelvbahelper.cxx
@@ -118,10 +118,10 @@ private:
bool bInitialWarningState;
static uno::Reference< beans::XPropertySet > getGlobalSheetSettings() throw ( uno::RuntimeException )
{
- static uno::Reference< beans::XPropertySet > xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
- static uno::Reference<uno::XComponentContext > xContext( xTmpProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
+ static uno::Reference<uno::XComponentContext > xContext(
+ comphelper::getProcessComponentContext() );
static uno::Reference<lang::XMultiComponentFactory > xServiceManager(
- xContext->getServiceManager(), uno::UNO_QUERY_THROW );
+ xContext->getServiceManager() );
static uno::Reference< beans::XPropertySet > xProps( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" ) ) ,xContext ), uno::UNO_QUERY_THROW );
return xProps;
}
diff --git a/sc/source/ui/vba/vbahelper.cxx b/sc/source/ui/vba/vbahelper.cxx
index a2a2217531f7..ce5e680f1c26 100644
--- a/sc/source/ui/vba/vbahelper.cxx
+++ b/sc/source/ui/vba/vbahelper.cxx
@@ -124,10 +124,10 @@ private:
bool bInitialWarningState;
static uno::Reference< beans::XPropertySet > getGlobalSheetSettings() throw ( uno::RuntimeException )
{
- static uno::Reference< beans::XPropertySet > xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
- static uno::Reference<uno::XComponentContext > xContext( xTmpProps->getPropertyValue( rtl::OUString( "DefaultContext" )), uno::UNO_QUERY_THROW );
+ static uno::Reference<uno::XComponentContext > xContext(
+ comphelper::getProcessComponentContext() );
static uno::Reference<lang::XMultiComponentFactory > xServiceManager(
- xContext->getServiceManager(), uno::UNO_QUERY_THROW );
+ xContext->getServiceManager() );
static uno::Reference< beans::XPropertySet > xProps( xServiceManager->createInstanceWithContext( rtl::OUString( "com.sun.star.sheet.GlobalSheetSettings" ) ,xContext ), uno::UNO_QUERY_THROW );
return xProps;
}
@@ -279,11 +279,10 @@ getCurrentDocument() throw (uno::RuntimeException)
if ( false == ( aModel >>= xModel ) ||
!xModel.is() )
{
- // trying last gasp try the current component
- uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
- // test if vba service is present
- uno::Reference< uno::XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( "DefaultContext" )), uno::UNO_QUERY_THROW );
- uno::Reference<lang::XMultiComponentFactory > xSMgr( xCtx->getServiceManager(), uno::UNO_QUERY_THROW );
+ uno::Reference< uno::XComponentContext > xCtx(
+ comphelper::getProcessComponentContext() );
+ uno::Reference<lang::XMultiComponentFactory > xSMgr(
+ xCtx->getServiceManager() );
uno::Reference< frame::XDesktop > xDesktop (xSMgr->createInstanceWithContext(::rtl::OUString("com.sun.star.frame.Desktop"), xCtx), uno::UNO_QUERY_THROW );
xModel.set( xDesktop->getCurrentComponent(), uno::UNO_QUERY );
if ( !xModel.is() )
diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx
index 528941b090d7..d5fe171afde2 100644
--- a/sc/source/ui/vba/vbaworksheet.cxx
+++ b/sc/source/ui/vba/vbaworksheet.cxx
@@ -167,10 +167,10 @@ openNewDoc(rtl::OUString aSheetName )
uno::Reference<frame::XModel> xModel;
try
{
- uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
- uno::Reference< uno::XComponentContext > xContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
+ uno::Reference< uno::XComponentContext > xContext(
+ comphelper::getProcessComponentContext() );
uno::Reference<lang::XMultiComponentFactory > xServiceManager(
- xContext->getServiceManager(), uno::UNO_QUERY_THROW );
+ xContext->getServiceManager() );
uno::Reference <frame::XComponentLoader > xComponentLoader(
xServiceManager->createInstanceWithContext(