| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: timer.cpp |
| 3 | // Purpose: wxTimer implementation |
| 4 | // Author: Julian Smart |
| 5 | // Modified by: |
| 6 | // Created: 17/09/98 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Julian Smart |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifdef __GNUG__ |
| 13 | #pragma implementation "timer.h" |
| 14 | #endif |
| 15 | |
| 16 | #include "wx/timer.h" |
| 17 | #include "wx/app.h" |
| 18 | #include "wx/list.h" |
| 19 | |
| 20 | #ifdef __VMS__ |
| 21 | #pragma message disable nosimpint |
| 22 | #endif |
| 23 | #include <Xm/Xm.h> |
| 24 | #ifdef __VMS__ |
| 25 | #pragma message enable nosimpint |
| 26 | #endif |
| 27 | |
| 28 | #include "wx/motif/private.h" |
| 29 | |
| 30 | #if !USE_SHARED_LIBRARY |
| 31 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) |
| 32 | #endif |
| 33 | |
| 34 | static wxList wxTimerList(wxKEY_INTEGER); |
| 35 | |
| 36 | void wxTimerCallback (wxTimer * timer) |
| 37 | { |
| 38 | // Check to see if it's still on |
| 39 | if (!wxTimerList.Find((long)timer)) |
| 40 | return; |
| 41 | |
| 42 | if (timer->m_id == 0) |
| 43 | return; // Avoid to process spurious timer events |
| 44 | |
| 45 | if (!timer->m_oneShot) |
| 46 | timer->m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(), |
| 47 | timer->m_milli, |
| 48 | (XtTimerCallbackProc) wxTimerCallback, |
| 49 | (XtPointer) timer); |
| 50 | else |
| 51 | timer->m_id = 0; |
| 52 | |
| 53 | timer->Notify(); |
| 54 | } |
| 55 | |
| 56 | wxTimer::wxTimer() |
| 57 | { |
| 58 | m_id = 0; |
| 59 | } |
| 60 | |
| 61 | wxTimer::~wxTimer() |
| 62 | { |
| 63 | wxTimer::Stop(); |
| 64 | wxTimerList.DeleteObject(this); |
| 65 | } |
| 66 | |
| 67 | bool wxTimer::Start(int milliseconds, bool mode) |
| 68 | { |
| 69 | Stop(); |
| 70 | |
| 71 | (void)wxTimerBase::Start(milliseconds, mode); |
| 72 | |
| 73 | if (!wxTimerList.Find((long)this)) |
| 74 | wxTimerList.Append((long)this, this); |
| 75 | |
| 76 | m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(), |
| 77 | m_milli, |
| 78 | (XtTimerCallbackProc) wxTimerCallback, |
| 79 | (XtPointer) this); |
| 80 | return TRUE; |
| 81 | } |
| 82 | |
| 83 | void wxTimer::Stop() |
| 84 | { |
| 85 | if (m_id > 0) |
| 86 | { |
| 87 | XtRemoveTimeOut (m_id); |
| 88 | m_id = 0; |
| 89 | } |
| 90 | m_milli = 0 ; |
| 91 | } |
| 92 | |
| 93 | |