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/branches/WX_2_8_BRANCH@53607 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis
2008-05-16 15:21:40 +00:00
parent 390d9ef3a8
commit 3cf88bbd74
8 changed files with 40 additions and 20 deletions

View File

@@ -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_

View File

@@ -137,7 +137,8 @@ bool wxApp::Yield(bool onlyIfNeeded)
wxLog::Suspend();
if ( wxEventLoop::GetActive() )
// 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

View File

@@ -74,11 +74,10 @@ bool wxApp::Yield(bool onlyIfNeeded)
wxLog::Suspend();
if ( wxEventLoop::GetActive() )
{
// 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

View File

@@ -437,6 +437,7 @@ bool wxApp::Yield(bool onlyIfNeeded)
s_inYield = true;
wxEventLoopGuarantor dummyLoopIfNeeded;
while (wxTheApp && wxTheApp->Pending())
wxTheApp->Dispatch();

View File

@@ -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 )

View File

@@ -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

View File

@@ -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;
}

View File

@@ -31,6 +31,7 @@
*TimeZone*Make*;
*wxBitmapButton*OnFocusChange*;
*wxDocManager*MakeNewDocumentName*;
*wxEventLoopGuarantor*;
*wxGridBagSizer*AdjustForOverflow*;
*wxRemotelyScrolledTreeCtrl*DoCalcScrolledPosition*;
*wxRemotelyScrolledTreeCtrl*SetScrollbar*;