]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/timer.cpp
More experimenting
[wxWidgets.git] / src / gtk / timer.cpp
... / ...
CommitLineData
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
23IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
24
25extern "C" {
26static 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
55void wxTimer::Init()
56{
57 m_tag = -1;
58 m_milli = 1000;
59}
60
61wxTimer::~wxTimer()
62{
63 wxTimer::Stop();
64}
65
66bool wxTimer::Start( int millisecs, bool oneShot )
67{
68 (void)wxTimerBase::Start(millisecs, oneShot);
69
70 if (m_tag != -1)
71 g_source_remove( m_tag );
72
73 m_tag = g_timeout_add( m_milli, timeout_callback, this );
74
75 return TRUE;
76}
77
78void wxTimer::Stop()
79{
80 if (m_tag != -1)
81 {
82 g_source_remove( m_tag );
83 m_tag = -1;
84 }
85}
86
87#endif // wxUSE_TIMER
88