]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/timer.cpp
Add wxRichMessageDialog class.
[wxWidgets.git] / src / gtk / timer.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
ed791986 2// Name: gtk/timer.cpp
1e6feb95 3// Purpose: wxTimer implementation
c801d85f 4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
1e6feb95
VZ
12
13#if wxUSE_TIMER
14
c2ca375c 15#include "wx/gtk/private/timer.h"
b63dc1c1 16#include "wx/app.h"
c801d85f 17
855f31eb 18#include <gtk/gtk.h>
83624f79 19
1e6feb95 20// ----------------------------------------------------------------------------
c2ca375c 21// wxTimerImpl
1e6feb95 22// ----------------------------------------------------------------------------
c801d85f 23
865bb325 24extern "C" {
c2ca375c 25
855f31eb 26static gboolean timeout_callback(gpointer data)
c801d85f 27{
c2ca375c 28 wxGTKTimerImpl *timer = (wxGTKTimerImpl*)data;
3d257b8d 29
c2ca375c
VZ
30 const bool keepGoing = !timer->IsOneShot();
31 if ( !keepGoing )
7b14c561 32 timer->Stop();
3d257b8d 33
7b14c561
RR
34 // When getting called from GDK's timer handler we
35 // are no longer within GDK's grab on the GUI
36 // thread so we must lock it here ourselves.
924ef850 37 gdk_threads_enter();
e1393d82 38
83624f79 39 timer->Notify();
03f38c58 40
7b14c561 41 // Release lock again.
924ef850 42 gdk_threads_leave();
f6577bba 43
b63dc1c1
PC
44 wxApp* app = wxTheApp;
45 if (app)
46 app->WakeUpIdle();
47
c2ca375c 48 return keepGoing;
ff7b1510 49}
c801d85f 50
c2ca375c 51} // extern "C"
c801d85f 52
c2ca375c 53bool wxGTKTimerImpl::Start(int millisecs, bool oneShot)
c801d85f 54{
c2ca375c
VZ
55 if ( !wxTimerImpl::Start(millisecs, oneShot) )
56 return false;
03f38c58 57
9a83f860 58 wxASSERT_MSG( !m_sourceId, wxT("shouldn't be still running") );
574bf507 59
855f31eb 60 m_sourceId = g_timeout_add(m_milli, timeout_callback, this);
03f38c58 61
855f31eb 62 return true;
ff7b1510 63}
c801d85f 64
c2ca375c 65void wxGTKTimerImpl::Stop()
c801d85f 66{
9a83f860 67 wxASSERT_MSG( m_sourceId, wxT("should be running") );
c2ca375c
VZ
68
69 g_source_remove(m_sourceId);
70 m_sourceId = 0;
ff7b1510 71}
c801d85f 72
1e6feb95
VZ
73#endif // wxUSE_TIMER
74