implementation headers go first to catch this kind of problem, don't move them to fix a build error git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58951 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
112 lines
2.9 KiB
Plaintext
112 lines
2.9 KiB
Plaintext
///////////////////////////////////////////////////////////////////////////////
|
|
// 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
|
|
{
|
|
wxMacAutoreleasePool autoreleasepool;
|
|
// 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;
|
|
}
|
|
|
|
int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
|
|
{
|
|
wxMacAutoreleasePool autoreleasepool;
|
|
|
|
NSEvent *event = [NSApp
|
|
nextEventMatchingMask:NSAnyEventMask
|
|
untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000]
|
|
inMode:NSDefaultRunLoopMode
|
|
dequeue: YES];
|
|
if ( !event )
|
|
return -1;
|
|
|
|
[NSApp sendEvent: event];
|
|
|
|
return true;
|
|
}
|