wxTimer/timercmn.cpp change

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4528 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-11-12 19:19:38 +00:00
parent 97d3f0eee6
commit 0470b1e6fe
15 changed files with 480 additions and 388 deletions

View File

@@ -12,41 +12,26 @@
#define __GTKTIMERH__
#ifdef __GNUG__
#pragma interface
#pragma interface "timer.h"
#endif
#include "wx/defs.h"
#include "wx/object.h"
//-----------------------------------------------------------------------------
// derived classes
//-----------------------------------------------------------------------------
class wxTimer;
//-----------------------------------------------------------------------------
// wxTimer
//-----------------------------------------------------------------------------
class wxTimer: public wxObject
class wxTimer : public wxTimerBase
{
public:
wxTimer();
~wxTimer();
int Interval() const { return m_time; }
bool OneShot() const { return m_oneShot; }
virtual bool Start( int millisecs = -1, bool oneShot = FALSE );
virtual void Stop();
virtual void Notify() = 0; // override this
virtual bool IsRunning() const { return m_tag != -1; }
protected:
int m_tag;
int m_time;
bool m_oneShot;
private:
DECLARE_ABSTRACT_CLASS(wxTimer)

View File

@@ -12,41 +12,26 @@
#define __GTKTIMERH__
#ifdef __GNUG__
#pragma interface
#pragma interface "timer.h"
#endif
#include "wx/defs.h"
#include "wx/object.h"
//-----------------------------------------------------------------------------
// derived classes
//-----------------------------------------------------------------------------
class wxTimer;
//-----------------------------------------------------------------------------
// wxTimer
//-----------------------------------------------------------------------------
class wxTimer: public wxObject
class wxTimer : public wxTimerBase
{
public:
wxTimer();
~wxTimer();
int Interval() const { return m_time; }
bool OneShot() const { return m_oneShot; }
virtual bool Start( int millisecs = -1, bool oneShot = FALSE );
virtual void Stop();
virtual void Notify() = 0; // override this
virtual bool IsRunning() const { return m_tag != -1; }
protected:
int m_tag;
int m_time;
bool m_oneShot;
private:
DECLARE_ABSTRACT_CLASS(wxTimer)

View File

@@ -13,36 +13,28 @@
#define _WX_TIMER_H_
#ifdef __GNUG__
#pragma interface "timer.h"
#pragma interface "timer.h"
#endif
#include "wx/object.h"
class WXDLLEXPORT wxTimer: public wxObject
class WXDLLEXPORT wxTimer : public wxTimerBase
{
DECLARE_DYNAMIC_CLASS(wxTimer)
friend void wxTimerCallback(wxTimer * timer);
friend void wxTimerCallback (wxTimer * timer);
public:
wxTimer();
~wxTimer();
public:
wxTimer();
~wxTimer();
virtual bool Start(int milliseconds = -1,bool one_shot = FALSE); // Start timer
virtual void Stop(); // Stop timer
virtual void Notify() = 0; // Override this member
inline int Interval() { return m_milli ; }; // Returns the current interval time (0 if stop)
virtual bool Start(int milliseconds = -1, bool oneShot = FALSE);
virtual void Stop();
virtual bool IsRunning() const { return m_id != 0; }
protected:
bool m_oneShot ;
int m_milli ;
int m_lastMilli ;
long m_id;
long m_id;
private:
DECLARE_DYNAMIC_CLASS(wxTimer)
};
/* Note: these are implemented in common/timercmn.cpp, so need to implement them separately.
* But you may need to modify timercmn.cpp.
*/
#endif
// _WX_TIMER_H_

View File

@@ -13,12 +13,10 @@
#define _WX_TIMER_H_
#ifdef __GNUG__
#pragma interface "timer.h"
#pragma interface "timer.h"
#endif
#include "wx/object.h"
class WXDLLEXPORT wxTimer : public wxObject
class WXDLLEXPORT wxTimer : public wxTimerBase
{
friend void wxProcessTimer(wxTimer& timer);
@@ -26,22 +24,13 @@ public:
wxTimer();
~wxTimer();
virtual bool Start(int milliseconds = -1,
bool one_shot = FALSE); // Start timer
virtual void Stop(); // Stop timer
virtual bool Start(int milliseconds = -1, bool oneShot = FALSE);
virtual void Stop();
virtual void Notify() = 0; // Override this member
// Returns the current interval time (0 if stop)
int Interval() const { return milli; };
bool OneShot() const { return oneShot; }
virtual bool IsRunning() const { return m_id != 0; }
protected:
bool oneShot;
int milli;
int lastMilli;
long id;
long m_id;
private:
DECLARE_ABSTRACT_CLASS(wxTimer)

View File

@@ -128,7 +128,7 @@
#ifdef StartDoc
#undef StartDoc
#ifdef __GNUWIN32__
#ifdef __GNUG__
#define DOCINFOW DOCINFO
#define DOCINFOA DOCINFO
#endif

View File

@@ -1,45 +1,139 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/timer.h
// Purpose: wxTimer class and global time-related functions
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TIMER_H_BASE_
#define _WX_TIMER_H_BASE_
#if defined(__WXMSW__)
#include "wx/msw/timer.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/timer.h"
#elif defined(__WXGTK__)
#include "wx/gtk/timer.h"
#elif defined(__WXQT__)
#include "wx/qt/timer.h"
#elif defined(__WXMAC__)
#include "wx/mac/timer.h"
#elif defined(__WXPM__)
#include "wx/os2/timer.h"
#elif defined(__WXSTUBS__)
#include "wx/stubs/timer.h"
#ifdef __GNUG__
#pragma interface "timerbase.h"
#endif
class WXDLLEXPORT wxChrono
#include "wx/object.h"
// ----------------------------------------------------------------------------
// wxTimer
// ----------------------------------------------------------------------------
// the interface of wxTimer class
class WXDLLEXPORT wxTimerBase : public wxObject
{
public:
wxChrono();
void Start(long t=0);
void Pause();
void Resume();
public:
wxTimerBase() { m_oneShot = FALSE; m_milli = 0; }
long Time();
// working with the timer
// ----------------------
private:
long m_t0;
long m_pause;
// start the timer: if milliseconds == -1, use the same value as for the
// last Start()
virtual bool Start(int milliseconds = -1, bool oneShot = FALSE)
{
if ( milliseconds != -1 )
{
m_milli = milliseconds;
}
m_oneShot = oneShot;
return TRUE;
}
// stop the timer
virtual void Stop() = 0;
// override this in your wxTimer-derived class
virtual void Notify() = 0;
// 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:
int m_milli; // the timer interval
bool m_oneShot; // TRUE if one shot
};
// Timer functions (milliseconds)
#if defined(__WXMSW__)
#include "wx/msw/timer.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/timer.h"
#elif defined(__WXGTK__)
#include "wx/gtk/timer.h"
#elif defined(__WXQT__)
#include "wx/qt/timer.h"
#elif defined(__WXMAC__)
#include "wx/mac/timer.h"
#elif defined(__WXPM__)
#include "wx/os2/timer.h"
#elif defined(__WXSTUBS__)
#include "wx/stubs/timer.h"
#endif
// ----------------------------------------------------------------------------
// wxStopWatch
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxStopWatch
{
public:
// ctor starts the stop watch
wxStopWatch() { Start(); }
void Start(long t = 0); // (re)start it t milliseconds ago
inline void Pause();
void Resume() { Start(m_pause); }
// get the elapsed time since the last Start() or Pause() in milliseconds
long Time() const;
protected:
// returns the elapsed time since t0
inline long GetElapsedTime() const;
private:
long m_t0; // the time of the last Start()
long m_pause; // the time of the last Pause() or 0
};
// the old name
#ifdef WXWIN_COMPATIBILITY_2
typedef wxStopWatch wxChrono;
#endif // WXWIN_COMPATIBILITY_2
// ----------------------------------------------------------------------------
// global time functions
// ----------------------------------------------------------------------------
// Timer functions (milliseconds) -- use wxStopWatch instead
void WXDLLEXPORT wxStartTimer();
// Gets time since last wxStartTimer or wxGetElapsedTime
// Gets time since last wxStartTimer or wxGetElapsedTime -- use wxStopWatch
// instead
long WXDLLEXPORT wxGetElapsedTime(bool resetTimer = TRUE);
// EXPERIMENTAL: comment this out if it doesn't compile.
// Get the local time
bool WXDLLEXPORT wxGetLocalTime(long *timeZone, int *dstObserved);
// Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
@@ -48,5 +142,19 @@ long WXDLLEXPORT wxGetCurrentTime();
// Get number of milliseconds since 00:00:00 GMT, Jan 1st 1970.
long WXDLLEXPORT wxGetCurrentMTime();
// ----------------------------------------------------------------------------
// inline functions
// ----------------------------------------------------------------------------
inline long wxStopWatch::GetElapsedTime() const
{
return wxGetCurrentMTime() - m_t0;
}
inline void wxStopWatch::Pause()
{
m_pause = GetElapsedTime();
}
#endif
// _WX_TIMER_H_BASE_