1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
28 #include "wx/ptr_scpd.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxEventLoopImpl
44 wxEventLoopImpl() { SetExitCode(0); }
46 // set/get the exit code
47 void SetExitCode(int exitcode
) { m_exitcode
= exitcode
; }
48 int GetExitCode() const { return m_exitcode
; }
51 // the exit code of the event loop
55 // ============================================================================
56 // wxEventLoop implementation
57 // ============================================================================
59 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopImpl
)
61 // ----------------------------------------------------------------------------
62 // wxEventLoop running and exiting
63 // ----------------------------------------------------------------------------
65 wxGUIEventLoop::~wxGUIEventLoop()
67 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
70 int wxGUIEventLoop::Run()
72 // event loops are not recursive, you need to create another loop!
73 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
75 wxEventLoopActivator
activate(this);
77 wxEventLoopImplTiedPtr
impl(&m_impl
, new wxEventLoopImpl
);
83 return m_impl
->GetExitCode();
86 void wxGUIEventLoop::Exit(int rc
)
88 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
90 m_impl
->SetExitCode(rc
);
95 // ----------------------------------------------------------------------------
96 // wxEventLoop message processing dispatching
97 // ----------------------------------------------------------------------------
99 bool wxGUIEventLoop::Pending() const
102 wxApp
* app
= wxTheApp
;
104 // app->EventsPending() avoids false positives from our idle source
105 pending
= app
->EventsPending();
107 pending
= gtk_events_pending() != 0;
111 bool wxGUIEventLoop::Dispatch()
113 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
115 gtk_main_iteration();