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"
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 // wxGUIEventLoop implementation
57 // ============================================================================
59 // ----------------------------------------------------------------------------
60 // wxGUIEventLoop running and exiting
61 // ----------------------------------------------------------------------------
63 wxGUIEventLoop::~wxGUIEventLoop()
65 wxASSERT_MSG( !m_impl
, _T("should have been deleted in Run()") );
68 int wxGUIEventLoop::Run()
70 // event loops are not recursive, you need to create another loop!
71 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
73 wxEventLoopActivator
activate(this);
75 m_impl
= new wxEventLoopImpl
;
81 int exitcode
= m_impl
->GetExitCode();
88 void wxGUIEventLoop::Exit(int rc
)
90 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
92 m_impl
->SetExitCode(rc
);
97 // ----------------------------------------------------------------------------
98 // wxEventLoop message processing dispatching
99 // ----------------------------------------------------------------------------
101 bool wxGUIEventLoop::Pending() const
105 // We need to remove idle callbacks or gtk_events_pending will
106 // never return false.
107 wxTheApp
->RemoveIdleTag();
110 return gtk_events_pending();
113 bool wxGUIEventLoop::Dispatch()
115 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
117 gtk_main_iteration();
122 //-----------------------------------------------------------------------------
124 //-----------------------------------------------------------------------------
126 bool wxGUIEventLoop::YieldFor(long eventsToProcess
)
129 if ( !wxThread::IsMain() )
131 // can't call gtk_main_iteration() from other threads like this
134 #endif // wxUSE_THREADS
136 m_isInsideYield
= true;
137 m_eventsToProcessInsideYield
= eventsToProcess
;
139 // We need to remove idle callbacks or the loop will
141 wxTheApp
->RemoveIdleTag();
144 // disable log flushing from here because a call to wxYield() shouldn't
145 // normally result in message boxes popping up &c
149 // TODO: implement event filtering using the eventsToProcess mask
150 while (gtk_events_pending())
151 gtk_main_iteration();
153 // It's necessary to call ProcessIdle() to update the frames sizes which
154 // might have been changed (it also will update other things set from
155 // OnUpdateUI() which is a nice (and desired) side effect). But we
156 // call ProcessIdle() only once since this is not meant for longish
157 // background jobs (controlled by wxIdleEvent::RequestMore() and the
158 // return value of Processidle().
162 // let the logs be flashed again
166 m_isInsideYield
= false;