1. wxTimer change - now generates EVT_TIMER()
[wxWidgets.git] / src / gtk1 / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/timer.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "timer.h"
13 #endif
14
15 #include "wx/timer.h"
16
17 #include "gtk/gtk.h"
18
19 //-----------------------------------------------------------------------------
20 // wxTimer
21 //-----------------------------------------------------------------------------
22
23 IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
24
25 static gint timeout_callback( gpointer data )
26 {
27 wxTimer *timer = (wxTimer*)data;
28
29 /* when getting called from GDK's timer handler we
30 are no longer within GDK's grab on the GUI
31 thread so we must lock it here ourselves */
32 gdk_threads_enter();
33
34 timer->Notify();
35
36 /* release lock again */
37 gdk_threads_leave();
38
39 if ( timer->IsOneShot() )
40 return FALSE;
41
42 return TRUE;
43 }
44
45 void wxTimer::Init()
46 {
47 m_tag = -1;
48 m_milli = 1000;
49 }
50
51 wxTimer::~wxTimer()
52 {
53 wxTimer::Stop();
54 }
55
56 bool wxTimer::Start( int millisecs, bool oneShot )
57 {
58 (void)wxTimerBase::Start(millisecs, oneShot);
59
60 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
61
62 return TRUE;
63 }
64
65 void wxTimer::Stop()
66 {
67 if (m_tag != -1)
68 {
69 gtk_timeout_remove( m_tag );
70 m_tag = -1;
71 }
72 }
73