Tag: cws_dev300_odbmacros3
User: fs      
Date: 2008-07-30 20:50:59+0000
Modified:
   dba/dbaccess/source/core/dataaccess/databasedocument.cxx

Log:
 #i76128# more event notification tweaking

File Changes:

Directory: /dba/dbaccess/source/core/dataaccess/
================================================

File [changed]: databasedocument.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasedocument.cxx?r1=1.40.6.16&r2=1.40.6.17
Delta lines:  +80 -35
---------------------
--- databasedocument.cxx        2008-07-29 20:19:28+0000        1.40.6.16
+++ databasedocument.cxx        2008-07-30 20:50:56+0000        1.40.6.17
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: databasedocument.cxx,v $
- * $Revision: 1.40.6.16 $
+ * $Revision: 1.40.6.17 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -122,19 +122,14 @@
 //--------------------------------------------------------------------------
 void ViewMonitor::onSetCurrentController( const Reference< XController >& 
_rxController )
 {
-    // we interpret this as "creation of a new view has been finished", if and 
only if
-    // the controller is the same which was recently connected to the document
-    bool bViewCreated = ( _rxController == m_xLastConnectedController );
-
-    // also, we interpret this as "loading the document (including UI) is 
finished",
-    // if and only if this was the first-ever controller
-    bool bLoadFinished = bViewCreated && m_bLastIsFirstEverController;
+    // we interpret this as "loading the document (including UI) is finished",
+    // if and only if this is the controller which was last connected, and it 
was the
+    // first controller ever connected
+    bool bLoadFinished = ( _rxController == m_xLastConnectedController ) && 
m_bLastIsFirstEverController;
 
     // notify the respective events
     if ( bLoadFinished )
         m_rEventNotifier.notifyDocumentEventAsync( m_bIsNewDocument ? "OnNew" 
: "OnLoad" );
-    if ( bViewCreated )
-        m_rEventNotifier.notifyDocumentEventAsync( "OnViewCreated", Reference< 
XController2 >( _rxController, UNO_QUERY ) );
 }
 
 //============================================================
@@ -159,6 +154,7 @@
             ,m_aEventNotifier( *this, getMutex() )
             ,m_aViewMonitor( m_aEventNotifier )
             ,m_eInitState( NotInitialized )
+            ,m_bClosing( false )
 {
        DBG_CTOR(ODatabaseDocument,NULL);
 
@@ -481,6 +477,8 @@
 
     m_aControllers.push_back( _xController );
 
+    m_aEventNotifier.notifyDocumentEventAsync( "OnViewCreated", Reference< 
XController2 >( _xController, UNO_QUERY ) );
+
     bool bFirstControllerEver = m_aViewMonitor.onControllerConnected( 
_xController );
     if ( !bFirstControllerEver )
         return;
@@ -492,6 +490,12 @@
 // 
-----------------------------------------------------------------------------
 void SAL_CALL ODatabaseDocument::disconnectController( const Reference< 
XController >& _xController ) throw (RuntimeException)
 {
+    bool bNotifyViewClosed = false;
+    bool bLastControllerGone = false;
+    bool bIsClosing = false;
+
+    // SYNCHRONIZED ->
+    {
     DocumentGuard aGuard( *this );
 
     Controllers::iterator pos = ::std::find( m_aControllers.begin(), 
m_aControllers.end(), _xController );
@@ -499,13 +503,21 @@
     if ( pos != m_aControllers.end() )
     {
         m_aControllers.erase( pos );
-        m_aEventNotifier.notifyDocumentEventAsync( "OnViewClosed", Reference< 
XController2 >( _xController, UNO_QUERY ) );
+            bNotifyViewClosed = true;
     }
 
        if ( m_xCurrentController == _xController )
                m_xCurrentController = NULL;
 
-    if ( m_aControllers.empty() )
+        bLastControllerGone = m_aControllers.empty();
+        bIsClosing = m_bClosing;
+    }
+    // <- SYNCHRONIZED
+
+    if ( bNotifyViewClosed )
+        m_aEventNotifier.notifyDocumentEvent( "OnViewClosed", Reference< 
XController2 >( _xController, UNO_QUERY ) );
+
+    if ( bLastControllerGone && !bIsClosing )
     {
         // if this was the last view, close the document as a whole
         // #i51157# / 2006-03-16 / [EMAIL PROTECTED]
@@ -790,6 +802,14 @@
     DocumentGuard aGuard( *this );
     ModifyLock aLock( *this );
 
+    {
+        aGuard.clear();
+        m_aEventNotifier.notifyDocumentEvent( "OnSaveTo" );
+        aGuard.reset();
+    }
+
+    try
+    {
     // create storage for target URL
     Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( _rURL ) 
);
 
@@ -798,6 +818,14 @@
 
     // store to this storage
     impl_storeToStorage_throw( xTargetStorage, aMediaDescriptor );
+    }
+    catch( const Exception& )
+    {
+        m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToFailed" );
+        throw;
+    }
+
+    m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToDone" );
 }
 
 // 
-----------------------------------------------------------------------------
@@ -1016,12 +1044,17 @@
 // 
-----------------------------------------------------------------------------
 void SAL_CALL ODatabaseDocument::close( sal_Bool _bDeliverOwnership ) throw 
(CloseVetoException, RuntimeException)
 {
-    // everything below can/must be done without our mutex locked, the below 
is just for
+    // nearly everything below can/must be done without our mutex locked, the 
below is just for
     // the checks for being disposed and the like
+    // SYNCHRONIZED ->
     {
         DocumentGuard aGuard( *this );
+        m_bClosing = true;
     }
+    // <- SYNCHRONIZED
 
+    try
+    {
     // allow listeners to veto
     lang::EventObject aEvent( *this );
     m_aCloseListener.forEach< XCloseListener >(
@@ -1035,6 +1068,18 @@
     m_aCloseListener.notifyEach( &XCloseListener::notifyClosing, (const 
lang::EventObject&)aEvent );
 
     dispose();
+    }
+    catch ( const Exception& )
+    {
+        ::osl::MutexGuard aGuard( m_xMutex->getMutex() );
+        m_bClosing = false;
+        throw;
+    }
+
+    // SYNCHRONIZED ->
+    ::osl::MutexGuard aGuard( m_xMutex->getMutex() );
+    m_bClosing = false;
+    // <- SYNCHRONIZED
 }
 // 
-----------------------------------------------------------------------------
 void SAL_CALL ODatabaseDocument::addCloseListener( const Reference< 
::com::sun::star::util::XCloseListener >& Listener ) throw (RuntimeException)




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to