]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/evtloop.cpp
streamlining OSX event support first step, see #11805, see #11797
[wxWidgets.git] / src / osx / carbon / evtloop.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/log.h"
32 #endif // WX_PRECOMP
33
34 #include "wx/osx/private.h"
35
36 // ============================================================================
37 // wxEventLoop implementation
38 // ============================================================================
39
40 wxGUIEventLoop::wxGUIEventLoop()
41 {
42 }
43
44 static void DispatchAndReleaseEvent(EventRef theEvent)
45 {
46 if ( wxTheApp )
47 wxTheApp->MacSetCurrentEvent( theEvent, NULL );
48
49 OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget());
50 if (status == eventNotHandledErr && wxTheApp)
51 wxTheApp->MacHandleUnhandledEvent(theEvent);
52
53 ReleaseEvent( theEvent );
54 }
55
56 int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
57 {
58 EventRef event;
59 OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event);
60 switch ( status )
61 {
62 default:
63 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
64 // fall through
65
66 case eventLoopTimedOutErr:
67 return -1;
68
69 case eventLoopQuitErr:
70 // according to QA1061 this may also occur
71 // when a WakeUp Process is executed
72 return 0;
73
74 case noErr:
75 DispatchAndReleaseEvent(event);
76 return 1;
77 }
78 }