From f212e222e736f9f24d86edb5717508a159c38692 Mon Sep 17 00:00:00 2001 From: Stefan Neis Date: Fri, 16 May 2008 12:50:26 +0000 Subject: [PATCH] Ensure that wxApp::Yield is always processing pending event by creating a temporary event loop if needed. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53606 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/evtloop.h | 26 ++++++++++++++++++++++++++ src/motif/app.cpp | 1 + src/msw/app.cpp | 1 + src/os2/app.cpp | 1 + src/x11/app.cpp | 15 +-------------- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/include/wx/evtloop.h b/include/wx/evtloop.h index 6a573d713c..5528d8be31 100644 --- a/include/wx/evtloop.h +++ b/include/wx/evtloop.h @@ -223,4 +223,30 @@ private: wxEventLoopBase *m_evtLoopOld; }; +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 // _WX_EVTLOOP_H_ diff --git a/src/motif/app.cpp b/src/motif/app.cpp index 6208995cd0..5807769612 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -486,6 +486,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 c4f599a507..fd609a244e 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -800,6 +800,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 49d5217b64..6bcf77e8cf 100644 --- a/src/os2/app.cpp +++ b/src/os2/app.cpp @@ -535,6 +535,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 90ea2a60af..4c9868ce0c 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -793,14 +793,7 @@ bool wxApp::Yield(bool onlyIfNeeded) // Make sure we have an event loop object, // or Pending/Dispatch will fail - wxEventLoopBase * const 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 wxTheApp->Dispatch(); @@ -813,12 +806,6 @@ bool wxApp::Yield(bool onlyIfNeeded) #endif ProcessIdle(); - if (newEventLoop) - { - wxEventLoop::SetActive(NULL); - delete newEventLoop; - } - s_inYield = false; } -- 2.45.2