X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3051a44a73502c2b03d1618d0a8e94274ee67e16..633e19307ce18ce24837db616feb9dda848056dd:/interface/wx/timer.h diff --git a/interface/wx/timer.h b/interface/wx/timer.h index 4b7d1fbb17..123c626fd6 100644 --- a/interface/wx/timer.h +++ b/interface/wx/timer.h @@ -3,9 +3,18 @@ // Purpose: interface of wxTimer // Author: wxWidgets team // RCS-ID: $Id$ -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// 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 + +wxEventType wxEVT_TIMER; + + /** @class wxTimer @@ -77,7 +86,7 @@ public: wxEvtHandler* GetOwner() const; /** - Returns @true if the timer is one shot, i.e. if it will stop after firing + Returns @true if the timer is one shot, i.e.\ if it will stop after firing the first notification automatically. */ bool IsOneShot() const; @@ -92,6 +101,10 @@ public: used and SetOwner() wasn't called. Perform whatever action which is to be taken periodically here. + + Notice that throwing exceptions from this method is currently not + supported, use event-based timer handling approach if an exception can + be thrown while handling timer notifications. */ virtual void Notify(); @@ -115,10 +128,21 @@ public: To make your code more readable you may also use the following symbolic constants: - wxTIMER_CONTINUOUS: Start a normal, continuously running, timer - wxTIMER_ONE_SHOT: Start a one shot timer + Alternatively, use StartOnce(). + If the timer was already running, it will be stopped by this method before restarting it. */ - virtual bool Start(int milliseconds = -1, bool oneShot = false); + virtual bool Start(int milliseconds = -1, bool oneShot = wxTIMER_CONTINUOUS); + + /** + Starts the timer for a once-only notification. + + This is a simple wrapper for Start() with @c wxTIMER_ONE_SHOT parameter. + + @since 2.9.5 + */ + bool StartOnce(int milliseconds = -1); /** Stops the timer. @@ -127,6 +151,19 @@ public: }; +/** + @class wxTimerRunner + + Starts the timer in its ctor, stops in the dtor. +*/ +class wxTimerRunner +{ +public: + wxTimerRunner(wxTimer& timer); + wxTimerRunner(wxTimer& timer, int milli, bool oneShot = false); + void Start(int milli, bool oneShot = false); + ~wxTimerRunner(); +}; /** @class wxTimerEvent @@ -145,11 +182,12 @@ public: private: wxTimer m_timer; + wxDECLARE_EVENT_TABLE(); }; - BEGIN_EVENT_TABLE(MyFrame, wxFrame) + wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_TIMER(TIMER_ID, MyFrame::OnTimer) - END_EVENT_TABLE() + wxEND_EVENT_TABLE() MyFrame::MyFrame() : m_timer(this, TIMER_ID) @@ -171,6 +209,9 @@ public: class wxTimerEvent : public wxEvent { public: + wxTimerEvent(); + wxTimerEvent(wxTimer& timer); + /** Returns the interval of the timer which generated this event. */