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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/evtloop.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class WXDLLEXPORT wxEventLoopImpl
40 wxEventLoopImpl() { SetExitCode(0); }
42 // set/get the exit code
43 void SetExitCode(int exitcode
) { m_exitcode
= exitcode
; }
44 int GetExitCode() const { return m_exitcode
; }
47 // the exit code of the event loop
51 // ============================================================================
52 // wxEventLoop implementation
53 // ============================================================================
55 // ----------------------------------------------------------------------------
56 // wxEventLoop running and exiting
57 // ----------------------------------------------------------------------------
59 wxEventLoop
*wxEventLoopBase::ms_activeLoop
= NULL
;
61 wxEventLoop::~wxEventLoop()
63 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
66 int wxEventLoop::Run()
68 // event loops are not recursive, you need to create another loop!
69 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
71 wxEventLoop
*oldLoop
= ms_activeLoop
;
74 m_impl
= new wxEventLoopImpl
;
78 int exitcode
= m_impl
->GetExitCode();
82 ms_activeLoop
= oldLoop
;
87 void wxEventLoop::Exit(int rc
)
89 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
91 m_impl
->SetExitCode(rc
);
96 // ----------------------------------------------------------------------------
97 // wxEventLoop message processing dispatching
98 // ----------------------------------------------------------------------------
100 bool wxEventLoop::Pending() const
104 // We need to remove idle callbacks or gtk_events_pending will
105 // never return false.
106 wxTheApp
->RemoveIdleTag();
109 return gtk_events_pending();
112 bool wxEventLoop::Dispatch()
114 wxCHECK_MSG( IsRunning(), FALSE
, _T("can't call Dispatch() if not running") );
116 gtk_main_iteration();