]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/timer.cpp
fix typo in OnClosingDocument() name
[wxWidgets.git] / src / gtk / 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 gboolean 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 return !timer->IsOneShot();
49 }
50 }
51
52 void wxTimer::Init()
53 {
54 m_sourceId = 0;
55 m_milli = 1000;
56 }
57
58 wxTimer::~wxTimer()
59 {
60 Stop();
61 }
62
63 bool wxTimer::Start( int millisecs, bool oneShot )
64 {
65 (void)wxTimerBase::Start(millisecs, oneShot);
66
67 if (m_sourceId != 0)
68 g_source_remove(m_sourceId);
69
70 m_sourceId = g_timeout_add(m_milli, timeout_callback, this);
71
72 return true;
73 }
74
75 void wxTimer::Stop()
76 {
77 if (m_sourceId != 0)
78 {
79 g_source_remove(m_sourceId);
80 m_sourceId = 0;
81 }
82 }
83
84 #endif // wxUSE_TIMER
85