timer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/private/timer.h
  3. // Purpose: Base class for wxTimer implementations
  4. // Author: Lukasz Michalski <lmichalski@sf.net>
  5. // Created: 31.10.2006
  6. // Copyright: (c) 2006-2007 wxWidgets dev team
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_TIMERIMPL_H_BASE_
  10. #define _WX_TIMERIMPL_H_BASE_
  11. #include "wx/defs.h"
  12. #include "wx/event.h"
  13. #include "wx/timer.h"
  14. // ----------------------------------------------------------------------------
  15. // wxTimerImpl: abstract base class for wxTimer implementations
  16. // ----------------------------------------------------------------------------
  17. class WXDLLIMPEXP_BASE wxTimerImpl
  18. {
  19. public:
  20. // default ctor, SetOwner() must be called after it (wxTimer does it)
  21. wxTimerImpl(wxTimer *owner);
  22. // this must be called initially but may be also called later
  23. void SetOwner(wxEvtHandler *owner, int timerid);
  24. // empty but virtual base class dtor, the caller is responsible for
  25. // stopping the timer before it's destroyed (it can't be done from here as
  26. // it's too late)
  27. virtual ~wxTimerImpl() { }
  28. // start the timer. When overriding call base version first.
  29. virtual bool Start(int milliseconds = -1, bool oneShot = false);
  30. // stop the timer, only called if the timer is really running (unlike
  31. // wxTimer::Stop())
  32. virtual void Stop() = 0;
  33. // return true if the timer is running
  34. virtual bool IsRunning() const = 0;
  35. // this should be called by the port-specific code when the timer expires
  36. virtual void Notify() { m_timer->Notify(); }
  37. // the default implementation of wxTimer::Notify(): generate a wxEVT_TIMER
  38. void SendEvent();
  39. // accessors for wxTimer:
  40. wxEvtHandler *GetOwner() const { return m_owner; }
  41. int GetId() const { return m_idTimer; }
  42. int GetInterval() const { return m_milli; }
  43. bool IsOneShot() const { return m_oneShot; }
  44. protected:
  45. wxTimer *m_timer;
  46. wxEvtHandler *m_owner;
  47. int m_idTimer; // id passed to wxTimerEvent
  48. int m_milli; // the timer interval
  49. bool m_oneShot; // true if one shot
  50. wxDECLARE_NO_COPY_CLASS(wxTimerImpl);
  51. };
  52. #endif // _WX_TIMERIMPL_H_BASE_