Update OpenVMS makefile
[wxWidgets.git] / src / gtk1 / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/timer.cpp
3 // Purpose: wxTimer implementation
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #include "wx/wxprec.h"
10
11 #if wxUSE_TIMER
12
13 #include "wx/gtk1/private/timer.h"
14
15 #include "gtk/gtk.h"
16
17 // ----------------------------------------------------------------------------
18 // wxTimer
19 // ----------------------------------------------------------------------------
20
21 extern "C" {
22 static gint timeout_callback(void *data)
23 {
24 wxTimerImpl * const timer = (wxTimerImpl *)data;
25
26 const bool keepGoing = !timer->IsOneShot();
27 if ( !keepGoing )
28 timer->Stop();
29
30 // When getting called from GDK's timer handler we
31 // are no longer within GDK's grab on the GUI
32 // thread so we must lock it here ourselves.
33 gdk_threads_enter();
34
35 timer->Notify();
36
37 // Release lock again.
38 gdk_threads_leave();
39
40 return keepGoing;
41 }
42 }
43
44 bool wxGTKTimerImpl::Start(int millisecs, bool oneShot)
45 {
46 if ( !wxTimerImpl::Start(millisecs, oneShot) )
47 return false;
48
49 wxASSERT_MSG( m_tag == -1, wxT("shouldn't be still running") );
50
51 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
52
53 return true;
54 }
55
56 void wxGTKTimerImpl::Stop()
57 {
58 wxASSERT_MSG( m_tag != -1, wxT("should be running") );
59
60 gtk_timeout_remove( m_tag );
61 m_tag = -1;
62 }
63
64 #endif // wxUSE_TIMER
65