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"
35 #include "wx/evtloop.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxEventLoopImpl
47 wxEventLoopImpl() { SetExitCode(0); }
49 // set/get the exit code
50 void SetExitCode(int exitcode
) { m_exitcode
= exitcode
; }
51 int GetExitCode() const { return m_exitcode
; }
54 // the exit code of the event loop
58 // ============================================================================
59 // wxEventLoop implementation
60 // ============================================================================
62 // ----------------------------------------------------------------------------
63 // wxEventLoop running and exiting
64 // ----------------------------------------------------------------------------
66 wxEventLoop
*wxEventLoopBase::ms_activeLoop
= NULL
;
68 wxEventLoop::~wxEventLoop()
70 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
73 int wxEventLoop::Run()
75 // event loops are not recursive, you need to create another loop!
76 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
78 wxEventLoop
*oldLoop
= ms_activeLoop
;
81 m_impl
= new wxEventLoopImpl
;
85 int exitcode
= m_impl
->GetExitCode();
89 ms_activeLoop
= oldLoop
;
94 void wxEventLoop::Exit(int rc
)
96 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
98 m_impl
->SetExitCode(rc
);
103 // ----------------------------------------------------------------------------
104 // wxEventLoop message processing dispatching
105 // ----------------------------------------------------------------------------
107 extern bool g_isIdle
;
109 bool wxEventLoop::Pending() const
111 if (wxTheApp
&& !g_isIdle
)
113 // We need to remove idle callbacks or gtk_events_pending will
114 // never return false.
115 gtk_idle_remove( wxTheApp
->m_idleTag
);
116 wxTheApp
->m_idleTag
= 0;
120 return gtk_events_pending();
123 bool wxEventLoop::Dispatch()
125 wxCHECK_MSG( IsRunning(), FALSE
, _T("can't call Dispatch() if not running") );
127 gtk_main_iteration();