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