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"
32 #include "wx/nonownedwnd.h"
35 #include "wx/osx/private.h"
37 // ============================================================================
38 // wxEventLoop implementation
39 // ============================================================================
41 wxGUIEventLoop::wxGUIEventLoop()
45 static void DispatchAndReleaseEvent(EventRef theEvent
)
48 wxTheApp
->MacSetCurrentEvent( theEvent
, NULL
);
50 OSStatus status
= SendEventToEventTarget(theEvent
, GetEventDispatcherTarget());
51 if (status
== eventNotHandledErr
&& wxTheApp
)
52 wxTheApp
->MacHandleUnhandledEvent(theEvent
);
54 ReleaseEvent( theEvent
);
57 int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout
)
59 wxMacAutoreleasePool autoreleasepool
;
62 OSStatus status
= ReceiveNextEvent(0, NULL
, timeout
/1000, true, &event
);
66 wxFAIL_MSG( "unexpected ReceiveNextEvent() error" );
69 case eventLoopTimedOutErr
:
72 case eventLoopQuitErr
:
73 // according to QA1061 this may also occur
74 // when a WakeUp Process is executed
78 DispatchAndReleaseEvent(event
);
83 void wxGUIEventLoop::DoRun()
85 wxMacAutoreleasePool autoreleasepool
;
86 RunApplicationEventLoop();
89 void wxGUIEventLoop::DoStop()
91 QuitApplicationEventLoop();
94 void wxModalEventLoop::DoRun()
96 wxMacAutoreleasePool autoreleasepool
;
97 WindowRef windowRef
= m_modalWindow
->GetWXWindow();
99 WindowGroupRef windowGroup
= NULL
;
100 WindowGroupRef formerParentGroup
= NULL
;
101 bool resetGroupParent
= false;
103 // make sure modal dialogs are in the right layer so that they are not covered
105 if ( m_modalWindow
->GetParent() == NULL
)
107 windowGroup
= GetWindowGroup(windowRef
) ;
108 if ( windowGroup
!= GetWindowGroupOfClass( kMovableModalWindowClass
) )
110 formerParentGroup
= GetWindowGroupParent( windowGroup
);
111 SetWindowGroupParent( windowGroup
, GetWindowGroupOfClass( kMovableModalWindowClass
) );
112 resetGroupParent
= true;
116 m_modalWindow
->SetFocus();
118 RunAppModalLoopForWindow(windowRef
);
120 if ( resetGroupParent
)
122 SetWindowGroupParent( windowGroup
, formerParentGroup
);
127 void wxModalEventLoop::DoStop()
129 wxMacAutoreleasePool autoreleasepool
;
130 WindowRef theWindow
= m_modalWindow
->GetWXWindow();
131 QuitAppModalLoopForWindow(theWindow
);