1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-02-05 01:57:38 +00:00
|
|
|
// Name: gtk/timer.cpp
|
2001-06-26 20:59:19 +00:00
|
|
|
// Purpose: wxTimer implementation
|
1998-05-20 14:01:55 +00:00
|
|
|
// Author: Robert Roebling
|
1998-10-27 15:04:35 +00:00
|
|
|
// Id: $Id$
|
1998-10-24 17:12:05 +00:00
|
|
|
// Copyright: (c) 1998 Robert Roebling
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-08-09 12:46:53 +00:00
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
#if wxUSE_TIMER
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
#include "wx/timer.h"
|
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
#include "gtk/gtk.h"
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
// wxTimer
|
2001-06-26 20:59:19 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2004-05-10 20:53:25 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2005-03-21 23:42:26 +00:00
|
|
|
extern "C" {
|
|
|
|
static gint timeout_callback( gpointer data )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-01-02 19:13:25 +00:00
|
|
|
wxTimer *timer = (wxTimer*)data;
|
1999-10-01 13:21:34 +00:00
|
|
|
|
2003-06-19 19:06:06 +00:00
|
|
|
// Don't change the order of anything in this callback!
|
2006-01-14 18:32:37 +00:00
|
|
|
|
2003-06-19 19:06:06 +00:00
|
|
|
if (timer->IsOneShot())
|
|
|
|
{
|
|
|
|
// This sets m_tag to -1
|
|
|
|
timer->Stop();
|
|
|
|
}
|
2006-01-14 18:32:37 +00:00
|
|
|
|
2003-06-19 19:06:06 +00:00
|
|
|
// When getting called from GDK's timer handler we
|
|
|
|
// are no longer within GDK's grab on the GUI
|
|
|
|
// thread so we must lock it here ourselves.
|
1999-12-29 17:16:55 +00:00
|
|
|
gdk_threads_enter();
|
1999-10-01 13:21:34 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
timer->Notify();
|
1998-10-12 13:09:15 +00:00
|
|
|
|
2003-06-19 19:06:06 +00:00
|
|
|
// Release lock again.
|
1999-12-29 17:16:55 +00:00
|
|
|
gdk_threads_leave();
|
1999-06-18 14:18:47 +00:00
|
|
|
|
2003-06-19 19:06:06 +00:00
|
|
|
if (timer->IsOneShot())
|
1999-10-01 13:21:34 +00:00
|
|
|
return FALSE;
|
1998-10-12 13:09:15 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
return TRUE;
|
1998-08-16 19:39:29 +00:00
|
|
|
}
|
2005-03-21 23:42:26 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2000-02-05 01:57:38 +00:00
|
|
|
void wxTimer::Init()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-01-02 19:13:25 +00:00
|
|
|
m_tag = -1;
|
1999-11-12 19:19:38 +00:00
|
|
|
m_milli = 1000;
|
1998-08-16 19:39:29 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-10-12 13:09:15 +00:00
|
|
|
wxTimer::~wxTimer()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-11-12 19:19:38 +00:00
|
|
|
wxTimer::Stop();
|
1998-08-16 19:39:29 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-10-12 13:09:15 +00:00
|
|
|
bool wxTimer::Start( int millisecs, bool oneShot )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-11-12 19:19:38 +00:00
|
|
|
(void)wxTimerBase::Start(millisecs, oneShot);
|
1998-10-12 13:09:15 +00:00
|
|
|
|
2001-11-25 20:10:46 +00:00
|
|
|
if (m_tag != -1)
|
2006-02-03 22:22:27 +00:00
|
|
|
g_source_remove( m_tag );
|
2001-11-25 20:10:46 +00:00
|
|
|
|
2006-02-03 22:22:27 +00:00
|
|
|
m_tag = g_timeout_add( m_milli, timeout_callback, this );
|
1998-10-12 13:09:15 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
return TRUE;
|
1998-08-16 19:39:29 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-10-12 13:09:15 +00:00
|
|
|
void wxTimer::Stop()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-01-02 19:13:25 +00:00
|
|
|
if (m_tag != -1)
|
|
|
|
{
|
2006-02-03 22:22:27 +00:00
|
|
|
g_source_remove( m_tag );
|
1999-01-02 19:13:25 +00:00
|
|
|
m_tag = -1;
|
|
|
|
}
|
1998-08-16 19:39:29 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#endif // wxUSE_TIMER
|
|
|
|
|