X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/46446cc2aa025f445815545b31552a509b5e3f7e..f7ed8c899f6c5806712cc4384d908d4bdb47a898:/src/common/timercmn.cpp diff --git a/src/common/timercmn.cpp b/src/common/timercmn.cpp index fc89d353ac..bb89232709 100644 --- a/src/common/timercmn.cpp +++ b/src/common/timercmn.cpp @@ -18,10 +18,6 @@ // wxWin headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "timerbase.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -32,9 +28,13 @@ #if wxUSE_TIMER #ifndef WX_PRECOMP - #include "wx/timer.h" + #include "wx/app.h" #endif +#include "wx/timer.h" +#include "wx/apptrait.h" +#include "wx/private/timer.h" + // ---------------------------------------------------------------------------- // wxWin macros // ---------------------------------------------------------------------------- @@ -45,46 +45,92 @@ IMPLEMENT_DYNAMIC_CLASS(wxTimerEvent, wxEvent) // wxTimerBase implementation // ============================================================================ -wxTimerBase::~wxTimerBase() +wxTimer::~wxTimer() +{ + Stop(); + + delete m_impl; +} + +void wxTimer::Init() +{ + wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; + m_impl = traits ? traits->CreateTimerImpl(this) : NULL; + if ( !m_impl ) + { + wxFAIL_MSG( _T("No timer implementation for this platform") ); + + } +} + +// ============================================================================ +// rest of wxTimer implementation forwarded to wxTimerImpl +// ============================================================================ + +void wxTimer::SetOwner(wxEvtHandler *owner, int timerid) { - // this destructor is required for Darwin + wxCHECK_RET( m_impl, _T("uninitialized timer") ); + + m_impl->SetOwner(owner, timerid); } -void wxTimerBase::Notify() +wxEvtHandler *wxTimer::GetOwner() const +{ + wxCHECK_MSG( m_impl, NULL, _T("uninitialized timer") ); + + return m_impl->GetOwner(); +} + +bool wxTimer::Start(int milliseconds, bool oneShot) +{ + wxCHECK_MSG( m_impl, false, _T("uninitialized timer") ); + + return m_impl->Start(milliseconds, oneShot); +} + +void wxTimer::Stop() +{ + wxCHECK_RET( m_impl, _T("uninitialized timer") ); + + if ( m_impl->IsRunning() ) + m_impl->Stop(); +} + +void wxTimer::Notify() { // the base class version generates an event if it has owner - which it // should because otherwise nobody can process timer events - wxCHECK_RET( m_owner, _T("wxTimer::Notify() should be overridden.") ); + wxCHECK_RET( GetOwner(), _T("wxTimer::Notify() should be overridden.") ); - wxTimerEvent event(m_idTimer, m_milli); - (void)m_owner->ProcessEvent(event); + m_impl->SendEvent(); } -bool wxTimerBase::Start(int milliseconds, bool oneShot) +bool wxTimer::IsRunning() const { - // under MSW timers only work when they're started from the main thread so - // let the caller know about it -#if wxUSE_THREADS - wxASSERT_MSG( wxThread::IsMain(), - _T("timer can only be started from the main thread") ); -#endif // wxUSE_THREADS - - 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(); - } + wxCHECK_MSG( m_impl, false, _T("uninitialized timer") ); - if ( milliseconds != -1 ) - { - m_milli = milliseconds; - } + return m_impl->IsRunning(); +} + +int wxTimer::GetId() const +{ + wxCHECK_MSG( m_impl, wxID_ANY, _T("uninitialized timer") ); + + return m_impl->GetId(); +} - m_oneShot = oneShot; +int wxTimer::GetInterval() const +{ + wxCHECK_MSG( m_impl, -1, _T("uninitialized timer") ); + + return m_impl->GetInterval(); +} + +bool wxTimer::IsOneShot() const +{ + wxCHECK_MSG( m_impl, false, _T("uninitialized timer") ); - return TRUE; + return m_impl->IsOneShot(); } #endif // wxUSE_TIMER