User: kz      
Date: 2008-03-06 18:10:38+0000
Modified:
   dba/dbaccess/source/ui/app/AppControllerGen.cxx

Log:
 INTEGRATION: CWS odbmacros2 (1.28.56); FILE MERGED
 2008/03/04 12:00:46 fs 1.28.56.7: RESYNC: (1.30-1.31); FILE MERGED
 2008/02/20 13:28:00 fs 1.28.56.6.2.1: some DBG_UNHANDLED_EXCEPTIONs
 2008/02/06 08:34:02 fs 1.28.56.6: slight refactoring during #i49133#
 2008/02/04 22:31:46 fs 1.28.56.5: #i10000#
 2008/02/04 13:07:51 fs 1.28.56.4: RESYNC: (1.28-1.30); FILE MERGED
 2008/01/28 11:35:59 fs 1.28.56.3: #i49133# implement new XDatabaseDocumentUI 
methods
 2008/01/26 21:19:10 fs 1.28.56.2: #new include necessary
 2007/12/13 11:21:52 fs 1.28.56.1: #i49133# some refactoring, mostly related to 
the m_xCurrentFrame->m_aCurrentFrame change

File Changes:

Directory: /dba/dbaccess/source/ui/app/
=======================================

File [changed]: AppControllerGen.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppControllerGen.cxx?r1=1.31&r2=1.32
Delta lines:  +144 -157
-----------------------
--- AppControllerGen.cxx        2008-02-12 13:24:53+0000        1.31
+++ AppControllerGen.cxx        2008-03-06 18:10:35+0000        1.32
@@ -143,8 +143,15 @@
 #ifndef DBACCESS_SOURCE_UI_MISC_DEFAULTOBJECTNAMECHECK_HXX
 #include "defaultobjectnamecheck.hxx"
 #endif
-
+#ifndef _VOS_MUTEX_HXX_
+#include <vos/mutex.hxx>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XEVENTLISTENER_HPP_
 #include <com/sun/star/lang/XEventListener.hpp>
+#endif
+#ifndef TOOLS_DIAGNOSE_EX_H
+#include <tools/diagnose_ex.h>
+#endif
 
 //........................................................................
 namespace dbaui
@@ -163,33 +170,33 @@
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::container;
 using namespace ::com::sun::star::ucb;
+using ::com::sun::star::util::XCloseable;
 //........................................................................
 // 
-----------------------------------------------------------------------------
 
 class CloseChecker : public ::cppu::WeakImplHelper1< 
com::sun::star::lang::XEventListener >
 {
-    sal_Bool m_bClosed;
+    bool    m_bClosed;
+
 public:
     CloseChecker()
-            :m_bClosed(sal_False)
+        :m_bClosed( false )
         {
-            // DBG_CTOR(CloseChecker,NULL);
-
         }
+
     virtual ~CloseChecker()
         {
-            // DBG_DTOR(CloseChecker,NULL);
         }
     
-       sal_Bool isClosed()
+       bool isClosed()
        {
-               return m_bClosed;
+               return true;
        }
-       // interface ::com::sun::star::lang::XEventListener
-    virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& 
Source) throw( ::com::sun::star::uno::RuntimeException )
+
+       // interface XEventListener
+    virtual void SAL_CALL disposing( const EventObject& /*Source*/ ) throw( 
RuntimeException )
         {
-            (void)Source;
-            m_bClosed = sal_True;
+        m_bClosed = true;
         }
 
 };
@@ -416,6 +423,15 @@
 }
 
 // 
-----------------------------------------------------------------------------
+Sequence< Reference< XComponent > > SAL_CALL 
OApplicationController::getSubComponents() throw (RuntimeException)
+{
+       ::osl::MutexGuard aGuard(m_aMutex);
+    Sequence< Reference< XComponent > > aComponents( m_aDocuments.size() );
+    ::std::transform( m_aDocuments.begin(), m_aDocuments.end(), 
aComponents.getArray(), ::std::select1st< TDocuments::value_type >() );
+    return aComponents;
+}
+
+// 
-----------------------------------------------------------------------------
 Reference< XConnection > SAL_CALL 
OApplicationController::getActiveConnection() throw (RuntimeException)
 {
        ::osl::MutexGuard aGuard(m_aMutex);
@@ -439,6 +455,103 @@
     return isConnected();
 }
 
+// 
-----------------------------------------------------------------------------
+namespace
+{
+    static Reference< XController > lcl_getController( const 
OApplicationController::TDocuments::iterator& _docPos )
+    {
+        Reference< XController > xController;
+
+        Reference< XComponent > xComponent( _docPos->first );
+           Reference< XModel > xModel( xComponent, UNO_QUERY );
+           if ( xModel.is() )
+                   xController = xModel->getCurrentController();
+           else
+           {
+                   xController.set( xComponent, UNO_QUERY );
+                   if ( !xController.is() )
+                   {
+                           Reference<XFrame> xFrame( xComponent, UNO_QUERY );
+                           if ( xFrame.is() )
+                                   xController = xFrame->getController();
+                   }
+           }
+        return xController;
+    }
+}
+
+// 
-----------------------------------------------------------------------------
+::sal_Bool SAL_CALL OApplicationController::closeSubComponents(  ) throw 
(RuntimeException)
+{
+       ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
+       ::osl::MutexGuard aGuard( m_aMutex );
+
+       try
+       {
+        typedef ::std::vector< Reference< XComponent > > ComponentArray;
+        ComponentArray aClosedComponents;
+
+        TDocuments aDocuments( m_aDocuments );
+               for (   TDocuments::iterator doc = aDocuments.begin();
+                doc != aDocuments.end();
+                ++doc
+            )
+        {
+            Reference< XController > xController( lcl_getController( doc ) );
+            OSL_ENSURE( xController.is(), 
"OApplicationController::closeSubComponents: did not find the sub controller!" 
);
+
+            // suspend the controller in the document
+            if  (   !xController.is()
+                ||  !xController->suspend( sal_True )
+                )
+                // break complete operation, no sense in continueing
+                break;
+
+            // revoke event listener
+            Reference< XComponent > xDocument = doc->first;
+            if ( xDocument.is() )
+                xDocument->removeEventListener( static_cast< 
XFrameActionListener* >( this ) );
+
+            bool bClosedSubDoc = false;
+            try
+            {
+                Reference< XCloseable > xCloseable( xController->getFrame(), 
UNO_QUERY_THROW );
+                xCloseable->close( sal_True );
+                bClosedSubDoc = true;
+            }
+            catch( const Exception& )
+            {
+                DBG_UNHANDLED_EXCEPTION();
+            }
+
+            if ( !bClosedSubDoc )
+                // no sense in continueing with the other docs
+                break;
+
+            aClosedComponents.push_back( doc->first );
+        }
+
+        // now remove all the components which we could successfully close
+        // (this might be none, or all, or something inbetween) from 
m_aDocuments
+        for (   ComponentArray::const_iterator comp = 
aClosedComponents.begin();
+                comp != aClosedComponents.end();
+                ++comp
+            )
+        {
+            TDocuments::iterator pos = m_aDocuments.find( *comp );
+            OSL_ENSURE( pos != m_aDocuments.end(),
+                "OApplicationController::closeSubComponents: closed a 
component which doesn't exist anymore!" );
+            if ( pos !=m_aDocuments.end() )
+                m_aDocuments.erase( pos );
+        }
+       }
+       catch ( const Exception& )
+       {
+        DBG_UNHANDLED_EXCEPTION();
+       }
+
+       return m_aDocuments.empty();
+}
 
 // 
-----------------------------------------------------------------------------
 void OApplicationController::previewChanged( sal_Int32 _nMode )
@@ -450,32 +563,17 @@
        {
                try
                {
-                       Sequence<PropertyValue> aFields;
-                       
m_xDataSource->getPropertyValue(PROPERTY_LAYOUTINFORMATION) >>= aFields;
-                       PropertyValue *pIter = aFields.getArray();
-                       PropertyValue *pEnd = pIter + aFields.getLength();
-                       const static ::rtl::OUString 
s_sPreview(RTL_CONSTASCII_USTRINGPARAM("Preview"));
-                       for (; pIter != pEnd && pIter->Name != s_sPreview; 
++pIter)
-                               ;
-
-                       if ( pIter == pEnd )
-                       {
-                               sal_Int32 nLen = aFields.getLength();
-                               aFields.realloc( nLen + 1 );
-                               pIter = aFields.getArray() + nLen;
-                               pIter->Name = s_sPreview;
-                       }
-                       sal_Int32 nOldMode = 0;
-                       pIter->Value >>= nOldMode;
+            ::comphelper::NamedValueCollection aLayoutInfo( 
m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
+            sal_Int32 nOldMode = aLayoutInfo.getOrDefault( "Preview", _nMode );
                        if ( nOldMode != _nMode )
                        {
-                               pIter->Value <<= _nMode;
-                               
m_xDataSource->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aFields));
+                aLayoutInfo.put( "Preview", _nMode );
+                               m_xDataSource->setPropertyValue( 
PROPERTY_LAYOUTINFORMATION, makeAny( aLayoutInfo.getPropertyValues() ) );
                        }
                }
-               catch(Exception)
+               catch ( const Exception& )
                {
-                       OSL_ENSURE(0,"Exception caught!");
+            DBG_UNHANDLED_EXCEPTION();
                }
        }
        InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW);
@@ -511,7 +609,7 @@
                        switch (aQry.Execute())
                        {
                                case RET_YES:
-                                       suspendDocuments(sal_True);
+                                       closeSubComponents();
                                        break;
                                default:
                                        bClear = sal_False;
@@ -523,125 +621,14 @@
                        ElementType eType = getContainer()->getElementType();
                        disconnect();
                        getContainer()->getDetailView()->clearPages(sal_False);
-                       getContainer()->changeContainer(E_NONE); // invalidate 
the old selection
-                       getContainer()->changeContainer(eType); // reselect the 
current one again
+                       getContainer()->selectContainer(E_NONE); // invalidate 
the old selection
+            m_eCurrentType = E_NONE;
+                       getContainer()->selectContainer(eType); // reselect the 
current one again
                }
        }
 }
-// 
-----------------------------------------------------------------------------
-sal_Bool OApplicationController::suspendDocument(const TDocuments::value_type& 
_aComponent,sal_Bool _bSuspend)
-{
-       sal_Bool bSuspended = sal_True;
-       Reference<XController> xController;
-       Reference<XModel> xModel(_aComponent.first,UNO_QUERY);
-       if ( xModel.is() )
-               xController = xModel->getCurrentController();
-       else
-       {
-               xController.set(_aComponent.first,UNO_QUERY);
-               if ( !xController.is() )
-               {
-                       Reference<XFrame> xFrame(_aComponent.first,UNO_QUERY);
-                       if ( xFrame.is() )
-                               xController = xFrame->getController();
-               }
-       }
-
-       if ( xController.is() && xController != *this )
-    {
-        Reference< XCommandProcessor > xContent(_aComponent.second,UNO_QUERY);
-               if ( xContent.is() )
-               {
-            if ( _bSuspend )
-            {
-                Command aCommand;
-                aCommand.Name = 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("shutdown"));
-                           
xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< 
XCommandEnvironment >()) >>= bSuspended;
-            }
-        }
-        else
-                   bSuspended = xController->suspend(_bSuspend);
-    }
-
-       return bSuspended;
-}
 
 // 
-----------------------------------------------------------------------------
-sal_Bool OApplicationController::suspendDocuments(sal_Bool bSuspend)
-{
-       sal_Bool bSubSuspended = sal_True;
-       Reference<XModel> xModel;
-       sal_Int32 nSuspendPos = 1;
-    
-       try
-       {
-        TDocuments aCopy = m_aDocuments;
-           TDocuments::iterator aIter = aCopy.begin();
-           TDocuments::iterator aEnd = aCopy.end();
-               for (; aIter != aEnd && bSubSuspended; ++aIter,++nSuspendPos)
-                       bSubSuspended = suspendDocument(*aIter,bSuspend);
-       }
-       catch(Exception)
-       {
-       }
-       if ( bSubSuspended && !m_aDocuments.empty() )
-       {
-               try
-               {
-                       TDocuments::iterator document = m_aDocuments.begin();
-                       TDocuments::iterator documentEnd = m_aDocuments.end();
-                       for (; document != documentEnd ;  ++document)
-                       {
-                               Reference< XComponent > xDocument = 
document->first;
-                               if ( xDocument.is() )
-                                       
xDocument->removeEventListener(static_cast<XFrameActionListener*>(this));
-                
-                Reference<XFrame> xFrame(document->first,UNO_QUERY);
-                if ( xFrame.is() )
-                {
-                    Reference<XController> xController = 
xFrame->getController();
-                    if ( xController.is() )
-                    {
-                        Reference< com::sun::star::util::XCloseable> 
xCloseable(xController->getFrame(),UNO_QUERY);
-                        if ( xCloseable.is() )
-                            xCloseable->close(sal_True);
-                    }
-                }
-                       }
-                       document = m_aDocuments.begin();
-                       // first of all we have to set the second to NULL
-                       for (; document != documentEnd ;  )
-                       {
-                               TDocuments::iterator aPos = document++;
-                               aPos->second = NULL; // this may also dispose 
the document
-                       }
-               }
-               catch(Exception)
-               {
-               }
-               if ( bSubSuspended )
-               {
-                       // remove the document only at save or discard, but not 
at cancel state.
-                       m_aDocuments.clear();
-               }
-       }
-       else // resuspend the documents again
-       {
-               TDocuments::iterator aIter = m_aDocuments.begin();
-               TDocuments::iterator aEnd = m_aDocuments.end();
-               try
-               {
-                       for (; aIter != aEnd && nSuspendPos ; 
++aIter,--nSuspendPos)
-                               suspendDocument(*aIter,!bSuspend);
-               }
-               catch(Exception)
-               {
-               }
-       }
-
-       return bSubSuspended;
-}
-// 
-----------------------------------------------------------------------------
 ::rtl::OUString OApplicationController::getStrippedDatabaseName() const
 {
        return ::dbaui::getStrippedDatabaseName(m_xDataSource,m_sDatabaseName);
@@ -786,7 +773,7 @@
             eResult = 
aSendMail.AttachDocument(aDocTypeString,xModel,componentIter->first);
                }
                if ( !aSendMail.IsEmpty() )
-                       aSendMail.Send( m_xCurrentFrame );
+                       aSendMail.Send( getFrame() );
        }
 }
 // 
-----------------------------------------------------------------------------




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

Reply via email to