diff --git a/include/wx/evtloop.h b/include/wx/evtloop.h index 226db925fa..b0645b5f06 100644 --- a/include/wx/evtloop.h +++ b/include/wx/evtloop.h @@ -198,4 +198,32 @@ private: wxEventLoop *m_evtLoopOld; }; +#if wxABI_VERSION >= 20808 +class wxEventLoopGuarantor +{ +public: + wxEventLoopGuarantor() + { + m_evtLoopNew = NULL; + if (!wxEventLoop::GetActive()) + { + m_evtLoopNew = new wxEventLoop; + wxEventLoop::SetActive(m_evtLoopNew); + } + } + + ~wxEventLoopGuarantor() + { + if (m_evtLoopNew) + { + wxEventLoop::SetActive(NULL); + delete m_evtLoopNew; + } + } + +private: + wxEventLoop *m_evtLoopNew; +}; +#endif // wxABI_VERSION >= 20805 + #endif // _WX_EVTLOOP_H_ diff --git a/src/dfb/app.cpp b/src/dfb/app.cpp index e84aa6ae98..eadd69a205 100644 --- a/src/dfb/app.cpp +++ b/src/dfb/app.cpp @@ -137,8 +137,9 @@ bool wxApp::Yield(bool onlyIfNeeded) wxLog::Suspend(); - if ( wxEventLoop::GetActive() ) - wxEventLoop::GetActive()->Yield(); + // A guarentee that there will be an active event loop: + wxEventLoopGuarantor dummyLoopIfNeeded; + wxEventLoop::GetActive()->Yield(); // it's necessary to call ProcessIdle() to update the frames sizes which // might have been changed (it also will update other things set from diff --git a/src/mgl/app.cpp b/src/mgl/app.cpp index 1a614e3f81..7b23f42f6a 100644 --- a/src/mgl/app.cpp +++ b/src/mgl/app.cpp @@ -74,11 +74,10 @@ bool wxApp::Yield(bool onlyIfNeeded) wxLog::Suspend(); - if ( wxEventLoop::GetActive() ) - { - while (wxEventLoop::GetActive()->Pending()) - wxEventLoop::GetActive()->Dispatch(); - } + // A guarentee that there will be an active event loop: + wxEventLoopGuarantor dummyLoopIfNeeded; + while (wxEventLoop::GetActive()->Pending()) + wxEventLoop::GetActive()->Dispatch(); /* it's necessary to call ProcessIdle() to update the frames sizes which might have been changed (it also will update other things set from diff --git a/src/motif/app.cpp b/src/motif/app.cpp index 51c70a94a5..93c56cb121 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -437,6 +437,7 @@ bool wxApp::Yield(bool onlyIfNeeded) s_inYield = true; + wxEventLoopGuarantor dummyLoopIfNeeded; while (wxTheApp && wxTheApp->Pending()) wxTheApp->Dispatch(); diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 7d254fbd21..461f3a2b6d 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -702,6 +702,7 @@ bool wxApp::Yield(bool onlyIfNeeded) // we don't want to process WM_QUIT from here - it should be processed in // the main event loop in order to stop it + wxEventLoopGuarantor dummyLoopIfNeeded; MSG msg; while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) && msg.message != WM_QUIT ) diff --git a/src/os2/app.cpp b/src/os2/app.cpp index 65b080d5e9..0e51814e26 100644 --- a/src/os2/app.cpp +++ b/src/os2/app.cpp @@ -551,6 +551,7 @@ bool wxApp::Yield(bool onlyIfNeeded) // We want to go back to the main message loop // if we see a WM_QUIT. (?) // + wxEventLoopGuarantor dummyLoopIfNeeded; while (::WinPeekMsg(vHab, &vMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) && vMsg.msg != WM_QUIT) { #if wxUSE_THREADS diff --git a/src/x11/app.cpp b/src/x11/app.cpp index a7165cf5ec..f828e7f4d8 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -796,13 +796,7 @@ bool wxApp::Yield(bool onlyIfNeeded) // Make sure we have an event loop object, // or Pending/Dispatch will fail - wxEventLoop* eventLoop = wxEventLoop::GetActive(); - wxEventLoop* newEventLoop = NULL; - if (!eventLoop) - { - newEventLoop = new wxEventLoop; - wxEventLoop::SetActive(newEventLoop); - } + wxEventLoopGuarantor dummyLoopIfNeeded; // Call dispatch at least once so that sockets // can be tested @@ -816,12 +810,6 @@ bool wxApp::Yield(bool onlyIfNeeded) #endif ProcessIdle(); - if (newEventLoop) - { - wxEventLoop::SetActive(NULL); - delete newEventLoop; - } - s_inYield = false; } diff --git a/version-script.in b/version-script.in index 36d064c8d5..19b1330108 100644 --- a/version-script.in +++ b/version-script.in @@ -31,6 +31,7 @@ *TimeZone*Make*; *wxBitmapButton*OnFocusChange*; *wxDocManager*MakeNewDocumentName*; + *wxEventLoopGuarantor*; *wxGridBagSizer*AdjustForOverflow*; *wxRemotelyScrolledTreeCtrl*DoCalcScrolledPosition*; *wxRemotelyScrolledTreeCtrl*SetScrollbar*;