1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: timer.cpp
|
|
|
|
// Purpose:
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#include "wx/timer.h"
|
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
#include "gtk/gtk.h"
|
1999-01-08 20:33:18 +00:00
|
|
|
/*
|
|
|
|
#include "glib.h"
|
|
|
|
*/
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// global functions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
static GTimer *g_timer = (GTimer*) NULL;
|
|
|
|
|
|
|
|
void wxStartTimer()
|
|
|
|
{
|
|
|
|
if (g_timer)
|
|
|
|
{
|
|
|
|
g_timer_rest( g_timer );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_timer = g_timer_new();
|
|
|
|
g_timer_start( g_timer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long wxGetElapsedTime( bool resetTimer )
|
|
|
|
{
|
|
|
|
gulong res = 0;
|
|
|
|
if (g_timer)
|
|
|
|
{
|
|
|
|
g_timer_elapsed( g_timer, &res );
|
1999-10-01 13:21:34 +00:00
|
|
|
if (resetTimer) g_timer_reset( g_timer );
|
1999-01-08 20:33:18 +00:00
|
|
|
}
|
1999-10-01 13:21:34 +00:00
|
|
|
|
1999-01-08 20:33:18 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxGetLocalTime( long *timeZone, int *dstObserved )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
long wxGetCurrentTime()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxTimer
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1998-10-12 13:09:15 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-22 08:01:17 +00:00
|
|
|
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
|
|
|
|
1999-06-18 14:18:47 +00:00
|
|
|
#if (GTK_MINOR_VERSION > 0)
|
|
|
|
/* 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 */
|
|
|
|
GDK_THREADS_ENTER ();
|
|
|
|
#endif
|
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
|
|
|
#if (GTK_MINOR_VERSION > 0)
|
|
|
|
/* release lock again */
|
|
|
|
GDK_THREADS_LEAVE ();
|
|
|
|
#endif
|
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
if (timer->OneShot())
|
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
|
|
|
|
1998-10-12 13:09:15 +00:00
|
|
|
wxTimer::wxTimer()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-01-02 19:13:25 +00:00
|
|
|
m_tag = -1;
|
|
|
|
m_time = 1000;
|
|
|
|
m_oneShot = FALSE;
|
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-01-02 19:13:25 +00:00
|
|
|
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-01-02 19:13:25 +00:00
|
|
|
if (millisecs != -1)
|
|
|
|
{
|
|
|
|
m_time = millisecs;
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
m_oneShot = oneShot;
|
1998-10-12 13:09:15 +00:00
|
|
|
|
1999-01-02 19:13:25 +00:00
|
|
|
m_tag = gtk_timeout_add( millisecs, 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
|
|
|
|