From f5e10026502fcd54f77e300ca26e3a99d36bd87a Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 3 Oct 2003 13:05:42 +0000 Subject: [PATCH] Extremely simple implementation of wxEventLoop using wxGTK as a skeleton git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24063 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/cocoa/evtloop.mm | 106 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/cocoa/evtloop.mm diff --git a/src/cocoa/evtloop.mm b/src/cocoa/evtloop.mm new file mode 100644 index 0000000000..bd1611587b --- /dev/null +++ b/src/cocoa/evtloop.mm @@ -0,0 +1,106 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: cocoa/evtloop.mm +// Purpose: implements wxEventLoop for Cocoa +// Author: David Elliott +// Modified by: +// Created: 2003/10/02 +// RCS-ID: $Id$ +// Copyright: (c) 2003 David Elliott +// License: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/log.h" +#endif //WX_PRECOMP + +#include "wx/evtloop.h" + +#import + +// ======================================================================== +// wxEventLoopImpl +// ======================================================================== + +class WXDLLEXPORT wxEventLoopImpl +{ +public: + // ctor + wxEventLoopImpl() { SetExitCode(0); } + + // set/get the exit code + void SetExitCode(int exitcode) { m_exitcode = exitcode; } + int GetExitCode() const { return m_exitcode; } + +private: + // the exit code of the event loop + int m_exitcode; +}; + +// ======================================================================== +// wxEventLoop +// ======================================================================== + +// ---------------------------------------------------------------------------- +// wxEventLoop running and exiting +// ---------------------------------------------------------------------------- + +wxEventLoop *wxEventLoop::ms_activeLoop = NULL; + +wxEventLoop::~wxEventLoop() +{ + wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") ); +} + +bool wxEventLoop::IsRunning() const +{ + return m_impl; +} + +int wxEventLoop::Run() +{ + // event loops are not recursive, you need to create another loop! + wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") ); + + wxEventLoop *oldLoop = ms_activeLoop; + ms_activeLoop = this; + + m_impl = new wxEventLoopImpl; + + [[NSApplication sharedApplication] run]; + + int exitcode = m_impl->GetExitCode(); + delete m_impl; + m_impl = NULL; + + ms_activeLoop = oldLoop; + + return exitcode; +} + +void wxEventLoop::Exit(int rc) +{ + wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") ); + + m_impl->SetExitCode(rc); + + NSApplication *cocoaApp = [NSApplication sharedApplication]; + wxLogDebug("wxEventLoop::Exit isRunning=%d", (int)[cocoaApp isRunning]); + [cocoaApp stop: cocoaApp]; +} + +// ---------------------------------------------------------------------------- +// wxEventLoop message processing dispatching +// ---------------------------------------------------------------------------- + +bool wxEventLoop::Pending() const +{ + return 0; +} + +bool wxEventLoop::Dispatch() +{ + wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") ); + return false; +} + -- 2.45.2