[Libreoffice-commits] .: vbahelper/source

Stephan Bergmann sbergmann at kemper.freedesktop.org
Thu Apr 12 04:04:57 PDT 2012


 vbahelper/source/vbahelper/vbaglobalbase.cxx |   29 ++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

New commits:
commit 0dda8f1933ef9cea3b10e2958e28023d9dc54399
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Apr 12 13:04:39 2012 +0200

    Set DefaultContext property of service manager/component context combo
    
    ...to avoid mismatch warnings from OServiceManager::createInstanceWithContext.

diff --git a/vbahelper/source/vbahelper/vbaglobalbase.cxx b/vbahelper/source/vbahelper/vbaglobalbase.cxx
index efb2848..615c6f5 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()


More information about the Libreoffice-commits mailing list