]>
Commit | Line | Data |
---|---|---|
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" | |
bcf79477 | 31 | #include "wx/log.h" |
489468fe SC |
32 | #endif // WX_PRECOMP |
33 | ||
2439f1d9 SC |
34 | #if wxUSE_GUI |
35 | #include "wx/nonownedwnd.h" | |
36 | #endif | |
37 | ||
524c47aa SC |
38 | #include "wx/osx/private.h" |
39 | ||
489468fe SC |
40 | // ============================================================================ |
41 | // wxEventLoop implementation | |
42 | // ============================================================================ | |
43 | ||
524c47aa | 44 | wxGUIEventLoop::wxGUIEventLoop() |
489468fe | 45 | { |
489468fe SC |
46 | } |
47 | ||
0056673c | 48 | static void DispatchAndReleaseEvent(EventRef theEvent) |
9af42efd VZ |
49 | { |
50 | if ( wxTheApp ) | |
51 | wxTheApp->MacSetCurrentEvent( theEvent, NULL ); | |
52 | ||
53 | OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget()); | |
54 | if (status == eventNotHandledErr && wxTheApp) | |
55 | wxTheApp->MacHandleUnhandledEvent(theEvent); | |
56 | ||
57 | ReleaseEvent( theEvent ); | |
58 | } | |
59 | ||
0056673c | 60 | int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout) |
9af42efd | 61 | { |
80eee837 | 62 | wxMacAutoreleasePool autoreleasepool; |
ce00f59b | 63 | |
9af42efd VZ |
64 | EventRef event; |
65 | OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event); | |
66 | switch ( status ) | |
67 | { | |
68 | default: | |
69 | wxFAIL_MSG( "unexpected ReceiveNextEvent() error" ); | |
70 | // fall through | |
71 | ||
72 | case eventLoopTimedOutErr: | |
73 | return -1; | |
74 | ||
75 | case eventLoopQuitErr: | |
0056673c SC |
76 | // according to QA1061 this may also occur |
77 | // when a WakeUp Process is executed | |
9af42efd VZ |
78 | return 0; |
79 | ||
80 | case noErr: | |
81 | DispatchAndReleaseEvent(event); | |
82 | return 1; | |
83 | } | |
84 | } | |
80eee837 | 85 | |
3e88d487 SC |
86 | void wxGUIEventLoop::WakeUp() |
87 | { | |
88 | OSStatus err = noErr; | |
89 | wxMacCarbonEvent wakeupEvent; | |
90 | wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), | |
91 | kEventAttributeNone ); | |
92 | err = PostEventToQueue(GetMainEventQueue(), wakeupEvent, | |
93 | kEventPriorityHigh ); | |
94 | } | |
95 | ||
8d40c05f | 96 | void wxGUIEventLoop::OSXDoRun() |
80eee837 SC |
97 | { |
98 | wxMacAutoreleasePool autoreleasepool; | |
d3ad22bd VZ |
99 | |
100 | while (!m_shouldExit) | |
101 | { | |
102 | RunApplicationEventLoop(); | |
103 | } | |
104 | ||
105 | // Force enclosing event loop to temporarily exit and check | |
106 | // if it should be stopped. | |
107 | QuitApplicationEventLoop(); | |
80eee837 SC |
108 | } |
109 | ||
8d40c05f | 110 | void wxGUIEventLoop::OSXDoStop() |
80eee837 SC |
111 | { |
112 | QuitApplicationEventLoop(); | |
113 | } | |
114 | ||
7934e447 SC |
115 | CFRunLoopRef wxGUIEventLoop::CFGetCurrentRunLoop() const |
116 | { | |
117 | return wxCFEventLoop::CFGetCurrentRunLoop(); | |
118 | } | |
119 | ||
cfb0ef70 SC |
120 | // TODO move into a evtloop_osx.cpp |
121 | ||
122 | wxModalEventLoop::wxModalEventLoop(wxWindow *modalWindow) | |
2439f1d9 | 123 | { |
b79aa500 | 124 | m_modalWindow = wxDynamicCast(modalWindow, wxNonOwnedWindow); |
2439f1d9 | 125 | wxASSERT_MSG( m_modalWindow != NULL, "must pass in a toplevel window for modal event loop" ); |
cfb0ef70 | 126 | m_modalNativeWindow = m_modalWindow->GetWXWindow(); |
2439f1d9 SC |
127 | } |
128 | ||
cfb0ef70 SC |
129 | wxModalEventLoop::wxModalEventLoop(WXWindow modalNativeWindow) |
130 | { | |
131 | m_modalWindow = NULL; | |
132 | wxASSERT_MSG( modalNativeWindow != NULL, "must pass in a toplevel window for modal event loop" ); | |
133 | m_modalNativeWindow = modalNativeWindow; | |
134 | } | |
135 | ||
136 | // END move into a evtloop_osx.cpp | |
137 | ||
8d40c05f | 138 | void wxModalEventLoop::OSXDoRun() |
80eee837 | 139 | { |
7934e447 | 140 | wxWindowDisabler disabler(m_modalWindow); |
80eee837 | 141 | wxMacAutoreleasePool autoreleasepool; |
cfb0ef70 SC |
142 | |
143 | bool resetGroupParent = false; | |
80eee837 SC |
144 | |
145 | WindowGroupRef windowGroup = NULL; | |
146 | WindowGroupRef formerParentGroup = NULL; | |
ce00f59b | 147 | |
80eee837 | 148 | // make sure modal dialogs are in the right layer so that they are not covered |
cfb0ef70 | 149 | if ( m_modalWindow != NULL ) |
80eee837 | 150 | { |
cfb0ef70 | 151 | if ( m_modalWindow->GetParent() == NULL ) |
80eee837 | 152 | { |
cfb0ef70 SC |
153 | windowGroup = GetWindowGroup(m_modalNativeWindow) ; |
154 | if ( windowGroup != GetWindowGroupOfClass( kMovableModalWindowClass ) ) | |
155 | { | |
156 | formerParentGroup = GetWindowGroupParent( windowGroup ); | |
157 | SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) ); | |
158 | resetGroupParent = true; | |
159 | } | |
80eee837 SC |
160 | } |
161 | } | |
162 | ||
163 | m_modalWindow->SetFocus(); | |
ce00f59b | 164 | |
cfb0ef70 | 165 | RunAppModalLoopForWindow(m_modalNativeWindow); |
80eee837 SC |
166 | |
167 | if ( resetGroupParent ) | |
168 | { | |
169 | SetWindowGroupParent( windowGroup , formerParentGroup ); | |
170 | } | |
171 | ||
172 | } | |
173 | ||
8d40c05f | 174 | void wxModalEventLoop::OSXDoStop() |
80eee837 SC |
175 | { |
176 | wxMacAutoreleasePool autoreleasepool; | |
cfb0ef70 | 177 | QuitAppModalLoopForWindow(m_modalNativeWindow); |
80eee837 SC |
178 | } |
179 | ||
180 |