]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/evtloop.cpp
In wxPropertyGrid::HandleCustomEditorEvent(), ignore events coming from a label editor
[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 #include "wx/nonownedwnd.h"
33 #endif // WX_PRECOMP
34
35 #include "wx/osx/private.h"
36
37 // ============================================================================
38 // wxEventLoop implementation
39 // ============================================================================
40
41 wxGUIEventLoop::wxGUIEventLoop()
42 {
43 }
44
45 static void DispatchAndReleaseEvent(EventRef theEvent)
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
57 int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
58 {
59 wxMacAutoreleasePool autoreleasepool;
60
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:
73 // according to QA1061 this may also occur
74 // when a WakeUp Process is executed
75 return 0;
76
77 case noErr:
78 DispatchAndReleaseEvent(event);
79 return 1;
80 }
81 }
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