1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/evtloop.cpp
3 // Purpose: implementation of wxEventLoop for wxMac
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/evtloop.h"
35 #include "wx/nonownedwnd.h"
38 #include "wx/osx/private.h"
40 // ============================================================================
41 // wxEventLoop implementation
42 // ============================================================================
44 wxGUIEventLoop::wxGUIEventLoop()
48 static void DispatchAndReleaseEvent(EventRef theEvent
)
51 wxTheApp
->MacSetCurrentEvent( theEvent
, NULL
);
53 OSStatus status
= SendEventToEventTarget(theEvent
, GetEventDispatcherTarget());
54 if (status
== eventNotHandledErr
&& wxTheApp
)
55 wxTheApp
->MacHandleUnhandledEvent(theEvent
);
57 ReleaseEvent( theEvent
);
60 int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout
)
62 wxMacAutoreleasePool autoreleasepool
;
65 OSStatus status
= ReceiveNextEvent(0, NULL
, timeout
/1000, true, &event
);
69 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
72 case eventLoopTimedOutErr
:
75 case eventLoopQuitErr
:
76 // according to QA1061 this may also occur
77 // when a WakeUp Process is executed
81 DispatchAndReleaseEvent(event
);
86 void wxGUIEventLoop::DoRun()
88 wxMacAutoreleasePool autoreleasepool
;
89 RunApplicationEventLoop();
92 void wxGUIEventLoop::DoStop()
94 QuitApplicationEventLoop();
97 wxModalEventLoop::wxModalEventLoop(wxWindow
*winModal
)
99 m_modalWindow
= dynamic_cast<wxNonOwnedWindow
*> (winModal
);
100 wxASSERT_MSG( m_modalWindow
!= NULL
, "must pass in a toplevel window for modal event loop" );
103 void wxModalEventLoop::DoRun()
105 wxMacAutoreleasePool autoreleasepool
;
106 WindowRef windowRef
= m_modalWindow
->GetWXWindow();
108 WindowGroupRef windowGroup
= NULL
;
109 WindowGroupRef formerParentGroup
= NULL
;
110 bool resetGroupParent
= false;
112 // make sure modal dialogs are in the right layer so that they are not covered
114 if ( m_modalWindow
->GetParent() == NULL
)
116 windowGroup
= GetWindowGroup(windowRef
) ;
117 if ( windowGroup
!= GetWindowGroupOfClass( kMovableModalWindowClass
) )
119 formerParentGroup
= GetWindowGroupParent( windowGroup
);
120 SetWindowGroupParent( windowGroup
, GetWindowGroupOfClass( kMovableModalWindowClass
) );
121 resetGroupParent
= true;
125 m_modalWindow
->SetFocus();
127 RunAppModalLoopForWindow(windowRef
);
129 if ( resetGroupParent
)
131 SetWindowGroupParent( windowGroup
, formerParentGroup
);
136 void wxModalEventLoop::DoStop()
138 wxMacAutoreleasePool autoreleasepool
;
139 WindowRef theWindow
= m_modalWindow
->GetWXWindow();
140 QuitAppModalLoopForWindow(theWindow
);