]>
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" |
bf06fbce | 32 | #include "wx/nonownedwnd.h" |
489468fe SC |
33 | #endif // WX_PRECOMP |
34 | ||
524c47aa SC |
35 | #include "wx/osx/private.h" |
36 | ||
489468fe SC |
37 | // ============================================================================ |
38 | // wxEventLoop implementation | |
39 | // ============================================================================ | |
40 | ||
524c47aa | 41 | wxGUIEventLoop::wxGUIEventLoop() |
489468fe | 42 | { |
489468fe SC |
43 | } |
44 | ||
0056673c | 45 | static void DispatchAndReleaseEvent(EventRef theEvent) |
9af42efd VZ |
46 | { |
47 | if ( wxTheApp ) | |
48 | wxTheApp->MacSetCurrentEvent( theEvent, NULL ); | |
49 | ||
50 | OSStatus status = SendEventToEventTarget(theEvent, GetEventDispatcherTarget()); | |
51 | if (status == eventNotHandledErr && wxTheApp) | |
52 | wxTheApp->MacHandleUnhandledEvent(theEvent); | |
53 | ||
54 | ReleaseEvent( theEvent ); | |
55 | } | |
56 | ||
0056673c | 57 | int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout) |
9af42efd | 58 | { |
80eee837 SC |
59 | wxMacAutoreleasePool autoreleasepool; |
60 | ||
9af42efd VZ |
61 | EventRef event; |
62 | OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event); | |
63 | switch ( status ) | |
64 | { | |
65 | default: | |
66 | wxFAIL_MSG( "unexpected ReceiveNextEvent() error" ); | |
67 | // fall through | |
68 | ||
69 | case eventLoopTimedOutErr: | |
70 | return -1; | |
71 | ||
72 | case eventLoopQuitErr: | |
0056673c SC |
73 | // according to QA1061 this may also occur |
74 | // when a WakeUp Process is executed | |
9af42efd VZ |
75 | return 0; |
76 | ||
77 | case noErr: | |
78 | DispatchAndReleaseEvent(event); | |
79 | return 1; | |
80 | } | |
81 | } | |
80eee837 SC |
82 | |
83 | void wxGUIEventLoop::DoRun() | |
84 | { | |
85 | wxMacAutoreleasePool autoreleasepool; | |
86 | RunApplicationEventLoop(); | |
87 | } | |
88 | ||
89 | void wxGUIEventLoop::DoStop() | |
90 | { | |
91 | QuitApplicationEventLoop(); | |
92 | } | |
93 | ||
94 | void wxModalEventLoop::DoRun() | |
95 | { | |
96 | wxMacAutoreleasePool autoreleasepool; | |
97 | WindowRef windowRef = m_modalWindow->GetWXWindow(); | |
98 | ||
99 | WindowGroupRef windowGroup = NULL; | |
100 | WindowGroupRef formerParentGroup = NULL; | |
101 | bool resetGroupParent = false; | |
102 | ||
103 | // make sure modal dialogs are in the right layer so that they are not covered | |
104 | ||
105 | if ( m_modalWindow->GetParent() == NULL ) | |
106 | { | |
107 | windowGroup = GetWindowGroup(windowRef) ; | |
108 | if ( windowGroup != GetWindowGroupOfClass( kMovableModalWindowClass ) ) | |
109 | { | |
110 | formerParentGroup = GetWindowGroupParent( windowGroup ); | |
111 | SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) ); | |
112 | resetGroupParent = true; | |
113 | } | |
114 | } | |
115 | ||
116 | m_modalWindow->SetFocus(); | |
117 | ||
118 | RunAppModalLoopForWindow(windowRef); | |
119 | ||
120 | if ( resetGroupParent ) | |
121 | { | |
122 | SetWindowGroupParent( windowGroup , formerParentGroup ); | |
123 | } | |
124 | ||
125 | } | |
126 | ||
127 | void wxModalEventLoop::DoStop() | |
128 | { | |
129 | wxMacAutoreleasePool autoreleasepool; | |
130 | WindowRef theWindow = m_modalWindow->GetWXWindow(); | |
131 | QuitAppModalLoopForWindow(theWindow); | |
132 | } | |
133 | ||
134 |