]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/evtloop.cpp
minor fixes; replace references to Windows95 with references to wxMSW where possible
[wxWidgets.git] / src / osx / carbon / evtloop.cpp
CommitLineData
489468fe 1///////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/evtloop.cpp
489468fe
SC
3// Purpose: implementation of wxEventLoop for wxMac
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 2006-01-12
7// RCS-ID: $Id$
8// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#include "wx/evtloop.h"
28
29#ifndef WX_PRECOMP
30 #include "wx/app.h"
31#endif // WX_PRECOMP
32
524c47aa
SC
33#include "wx/osx/private.h"
34
489468fe
SC
35// ============================================================================
36// wxEventLoop implementation
37// ============================================================================
38
524c47aa 39wxGUIEventLoop::wxGUIEventLoop()
489468fe 40{
524c47aa 41 m_sleepTime = kEventDurationNoWait;
489468fe
SC
42}
43
489468fe
SC
44void wxGUIEventLoop::WakeUp()
45{
46 extern void wxMacWakeUp();
47
48 wxMacWakeUp();
49}
50
489468fe
SC
51bool wxGUIEventLoop::Pending() const
52{
53 EventRef theEvent;
54
55 return ReceiveNextEvent
56 (
57 0, // we want any event at all so we don't specify neither
58 NULL, // the number of event types nor the types themselves
59 kEventDurationNoWait,
60 false, // don't remove the event from queue
61 &theEvent
62 ) == noErr;
63}
64
65bool wxGUIEventLoop::Dispatch()
66{
489468fe
SC
67 if ( !wxTheApp )
68 return false;
69
524c47aa
SC
70 wxMacAutoreleasePool autoreleasepool;
71
72 EventRef theEvent;
73
74 OSStatus status = ReceiveNextEvent(0, NULL, m_sleepTime, true, &theEvent) ;
75
76 switch (status)
77 {
78 case eventLoopTimedOutErr :
79 if ( wxTheApp->ProcessIdle() )
80 m_sleepTime = kEventDurationNoWait ;
81 else
82 {
83 m_sleepTime = kEventDurationSecond;
84#if wxUSE_THREADS
85 wxMutexGuiLeave();
86 wxMilliSleep(20);
87 wxMutexGuiEnter();
b2680ced 88#endif
524c47aa
SC
89 }
90 break;
91
92 case eventLoopQuitErr :
93 // according to QA1061 this may also occur
94 // when a WakeUp Process is executed
95 break;
96
97 default:
98 if ( wxTheApp )
99 wxTheApp->MacSetCurrentEvent( theEvent, NULL );
100
101 OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget());
102 if (status == eventNotHandledErr && wxTheApp)
103 wxTheApp->MacHandleUnhandledEvent(theEvent);
104
105 ReleaseEvent( theEvent );
106 m_sleepTime = kEventDurationNoWait ;
107 break;
108 }
109
489468fe
SC
110 return true;
111}