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
|
1999-10-01 13:21:34 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "timer.h"
|
|
|
|
#endif
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2002-01-09 12:49:12 +00:00
|
|
|
extern "C" 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
|
|
|
|
1999-06-18 14:18:47 +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
|
|
|
|
1999-06-18 14:18:47 +00:00
|
|
|
/* release lock again */
|
1999-12-29 17:16:55 +00:00
|
|
|
gdk_threads_leave();
|
1999-06-18 14:18:47 +00:00
|
|
|
|
1999-11-12 19:19:38 +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
|
|
|
}
|
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)
|
|
|
|
gtk_timeout_remove( m_tag );
|
|
|
|
|
1999-11-12 19:19:38 +00:00
|
|
|
m_tag = gtk_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)
|
|
|
|
{
|
|
|
|
gtk_timeout_remove( m_tag );
|
|
|
|
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
|
|
|
|
|