X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4bb6408c2631988fab9925014c6619358bf867de..9d8fe14a97d1092989eecbe43c4e1f730fba17ad:/src/motif/timer.cpp?ds=sidebyside diff --git a/src/motif/timer.cpp b/src/motif/timer.cpp index bca8e00e0c..fb6815fc06 100644 --- a/src/motif/timer.cpp +++ b/src/motif/timer.cpp @@ -1,52 +1,94 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: timer.cpp +// Name: src/motif/timer.cpp // Purpose: wxTimer implementation // Author: Julian Smart // Modified by: // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "timer.h" -#endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#include "wx/motif/private/timer.h" -#include "wx/timer.h" +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/hashmap.h" +#endif -#if !USE_SHARED_LIBRARY -IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) +#ifdef __VMS__ +#pragma message disable nosimpint #endif +#include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif + +#include "wx/motif/private.h" -wxTimer::wxTimer() +WX_DECLARE_VOIDPTR_HASH_MAP(wxMotifTimerImpl*, wxTimerHashMap); + +static wxTimerHashMap gs_timers; + +void wxTimerCallback (wxMotifTimerImpl *timer) { - m_milli = 0 ; - m_id = 0; - m_oneShot = FALSE; + // Check to see if it's still on + if ( gs_timers.find(timer) == gs_timers.end() ) + return; + + if ( !timer->IsRunning() ) + return; // Avoid to process spurious timer events + + timer->Notify(); } -wxTimer::~wxTimer() +wxMotifTimerImpl::~wxMotifTimerImpl() { - Stop(); + gs_timers.erase(this); } -bool wxTimer::Start(int milliseconds,bool mode) +void wxMotifTimerImpl::DoStart() { - m_oneShot = mode ; - if (milliseconds <= 0) - return FALSE; + m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(), + m_milli, + (XtTimerCallbackProc) wxTimerCallback, + (XtPointer) this); +} + +bool wxMotifTimerImpl::Start(int milliseconds, bool mode) +{ + if ( !wxTimerImpl::Start(milliseconds, mode) ) + return false; + + if ( gs_timers.find(this) == gs_timers.end() ) + gs_timers[this] = this; - m_milli = milliseconds; + DoStart(); - // TODO: set the timer going. - return FALSE; + return true; } -void wxTimer::Stop() +void wxMotifTimerImpl::Stop() { - m_id = 0 ; - m_milli = 0 ; + XtRemoveTimeOut (m_id); + m_id = 0; } +void wxMotifTimerImpl::Notify() +{ + if ( IsOneShot() ) + { + // nothing to do, timeout is removed automatically by X + m_id = 0; + } + else // rearm the timer + { + DoStart(); + } + + wxTimerImpl::Notify(); +}