]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/timer.cpp
Minor header cleaning.
[wxWidgets.git] / src / gtk1 / 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
c801d85f
KB
15#include "wx/timer.h"
16
83624f79
RR
17#include "gtk/gtk.h"
18
1e6feb95 19// ----------------------------------------------------------------------------
c801d85f 20// wxTimer
1e6feb95 21// ----------------------------------------------------------------------------
c801d85f 22
313feadc 23IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
c801d85f 24
865bb325
VZ
25extern "C" {
26static gint timeout_callback( gpointer data )
c801d85f 27{
83624f79 28 wxTimer *timer = (wxTimer*)data;
e1393d82 29
7b14c561 30 // Don't change the order of anything in this callback!
3d257b8d 31
7b14c561
RR
32 if (timer->IsOneShot())
33 {
34 // This sets m_tag to -1
35 timer->Stop();
36 }
3d257b8d 37
7b14c561
RR
38 // When getting called from GDK's timer handler we
39 // are no longer within GDK's grab on the GUI
40 // thread so we must lock it here ourselves.
924ef850 41 gdk_threads_enter();
e1393d82 42
83624f79 43 timer->Notify();
03f38c58 44
7b14c561 45 // Release lock again.
924ef850 46 gdk_threads_leave();
f6577bba 47
7b14c561 48 if (timer->IsOneShot())
e1393d82 49 return FALSE;
03f38c58 50
83624f79 51 return TRUE;
ff7b1510 52}
865bb325 53}
c801d85f 54
ed791986 55void wxTimer::Init()
c801d85f 56{
83624f79 57 m_tag = -1;
0470b1e6 58 m_milli = 1000;
ff7b1510 59}
c801d85f 60
03f38c58 61wxTimer::~wxTimer()
c801d85f 62{
0470b1e6 63 wxTimer::Stop();
ff7b1510 64}
c801d85f 65
03f38c58 66bool wxTimer::Start( int millisecs, bool oneShot )
c801d85f 67{
0470b1e6 68 (void)wxTimerBase::Start(millisecs, oneShot);
03f38c58 69
574bf507
RR
70 if (m_tag != -1)
71 gtk_timeout_remove( m_tag );
72
0470b1e6 73 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
03f38c58 74
83624f79 75 return TRUE;
ff7b1510 76}
c801d85f 77
03f38c58 78void wxTimer::Stop()
c801d85f 79{
83624f79
RR
80 if (m_tag != -1)
81 {
82 gtk_timeout_remove( m_tag );
83 m_tag = -1;
84 }
ff7b1510 85}
c801d85f 86
1e6feb95
VZ
87#endif // wxUSE_TIMER
88