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