]>
Commit | Line | Data |
---|---|---|
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 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) | |
31 | ||
32 | static wxList wxTimerList(wxKEY_INTEGER); | |
33 | ||
34 | void wxTimerCallback (wxTimer * timer) | |
35 | { | |
36 | // Check to see if it's still on | |
37 | if (!wxTimerList.Find((long)timer)) | |
38 | return; | |
39 | ||
40 | if (timer->m_id == 0) | |
41 | return; // Avoid to process spurious timer events | |
42 | ||
43 | if (!timer->m_oneShot) | |
44 | timer->m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(), | |
45 | timer->m_milli, | |
46 | (XtTimerCallbackProc) wxTimerCallback, | |
47 | (XtPointer) timer); | |
48 | else | |
49 | timer->m_id = 0; | |
50 | ||
51 | timer->Notify(); | |
52 | } | |
53 | ||
54 | wxTimer::wxTimer() | |
55 | { | |
56 | m_id = 0; | |
57 | } | |
58 | ||
59 | wxTimer::~wxTimer() | |
60 | { | |
61 | wxTimer::Stop(); | |
62 | wxTimerList.DeleteObject(this); | |
63 | } | |
64 | ||
65 | bool wxTimer::Start(int milliseconds, bool mode) | |
66 | { | |
67 | Stop(); | |
68 | ||
69 | (void)wxTimerBase::Start(milliseconds, mode); | |
70 | ||
71 | if (!wxTimerList.Find((long)this)) | |
72 | wxTimerList.Append((long)this, this); | |
73 | ||
74 | m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(), | |
75 | m_milli, | |
76 | (XtTimerCallbackProc) wxTimerCallback, | |
77 | (XtPointer) this); | |
78 | return TRUE; | |
79 | } | |
80 | ||
81 | void wxTimer::Stop() | |
82 | { | |
83 | if (m_id > 0) | |
84 | { | |
85 | XtRemoveTimeOut (m_id); | |
86 | m_id = 0; | |
87 | } | |
88 | m_milli = 0 ; | |
89 | } | |
90 | ||
91 |