1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxEventLoopImpl
43 wxEventLoopImpl() { SetExitCode(0); }
45 // set/get the exit code
46 void SetExitCode(int exitcode
) { m_exitcode
= exitcode
; }
47 int GetExitCode() const { return m_exitcode
; }
50 // the exit code of the event loop
54 // ============================================================================
55 // wxEventLoop implementation
56 // ============================================================================
58 // ----------------------------------------------------------------------------
59 // wxEventLoop running and exiting
60 // ----------------------------------------------------------------------------
62 wxEventLoop::~wxEventLoop()
64 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
67 int wxEventLoop::Run()
69 // event loops are not recursive, you need to create another loop!
70 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
72 wxEventLoopActivator
activate(this);
74 m_impl
= new wxEventLoopImpl
;
80 int exitcode
= m_impl
->GetExitCode();
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();