]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/timer.cpp
no message
[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_ABSTRACT_CLASS(wxTimer,wxObject)
23
24 gint timeout_callback( gpointer data )
25 {
26 wxTimer *timer = (wxTimer*)data;
27 timer->Notify();
28
29 if ( timer->OneShot() )
30 timer->Stop();
31
32 return TRUE;
33 }
34
35 wxTimer::wxTimer()
36 {
37 m_tag = -1;
38 m_time = 1000;
39 m_oneShot = FALSE;
40 }
41
42 wxTimer::~wxTimer()
43 {
44 Stop();
45 }
46
47 bool wxTimer::Start( int millisecs, bool oneShot )
48 {
49 if ( millisecs != -1 )
50 m_time = millisecs;
51
52 m_oneShot = oneShot;
53
54 m_tag = gtk_timeout_add( millisecs, timeout_callback, this );
55
56 return TRUE;
57 }
58
59 void wxTimer::Stop()
60 {
61 if ( m_tag != -1 )
62 {
63 gtk_timeout_remove( m_tag );
64
65 m_tag = -1;
66 }
67 }
68