X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c7789014106c9269b0f4ecc1a3071b14f351d3f..9a6aafe0039fef580ca1bfcf0e87c1ba8e2953ba:/src/common/appbase.cpp diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index a358cf0dde..d159c9bdd8 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -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" @@ -164,6 +164,7 @@ bool wxAppConsoleBase::Initialize(int& WXUNUSED(argc), wxChar **argv) #if wxUSE_THREADS wxHandlersWithPendingEventsLocker = new wxCriticalSection; + wxHandlersWithPendingDelayedEvents = new wxList; #endif #ifndef __WXPALMOS__ @@ -193,6 +194,9 @@ void wxAppConsoleBase::CleanUp() delete wxHandlersWithPendingEvents; wxHandlersWithPendingEvents = NULL; + delete wxHandlersWithPendingDelayedEvents; + wxHandlersWithPendingDelayedEvents = NULL; + #if wxUSE_THREADS delete wxHandlersWithPendingEventsLocker; wxHandlersWithPendingEventsLocker = NULL; @@ -243,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; @@ -336,6 +340,16 @@ bool wxAppConsoleBase::HasPendingEvents() const return has; } +void wxAppConsoleBase::SuspendProcessingOfPendingEvents() +{ + wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); +} + +void wxAppConsoleBase::ResumeProcessingOfPendingEvents() +{ + wxLEAVE_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); +} + /* static */ bool wxAppConsoleBase::IsMainLoopRunning() { @@ -353,6 +367,9 @@ void wxAppConsoleBase::ProcessPendingEvents() wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); + wxCHECK_RET( wxHandlersWithPendingDelayedEvents->IsEmpty(), + "this helper list should be empty" ); + if (wxHandlersWithPendingEvents) { // iterate until the list becomes empty: the handlers remove themselves @@ -360,7 +377,7 @@ void wxAppConsoleBase::ProcessPendingEvents() 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( *wxHandlersWithPendingEventsLocker ); @@ -374,6 +391,20 @@ void wxAppConsoleBase::ProcessPendingEvents() } } + // 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 ); }