separating observers for default mode (outer 'normal' loop) and common mode loops, fixes #13208

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67724 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2011-05-11 06:46:07 +00:00
parent 76ba33d39a
commit 3cac36541b
2 changed files with 47 additions and 17 deletions

View File

@ -53,9 +53,14 @@ public:
AddSourceForFD(int fd, wxEventLoopSourceHandler *handler, int flags);
#endif // wxUSE_EVENTLOOP_SOURCE
void ObserverCallBack(CFRunLoopObserverRef observer, int activity);
protected:
void CommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
void DefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
static void OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info);
static void OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info);
// get the currently executing CFRunLoop
virtual CFRunLoopRef CFGetCurrentRunLoop() const;
@ -74,8 +79,11 @@ protected:
// cfrunloop
CFRunLoopRef m_runLoop;
// runloop observer
CFRunLoopObserverRef m_runLoopObserver;
// common modes runloop observer
CFRunLoopObserverRef m_commonModeRunLoopObserver;
// default mode runloop observer
CFRunLoopObserverRef m_defaultModeRunLoopObserver;
private:
// process all already pending events and dispatch a new one (blocking

View File

@ -147,14 +147,21 @@ wxCFEventLoop::AddSourceForFD(int WXUNUSED(fd),
#endif // wxUSE_EVENTLOOP_SOURCE
extern "C" void wxObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info)
void wxCFEventLoop::OSXCommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info)
{
wxCFEventLoop * eventloop = static_cast<wxCFEventLoop *>(info);
if ( eventloop )
eventloop->ObserverCallBack(observer, activity);
eventloop->CommonModeObserverCallBack(observer, activity);
}
void wxCFEventLoop::ObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), int activity)
void wxCFEventLoop::OSXDefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity, void *info)
{
wxCFEventLoop * eventloop = static_cast<wxCFEventLoop *>(info);
if ( eventloop )
eventloop->DefaultModeObserverCallBack(observer, activity);
}
void wxCFEventLoop::CommonModeObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), int activity)
{
if ( activity & kCFRunLoopBeforeTimers )
{
@ -170,21 +177,30 @@ void wxCFEventLoop::ObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), in
wxTheApp->ProcessPendingEvents();
}
if ( activity & kCFRunLoopBeforeWaiting )
{
#if wxUSE_THREADS
wxMutexGuiLeaveOrEnter();
#endif
}
}
void wxCFEventLoop::DefaultModeObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), int activity)
{
if ( activity & kCFRunLoopBeforeTimers )
{
}
if ( activity & kCFRunLoopBeforeWaiting )
{
if ( ProcessIdle() )
{
WakeUp();
}
else
{
#if wxUSE_THREADS
wxMutexGuiLeaveOrEnter();
#endif
}
}
}
wxCFEventLoop::wxCFEventLoop()
{
m_shouldExit = false;
@ -194,15 +210,21 @@ wxCFEventLoop::wxCFEventLoop()
CFRunLoopObserverContext ctxt;
bzero( &ctxt, sizeof(ctxt) );
ctxt.info = this;
m_runLoopObserver = CFRunLoopObserverCreate( kCFAllocatorDefault, kCFRunLoopBeforeTimers | kCFRunLoopBeforeWaiting , true /* repeats */, 0,
wxObserverCallBack, &ctxt );
CFRunLoopAddObserver(m_runLoop, m_runLoopObserver, kCFRunLoopCommonModes);
CFRelease(m_runLoopObserver);
m_commonModeRunLoopObserver = CFRunLoopObserverCreate( kCFAllocatorDefault, kCFRunLoopBeforeTimers | kCFRunLoopBeforeWaiting , true /* repeats */, 0,
(CFRunLoopObserverCallBack) wxCFEventLoop::OSXCommonModeObserverCallBack, &ctxt );
CFRunLoopAddObserver(m_runLoop, m_commonModeRunLoopObserver, kCFRunLoopCommonModes);
CFRelease(m_commonModeRunLoopObserver);
m_defaultModeRunLoopObserver = CFRunLoopObserverCreate( kCFAllocatorDefault, kCFRunLoopBeforeTimers | kCFRunLoopBeforeWaiting , true /* repeats */, 0,
(CFRunLoopObserverCallBack) wxCFEventLoop::OSXDefaultModeObserverCallBack, &ctxt );
CFRunLoopAddObserver(m_runLoop, m_defaultModeRunLoopObserver, kCFRunLoopDefaultMode);
CFRelease(m_defaultModeRunLoopObserver);
}
wxCFEventLoop::~wxCFEventLoop()
{
CFRunLoopRemoveObserver(m_runLoop, m_runLoopObserver, kCFRunLoopCommonModes);
CFRunLoopRemoveObserver(m_runLoop, m_commonModeRunLoopObserver, kCFRunLoopCommonModes);
CFRunLoopRemoveObserver(m_runLoop, m_defaultModeRunLoopObserver, kCFRunLoopDefaultMode);
}