]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/evtloop.cpp
streamlining OSX event support third step, using platform specific native run methods...
[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 wxMacAutoreleasePool autoreleasepool;
59
60 EventRef event;
61 OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event);
62 switch ( status )
63 {
64 default:
65 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
66 // fall through
67
68 case eventLoopTimedOutErr:
69 return -1;
70
71 case eventLoopQuitErr:
72 // according to QA1061 this may also occur
73 // when a WakeUp Process is executed
74 return 0;
75
76 case noErr:
77 DispatchAndReleaseEvent(event);
78 return 1;
79 }
80 }
81
82 void wxGUIEventLoop::DoRun()
83 {
84 wxMacAutoreleasePool autoreleasepool;
85 RunApplicationEventLoop();
86 }
87
88 void wxGUIEventLoop::DoStop()
89 {
90 QuitApplicationEventLoop();
91 }
92
93 void wxModalEventLoop::DoRun()
94 {
95 wxMacAutoreleasePool autoreleasepool;
96 WindowRef windowRef = m_modalWindow->GetWXWindow();
97
98 WindowGroupRef windowGroup = NULL;
99 WindowGroupRef formerParentGroup = NULL;
100 bool resetGroupParent = false;
101
102 // make sure modal dialogs are in the right layer so that they are not covered
103
104 if ( m_modalWindow->GetParent() == NULL )
105 {
106 windowGroup = GetWindowGroup(windowRef) ;
107 if ( windowGroup != GetWindowGroupOfClass( kMovableModalWindowClass ) )
108 {
109 formerParentGroup = GetWindowGroupParent( windowGroup );
110 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
111 resetGroupParent = true;
112 }
113 }
114
115 m_modalWindow->SetFocus();
116
117 RunAppModalLoopForWindow(windowRef);
118
119 if ( resetGroupParent )
120 {
121 SetWindowGroupParent( windowGroup , formerParentGroup );
122 }
123
124 }
125
126 void wxModalEventLoop::DoStop()
127 {
128 wxMacAutoreleasePool autoreleasepool;
129 WindowRef theWindow = m_modalWindow->GetWXWindow();
130 QuitAppModalLoopForWindow(theWindow);
131 }
132
133