Tag: cws_dev300_odbmacros3 User: fs Date: 2008-07-29 08:24:18+0000 Modified: dba/dbaccess/source/core/dataaccess/documenteventnotifier.cxx dba/dbaccess/source/core/dataaccess/documenteventnotifier.hxx
Log: #i76128# only fire events when the document is initialized completely File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: documenteventnotifier.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/documenteventnotifier.cxx?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +47 -15 --------------------- --- documenteventnotifier.cxx 2008-07-28 06:26:58+0000 1.1.2.1 +++ documenteventnotifier.cxx 2008-07-29 08:24:15+0000 1.1.2.2 @@ -7,7 +7,7 @@ * * $RCSfile: documenteventnotifier.cxx,v $ * -* $Revision: 1.1.2.1 $ +* $Revision: 1.1.2.2 $ * * This file is part of OpenOffice.org. * @@ -33,6 +33,7 @@ #include "documenteventnotifier.hxx" /** === begin UNO includes === **/ +#include <com/sun/star/frame/DoubleInitializationException.hpp> /** === end UNO includes === **/ #include <comphelper/asyncnotification.hxx> @@ -57,6 +58,7 @@ using ::com::sun::star::uno::makeAny; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Type; + using ::com::sun::star::frame::DoubleInitializationException; /** === end UNO using === **/ using namespace ::com::sun::star; @@ -73,6 +75,7 @@ oslInterlockedCount m_refCount; ::cppu::OWeakObject& m_rDocument; ::osl::Mutex& m_rMutex; + bool m_bInitialized; bool m_bDisposed; ::rtl::Reference< ::comphelper::AsyncEventNotifier > m_pEventBroadcaster; ::cppu::OInterfaceContainerHelper m_aDocumentEventListeners; @@ -82,6 +85,7 @@ :m_refCount( 0 ) ,m_rDocument( _rBroadcasterDocument ) ,m_rMutex( _rMutex ) + ,m_bInitialized( false ) ,m_bDisposed( false ) ,m_aDocumentEventListeners( _rMutex ) { @@ -101,18 +105,9 @@ m_aDocumentEventListeners.removeInterface( _Listener ); } - inline void disposing() - { - // cancel any pending asynchronous events - ::osl::MutexGuard aGuard( m_rMutex ); - if ( m_pEventBroadcaster.is() ) - { - m_pEventBroadcaster->removeEventsForProcessor( this ); - m_pEventBroadcaster->terminate(); - m_pEventBroadcaster = NULL; - } - m_bDisposed = true; - } + void disposing(); + + void onDocumentInitialized(); void notifyDocumentEvent( const sal_Char* _pAsciiEventName ) { @@ -154,8 +149,36 @@ } //-------------------------------------------------------------------- + void DocumentEventNotifier_Impl::disposing() + { + // cancel any pending asynchronous events + ::osl::MutexGuard aGuard( m_rMutex ); + if ( m_pEventBroadcaster.is() ) + { + m_pEventBroadcaster->removeEventsForProcessor( this ); + m_pEventBroadcaster->terminate(); + m_pEventBroadcaster = NULL; + } + m_bDisposed = true; + } + + //-------------------------------------------------------------------- + void DocumentEventNotifier_Impl::onDocumentInitialized() + { + if ( m_bInitialized ) + throw DoubleInitializationException(); + + m_bInitialized = true; + if ( m_pEventBroadcaster.is() ) + // there are already pending asynchronous events + m_pEventBroadcaster->create(); + } + + //-------------------------------------------------------------------- void DocumentEventNotifier_Impl::impl_notifyEvent_nothrow( const document::EventObject& _rEvent ) { + OSL_PRECOND( m_bInitialized, + "DocumentEventNotifier_Impl::impl_notifyEvent_nothrow: only to be called when the document is already initialized!" ); try { m_aDocumentEventListeners.notifyEach( &document::XEventListener::notifyEvent, _rEvent ); @@ -172,6 +195,9 @@ if ( !m_pEventBroadcaster.is() ) { m_pEventBroadcaster.set( new ::comphelper::AsyncEventNotifier ); + if ( m_bInitialized ) + // start processing the events if and only if we (our document, respectively) are + // already initialized m_pEventBroadcaster->create(); } m_pEventBroadcaster->addEvent( new DocumentEventHolder( _rEvent ), this ); @@ -211,6 +237,12 @@ } //-------------------------------------------------------------------- + void DocumentEventNotifier::onDocumentInitialized() + { + m_pImpl->onDocumentInitialized(); + } + + //-------------------------------------------------------------------- void DocumentEventNotifier::addDocumentEventListener( const Reference< document::XEventListener >& _Listener ) throw (RuntimeException) { m_pImpl->addDocumentEventListener( _Listener ); File [changed]: documenteventnotifier.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/documenteventnotifier.hxx?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +16 -2 -------------------- --- documenteventnotifier.hxx 2008-07-28 06:26:58+0000 1.1.2.1 +++ documenteventnotifier.hxx 2008-07-29 08:24:15+0000 1.1.2.2 @@ -8,7 +8,7 @@ * * $RCSfile: documenteventnotifier.hxx,v $ * -* $Revision: 1.1.2.1 $ +* $Revision: 1.1.2.2 $ * * This file is part of OpenOffice.org. * @@ -71,14 +71,28 @@ */ void disposing(); + /** tells the instance that its document is completely initialized now. + + Before you call this method, no notification will actually happen + + @precond + the mutex is locked + */ + void onDocumentInitialized(); + /** notifies a document event to all registered listeners + @precond the mutex is not locked + @precond + ->onDocumentInitialized has been called */ void notifyDocumentEvent( const sal_Char* _pAsciiEventName ); /** notifies a document event to all registered listeners, asynchronously + Note that no event is actually notified before you called ->onDocumentInitialized. + @precond the mutex is locked */ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
