]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/evtloop.cpp
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"
35 // ============================================================================
36 // wxEventLoop implementation
37 // ============================================================================
39 // ----------------------------------------------------------------------------
40 // wxEventLoop running and exiting
41 // ----------------------------------------------------------------------------
43 wxGUIEventLoop::wxGUIEventLoop()
48 int wxGUIEventLoop::Run()
50 // event loops are not recursive, you need to create another loop!
51 wxCHECK_MSG( !IsRunning(), -1, "can't reenter a message loop" );
53 wxEventLoopActivator
activate(this);
62 void wxGUIEventLoop::Exit(int rc
)
64 wxCHECK_RET( IsRunning(), "can't call Exit() if not running" );
71 void wxGUIEventLoop::WakeUp()
73 // TODO: idle events handling should really be done by wxEventLoop itself
74 // but for now it's completely in gtk/app.cpp so just call there when
75 // we have wxTheApp and hope that it doesn't matter that we do
76 // nothing when we don't...
78 wxTheApp
->WakeUpIdle();
81 // ----------------------------------------------------------------------------
82 // wxEventLoop message processing dispatching
83 // ----------------------------------------------------------------------------
85 bool wxGUIEventLoop::Pending() const
89 // this avoids false positives from our idle source
90 return wxTheApp
->EventsPending();
93 return gtk_events_pending() != 0;
96 bool wxGUIEventLoop::Dispatch()
98 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
100 // gtk_main_iteration() returns TRUE only if gtk_main_quit() was called
101 return !gtk_main_iteration();
105 static gboolean
wx_event_loop_timeout(void* data
)
107 bool* expired
= static_cast<bool*>(data
);
110 // return FALSE to remove this timeout
115 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout
)
117 bool expired
= false;
118 const unsigned id
= g_timeout_add(timeout
, wx_event_loop_timeout
, &expired
);
119 bool quit
= gtk_main_iteration() != 0;