diff options
Diffstat (limited to 'embedserv/source')
-rw-r--r-- | embedserv/source/embed/intercept.cxx | 164 | ||||
-rw-r--r-- | embedserv/source/inc/intercept.hxx | 29 |
2 files changed, 183 insertions, 10 deletions
diff --git a/embedserv/source/embed/intercept.cxx b/embedserv/source/embed/intercept.cxx index f009eba0dd13..bf107b02bfac 100644 --- a/embedserv/source/embed/intercept.cxx +++ b/embedserv/source/embed/intercept.cxx @@ -2,9 +2,9 @@ * * $RCSfile: intercept.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: abi $ $Date: 2003-03-28 16:31:27 $ + * last change: $Author: abi $ $Date: 2003-04-04 09:03:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -58,15 +58,15 @@ * * ************************************************************************/ - - +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif #include "intercept.hxx" #ifndef _EMBEDDOC_HXX_ #include "embeddoc.hxx" #endif - using namespace ::com::sun::star; @@ -79,8 +79,91 @@ uno::Sequence<::rtl::OUString> Interceptor::m_aInterceptedURL(IUL); + +struct equalOUString +{ + bool operator()( + const rtl::OUString& rKey1, + const rtl::OUString& rKey2 ) const + { + return !!( rKey1 == rKey2 ); + } +}; + + +struct hashOUString +{ + size_t operator()( const rtl::OUString& rName ) const + { + return rName.hashCode(); + } +}; + + + +class StatusChangeListenerContainer + : public ::cppu::OMultiTypeInterfaceContainerHelperVar< +rtl::OUString,hashOUString,equalOUString> +{ +public: + StatusChangeListenerContainer( ::osl::Mutex& aMutex ) + : cppu::OMultiTypeInterfaceContainerHelperVar< + rtl::OUString,hashOUString,equalOUString>(aMutex) + { + } +}; + + +void SAL_CALL +Interceptor::addEventListener( + const uno::Reference<lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + if ( ! m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new cppu::OInterfaceContainerHelper( m_aMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + + +void SAL_CALL +Interceptor::removeEventListener( + const uno::Reference< lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + + +void SAL_CALL Interceptor::dispose() +{ + lang::EventObject aEvt; + aEvt.Source = static_cast< frame::XDispatch* >( this ); + + osl::MutexGuard aGuard(m_aMutex); + + if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + m_pDisposeEventListeners->disposeAndClear( aEvt ); + + if(m_pStatCL) + m_pStatCL->disposeAndClear( aEvt ); + + m_xSlaveDispatchProvider = 0; + m_xMasterDispatchProvider = 0; +} + + + Interceptor::Interceptor(EmbedDocument_Impl* pOLEInterface) - : m_pOLEInterface(pOLEInterface) + : m_pOLEInterface(pOLEInterface), + m_pStatCL(0), + m_pDisposeEventListeners(0) { m_aInterceptedURL[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:Save")); @@ -95,6 +178,15 @@ Interceptor::Interceptor(EmbedDocument_Impl* pOLEInterface) } +Interceptor::~Interceptor() +{ + if( m_pDisposeEventListeners ) + delete m_pDisposeEventListeners; + + if(m_pStatCL) + delete m_pStatCL; +} + //XDispatch @@ -124,7 +216,58 @@ Interceptor::addStatusListener( uno::RuntimeException ) { - return; + if(!Control.is()) + return; + + if(URL.Complete == m_aInterceptedURL[0]) + { // Save + frame::FeatureStateEvent aStateEvent; + aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0]; + aStateEvent.FeatureDescriptor = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Update")); + aStateEvent.IsEnabled = sal_True; + aStateEvent.Requery = sal_False; + aStateEvent.State <<= rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("update")); + Control->statusChanged(aStateEvent); + + { + osl::MutexGuard aGuard(m_aMutex); + if(!m_pStatCL) + m_pStatCL = + new StatusChangeListenerContainer(m_aMutex); + } + + m_pStatCL->addInterface(URL.Complete,Control); + return; + } + + sal_Int32 i = 2; + if(URL.Complete == m_aInterceptedURL[i] || + URL.Complete == m_aInterceptedURL[++i] || + URL.Complete == m_aInterceptedURL[++i] ) + { // Close and return + frame::FeatureStateEvent aStateEvent; + aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i]; + aStateEvent.FeatureDescriptor = rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Close and Return")); + aStateEvent.IsEnabled = sal_True; + aStateEvent.Requery = sal_False; + aStateEvent.State <<= rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("closeandreturn")); + Control->statusChanged(aStateEvent); + + + { + osl::MutexGuard aGuard(m_aMutex); + if(!m_pStatCL) + m_pStatCL = + new StatusChangeListenerContainer(m_aMutex); + } + + m_pStatCL->addInterface(URL.Complete,Control); + return; + } } @@ -137,7 +280,12 @@ Interceptor::removeStatusListener( uno::RuntimeException ) { - return; + if(!(Control.is() && m_pStatCL)) + return; + else { + m_pStatCL->removeInterface(URL.Complete,Control); + return; + } } diff --git a/embedserv/source/inc/intercept.hxx b/embedserv/source/inc/intercept.hxx index 96fc84c33787..9ecc786dadff 100644 --- a/embedserv/source/inc/intercept.hxx +++ b/embedserv/source/inc/intercept.hxx @@ -2,9 +2,9 @@ * * $RCSfile: intercept.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2003-03-27 16:09:44 $ + * last change: $Author: abi $ $Date: 2003-04-04 09:03:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,6 +68,9 @@ #ifndef _CPPUHELPER_IMPLBASE3_HXX_ #include <cppuhelper/implbase3.hxx> #endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif #ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDERINTERCEPTOR_HPP_ #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> #endif @@ -79,6 +82,7 @@ #endif +class StatusChangeListenerContainer; class EmbedDocument_Impl; @@ -91,6 +95,24 @@ class Interceptor public: Interceptor(EmbedDocument_Impl* pOLEInterface); + ~Interceptor(); + + // overwritten to release the statuslistner. + + // XComponent + virtual void SAL_CALL + addEventListener( + const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& xListener ) + 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 ); + + void SAL_CALL + dispose() throw(::com::sun::star::uno::RuntimeException); + + //XDispatch virtual void SAL_CALL @@ -194,6 +216,9 @@ private: static ::com::sun::star::uno::Sequence<::rtl::OUString> m_aInterceptedURL; + + cppu::OInterfaceContainerHelper* m_pDisposeEventListeners; + StatusChangeListenerContainer* m_pStatCL; }; #endif |