diff options
author | Mikhail Voitenko <mav@openoffice.org> | 2003-11-17 15:19:26 +0000 |
---|---|---|
committer | Mikhail Voitenko <mav@openoffice.org> | 2003-11-17 15:19:26 +0000 |
commit | 63624caf55e8a6c24074b9cb7bba7dfe6b8173c1 (patch) | |
tree | 730b1a868d52f51b91d76adc11607bff92d9a25b /embeddedobj | |
parent | new version for SRX645 (diff) | |
download | core-63624caf55e8a6c24074b9cb7bba7dfe6b8173c1.tar.gz core-63624caf55e8a6c24074b9cb7bba7dfe6b8173c1.zip |
#112923# XCloseable support
Diffstat (limited to 'embeddedobj')
-rw-r--r-- | embeddedobj/source/commonembedding/miscobj.cxx | 129 | ||||
-rw-r--r-- | embeddedobj/source/inc/commonembobj.hxx | 37 | ||||
-rw-r--r-- | embeddedobj/source/inc/oleembobj.hxx | 41 | ||||
-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 |
7 files changed, 249 insertions, 129 deletions
diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx index 0dd1a2321b3a..0b9a805391ba 100644 --- a/embeddedobj/source/commonembedding/miscobj.cxx +++ b/embeddedobj/source/commonembedding/miscobj.cxx @@ -2,9 +2,9 @@ * * $RCSfile: miscobj.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: mav $ $Date: 2003-11-04 14:30:19 $ + * last change: $Author: mav $ $Date: 2003-11-17 16:19:21 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -174,17 +174,30 @@ void OCommonEmbeddedObject::CommonInit_Impl() m_aVerbTable[2].realloc( 2 ); m_aVerbTable[2][0] = embed::EmbedVerbs::MS_OLEVERB_OPEN; m_aVerbTable[2][1] = embed::EmbedStates::EMBED_ACTIVE; - - m_xClosePreventer = uno::Reference< util::XCloseListener >( - static_cast< ::cppu::OWeakObject* >( new OClosePreventer() ), - uno::UNO_QUERY ); } //------------------------------------------------------ OCommonEmbeddedObject::~OCommonEmbeddedObject() { + OSL_ENSURE( !m_pInterfaceContainer && !m_pDocHolder, "The object was not closed! DISASTER is possible!" ); + + if ( m_pInterfaceContainer || m_pDocHolder ) + { + m_refCount++; + try { + Dispose(); + } catch( uno::Exception& ) {} + } +} + +//------------------------------------------------------ +void OCommonEmbeddedObject::Dispose() +{ if ( m_pInterfaceContainer ) { + lang::EventObject aEvent( (embed::XEmbeddedObject*)this ); + m_pInterfaceContainer->disposeAndClear( aEvent ); + delete m_pInterfaceContainer; m_pInterfaceContainer = NULL; } @@ -198,8 +211,11 @@ OCommonEmbeddedObject::~OCommonEmbeddedObject() m_pDocHolder->release(); m_pDocHolder = NULL; } + + m_bDisposed = true; } + //------------------------------------------------------ void OCommonEmbeddedObject::PostEvent_Impl( const ::rtl::OUString& aEventName ) { @@ -366,65 +382,89 @@ uno::Reference< lang::XComponent > SAL_CALL OCommonEmbeddedObject::getComponent( return uno::Reference< lang::XComponent >( m_pDocHolder->GetDocument(), uno::UNO_QUERY ); } -//------------------------------------------------------ -void SAL_CALL OCommonEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener ) - throw ( uno::RuntimeException ) +//---------------------------------------------- +void SAL_CALL OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership ) + throw ( util::CloseVetoException, + uno::RuntimeException ) { ::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO - if ( !m_pInterfaceContainer ) - m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex ); + uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) ); + lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) ); - m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ), xListener ); + if ( m_pInterfaceContainer ) + { + ::cppu::OInterfaceContainerHelper* pContainer = + m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) ); + if ( pContainer != NULL ) + { + ::cppu::OInterfaceIteratorHelper pIterator(*pContainer); + while (pIterator.hasMoreElements()) + { + try + { + ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership ); + } + catch( uno::RuntimeException& ) + { + pIterator.remove(); + } + } + } + + 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(); + } + } + } + } + + Dispose(); } -//------------------------------------------------------ -void SAL_CALL OCommonEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener ) - throw ( uno::RuntimeException ) +//---------------------------------------------- +void SAL_CALL OCommonEmbeddedObject::addCloseListener( 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< document::XEventListener >*)0 ), - xListener ); + if ( !m_pInterfaceContainer ) + m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex ); + + m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ), xListener ); } -//------------------------------------------------------ -void SAL_CALL OCommonEmbeddedObject::dispose() - throw ( uno::RuntimeException ) +//---------------------------------------------- +void SAL_CALL OCommonEmbeddedObject::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 ) - { - lang::EventObject aEvent( (embed::XEmbeddedObject*)this ); - m_pInterfaceContainer->disposeAndClear( aEvent ); - - delete m_pInterfaceContainer; - m_pInterfaceContainer = NULL; - } - - if ( m_pDocHolder ) - { - m_pDocHolder->CloseFrame(); - m_pDocHolder->CloseDocument(); - m_pDocHolder->FreeOffice(); - - m_pDocHolder->release(); - m_pDocHolder = NULL; - } - - m_bDisposed = true; + m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ), + xListener ); } //------------------------------------------------------ -void SAL_CALL OCommonEmbeddedObject::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) +void SAL_CALL OCommonEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener ) throw ( uno::RuntimeException ) { ::osl::MutexGuard aGuard( m_aMutex ); @@ -434,12 +474,11 @@ void SAL_CALL OCommonEmbeddedObject::addEventListener( const uno::Reference< lan 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< document::XEventListener >*)0 ), xListener ); } //------------------------------------------------------ -void SAL_CALL OCommonEmbeddedObject::removeEventListener( - const uno::Reference< lang::XEventListener >& xListener ) +void SAL_CALL OCommonEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener ) throw ( uno::RuntimeException ) { ::osl::MutexGuard aGuard( m_aMutex ); @@ -447,7 +486,7 @@ void SAL_CALL OCommonEmbeddedObject::removeEventListener( throw lang::DisposedException(); // TODO if ( m_pInterfaceContainer ) - m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< lang::XEventListener >*)0 ), + m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ), xListener ); } diff --git a/embeddedobj/source/inc/commonembobj.hxx b/embeddedobj/source/inc/commonembobj.hxx index 86db331f5bb8..0fcf48a7ae9b 100644 --- a/embeddedobj/source/inc/commonembobj.hxx +++ b/embeddedobj/source/inc/commonembobj.hxx @@ -2,9 +2,9 @@ * * $RCSfile: commonembobj.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mav $ $Date: 2003-11-14 15:24:26 $ + * last change: $Author: mav $ $Date: 2003-11-17 16:19:21 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -95,6 +95,10 @@ #include <com/sun/star/document/XEventBroadcaster.hpp> #endif +#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_ +#include <com/sun/star/util/XCloseable.hpp> +#endif + #ifndef _CPPUHELPER_WEAK_HXX_ #include <cppuhelper/weak.hxx> #endif @@ -132,6 +136,7 @@ class OCommonEmbeddedObject : public ::com::sun::star::embed::XEmbeddedObject , public ::com::sun::star::embed::XLinkageSupport , public ::com::sun::star::embed::XClassifiedObject , public ::com::sun::star::embed::XComponentSupplier + , public ::com::sun::star::util::XCloseable , public ::com::sun::star::document::XEventBroadcaster , public ::cppu::OWeakObject { @@ -162,8 +167,6 @@ class OCommonEmbeddedObject : public ::com::sun::star::embed::XEmbeddedObject ::rtl::OUString m_aContainerName; - ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener > m_xClosePreventer; - Interceptor* m_pInterceptor; // following information will be used between SaveAs and SaveCompleted @@ -186,6 +189,8 @@ class OCommonEmbeddedObject : public ::com::sun::star::embed::XEmbeddedObject private: void CommonInit_Impl(); + void Dispose(); + ::rtl::OUString GetDocumentServiceName() { return m_aDocServiceName; } ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StoreDocumentToTempStream_Impl(); @@ -423,28 +428,28 @@ public: virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL getComponent() throw ( ::com::sun::star::uno::RuntimeException ); +// XCloseable -// XEventBroadcaster - virtual void SAL_CALL addEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) - throw ( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL close( sal_Bool DeliverOwnership ) + throw ( ::com::sun::star::util::CloseVetoException, + ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) + virtual void SAL_CALL addCloseListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw ( ::com::sun::star::uno::RuntimeException ); -// XComponent - virtual void SAL_CALL dispose() + virtual void SAL_CALL removeCloseListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw ( ::com::sun::star::uno::RuntimeException ); +// XEventBroadcaster virtual void SAL_CALL addEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) throw ( ::com::sun::star::uno::RuntimeException ); virtual void SAL_CALL removeEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) - throw (::com::sun::star::uno::RuntimeException); - + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) + throw ( ::com::sun::star::uno::RuntimeException ); }; #endif diff --git a/embeddedobj/source/inc/oleembobj.hxx b/embeddedobj/source/inc/oleembobj.hxx index 376e1f821463..68232e85cc37 100644 --- a/embeddedobj/source/inc/oleembobj.hxx +++ b/embeddedobj/source/inc/oleembobj.hxx @@ -2,9 +2,9 @@ * * $RCSfile: oleembobj.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: mav $ $Date: 2003-11-14 15:25:05 $ + * last change: $Author: mav $ $Date: 2003-11-17 16:19:22 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -98,12 +98,15 @@ #include <com/sun/star/document/XEventBroadcaster.hpp> #endif +#ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_ +#include <com/sun/star/util/XCloseable.hpp> +#endif #ifndef _COM_SUN_STAR_UTIL_XCLOSELISTENER_HPP_ #include <com/sun/star/util/XCloseListener.hpp> #endif -#ifndef _CPPUHELPER_IMPLBASE7_HXX_ -#include <cppuhelper/implbase7.hxx> +#ifndef _CPPUHELPER_IMPLBASE8_HXX_ +#include <cppuhelper/implbase8.hxx> #endif namespace cppu { @@ -111,13 +114,14 @@ namespace cppu { } class OleComponent; -class OleEmbeddedObject : public ::cppu::WeakImplHelper7 +class OleEmbeddedObject : public ::cppu::WeakImplHelper8 < ::com::sun::star::embed::XEmbeddedObject , ::com::sun::star::embed::XVisualObject , ::com::sun::star::embed::XEmbedPersist , ::com::sun::star::embed::XLinkageSupport , ::com::sun::star::embed::XClassifiedObject , ::com::sun::star::embed::XComponentSupplier + , ::com::sun::star::util::XCloseable , ::com::sun::star::document::XEventBroadcaster > { ::osl::Mutex m_aMutex; @@ -166,6 +170,9 @@ protected: ::com::sun::star::uno::Sequence< sal_Int32 > GetReachableStatesList_Impl( const ::com::sun::star::uno::Sequence< ::com::sun::star::embed::VerbDescr >& aVerbList ); + void CloseComponent(); + void Dispose(); + public: // in case a new object must be created the class ID must be specified OleEmbeddedObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, @@ -356,27 +363,29 @@ public: virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL getComponent() throw ( ::com::sun::star::uno::RuntimeException ); +// XCloseable -// XEventBroadcaster - virtual void SAL_CALL addEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) - throw ( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL close( sal_Bool DeliverOwnership ) + throw ( ::com::sun::star::util::CloseVetoException, + ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) + virtual void SAL_CALL addCloseListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw ( ::com::sun::star::uno::RuntimeException ); -// XComponent - virtual void SAL_CALL dispose() + virtual void SAL_CALL removeCloseListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw ( ::com::sun::star::uno::RuntimeException ); +// XEventBroadcaster virtual void SAL_CALL addEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) throw ( ::com::sun::star::uno::RuntimeException ); virtual void SAL_CALL removeEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) - throw (::com::sun::star::uno::RuntimeException); + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener ) + throw ( ::com::sun::star::uno::RuntimeException ); + }; #endif 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" ); |