]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/evtloop.cpp
cfe38c8b4cb1af15a36b328241cf42f89deed470
[wxWidgets.git] / src / mac / carbon / evtloop.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/carbon/evtloop.cpp
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 #include <Carbon/Carbon.h>
30
31 // ============================================================================
32 // implementation
33 // ============================================================================
34
35 wxEventLoop::wxEventLoop()
36 {
37 m_exitcode = 0;
38 #if !wxMAC_USE_RUN_APP_EVENT_LOOP
39 m_shouldExit = false;
40 #endif
41 }
42
43 int wxEventLoop::Run()
44 {
45 wxEventLoopActivator activate(this);
46
47 #if wxMAC_USE_RUN_APP_EVENT_LOOP
48 RunApplicationEventLoop();
49 #else // manual event loop
50 while ( !m_shouldExit )
51 {
52 Dispatch();
53 }
54 #endif // auto/manual event loop
55
56 return m_exitcode;
57 }
58
59 void wxEventLoop::Exit(int rc)
60 {
61 m_exitcode = rc;
62
63 #if wxMAC_USE_RUN_APP_EVENT_LOOP
64 QuitApplicationEventLoop();
65 #else // manual event loop
66 m_shouldExit = true;
67 #endif // auto/manual event loop
68 }
69
70 bool wxEventLoop::Pending() const
71 {
72 EventRef theEvent;
73
74 return ReceiveNextEvent
75 (
76 0, // we want any event at all so we don't specify neither
77 NULL, // the number of event types nor the types themselves
78 kEventDurationNoWait,
79 false, // don't remove the event from queue
80 &theEvent
81 ) == noErr;
82 }
83
84 bool wxEventLoop::Dispatch()
85 {
86 // TODO: we probably should do the dispatching directly from here but for
87 // now it's easier to forward to wxApp which has all the code to do
88 // it
89 if ( !wxTheApp )
90 return false;
91
92 wxTheApp->MacDoOneEvent();
93 return true;
94 }
95