]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/timer.cpp
Updated CW project file
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12 #pragma implementation "timer.h"
13 #endif
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #if wxUSE_TIMER
19
20 #include "wx/timer.h"
21
22 #include "gtk/gtk.h"
23
24 // ----------------------------------------------------------------------------
25 // wxTimer
26 // ----------------------------------------------------------------------------
27
28 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
29
30 extern "C" gint timeout_callback( gpointer data )
31 {
32 wxTimer *timer = (wxTimer*)data;
33
34 // Don't change the order of anything in this callback!
35
36 if (timer->IsOneShot())
37 {
38 // This sets m_tag to -1
39 timer->Stop();
40 }
41
42 // When getting called from GDK's timer handler we
43 // are no longer within GDK's grab on the GUI
44 // thread so we must lock it here ourselves.
45 gdk_threads_enter();
46
47 timer->Notify();
48
49 // Release lock again.
50 gdk_threads_leave();
51
52 if (timer->IsOneShot())
53 return FALSE;
54
55 return TRUE;
56 }
57
58 void wxTimer::Init()
59 {
60 m_tag = -1;
61 m_milli = 1000;
62 }
63
64 wxTimer::~wxTimer()
65 {
66 wxTimer::Stop();
67 }
68
69 bool wxTimer::Start( int millisecs, bool oneShot )
70 {
71 (void)wxTimerBase::Start(millisecs, oneShot);
72
73 if (m_tag != -1)
74 gtk_timeout_remove( m_tag );
75
76 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
77
78 return TRUE;
79 }
80
81 void wxTimer::Stop()
82 {
83 if (m_tag != -1)
84 {
85 gtk_timeout_remove( m_tag );
86 m_tag = -1;
87 }
88 }
89
90 #endif // wxUSE_TIMER
91