From 99646f7ee4afb3d7d929e1d396e56de8c1aed622 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 13 Sep 2000 09:04:48 +0000 Subject: [PATCH] wxTimer::Start() now calls Stop() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8347 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/timer.tex | 3 +++ include/wx/timer.h | 16 ++++------------ src/common/timercmn.cpp | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/docs/latex/wx/timer.tex b/docs/latex/wx/timer.tex index 62ddfb3f1a..97939eb2ba 100644 --- a/docs/latex/wx/timer.tex +++ b/docs/latex/wx/timer.tex @@ -101,6 +101,9 @@ If {\it oneShot} is FALSE (the default), the \helpref{Notify}{wxtimernotify} function will be called repeatedly until the timer is stopped. If TRUE, it will be called only once and the timer will stop automatically. +If the timer was already running, it will be stopped by this method before +restarting it. + \membersection{wxTimer::Stop}\label{wxtimerstop} \func{void}{Stop}{\void} diff --git a/include/wx/timer.h b/include/wx/timer.h index 7ea894d04a..8c1724df97 100644 --- a/include/wx/timer.h +++ b/include/wx/timer.h @@ -54,18 +54,10 @@ public: // 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; - } - + // + // 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); // stop the timer virtual void Stop() = 0; diff --git a/src/common/timercmn.cpp b/src/common/timercmn.cpp index f1173ff163..e90b5fd4ad 100644 --- a/src/common/timercmn.cpp +++ b/src/common/timercmn.cpp @@ -115,6 +115,26 @@ void wxTimerBase::Notify() (void)m_owner->ProcessEvent(event); } +bool wxTimerBase::Start(int milliseconds, bool oneShot) +{ + if ( IsRunning() ) + { + // not stopping the already running timer might work for some + // platforms (no problems under MSW) but leads to mysterious crashes + // on the others (GTK), so to be on the safe side do it here + Stop(); + } + + if ( milliseconds != -1 ) + { + m_milli = milliseconds; + } + + m_oneShot = oneShot; + + return TRUE; +} + #endif // wxUSE_GUI // ---------------------------------------------------------------------------- -- 2.45.2