]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/timer.cpp
Watcom compilation fix
[wxWidgets.git] / src / gtk1 / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/timer.cpp
3 // Purpose: wxTimer implementation
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/defs.h"
16
17 #if wxUSE_TIMER
18
19 #include "wx/timer.h"
20
21 #include "gtk/gtk.h"
22
23 // ----------------------------------------------------------------------------
24 // wxTimer
25 // ----------------------------------------------------------------------------
26
27 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
28
29 extern "C" gint timeout_callback( gpointer data )
30 {
31 wxTimer *timer = (wxTimer*)data;
32
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.
44 gdk_threads_enter();
45
46 timer->Notify();
47
48 // Release lock again.
49 gdk_threads_leave();
50
51 if (timer->IsOneShot())
52 return FALSE;
53
54 return TRUE;
55 }
56
57 void wxTimer::Init()
58 {
59 m_tag = -1;
60 m_milli = 1000;
61 }
62
63 wxTimer::~wxTimer()
64 {
65 wxTimer::Stop();
66 }
67
68 bool wxTimer::Start( int millisecs, bool oneShot )
69 {
70 (void)wxTimerBase::Start(millisecs, oneShot);
71
72 if (m_tag != -1)
73 gtk_timeout_remove( m_tag );
74
75 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
76
77 return TRUE;
78 }
79
80 void wxTimer::Stop()
81 {
82 if (m_tag != -1)
83 {
84 gtk_timeout_remove( m_tag );
85 m_tag = -1;
86 }
87 }
88
89 #endif // wxUSE_TIMER
90