X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5ebdc86afc95a60fbeb0b2a71c38dd26c8a1b0b4..54a8f42b9d7111ab7ee7ccbcca8fcc6873906507:/src/common/timercmn.cpp diff --git a/src/common/timercmn.cpp b/src/common/timercmn.cpp index 6409e809e7..3d8db4c936 100644 --- a/src/common/timercmn.cpp +++ b/src/common/timercmn.cpp @@ -11,7 +11,7 @@ // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem // (c) 1999 Guillermo Rodriguez -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -57,6 +57,12 @@ #include #endif +// ---------------------------------------------------------------------------- +// wxWin macros +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxTimerEvent, wxEvent) + // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- @@ -72,11 +78,29 @@ #endif #endif // HAVE_GETTIMEOFDAY +// ---------------------------------------------------------------------------- +// prototypes +// ---------------------------------------------------------------------------- + +wxLongLong wxGetLocalTimeMillis(); + // ============================================================================ // implementation // ============================================================================ -wxLongLong wxGetLocalTimeMillis(); +// ---------------------------------------------------------------------------- +// wxTimerBase +// ---------------------------------------------------------------------------- + +void wxTimerBase::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.") ); + + wxTimerEvent event(m_idTimer, m_milli); + (void)m_owner->ProcessEvent(event); +} // ---------------------------------------------------------------------------- // wxStopWatch @@ -85,25 +109,24 @@ wxLongLong wxGetLocalTimeMillis(); void wxStopWatch::Start(long t) { m_t0 = wxGetLocalTimeMillis() - t; - m_pause = 0; } -long wxStopWatch::Time() const +long wxStopWatch::GetElapsedTime() const { - return (m_pause ? m_pause : GetElapsedTime()); + return (wxGetLocalTimeMillis() - m_t0).GetLo(); } -long wxStopWatch::GetElapsedTime() const +long wxStopWatch::Time() const { - return (wxGetLocalTimeMillis() - m_t0).GetLo(); + return (m_pause ? m_pause : GetElapsedTime()); } // ---------------------------------------------------------------------------- // old timer functions superceded by wxStopWatch // ---------------------------------------------------------------------------- -static wxLongLong wxStartTime = 0; +static wxLongLong wxStartTime = 0l; // starts the global timer void wxStartTimer() @@ -207,11 +230,22 @@ long wxGetUTCTime() // Get local time as milliseconds since 00:00:00, Jan 1st 1970 wxLongLong wxGetLocalTimeMillis() { + wxLongLong val = 1000l; + +#if defined(HAVE_GETTIMEOFDAY) + struct timeval tp; + if ( wxGetTimeOfDay(&tp, (struct timezone *)NULL) != -1 ) + { + val *= tp.tv_sec; + return (val + (tp.tv_usec / 1000)); + } +#else + // We use wxGetLocalTime() to get the seconds since // 00:00:00 Jan 1st 1970 and then whatever is available // to get millisecond resolution. - // - wxLongLong val = 1000 * wxGetLocalTime(); + // THIS LEADS TO A BUG SINCE REFERENCE TIME ARE DIFFERENT + val *= wxGetLocalTime(); // If we got here, do not fail even if we can't get // millisecond resolution. @@ -220,18 +254,19 @@ wxLongLong wxGetLocalTimeMillis() SYSTEMTIME st; ::GetLocalTime(&st); return (val + st.wMilliseconds); -#elif defined(HAVE_GETTIMEOFDAY) - struct timeval tp; - if ( wxGetTimeOfDay(&tp, (struct timezone *)NULL) != -1 ) - { - return (val + (tp.tv_usec / 1000)); - } +#elif defined(__VISAGECPP__) + DATETIME dt; + ::DosGetDateTime(&dt); + return (val + dt.hundredths*10); #elif defined(HAVE_FTIME) struct timeb tp; if ( ftime(&tp) == 0 ) { return (val + tp.millitm); } +#elif !defined(__BORLANDC__) && !(defined(__VISUALC__) && defined(__WIN16__)) + #warning "wxStopWatch will be up to second resolution!" +#endif #endif return val;