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:
Stefan Csomor
2008-08-22 06:47:58 +00:00
parent 45c6df33ec
commit b503b036c1

93
src/osx/cocoa/evtloop.mm Normal file
View 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;
}