]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/timer.cpp
don't use -q option with egrep, Solaris doesn't have it (bug 517145)
[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 /* when getting called from GDK's timer handler we
34 are no longer within GDK's grab on the GUI
35 thread so we must lock it here ourselves */
36 gdk_threads_enter();
37
38 timer->Notify();
39
40 /* release lock again */
41 gdk_threads_leave();
42
43 if ( timer->IsOneShot() )
44 return FALSE;
45
46 return TRUE;
47 }
48
49 void wxTimer::Init()
50 {
51 m_tag = -1;
52 m_milli = 1000;
53 }
54
55 wxTimer::~wxTimer()
56 {
57 wxTimer::Stop();
58 }
59
60 bool wxTimer::Start( int millisecs, bool oneShot )
61 {
62 (void)wxTimerBase::Start(millisecs, oneShot);
63
64 if (m_tag != -1)
65 gtk_timeout_remove( m_tag );
66
67 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
68
69 return TRUE;
70 }
71
72 void wxTimer::Stop()
73 {
74 if (m_tag != -1)
75 {
76 gtk_timeout_remove( m_tag );
77 m_tag = -1;
78 }
79 }
80
81 #endif // wxUSE_TIMER
82