]> git.saurik.com Git - wxWidgets.git/commitdiff
Ensure that wxApp::Yield is always processing pending event by creating a
authorStefan Neis <Stefan.Neis@t-online.de>
Fri, 16 May 2008 12:50:26 +0000 (12:50 +0000)
committerStefan Neis <Stefan.Neis@t-online.de>
Fri, 16 May 2008 12:50:26 +0000 (12:50 +0000)
        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
src/motif/app.cpp
src/msw/app.cpp
src/os2/app.cpp
src/x11/app.cpp

index 6a573d713c8bc23f45cb09091a07639974145bea..5528d8be312b73ec9d286552add7499fb10152ae 100644 (file)
@@ -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_
index 6208995cd0df97d15d4c513b36dde0c6349f4555..5807769612fa27669102af4b1949882766e9c4d3 100644 (file)
@@ -486,6 +486,7 @@ bool wxApp::Yield(bool onlyIfNeeded)
 
     s_inYield = true;
 
+    wxEventLoopGuarantor dummyLoopIfNeeded;
     while (wxTheApp && wxTheApp->Pending())
         wxTheApp->Dispatch();
 
index c4f599a5075d83baf365722a027805c800b17172..fd609a244ead681408132abdf39576401a544eb8 100644 (file)
@@ -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 )
index 49d5217b64404f94a9e542bd753e53337c524ea7..6bcf77e8cf4be54d2313a96c858848aabe1929a5 100644 (file)
@@ -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
index 90ea2a60af89ebf1e8eee0b0eb7f657091ec3a13..4c9868ce0c98d82ce22c26087c671eb3912a98af 100644 (file)
@@ -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;
     }