GUI thread update and event corrections.
[wxWidgets.git] / src / gtk1 / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 wxTimer::wxTimer()
46 {
47 m_tag = -1;
48 m_milli = 1000;
49 m_oneShot = FALSE;
50 }
51
52 wxTimer::~wxTimer()
53 {
54 wxTimer::Stop();
55 }
56
57 bool wxTimer::Start( int millisecs, bool oneShot )
58 {
59 (void)wxTimerBase::Start(millisecs, oneShot);
60
61 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
62
63 return TRUE;
64 }
65
66 void wxTimer::Stop()
67 {
68 if (m_tag != -1)
69 {
70 gtk_timeout_remove( m_tag );
71 m_tag = -1;
72 }
73 }
74