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
;
78 int exitcode
= m_impl
->GetExitCode();
85 void wxEventLoop::Exit(int rc
)
87 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
89 m_impl
->SetExitCode(rc
);
94 // ----------------------------------------------------------------------------
95 // wxEventLoop message processing dispatching
96 // ----------------------------------------------------------------------------
98 bool wxEventLoop::Pending() const
102 // We need to remove idle callbacks or gtk_events_pending will
103 // never return false.
104 wxTheApp
->RemoveIdleTag();
107 return gtk_events_pending();
110 bool wxEventLoop::Dispatch()
112 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
114 gtk_main_iteration();