summaryrefslogtreecommitdiff
path: root/vbahelper
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-04-12 13:04:39 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-04-12 13:04:39 +0200
commit0dda8f1933ef9cea3b10e2958e28023d9dc54399 (patch)
treed6b5195f1a0c9c43dbb5b965c0b74609ef67fb38 /vbahelper
parent30fb54aca35c744517ad697f2d299481b02d457f (diff)
Set DefaultContext property of service manager/component context combo
...to avoid mismatch warnings from OServiceManager::createInstanceWithContext.
Diffstat (limited to 'vbahelper')
-rw-r--r--vbahelper/source/vbahelper/vbaglobalbase.cxx29
1 files changed, 26 insertions, 3 deletions
diff --git a/vbahelper/source/vbahelper/vbaglobalbase.cxx b/vbahelper/source/vbahelper/vbaglobalbase.cxx
index efb28486f4a6..615c6f53d7e8 100644
--- a/vbahelper/source/vbahelper/vbaglobalbase.cxx
+++ b/vbahelper/source/vbahelper/vbaglobalbase.cxx
@@ -29,8 +29,10 @@
#include <sal/macros.h>
#include <cppuhelper/component_context.hxx>
+#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
using namespace com::sun::star;
using namespace ooo::vba;
@@ -47,21 +49,42 @@ const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& s
{
// overwrite context with custom one ( that contains the application )
// wrap the service manager as we don't want the disposing context to tear down the 'normal' ServiceManager ( or at least thats what the code appears like it wants to do )
- uno::Any aSrvMgr;
+ uno::Reference< uno::XInterface > aSrvMgr;
if ( xContext.is() && xContext->getServiceManager().is() )
{
- aSrvMgr = uno::makeAny( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.OServiceManagerWrapper") ), xContext ) );
+ aSrvMgr = xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.OServiceManagerWrapper") ), xContext );
}
::cppu::ContextEntry_Init aHandlerContextInfo[] =
{
::cppu::ContextEntry_Init( msApplication, uno::Any() ),
::cppu::ContextEntry_Init( sDocCtxName, uno::Any() ),
- ::cppu::ContextEntry_Init( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.lang.theServiceManager" ) ), aSrvMgr )
+ ::cppu::ContextEntry_Init( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.lang.theServiceManager" ) ), uno::makeAny( aSrvMgr ) )
};
// don't pass a delegate, this seems to introduce yet another cyclic dependency ( and
// some strange behavior
mxContext = ::cppu::createComponentContext( aHandlerContextInfo, SAL_N_ELEMENTS( aHandlerContextInfo ), NULL );
+ if ( aSrvMgr.is() )
+ {
+ try
+ {
+ uno::Reference< beans::XPropertySet >(
+ aSrvMgr, uno::UNO_QUERY_THROW )->
+ setPropertyValue( "DefaultContext", uno::makeAny( mxContext ) );
+ }
+ catch ( uno::RuntimeException & )
+ {
+ throw;
+ }
+ catch ( uno::Exception & )
+ {
+ uno::Any e(cppu::getCaughtException());
+ throw lang::WrappedTargetRuntimeException(
+ ("VbaGlobalsBase ctor, setting OServiceManagerWrapper"
+ " DefaultContext failed"),
+ uno::Reference< uno::XInterface >(), e);
+ }
+ }
}
VbaGlobalsBase::~VbaGlobalsBase()