]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/timer.cpp
Use wxMBConvUTF8 when G_FILENAME_ENCODING is UTF-8, and set
[wxWidgets.git] / src / gtk / timer.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
ed791986 2// Name: gtk/timer.cpp
1e6feb95 3// Purpose: wxTimer implementation
c801d85f 4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10
14f355c2 11#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c801d85f
KB
12#pragma implementation "timer.h"
13#endif
14
14f355c2
VS
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
1e6feb95
VZ
17
18#if wxUSE_TIMER
19
c801d85f
KB
20#include "wx/timer.h"
21
83624f79
RR
22#include "gtk/gtk.h"
23
1e6feb95 24// ----------------------------------------------------------------------------
c801d85f 25// wxTimer
1e6feb95 26// ----------------------------------------------------------------------------
c801d85f 27
313feadc 28IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
c801d85f 29
865bb325
VZ
30extern "C" {
31static gint timeout_callback( gpointer data )
c801d85f 32{
83624f79 33 wxTimer *timer = (wxTimer*)data;
e1393d82 34
7b14c561
RR
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.
924ef850 46 gdk_threads_enter();
e1393d82 47
83624f79 48 timer->Notify();
03f38c58 49
7b14c561 50 // Release lock again.
924ef850 51 gdk_threads_leave();
f6577bba 52
7b14c561 53 if (timer->IsOneShot())
e1393d82 54 return FALSE;
03f38c58 55
83624f79 56 return TRUE;
ff7b1510 57}
865bb325 58}
c801d85f 59
ed791986 60void wxTimer::Init()
c801d85f 61{
83624f79 62 m_tag = -1;
0470b1e6 63 m_milli = 1000;
ff7b1510 64}
c801d85f 65
03f38c58 66wxTimer::~wxTimer()
c801d85f 67{
0470b1e6 68 wxTimer::Stop();
ff7b1510 69}
c801d85f 70
03f38c58 71bool wxTimer::Start( int millisecs, bool oneShot )
c801d85f 72{
0470b1e6 73 (void)wxTimerBase::Start(millisecs, oneShot);
03f38c58 74
574bf507
RR
75 if (m_tag != -1)
76 gtk_timeout_remove( m_tag );
77
0470b1e6 78 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
03f38c58 79
83624f79 80 return TRUE;
ff7b1510 81}
c801d85f 82
03f38c58 83void wxTimer::Stop()
c801d85f 84{
83624f79
RR
85 if (m_tag != -1)
86 {
87 gtk_timeout_remove( m_tag );
88 m_tag = -1;
89 }
ff7b1510 90}
c801d85f 91
1e6feb95
VZ
92#endif // wxUSE_TIMER
93