]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/evtloop.cpp
Added ability to switch off more components of the size page UI
[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 #if wxUSE_GUI
35 #include "wx/nonownedwnd.h"
36 #endif
37
38 #include "wx/osx/private.h"
39
40 // ============================================================================
41 // wxEventLoop implementation
42 // ============================================================================
43
44 wxGUIEventLoop::wxGUIEventLoop()
45 {
46 }
47
48 static void DispatchAndReleaseEvent(EventRef theEvent)
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
60 int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
61 {
62 wxMacAutoreleasePool autoreleasepool;
63
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:
76 // according to QA1061 this may also occur
77 // when a WakeUp Process is executed
78 return 0;
79
80 case noErr:
81 DispatchAndReleaseEvent(event);
82 return 1;
83 }
84 }
85
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
96 void wxGUIEventLoop::DoRun()
97 {
98 wxMacAutoreleasePool autoreleasepool;
99 RunApplicationEventLoop();
100 }
101
102 void wxGUIEventLoop::DoStop()
103 {
104 QuitApplicationEventLoop();
105 }
106
107 CFRunLoopRef wxGUIEventLoop::CFGetCurrentRunLoop() const
108 {
109 return wxCFEventLoop::CFGetCurrentRunLoop();
110 }
111
112 // TODO move into a evtloop_osx.cpp
113
114 wxModalEventLoop::wxModalEventLoop(wxWindow *modalWindow)
115 {
116 m_modalWindow = wxDynamicCast(modalWindow, wxNonOwnedWindow);
117 wxASSERT_MSG( m_modalWindow != NULL, "must pass in a toplevel window for modal event loop" );
118 m_modalNativeWindow = m_modalWindow->GetWXWindow();
119 }
120
121 wxModalEventLoop::wxModalEventLoop(WXWindow modalNativeWindow)
122 {
123 m_modalWindow = NULL;
124 wxASSERT_MSG( modalNativeWindow != NULL, "must pass in a toplevel window for modal event loop" );
125 m_modalNativeWindow = modalNativeWindow;
126 }
127
128 // END move into a evtloop_osx.cpp
129
130 void wxModalEventLoop::DoRun()
131 {
132 wxWindowDisabler disabler(m_modalWindow);
133 wxMacAutoreleasePool autoreleasepool;
134
135 bool resetGroupParent = false;
136
137 WindowGroupRef windowGroup = NULL;
138 WindowGroupRef formerParentGroup = NULL;
139
140 // make sure modal dialogs are in the right layer so that they are not covered
141 if ( m_modalWindow != NULL )
142 {
143 if ( m_modalWindow->GetParent() == NULL )
144 {
145 windowGroup = GetWindowGroup(m_modalNativeWindow) ;
146 if ( windowGroup != GetWindowGroupOfClass( kMovableModalWindowClass ) )
147 {
148 formerParentGroup = GetWindowGroupParent( windowGroup );
149 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
150 resetGroupParent = true;
151 }
152 }
153 }
154
155 m_modalWindow->SetFocus();
156
157 RunAppModalLoopForWindow(m_modalNativeWindow);
158
159 if ( resetGroupParent )
160 {
161 SetWindowGroupParent( windowGroup , formerParentGroup );
162 }
163
164 }
165
166 void wxModalEventLoop::DoStop()
167 {
168 wxMacAutoreleasePool autoreleasepool;
169 QuitAppModalLoopForWindow(m_modalNativeWindow);
170 }
171
172