wxApp::DoYield => wxGUIEventLoop::YieldFor (part of r58911)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58923 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -294,75 +294,6 @@ void wxApp::Exit()
|
|||||||
wxAppConsole::Exit();
|
wxAppConsole::Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yield to other processes
|
|
||||||
bool wxApp::DoYield(bool onlyIfNeeded, long eventsToProcess)
|
|
||||||
{
|
|
||||||
#if wxUSE_LOG
|
|
||||||
// disable log flushing from here because a call to wxYield() shouldn't
|
|
||||||
// normally result in message boxes popping up &c
|
|
||||||
wxLog::Suspend();
|
|
||||||
#endif // wxUSE_LOG
|
|
||||||
|
|
||||||
if (m_isInsideYield)
|
|
||||||
{
|
|
||||||
if ( !onlyIfNeeded )
|
|
||||||
{
|
|
||||||
wxFAIL_MSG( wxT("wxYield called recursively" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_isInsideYield = true;
|
|
||||||
m_eventsToProcessInsideYield = eventsToProcess;
|
|
||||||
|
|
||||||
// Run the event loop until it is out of events
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
// TODO: implement event filtering using the eventsToProcess mask
|
|
||||||
|
|
||||||
wxAutoNSAutoreleasePool pool;
|
|
||||||
/* NOTE: It may be better to use something like
|
|
||||||
NSEventTrackingRunLoopMode since we don't necessarily want all
|
|
||||||
timers/sources/observers to run, only those which would
|
|
||||||
run while tracking events. However, it should be noted that
|
|
||||||
NSEventTrackingRunLoopMode is in the common set of modes
|
|
||||||
so it may not effectively make much of a difference.
|
|
||||||
*/
|
|
||||||
NSEvent *event = [GetNSApplication()
|
|
||||||
nextEventMatchingMask:NSAnyEventMask
|
|
||||||
untilDate:[NSDate distantPast]
|
|
||||||
inMode:NSDefaultRunLoopMode
|
|
||||||
dequeue: YES];
|
|
||||||
if(!event)
|
|
||||||
break;
|
|
||||||
[GetNSApplication() sendEvent: event];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Because we just told NSApplication to avoid blocking it will in turn
|
|
||||||
run the CFRunLoop with a timeout of 0 seconds. In that case, our
|
|
||||||
run loop observer on kCFRunLoopBeforeWaiting never fires because
|
|
||||||
no waiting occurs. Therefore, no idle events are sent.
|
|
||||||
|
|
||||||
Believe it or not, this is actually desirable because we do not want
|
|
||||||
to process idle from here. However, we do want to process pending
|
|
||||||
events because some user code expects to do work in a thread while
|
|
||||||
the main thread waits and then notify the main thread by posting
|
|
||||||
an event.
|
|
||||||
*/
|
|
||||||
ProcessPendingEvents();
|
|
||||||
|
|
||||||
#if wxUSE_LOG
|
|
||||||
// let the logs be flashed again
|
|
||||||
wxLog::Resume();
|
|
||||||
#endif // wxUSE_LOG
|
|
||||||
|
|
||||||
m_isInsideYield = false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxApp::WakeUpIdle()
|
void wxApp::WakeUpIdle()
|
||||||
{
|
{
|
||||||
/* When called from the main thread the NSAutoreleasePool managed by
|
/* When called from the main thread the NSAutoreleasePool managed by
|
||||||
|
@@ -117,3 +117,60 @@ int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxGUIEventLoop::YieldFor(long eventsToProcess)
|
||||||
|
{
|
||||||
|
#if wxUSE_LOG
|
||||||
|
// disable log flushing from here because a call to wxYield() shouldn't
|
||||||
|
// normally result in message boxes popping up &c
|
||||||
|
wxLog::Suspend();
|
||||||
|
#endif // wxUSE_LOG
|
||||||
|
|
||||||
|
m_isInsideYield = true;
|
||||||
|
m_eventsToProcessInsideYield = eventsToProcess;
|
||||||
|
|
||||||
|
// Run the event loop until it is out of events
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
// TODO: implement event filtering using the eventsToProcess mask
|
||||||
|
|
||||||
|
wxAutoNSAutoreleasePool pool;
|
||||||
|
/* NOTE: It may be better to use something like
|
||||||
|
NSEventTrackingRunLoopMode since we don't necessarily want all
|
||||||
|
timers/sources/observers to run, only those which would
|
||||||
|
run while tracking events. However, it should be noted that
|
||||||
|
NSEventTrackingRunLoopMode is in the common set of modes
|
||||||
|
so it may not effectively make much of a difference.
|
||||||
|
*/
|
||||||
|
NSEvent *event = [GetNSApplication()
|
||||||
|
nextEventMatchingMask:NSAnyEventMask
|
||||||
|
untilDate:[NSDate distantPast]
|
||||||
|
inMode:NSDefaultRunLoopMode
|
||||||
|
dequeue: YES];
|
||||||
|
if(!event)
|
||||||
|
break;
|
||||||
|
[GetNSApplication() sendEvent: event];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Because we just told NSApplication to avoid blocking it will in turn
|
||||||
|
run the CFRunLoop with a timeout of 0 seconds. In that case, our
|
||||||
|
run loop observer on kCFRunLoopBeforeWaiting never fires because
|
||||||
|
no waiting occurs. Therefore, no idle events are sent.
|
||||||
|
|
||||||
|
Believe it or not, this is actually desirable because we do not want
|
||||||
|
to process idle from here. However, we do want to process pending
|
||||||
|
events because some user code expects to do work in a thread while
|
||||||
|
the main thread waits and then notify the main thread by posting
|
||||||
|
an event.
|
||||||
|
*/
|
||||||
|
ProcessPendingEvents();
|
||||||
|
|
||||||
|
#if wxUSE_LOG
|
||||||
|
// let the logs be flashed again
|
||||||
|
wxLog::Resume();
|
||||||
|
#endif // wxUSE_LOG
|
||||||
|
|
||||||
|
m_isInsideYield = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@@ -1117,60 +1117,6 @@ void wxCYield()
|
|||||||
wxYield() ;
|
wxYield() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yield to other processes
|
|
||||||
|
|
||||||
bool wxApp::DoYield(bool onlyIfNeeded, long eventsToProcess)
|
|
||||||
{
|
|
||||||
#if wxUSE_THREADS
|
|
||||||
// Yielding from a non-gui thread needs to bail out, otherwise we end up
|
|
||||||
// possibly sending events in the thread too.
|
|
||||||
if ( !wxThread::IsMain() )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif // wxUSE_THREADS
|
|
||||||
|
|
||||||
if (m_isInsideYield)
|
|
||||||
{
|
|
||||||
if ( !onlyIfNeeded )
|
|
||||||
{
|
|
||||||
wxFAIL_MSG( wxT("wxYield called recursively" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_isInsideYield = true;
|
|
||||||
m_eventsToProcessInsideYield = eventsToProcess;
|
|
||||||
|
|
||||||
#if wxUSE_LOG
|
|
||||||
// disable log flushing from here because a call to wxYield() shouldn't
|
|
||||||
// normally result in message boxes popping up &c
|
|
||||||
wxLog::Suspend();
|
|
||||||
#endif // wxUSE_LOG
|
|
||||||
|
|
||||||
wxEventLoop * const
|
|
||||||
loop = static_cast<wxEventLoop *>(wxEventLoop::GetActive());
|
|
||||||
if ( loop )
|
|
||||||
{
|
|
||||||
// process all pending events:
|
|
||||||
while ( loop->Pending() )
|
|
||||||
loop->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
|
|
||||||
// OnUpdateUI() which is a nice (and desired) side effect)
|
|
||||||
while ( ProcessIdle() ) {}
|
|
||||||
|
|
||||||
#if wxUSE_LOG
|
|
||||||
wxLog::Resume();
|
|
||||||
#endif // wxUSE_LOG
|
|
||||||
m_isInsideYield = false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
void wxApp::MacHandleUnhandledEvent( WXEVENTREF WXUNUSED(evr) )
|
void wxApp::MacHandleUnhandledEvent( WXEVENTREF WXUNUSED(evr) )
|
||||||
{
|
{
|
||||||
|
@@ -137,3 +137,39 @@ int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxGUIEventLoop::YieldFor(long eventsToProcess)
|
||||||
|
{
|
||||||
|
#if wxUSE_THREADS
|
||||||
|
// Yielding from a non-gui thread needs to bail out, otherwise we end up
|
||||||
|
// possibly sending events in the thread too.
|
||||||
|
if ( !wxThread::IsMain() )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif // wxUSE_THREADS
|
||||||
|
|
||||||
|
m_isInsideYield = true;
|
||||||
|
m_eventsToProcessInsideYield = eventsToProcess;
|
||||||
|
|
||||||
|
#if wxUSE_LOG
|
||||||
|
// disable log flushing from here because a call to wxYield() shouldn't
|
||||||
|
// normally result in message boxes popping up &c
|
||||||
|
wxLog::Suspend();
|
||||||
|
#endif // wxUSE_LOG
|
||||||
|
|
||||||
|
// process all pending events:
|
||||||
|
while ( Pending() )
|
||||||
|
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
|
||||||
|
// OnUpdateUI() which is a nice (and desired) side effect)
|
||||||
|
while ( ProcessIdle() ) {}
|
||||||
|
|
||||||
|
#if wxUSE_LOG
|
||||||
|
wxLog::Resume();
|
||||||
|
#endif // wxUSE_LOG
|
||||||
|
m_isInsideYield = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user