1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/evtloop.mm
3 // Purpose: implements wxEventLoop for Cocoa
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott <dfe@cox.net>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
17 #include "wx/evtloop.h"
19 #import <AppKit/NSApplication.h>
21 // ========================================================================
23 // ========================================================================
25 class WXDLLEXPORT wxEventLoopImpl
29 wxEventLoopImpl() { SetExitCode(0); }
31 // set/get the exit code
32 void SetExitCode(int exitcode) { m_exitcode = exitcode; }
33 int GetExitCode() const { return m_exitcode; }
36 // the exit code of the event loop
40 // ========================================================================
42 // ========================================================================
44 // ----------------------------------------------------------------------------
45 // wxEventLoop running and exiting
46 // ----------------------------------------------------------------------------
48 wxEventLoop *wxEventLoop::ms_activeLoop = NULL;
50 wxEventLoop::~wxEventLoop()
52 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
55 bool wxEventLoop::IsRunning() const
60 int wxEventLoop::Run()
62 // event loops are not recursive, you need to create another loop!
63 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
65 wxEventLoop *oldLoop = ms_activeLoop;
68 m_impl = new wxEventLoopImpl;
70 [[NSApplication sharedApplication] run];
72 int exitcode = m_impl->GetExitCode();
76 ms_activeLoop = oldLoop;
81 void wxEventLoop::Exit(int rc)
83 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
85 m_impl->SetExitCode(rc);
87 NSApplication *cocoaApp = [NSApplication sharedApplication];
88 wxLogDebug("wxEventLoop::Exit isRunning=%d", (int)[cocoaApp isRunning]);
89 [cocoaApp stop: cocoaApp];
92 // ----------------------------------------------------------------------------
93 // wxEventLoop message processing dispatching
94 // ----------------------------------------------------------------------------
96 bool wxEventLoop::Pending() const
101 bool wxEventLoop::Dispatch()
103 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );