diff options
Diffstat (limited to 'embeddedobj/source/msole')
-rw-r--r-- | embeddedobj/source/msole/olecomponent.cxx | 39 | ||||
-rw-r--r-- | embeddedobj/source/msole/olecomponent.hxx | 6 | ||||
-rw-r--r-- | embeddedobj/source/msole/olemisc.cxx | 116 | ||||
-rw-r--r-- | embeddedobj/source/msole/olepersist.cxx | 10 |
4 files changed, 119 insertions, 52 deletions
diff --git a/embeddedobj/source/msole/olecomponent.cxx b/embeddedobj/source/msole/olecomponent.cxx index 80a4cd55f8e5..d1116b35bf51 100644 --- a/embeddedobj/source/msole/olecomponent.cxx +++ b/embeddedobj/source/msole/olecomponent.cxx @@ -2,9 +2,9 @@ * * $RCSfile: olecomponent.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mav $ $Date: 2003-11-14 15:24:27 $ + * last change: $Author: mav $ $Date: 2003-11-17 16:19:24 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -331,12 +331,23 @@ OleComponent::OleComponent( const uno::Reference< lang::XMultiServiceFactory >& //---------------------------------------------- OleComponent::~OleComponent() { - if ( m_pOleWrapClientSite ) + OSL_ENSURE( !m_pOleWrapClientSite && !m_pImplAdviseSink && !m_pInterfaceContainer && !m_bOleInitialized, + "The object was not closed successfully! DISASTER is possible!" ); + + if ( m_pOleWrapClientSite || m_pImplAdviseSink || m_pInterfaceContainer || m_bOleInitialized ) { - // must be done on close() - // here it means an error - OSL_ENSURE( sal_False, "Looks like the object was not closed before destruction - DISASTER is possible!" ); + m_refCount++; + try { + Dispose(); + } catch( uno::Exception& ) {} + } +} +//---------------------------------------------- +void OleComponent::Dispose() +{ + if ( m_pOleWrapClientSite ) + { m_pOleWrapClientSite->disconnectOleComponent(); m_pOleWrapClientSite->Release(); m_pOleWrapClientSite = NULL; @@ -344,10 +355,6 @@ OleComponent::~OleComponent() if ( m_pImplAdviseSink ) { - // must be done on close() - // here it means an error - OSL_ENSURE( sal_False, "Looks like the object was not closed before destruction - DISASTER is possible!" ); - m_pImplAdviseSink->disconnectOleComponent(); m_pImplAdviseSink->Release(); m_pImplAdviseSink = NULL; @@ -355,12 +362,20 @@ OleComponent::~OleComponent() if ( m_pInterfaceContainer ) { + lang::EventObject aEvent( (embed::XEmbeddedObject*)this ); + m_pInterfaceContainer->disposeAndClear( aEvent ); + delete m_pInterfaceContainer; m_pInterfaceContainer = NULL; } if ( m_bOleInitialized ) + { OleUninitialize(); + m_bOleInitialized = sal_False; + } + + m_bDisposed = sal_True; } //---------------------------------------------- @@ -956,9 +971,9 @@ void SAL_CALL OleComponent::close( sal_Bool bDeliverOwnership ) } } } - - m_pInterfaceContainer->disposeAndClear( aSource ); } + + Dispose(); } //---------------------------------------------- diff --git a/embeddedobj/source/msole/olecomponent.hxx b/embeddedobj/source/msole/olecomponent.hxx index d199ebd4a406..af17009295e2 100644 --- a/embeddedobj/source/msole/olecomponent.hxx +++ b/embeddedobj/source/msole/olecomponent.hxx @@ -2,9 +2,9 @@ * * $RCSfile: olecomponent.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mav $ $Date: 2003-11-14 15:24:27 $ + * last change: $Author: mav $ $Date: 2003-11-17 16:19:24 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -156,6 +156,8 @@ class OleComponent : public ::cppu::WeakImplHelper2< ::com::sun::star::util::XCl void RetrieveObjectDataFlavors_Impl(); + void Dispose(); + public: OleComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& m_xFactory, OleEmbeddedObject* pOleObj ); diff --git a/embeddedobj/source/msole/olemisc.cxx b/embeddedobj/source/msole/olemisc.cxx index c5b1ec0270f9..772f61408100 100644 --- a/embeddedobj/source/msole/olemisc.cxx +++ b/embeddedobj/source/msole/olemisc.cxx @@ -2,9 +2,9 @@ * * $RCSfile: olemisc.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mav $ $Date: 2003-11-13 17:01:14 $ + * last change: $Author: mav $ $Date: 2003-11-17 16:19:25 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -118,15 +118,44 @@ OleEmbeddedObject::OleEmbeddedObject( const uno::Reference< lang::XMultiServiceF //------------------------------------------------------ OleEmbeddedObject::~OleEmbeddedObject() { + OSL_ENSURE( !m_pInterfaceContainer && !m_pOleComponent, "The object is not closed! DISASTER is possible!" ); + + if ( m_pOleComponent || m_pInterfaceContainer ) + { + // the component must be cleaned during closing + m_refCount++; // to avoid crash + try { + Dispose(); + } catch( uno::Exception& ) {} + } +} + +//------------------------------------------------------ +void OleEmbeddedObject::Dispose() +{ + if ( m_pInterfaceContainer ) + { + lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) ); + m_pInterfaceContainer->disposeAndClear( aSource ); + delete m_pInterfaceContainer; + m_pInterfaceContainer = NULL; + } + if ( m_pOleComponent ) { - // the component must be cleaned during disposing - OSL_ENSURE( sal_False, "Looks like the object was not disposed - DISASTER is possible!\n" ); + if ( m_nObjectState != embed::EmbedStates::EMBED_LOADED ) + { + SaveObject_Impl(); + m_pOleComponent->CloseObject(); + } + m_pOleComponent->removeCloseListener( m_xClosePreventer ); m_pOleComponent->disconnectEmbeddedObject(); m_pOleComponent->release(); m_pOleComponent = NULL; } + + m_bDisposed = true; } //------------------------------------------------------ @@ -188,45 +217,63 @@ uno::Reference< lang::XComponent > SAL_CALL OleEmbeddedObject::getComponent() return uno::Reference< lang::XComponent >(); } -// TODO: The object will support XCloseable -//------------------------------------------------------ -void SAL_CALL OleEmbeddedObject::dispose() - throw ( uno::RuntimeException ) +//---------------------------------------------- +void SAL_CALL OleEmbeddedObject::close( sal_Bool bDeliverOwnership ) + throw ( util::CloseVetoException, + uno::RuntimeException ) { ::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO - if ( m_pInterfaceContainer ) - { - lang::EventObject aEvent( (embed::XEmbeddedObject*)this ); - m_pInterfaceContainer->disposeAndClear( aEvent ); - - delete m_pInterfaceContainer; - m_pInterfaceContainer = NULL; - } + uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) ); + lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) ); - if ( m_pOleComponent ) + if ( m_pInterfaceContainer ) { - if ( m_nObjectState != embed::EmbedStates::EMBED_LOADED ) + ::cppu::OInterfaceContainerHelper* pContainer = + m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) ); + if ( pContainer != NULL ) { - SaveObject_Impl(); - m_pOleComponent->CloseObject(); + ::cppu::OInterfaceIteratorHelper pIterator(*pContainer); + while (pIterator.hasMoreElements()) + { + try + { + ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership ); + } + catch( uno::RuntimeException& ) + { + pIterator.remove(); + } + } } - m_pOleComponent->disconnectEmbeddedObject(); - m_pOleComponent->release(); - m_pOleComponent = NULL; + pContainer = m_pInterfaceContainer->getContainer( + ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) ); + if ( pContainer != NULL ) + { + ::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer); + while (pCloseIterator.hasMoreElements()) + { + try + { + ((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource ); + } + catch( uno::RuntimeException& ) + { + pCloseIterator.remove(); + } + } + } } - // TODO: dispose object - - m_bDisposed = true; + Dispose(); } -//------------------------------------------------------ -void SAL_CALL OleEmbeddedObject::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) +//---------------------------------------------- +void SAL_CALL OleEmbeddedObject::addCloseListener( const uno::Reference< util::XCloseListener >& xListener ) + throw ( uno::RuntimeException ) { ::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) @@ -235,20 +282,19 @@ void SAL_CALL OleEmbeddedObject::addEventListener( const uno::Reference< lang::X if ( !m_pInterfaceContainer ) m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex ); - m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< lang::XEventListener >*)0 ), xListener ); + m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ), xListener ); } -//------------------------------------------------------ -void SAL_CALL OleEmbeddedObject::removeEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) +//---------------------------------------------- +void SAL_CALL OleEmbeddedObject::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener ) + throw (uno::RuntimeException) { ::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO if ( m_pInterfaceContainer ) - m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< lang::XEventListener >*)0 ), + m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ), xListener ); } diff --git a/embeddedobj/source/msole/olepersist.cxx b/embeddedobj/source/msole/olepersist.cxx index 181e73bd15f6..91dcbb74ebda 100644 --- a/embeddedobj/source/msole/olepersist.cxx +++ b/embeddedobj/source/msole/olepersist.cxx @@ -2,9 +2,9 @@ * * $RCSfile: olepersist.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mav $ $Date: 2003-11-13 17:01:14 $ + * last change: $Author: mav $ $Date: 2003-11-17 16:19:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -92,6 +92,7 @@ #endif #include <olecomponent.hxx> +#include <closepreventer.hxx> using namespace ::com::sun::star; @@ -154,7 +155,10 @@ void OleEmbeddedObject::CreateOleComponent_Impl() { m_pOleComponent = new OleComponent( m_xFactory, this ); m_pOleComponent->acquire(); // TODO: needs holder? - // TODO: register close listener + m_xClosePreventer = uno::Reference< util::XCloseListener >( + static_cast< ::cppu::OWeakObject* >( new OClosePreventer ), + uno::UNO_QUERY ); + m_pOleComponent->addCloseListener( m_xClosePreventer ); } else OSL_ENSURE( sal_False, "Trying to recreate OLE component!\n" ); |