1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        gtk/evtloop.cpp 
   3 // Purpose:     implements wxEventLoop for GTK+ 
   4 // Author:      Vadim Zeitlin 
   8 // Copyright:   (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> 
   9 // License:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  21     #pragma implementation "evtloop.h" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  34 #include "wx/evtloop.h" 
  38 // ---------------------------------------------------------------------------- 
  40 // ---------------------------------------------------------------------------- 
  42 class WXDLLEXPORT wxEventLoopImpl
 
  46     wxEventLoopImpl() { SetExitCode(0); } 
  48     // set/get the exit code 
  49     void SetExitCode(int exitcode
) { m_exitcode 
= exitcode
; } 
  50     int GetExitCode() const { return m_exitcode
; } 
  53     // the exit code of the event loop 
  57 // ============================================================================ 
  58 // wxEventLoop implementation 
  59 // ============================================================================ 
  61 // ---------------------------------------------------------------------------- 
  62 // wxEventLoop running and exiting 
  63 // ---------------------------------------------------------------------------- 
  65 wxEventLoop 
*wxEventLoop::ms_activeLoop 
= NULL
; 
  67 wxEventLoop::~wxEventLoop() 
  69     wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") ); 
  72 bool wxEventLoop::IsRunning() const 
  74     return m_impl 
!= NULL
; 
  77 int wxEventLoop::Run() 
  79     // event loops are not recursive, you need to create another loop! 
  80     wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") ); 
  82     wxEventLoop 
*oldLoop 
= ms_activeLoop
; 
  85     m_impl 
= new wxEventLoopImpl
; 
  89     int exitcode 
= m_impl
->GetExitCode(); 
  93     ms_activeLoop 
= oldLoop
; 
  98 void wxEventLoop::Exit(int rc
) 
 100     wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") ); 
 102     m_impl
->SetExitCode(rc
); 
 107 // ---------------------------------------------------------------------------- 
 108 // wxEventLoop message processing dispatching 
 109 // ---------------------------------------------------------------------------- 
 111 bool wxEventLoop::Pending() const 
 113     return gtk_events_pending() > 0; 
 116 bool wxEventLoop::Dispatch() 
 118     wxCHECK_MSG( IsRunning(), FALSE
, _T("can't call Dispatch() if not running") ); 
 120     gtk_main_iteration();