1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/evtloop.cpp
3 // Purpose: implements wxEventLoop for GTK+
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #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 // wxGUIEventLoop implementation
56 // ============================================================================
58 // ----------------------------------------------------------------------------
59 // wxGUIEventLoop running and exiting
60 // ----------------------------------------------------------------------------
62 wxGUIEventLoop::~wxGUIEventLoop()
64 wxASSERT_MSG( !m_impl
, wxT("should have been deleted in Run()") );
67 int wxGUIEventLoop::DoRun()
69 m_impl
= new wxEventLoopImpl
;
71 guint loopLevel
= gtk_main_level();
73 // This is placed inside of a loop to take into account nested
74 // event loops. For example, inside this event loop, we may recieve
75 // Exit() for a different event loop (which we are currently inside of)
76 // That Exit() will cause this gtk_main() to exit so we need to re-enter it.
77 while ( !m_shouldExit
)
82 // Force the enclosing event loop to also exit to see if it is done
83 // in case that event loop ended inside of this one. If it is not time
84 // yet for that event loop to exit, it will be executed again due to
85 // the while() loop on m_shouldExit().
87 // This is unnecessary if we are the top level loop, i.e. loop of level 0.
95 int exitcode
= m_impl
->GetExitCode();
101 void wxGUIEventLoop::ScheduleExit(int rc
)
103 wxCHECK_RET( IsInsideRun(), wxT("can't call ScheduleExit() if not started") );
105 m_impl
->SetExitCode(rc
);
112 // ----------------------------------------------------------------------------
113 // wxEventLoop message processing dispatching
114 // ----------------------------------------------------------------------------
116 bool wxGUIEventLoop::Pending() const
120 // We need to remove idle callbacks or gtk_events_pending will
121 // never return false.
122 wxTheApp
->RemoveIdleTag();
125 return gtk_events_pending();
128 bool wxGUIEventLoop::Dispatch()
130 wxCHECK_MSG( IsRunning(), false, wxT("can't call Dispatch() if not running") );
132 gtk_main_iteration();
137 //-----------------------------------------------------------------------------
139 //-----------------------------------------------------------------------------
141 bool wxGUIEventLoop::YieldFor(long eventsToProcess
)
144 if ( !wxThread::IsMain() )
146 // can't call gtk_main_iteration() from other threads like this
149 #endif // wxUSE_THREADS
151 m_isInsideYield
= true;
152 m_eventsToProcessInsideYield
= eventsToProcess
;
154 // We need to remove idle callbacks or the loop will
156 wxTheApp
->RemoveIdleTag();
159 // disable log flushing from here because a call to wxYield() shouldn't
160 // normally result in message boxes popping up &c
164 // TODO: implement event filtering using the eventsToProcess mask
165 while (gtk_events_pending())
166 gtk_main_iteration();
168 // It's necessary to call ProcessIdle() to update the frames sizes which
169 // might have been changed (it also will update other things set from
170 // OnUpdateUI() which is a nice (and desired) side effect). But we
171 // call ProcessIdle() only once since this is not meant for longish
172 // background jobs (controlled by wxIdleEvent::RequestMore() and the
173 // return value of Processidle().
177 // let the logs be flashed again
181 m_isInsideYield
= false;