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