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"
34 #include "wx/osx/private.h"
36 // ============================================================================
37 // wxEventLoop implementation
38 // ============================================================================
40 wxGUIEventLoop::wxGUIEventLoop()
44 static void DispatchAndReleaseEvent(EventRef theEvent
)
47 wxTheApp
->MacSetCurrentEvent( theEvent
, NULL
);
49 OSStatus status
= SendEventToEventTarget(theEvent
, GetEventDispatcherTarget());
50 if (status
== eventNotHandledErr
&& wxTheApp
)
51 wxTheApp
->MacHandleUnhandledEvent(theEvent
);
53 ReleaseEvent( theEvent
);
56 int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout
)
58 wxMacAutoreleasePool autoreleasepool
;
61 OSStatus status
= ReceiveNextEvent(0, NULL
, timeout
/1000, true, &event
);
65 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
68 case eventLoopTimedOutErr
:
71 case eventLoopQuitErr
:
72 // according to QA1061 this may also occur
73 // when a WakeUp Process is executed
77 DispatchAndReleaseEvent(event
);
82 void wxGUIEventLoop::DoRun()
84 wxMacAutoreleasePool autoreleasepool
;
85 RunApplicationEventLoop();
88 void wxGUIEventLoop::DoStop()
90 QuitApplicationEventLoop();
93 void wxModalEventLoop::DoRun()
95 wxMacAutoreleasePool autoreleasepool
;
96 WindowRef windowRef
= m_modalWindow
->GetWXWindow();
98 WindowGroupRef windowGroup
= NULL
;
99 WindowGroupRef formerParentGroup
= NULL
;
100 bool resetGroupParent
= false;
102 // make sure modal dialogs are in the right layer so that they are not covered
104 if ( m_modalWindow
->GetParent() == NULL
)
106 windowGroup
= GetWindowGroup(windowRef
) ;
107 if ( windowGroup
!= GetWindowGroupOfClass( kMovableModalWindowClass
) )
109 formerParentGroup
= GetWindowGroupParent( windowGroup
);
110 SetWindowGroupParent( windowGroup
, GetWindowGroupOfClass( kMovableModalWindowClass
) );
111 resetGroupParent
= true;
115 m_modalWindow
->SetFocus();
117 RunAppModalLoopForWindow(windowRef
);
119 if ( resetGroupParent
)
121 SetWindowGroupParent( windowGroup
, formerParentGroup
);
126 void wxModalEventLoop::DoStop()
128 wxMacAutoreleasePool autoreleasepool
;
129 WindowRef theWindow
= m_modalWindow
->GetWXWindow();
130 QuitAppModalLoopForWindow(theWindow
);