summaryrefslogtreecommitdiff
path: root/comphelper/inc
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2006-03-14 10:39:51 +0000
committerVladimir Glazounov <vg@openoffice.org>2006-03-14 10:39:51 +0000
commit0b4255dc5c2fc379d31c6405c25f6ea301a23f5c (patch)
tree701604ced5ffde3f58180fe245a0786ec232bf90 /comphelper/inc
parente7fdddd88d8f91faea9f14083131c71b9357fa79 (diff)
INTEGRATION: CWS pbrwuno (1.5.12); FILE MERGED
2005/10/25 07:25:39 fs 1.5.12.3: #i53095# iterating 2005/10/19 07:46:39 fs 1.5.12.2: #i53095# +clear 2005/10/13 13:03:59 fs 1.5.12.1: #i53095# OSimpleListenerContainer, which works with function pointers and thus makes deriving unnecessary for straight Listener::method(event) calls
Diffstat (limited to 'comphelper/inc')
-rw-r--r--comphelper/inc/comphelper/listenernotification.hxx101
1 files changed, 99 insertions, 2 deletions
diff --git a/comphelper/inc/comphelper/listenernotification.hxx b/comphelper/inc/comphelper/listenernotification.hxx
index c9c1205bd0c8..5c17fab37a16 100644
--- a/comphelper/inc/comphelper/listenernotification.hxx
+++ b/comphelper/inc/comphelper/listenernotification.hxx
@@ -4,9 +4,9 @@
*
* $RCSfile: listenernotification.hxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: rt $ $Date: 2005-09-08 02:32:20 $
+ * last change: $Author: vg $ $Date: 2006-03-14 11:39:51 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -50,6 +50,8 @@
#include "comphelper/comphelperdllapi.h"
#endif
+#include <memory>
+
//........................................................................
namespace comphelper
{
@@ -90,6 +92,11 @@ namespace comphelper
*/
void disposing( const ::com::sun::star::lang::EventObject& _rEventSource );
+ /** clears the container without calling <member scope="com::sun::star::lang">XEventListener::disposing</member>
+ at the listeners
+ */
+ void clear();
+
/** determines whether the listener container is currently empty
*/
inline bool
@@ -100,6 +107,11 @@ namespace comphelper
inline size_t
size() const SAL_THROW(());
+ /** creates an iterator for looping through all registered listeners
+ */
+ inline ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper >
+ createIterator();
+
protected:
OListenerContainer( ::osl::Mutex& _rMutex );
@@ -158,6 +170,91 @@ namespace comphelper
return m_aListeners.getLength();
}
+ inline ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > OListenerContainer::createIterator()
+ {
+ ::std::auto_ptr< ::cppu::OInterfaceIteratorHelper > pIterator( new ::cppu::OInterfaceIteratorHelper( m_aListeners ) );
+ return pIterator;
+ }
+
+ //====================================================================
+ //= OSimpleListenerContainer
+ //====================================================================
+ /** helper class for simple notification of the form LISTENER::METHOD( EVENT )
+
+ This class is not threadsafe!
+
+ @param LISTENER
+ the listener class to call, e.g. <type scope="com::sun::star::lang">XEventListener</type>
+ @param EVENT
+ the event type to notify, e.g. <type scope="com::sun::star::lang">EventObject</type>
+ */
+ template< class LISTENER, class EVENT >
+ class OSimpleListenerContainer : protected OListenerContainer
+ {
+ public:
+ typedef LISTENER ListenerClass;
+ typedef EVENT EventClass;
+ typedef void ( SAL_CALL LISTENER::*NotificationMethod )( const EventClass& );
+
+ private:
+ NotificationMethod m_pNotificationMethod;
+
+ public:
+ OSimpleListenerContainer( ::osl::Mutex& _rMutex )
+ :OListenerContainer( _rMutex )
+ ,m_pNotificationMethod( NULL )
+ {
+ }
+
+ inline void addListener( const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener )
+ {
+ OListenerContainer::addListener( _rxListener.get() );
+ }
+
+ inline void removeListener( const ::com::sun::star::uno::Reference< ListenerClass >& _rxListener )
+ {
+ OListenerContainer::removeListener( _rxListener.get() );
+ }
+
+ // publish some otherwise hidden base functionality
+ OListenerContainer::disposing;
+ OListenerContainer::clear;
+ OListenerContainer::empty;
+ OListenerContainer::size;
+ OListenerContainer::createIterator;
+
+ /// typed notification
+ bool notify( const EventClass& _rEvent, NotificationMethod _pNotify ) SAL_THROW(( ::com::sun::star::uno::Exception ));
+
+ protected:
+ virtual bool implNotify(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener,
+ const ::com::sun::star::lang::EventObject& _rEvent
+ ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
+ };
+
+ //--------------------------------------------------------------------
+ template< class LISTENER, class EVENT >
+ bool OSimpleListenerContainer< LISTENER, EVENT >::notify( const EventClass& _rEvent, NotificationMethod _pNotify ) SAL_THROW(( ::com::sun::star::uno::Exception ))
+ {
+ m_pNotificationMethod = _pNotify;
+ bool bRet = OListenerContainer::notify( _rEvent );
+ m_pNotificationMethod = NULL;
+ return bRet;
+ }
+
+ //--------------------------------------------------------------------
+ template< class LISTENER, class EVENT >
+ bool OSimpleListenerContainer< LISTENER, EVENT >::implNotify(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& _rxListener,
+ const ::com::sun::star::lang::EventObject& _rEvent ) SAL_THROW( ( ::com::sun::star::uno::Exception ) )
+ {
+ const EventClass& rTypedEvent( static_cast< const EventClass& >( _rEvent ) );
+ ListenerClass* pTypedListener( static_cast< ListenerClass* >( _rxListener.get() ) );
+ (pTypedListener->*m_pNotificationMethod)( rTypedEvent );
+ return true;
+ }
+
//====================================================================
//= OListenerContainerBase
//====================================================================