]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/timer.cpp
Version 0.4 of wxPython for MSW.
[wxWidgets.git] / src / gtk1 / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: timer.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11
12 #ifdef __GNUG__
13 #pragma implementation "timer.h"
14 #endif
15
16 #include "wx/timer.h"
17
18 //-----------------------------------------------------------------------------
19 // wxTimer
20 //-----------------------------------------------------------------------------
21
22 IMPLEMENT_DYNAMIC_CLASS(wxTimer,wxObject)
23
24 gint timeout_callback( gpointer data )
25 {
26 wxTimer *timer = (wxTimer*)data;
27 timer->Notify();
28 if (timer->OneShot()) timer->Stop();
29 return TRUE;
30 }
31
32 wxTimer::wxTimer(void)
33 {
34 m_tag = -1;
35 m_time = 1000;
36 m_oneShot = FALSE;
37 }
38
39 wxTimer::~wxTimer(void)
40 {
41 Stop();
42 }
43
44 int wxTimer::Interval(void)
45 {
46 return m_time;
47 }
48
49 bool wxTimer::OneShot(void)
50 {
51 return m_oneShot;
52 }
53
54 void wxTimer::Notify(void)
55 {
56 }
57
58 void wxTimer::Start( int millisecs, bool oneShot )
59 {
60 if (millisecs != -1) m_time = millisecs;
61 m_oneShot = oneShot;
62 m_tag = gtk_timeout_add( millisecs, timeout_callback, this );
63 }
64
65 void wxTimer::Stop(void)
66 {
67 if (m_tag != -1)
68 gtk_timeout_remove( m_tag );
69 m_tag = -1;
70 }
71