]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/appbase.cpp
no real change: put event handlers together at the end of the file
[wxWidgets.git] / src / common / appbase.cpp
index 7b2636e47cc930e58c1f15a4ef68c9cb3e637ff7..d159c9bdd8eb71738a15fa4b43e776ff77318fa0 100644 (file)
@@ -42,7 +42,7 @@
 #include "wx/evtloop.h"
 #include "wx/filename.h"
 #include "wx/msgout.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
 #include "wx/tokenzr.h"
 #include "wx/thread.h"
 
@@ -111,6 +111,8 @@ wxAppConsole *wxAppConsoleBase::ms_appInstance = NULL;
 
 wxAppInitializerFunction wxAppConsoleBase::ms_appInitFn = NULL;
 
+wxSocketManager *wxAppTraitsBase::ms_manager = NULL;
+
 // ----------------------------------------------------------------------------
 // wxEventLoopPtr
 // ----------------------------------------------------------------------------
@@ -161,7 +163,8 @@ bool wxAppConsoleBase::Initialize(int& WXUNUSED(argc), wxChar **argv)
 #endif // wxUSE_INTL
 
 #if wxUSE_THREADS
-    wxPendingEventsLocker = new wxCriticalSection;
+    wxHandlersWithPendingEventsLocker = new wxCriticalSection;
+    wxHandlersWithPendingDelayedEvents = new wxList;
 #endif
 
 #ifndef __WXPALMOS__
@@ -188,12 +191,15 @@ void wxAppConsoleBase::CleanUp()
         m_mainLoop = NULL;
     }
 
-    delete wxPendingEvents;
-    wxPendingEvents = NULL;
+    delete wxHandlersWithPendingEvents;
+    wxHandlersWithPendingEvents = NULL;
+
+    delete wxHandlersWithPendingDelayedEvents;
+    wxHandlersWithPendingDelayedEvents = NULL;
 
 #if wxUSE_THREADS
-    delete wxPendingEventsLocker;
-    wxPendingEventsLocker = NULL;
+    delete wxHandlersWithPendingEventsLocker;
+    wxHandlersWithPendingEventsLocker = NULL;
 #endif // wxUSE_THREADS
 }
 
@@ -241,7 +247,7 @@ int wxAppConsoleBase::OnExit()
 #if wxUSE_CONFIG
     // delete the config object if any (don't use Get() here, but Set()
     // because Get() could create a new config object)
-    delete wxConfigBase::Set((wxConfigBase *) NULL);
+    delete wxConfigBase::Set(NULL);
 #endif // wxUSE_CONFIG
 
     return 0;
@@ -325,15 +331,25 @@ bool wxAppConsoleBase::Dispatch()
 
 bool wxAppConsoleBase::HasPendingEvents() const
 {
-    wxENTER_CRIT_SECT( *wxPendingEventsLocker );
+    wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker );
 
-    bool has = wxPendingEvents && !wxPendingEvents->IsEmpty();
+    bool has = wxHandlersWithPendingEvents && !wxHandlersWithPendingEvents->IsEmpty();
 
-    wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
+    wxLEAVE_CRIT_SECT( *wxHandlersWithPendingEventsLocker );
 
     return has;
 }
 
+void wxAppConsoleBase::SuspendProcessingOfPendingEvents()
+{
+    wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker );
+}
+
+void wxAppConsoleBase::ResumeProcessingOfPendingEvents()
+{
+    wxLEAVE_CRIT_SECT( *wxHandlersWithPendingEventsLocker );
+}
+
 /* static */
 bool wxAppConsoleBase::IsMainLoopRunning()
 {
@@ -345,34 +361,51 @@ bool wxAppConsoleBase::IsMainLoopRunning()
 void wxAppConsoleBase::ProcessPendingEvents()
 {
 #if wxUSE_THREADS
-    if ( !wxPendingEventsLocker )
+    if ( !wxHandlersWithPendingEventsLocker )
         return;
 #endif
 
-    wxENTER_CRIT_SECT( *wxPendingEventsLocker );
+    wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker );
 
-    if (wxPendingEvents)
+    wxCHECK_RET( wxHandlersWithPendingDelayedEvents->IsEmpty(),
+                 "this helper list should be empty" );
+
+    if (wxHandlersWithPendingEvents)
     {
         // iterate until the list becomes empty: the handlers remove themselves
         // from it when they don't have any more pending events
-        wxList::compatibility_iterator node = wxPendingEvents->GetFirst();
+        wxList::compatibility_iterator node = wxHandlersWithPendingEvents->GetFirst();
         while (node)
         {
-            // In ProcessPendingEvents(), new handlers might be add
+            // In ProcessPendingEvents(), new handlers might be added
             // and we can safely leave the critical section here.
-            wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
+            wxLEAVE_CRIT_SECT( *wxHandlersWithPendingEventsLocker );
 
             wxEvtHandler *handler = (wxEvtHandler *)node->GetData();
             handler->ProcessPendingEvents();
 
-            wxENTER_CRIT_SECT( *wxPendingEventsLocker );
+            wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker );
 
             // restart as the iterators could have been invalidated
-            node = wxPendingEvents->GetFirst();
+            node = wxHandlersWithPendingEvents->GetFirst();
         }
     }
 
-    wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
+    // now the wxHandlersWithPendingEvents is surely empty; however some event
+    // handlers may have moved themselves into wxHandlersWithPendingDelayedEvents
+    // because of a selective wxYield call in progress.
+    // Now we need to move them back to wxHandlersWithPendingEvents so the next
+    // call to this function has the chance of processing them:
+    if (!wxHandlersWithPendingDelayedEvents->IsEmpty())
+    {
+        if (!wxHandlersWithPendingEvents)
+            wxHandlersWithPendingEvents = new wxList;
+
+        WX_APPEND_LIST(wxHandlersWithPendingEvents, wxHandlersWithPendingDelayedEvents);
+        wxHandlersWithPendingDelayedEvents->Clear();
+    }
+
+    wxLEAVE_CRIT_SECT( *wxHandlersWithPendingEventsLocker );
 }
 
 void wxAppConsoleBase::WakeUpIdle()
@@ -383,6 +416,9 @@ void wxAppConsoleBase::WakeUpIdle()
 
 bool wxAppConsoleBase::ProcessIdle()
 {
+    // process pending wx events before sending idle events
+    ProcessPendingEvents();
+
     wxIdleEvent event;
 
     event.SetEventObject(this);
@@ -411,6 +447,20 @@ wxAppConsoleBase::HandleEvent(wxEvtHandler *handler,
     (handler->*func)(event);
 }
 
+void wxAppConsoleBase::CallEventHandler(wxEvtHandler *handler,
+                                        wxEventFunctor& functor,
+                                        wxEvent& event) const
+{
+    // If the functor holds a method then, for backward compatibility, call
+    // HandleEvent():
+    wxEventFunction eventFunction = functor.GetMethod();
+
+    if ( eventFunction )
+        HandleEvent(handler, eventFunction, event);
+    else
+        functor(handler, event);
+}
+
 void wxAppConsoleBase::OnUnhandledException()
 {
 #ifdef __WXDEBUG__