]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/timer.cpp
reSWIGged
[wxWidgets.git] / src / gtk1 / 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
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
28IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
29
30extern "C" {
31static gint timeout_callback( gpointer data )
32{
33 wxTimer *timer = (wxTimer*)data;
34
35 // Don't change the order of anything in this callback!
36
37 if (timer->IsOneShot())
38 {
39 // This sets m_tag to -1
40 timer->Stop();
41 }
42
43 // When getting called from GDK's timer handler we
44 // are no longer within GDK's grab on the GUI
45 // thread so we must lock it here ourselves.
46 gdk_threads_enter();
47
48 timer->Notify();
49
50 // Release lock again.
51 gdk_threads_leave();
52
53 if (timer->IsOneShot())
54 return FALSE;
55
56 return TRUE;
57}
58}
59
60void wxTimer::Init()
61{
62 m_tag = -1;
63 m_milli = 1000;
64}
65
66wxTimer::~wxTimer()
67{
68 wxTimer::Stop();
69}
70
71bool wxTimer::Start( int millisecs, bool oneShot )
72{
73 (void)wxTimerBase::Start(millisecs, oneShot);
74
75 if (m_tag != -1)
76 gtk_timeout_remove( m_tag );
77
78 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
79
80 return TRUE;
81}
82
83void wxTimer::Stop()
84{
85 if (m_tag != -1)
86 {
87 gtk_timeout_remove( m_tag );
88 m_tag = -1;
89 }
90}
91
92#endif // wxUSE_TIMER
93