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