osx-cocoa event loop
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55166 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
93
src/osx/cocoa/evtloop.mm
Normal file
93
src/osx/cocoa/evtloop.mm
Normal file
@@ -0,0 +1,93 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/osx/cocoa/evtloop.mm
|
||||
// Purpose: implementation of wxEventLoop for OS X
|
||||
// Author: Vadim Zeitlin, Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 2006-01-12
|
||||
// RCS-ID: $Id: evtloop.cpp 54845 2008-07-30 14:52:41Z SC $
|
||||
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// for compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/evtloop.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/osx/private.h"
|
||||
|
||||
// ============================================================================
|
||||
// wxEventLoop implementation
|
||||
// ============================================================================
|
||||
|
||||
wxGUIEventLoop::wxGUIEventLoop()
|
||||
{
|
||||
m_sleepTime = 0.0;
|
||||
}
|
||||
|
||||
void wxGUIEventLoop::WakeUp()
|
||||
{
|
||||
extern void wxMacWakeUp();
|
||||
|
||||
wxMacWakeUp();
|
||||
}
|
||||
|
||||
bool wxGUIEventLoop::Pending() const
|
||||
{
|
||||
// a pointer to the event is returned if there is one, or nil if not
|
||||
return [[NSApplication sharedApplication]
|
||||
nextEventMatchingMask: NSAnyEventMask
|
||||
untilDate: nil
|
||||
inMode: NSDefaultRunLoopMode
|
||||
dequeue: NO];
|
||||
}
|
||||
|
||||
bool wxGUIEventLoop::Dispatch()
|
||||
{
|
||||
if ( !wxTheApp )
|
||||
return false;
|
||||
|
||||
wxMacAutoreleasePool autoreleasepool;
|
||||
|
||||
if(NSEvent *event = [NSApp
|
||||
nextEventMatchingMask:NSAnyEventMask
|
||||
untilDate:[NSDate dateWithTimeIntervalSinceNow: m_sleepTime]
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue: YES])
|
||||
{
|
||||
m_sleepTime = 0.0;
|
||||
[NSApp sendEvent: event];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( wxTheApp->ProcessIdle() )
|
||||
m_sleepTime = 0.0 ;
|
||||
else
|
||||
{
|
||||
m_sleepTime = 1.0;
|
||||
#if wxUSE_THREADS
|
||||
wxMutexGuiLeave();
|
||||
wxMilliSleep(20);
|
||||
wxMutexGuiEnter();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user