1999-11-12 14:19:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/timer.h
|
2000-02-04 20:57:38 -05:00
|
|
|
// Purpose: wxTimer, wxStopWatch and global time-related functions
|
|
|
|
// Author: Julian Smart (wxTimer), Sylvain Bougnoux (wxStopWatch)
|
|
|
|
// Modified by: Vadim Zeitlin (wxTimerBase)
|
|
|
|
// Guillermo Rodriguez (global clean up)
|
1999-11-12 14:19:38 -05:00
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2000-02-04 20:57:38 -05:00
|
|
|
// Copyright: (c) wxWindows team
|
2003-03-17 05:34:04 -05:00
|
|
|
// Licence: wxWindows licence
|
1999-11-12 14:19:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-14 20:23:28 -04:00
|
|
|
#ifndef _WX_TIMER_H_BASE_
|
|
|
|
#define _WX_TIMER_H_BASE_
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-08-31 07:29:13 -04:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
1999-11-12 14:19:38 -05:00
|
|
|
#pragma interface "timerbase.h"
|
|
|
|
#endif
|
|
|
|
|
1999-12-16 20:28:44 -05:00
|
|
|
#include "wx/setup.h"
|
1999-11-12 14:19:38 -05:00
|
|
|
#include "wx/object.h"
|
1999-12-16 20:28:44 -05:00
|
|
|
#include "wx/longlong.h"
|
2000-02-04 20:57:38 -05:00
|
|
|
#include "wx/event.h"
|
1999-11-12 14:19:38 -05:00
|
|
|
|
2003-06-25 19:49:45 -04:00
|
|
|
#include "wx/stopwatch.h" // for backwards compatibility
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#if wxUSE_GUI && wxUSE_TIMER
|
2000-02-25 11:21:53 -05:00
|
|
|
|
1999-11-12 14:19:38 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTimer
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2002-06-04 10:59:52 -04:00
|
|
|
// more readable flags for Start():
|
|
|
|
|
|
|
|
// generate notifications periodically until the timer is stopped (default)
|
|
|
|
#define wxTIMER_CONTINUOUS FALSE
|
|
|
|
|
|
|
|
// only send the notification once and then stop the timer
|
|
|
|
#define wxTIMER_ONE_SHOT TRUE
|
|
|
|
|
1999-11-12 14:19:38 -05:00
|
|
|
// the interface of wxTimer class
|
2003-06-16 08:31:45 -04:00
|
|
|
class WXDLLEXPORT wxTimerBase : public wxEvtHandler
|
1999-11-12 14:19:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2000-02-04 20:57:38 -05:00
|
|
|
// ctors and initializers
|
|
|
|
// ----------------------
|
|
|
|
|
|
|
|
// default: if you don't call SetOwner(), your only chance to get timer
|
|
|
|
// notifications is to override Notify() in the derived class
|
2003-06-16 08:31:45 -04:00
|
|
|
wxTimerBase() { Init(); SetOwner(this); }
|
2000-02-04 20:57:38 -05:00
|
|
|
|
|
|
|
// ctor which allows to avoid having to override Notify() in the derived
|
|
|
|
// class: the owner will get timer notifications which can be handled with
|
|
|
|
// EVT_TIMER
|
|
|
|
wxTimerBase(wxEvtHandler *owner, int id = -1)
|
2000-02-09 12:51:16 -05:00
|
|
|
{ Init(); SetOwner(owner, id); }
|
2000-02-04 20:57:38 -05:00
|
|
|
|
|
|
|
// same as ctor above
|
|
|
|
void SetOwner(wxEvtHandler *owner, int id = -1)
|
|
|
|
{ m_owner = owner; m_idTimer = id; }
|
1999-11-12 14:19:38 -05:00
|
|
|
|
2002-01-07 16:52:28 -05:00
|
|
|
virtual ~wxTimerBase();
|
2001-02-15 16:51:14 -05:00
|
|
|
|
1999-11-12 14:19:38 -05:00
|
|
|
// working with the timer
|
|
|
|
// ----------------------
|
|
|
|
|
|
|
|
// start the timer: if milliseconds == -1, use the same value as for the
|
|
|
|
// last Start()
|
2000-09-13 05:04:48 -04:00
|
|
|
//
|
|
|
|
// it is now valid to call Start() multiple times: this just restarts the
|
|
|
|
// timer if it is already running
|
|
|
|
virtual bool Start(int milliseconds = -1, bool oneShot = FALSE);
|
1999-11-12 14:19:38 -05:00
|
|
|
|
|
|
|
// stop the timer
|
|
|
|
virtual void Stop() = 0;
|
|
|
|
|
2000-02-04 20:57:38 -05:00
|
|
|
// override this in your wxTimer-derived class if you want to process timer
|
|
|
|
// messages in it, use non default ctor or SetOwner() otherwise
|
|
|
|
virtual void Notify();
|
1999-11-12 14:19:38 -05:00
|
|
|
|
|
|
|
// getting info
|
|
|
|
// ------------
|
|
|
|
|
|
|
|
// return TRUE if the timer is running
|
|
|
|
virtual bool IsRunning() const = 0;
|
|
|
|
|
|
|
|
// get the (last) timer interval in the milliseconds
|
|
|
|
int GetInterval() const { return m_milli; }
|
|
|
|
|
|
|
|
// return TRUE if the timer is one shot
|
|
|
|
bool IsOneShot() const { return m_oneShot; }
|
|
|
|
|
|
|
|
#if WXWIN_COMPATIBILITY_2
|
|
|
|
// deprecated functions
|
|
|
|
int Interval() const { return GetInterval(); };
|
|
|
|
bool OneShot() const { return IsOneShot(); }
|
|
|
|
#endif // WXWIN_COMPATIBILITY_2
|
|
|
|
|
|
|
|
protected:
|
2000-02-04 20:57:38 -05:00
|
|
|
// common part of all ctors
|
|
|
|
void Init() { m_oneShot = FALSE; m_milli = 0; }
|
|
|
|
|
|
|
|
wxEvtHandler *m_owner;
|
|
|
|
int m_idTimer;
|
|
|
|
|
1999-11-12 14:19:38 -05:00
|
|
|
int m_milli; // the timer interval
|
|
|
|
bool m_oneShot; // TRUE if one shot
|
2003-01-02 18:38:11 -05:00
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(wxTimerBase)
|
1999-11-12 14:19:38 -05:00
|
|
|
};
|
|
|
|
|
2000-02-04 20:57:38 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTimer itself
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-07-10 10:15:17 -04:00
|
|
|
#if defined(__WXMSW__)
|
1999-11-12 14:19:38 -05:00
|
|
|
#include "wx/msw/timer.h"
|
1998-07-10 10:15:17 -04:00
|
|
|
#elif defined(__WXMOTIF__)
|
1999-11-12 14:19:38 -05:00
|
|
|
#include "wx/motif/timer.h"
|
1998-07-10 10:15:17 -04:00
|
|
|
#elif defined(__WXGTK__)
|
1999-11-12 14:19:38 -05:00
|
|
|
#include "wx/gtk/timer.h"
|
2003-03-22 01:07:53 -05:00
|
|
|
#elif defined(__WXX11__) || defined(__WXMGL__) || defined(__WXCOCOA__)
|
2002-02-17 09:57:33 -05:00
|
|
|
#include "wx/generic/timer.h"
|
1998-08-14 20:23:28 -04:00
|
|
|
#elif defined(__WXMAC__)
|
1999-11-12 14:19:38 -05:00
|
|
|
#include "wx/mac/timer.h"
|
1999-07-27 23:38:12 -04:00
|
|
|
#elif defined(__WXPM__)
|
1999-11-12 14:19:38 -05:00
|
|
|
#include "wx/os2/timer.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
2000-02-25 11:21:53 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTimerRunner: starts the timer in its ctor, stops in the dtor
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxTimerRunner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxTimerRunner(wxTimer& timer) : m_timer(timer) { }
|
|
|
|
wxTimerRunner(wxTimer& timer, int milli, bool oneShot = FALSE)
|
|
|
|
: m_timer(timer)
|
|
|
|
{
|
|
|
|
m_timer.Start(milli, oneShot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Start(int milli, bool oneShot = FALSE)
|
|
|
|
{
|
|
|
|
m_timer.Start(milli, oneShot);
|
|
|
|
}
|
|
|
|
|
|
|
|
~wxTimerRunner()
|
|
|
|
{
|
|
|
|
if ( m_timer.IsRunning() )
|
|
|
|
{
|
|
|
|
m_timer.Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxTimer& m_timer;
|
2003-07-21 20:24:07 -04:00
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(wxTimerRunner)
|
2000-02-25 11:21:53 -05:00
|
|
|
};
|
|
|
|
|
1999-11-12 14:19:38 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2000-02-04 20:57:38 -05:00
|
|
|
// wxTimerEvent
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxTimerEvent : public wxEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxTimerEvent(int id = 0, int interval = 0) : wxEvent(id)
|
|
|
|
{
|
|
|
|
m_eventType = wxEVT_TIMER;
|
|
|
|
|
|
|
|
m_interval = interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accessors
|
|
|
|
int GetInterval() const { return m_interval; }
|
|
|
|
|
2001-11-21 16:44:52 -05:00
|
|
|
// implement the base class pure virtual
|
|
|
|
virtual wxEvent *Clone() const { return new wxTimerEvent(*this); }
|
|
|
|
|
2000-02-04 20:57:38 -05:00
|
|
|
private:
|
|
|
|
int m_interval;
|
|
|
|
|
2003-07-21 20:24:07 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxTimerEvent)
|
2000-02-04 20:57:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (wxEvtHandler::*wxTimerEventFunction)(wxTimerEvent&);
|
|
|
|
|
2001-01-26 12:35:36 -05:00
|
|
|
#define EVT_TIMER(id, func) \
|
2001-01-31 12:16:40 -05:00
|
|
|
DECLARE_EVENT_TABLE_ENTRY( wxEVT_TIMER, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTimerEventFunction) & func, NULL),
|
2000-02-04 20:57:38 -05:00
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#endif // wxUSE_GUI && wxUSE_TIMER
|
2000-02-25 11:21:53 -05:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
1998-08-14 20:23:28 -04:00
|
|
|
// _WX_TIMER_H_BASE_
|