diff options
-rw-r--r-- | vbahelper/inc/vbahelper/vbaglobalbase.hxx | 4 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbaapplicationbase.cxx | 1 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbaglobalbase.cxx | 33 |
3 files changed, 31 insertions, 7 deletions
diff --git a/vbahelper/inc/vbahelper/vbaglobalbase.hxx b/vbahelper/inc/vbahelper/vbaglobalbase.hxx index e75cbb7e7af8..61aaa1d65657 100644 --- a/vbahelper/inc/vbahelper/vbaglobalbase.hxx +++ b/vbahelper/inc/vbahelper/vbaglobalbase.hxx @@ -32,16 +32,16 @@ typedef InheritedHelperInterfaceImpl1< ov::XGlobalsBase > Globals_BASE; class VBAHELPER_DLLPUBLIC VbaGlobalsBase : public Globals_BASE - { protected: + rtl::OUString msDocCtxName; bool hasServiceName( const rtl::OUString& serviceName ); void init( const css::uno::Sequence< css::beans::PropertyValue >& aInitArgs ); public: VbaGlobalsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName ); - virtual ~VbaGlobalsBase(){}; + virtual ~VbaGlobalsBase(); // XMultiServiceFactory virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (css::uno::Exception, css::uno::RuntimeException); virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const css::uno::Sequence< css::uno::Any >& Arguments ) throw (css::uno::Exception, css::uno::RuntimeException); diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx index 213133998def..8af75a6bd043 100644 --- a/vbahelper/source/vbahelper/vbaapplicationbase.cxx +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -182,7 +182,6 @@ VbaApplicationBase::VbaApplicationBase( const uno::Reference< uno::XComponentCon VbaApplicationBase::~VbaApplicationBase() { - m_pImpl = 0; delete m_pImpl; } diff --git a/vbahelper/source/vbahelper/vbaglobalbase.cxx b/vbahelper/source/vbahelper/vbaglobalbase.cxx index b4b39344fd61..e0df37583df5 100644 --- a/vbahelper/source/vbahelper/vbaglobalbase.cxx +++ b/vbahelper/source/vbahelper/vbaglobalbase.cxx @@ -41,19 +41,44 @@ rtl::OUString sAppService( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.Application") ); VbaGlobalsBase::VbaGlobalsBase( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName ) -: Globals_BASE( xParent, xContext ) +: Globals_BASE( xParent, xContext ), msDocCtxName( sDocCtxName ) { // 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; + if ( xContext.is() && xContext->getServiceManager().is() ) + { + aSrvMgr = uno::makeAny( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.OServiceManagerWrapper") ), xContext ) ); + } + ::cppu::ContextEntry_Init aHandlerContextInfo[] = { ::cppu::ContextEntry_Init( sApplication, uno::Any() ), ::cppu::ContextEntry_Init( sDocCtxName, uno::Any() ), + ::cppu::ContextEntry_Init( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.lang.theServiceManager" ) ), aSrvMgr ) }; - - mxContext = ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ), xContext ); - + // don't pass a delegate, this seems to introduce yet another cyclic dependency ( and + // some strange behavior + mxContext = ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ), NULL ); } +VbaGlobalsBase::~VbaGlobalsBase() +{ + try + { + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY ); + if ( xNameContainer.is() ) + { + // release document reference ( we don't wan't the component context trying to dispose that ) + xNameContainer->removeByName( msDocCtxName ); + // release application reference, as it is holding onto the context + xNameContainer->removeByName( sApplication ); + } + } + catch ( const uno::Exception& ) + { + } +} void VbaGlobalsBase::init( const uno::Sequence< beans::PropertyValue >& aInitArgs ) |