]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
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 | |
65571936 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
4bb6408c JS |
13 | #pragma implementation "timer.h" |
14 | #endif | |
15 | ||
1248b41f MB |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
4bb6408c | 19 | #include "wx/timer.h" |
0d57be45 | 20 | #include "wx/app.h" |
4410d619 | 21 | #include "wx/hashmap.h" |
0d57be45 | 22 | |
338dd992 JJ |
23 | #ifdef __VMS__ |
24 | #pragma message disable nosimpint | |
25 | #endif | |
0d57be45 | 26 | #include <Xm/Xm.h> |
338dd992 JJ |
27 | #ifdef __VMS__ |
28 | #pragma message enable nosimpint | |
29 | #endif | |
0d57be45 JS |
30 | |
31 | #include "wx/motif/private.h" | |
4bb6408c | 32 | |
313feadc | 33 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler); |
4bb6408c | 34 | |
4410d619 MB |
35 | WX_DECLARE_VOIDPTR_HASH_MAP(wxTimer*, wxTimerHashMap); |
36 | ||
37 | static wxTimerHashMap s_timers; | |
0d57be45 JS |
38 | |
39 | void wxTimerCallback (wxTimer * timer) | |
40 | { | |
41 | // Check to see if it's still on | |
4410d619 | 42 | if (s_timers.find(timer) == s_timers.end()) |
0d57be45 JS |
43 | return; |
44 | ||
45 | if (timer->m_id == 0) | |
46 | return; // Avoid to process spurious timer events | |
47 | ||
48 | if (!timer->m_oneShot) | |
0470b1e6 VZ |
49 | timer->m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(), |
50 | timer->m_milli, | |
51 | (XtTimerCallbackProc) wxTimerCallback, | |
52 | (XtPointer) timer); | |
0d57be45 JS |
53 | else |
54 | timer->m_id = 0; | |
0470b1e6 VZ |
55 | |
56 | timer->Notify(); | |
0d57be45 JS |
57 | } |
58 | ||
b3ddc4c2 | 59 | void wxTimer::Init() |
4bb6408c | 60 | { |
0d57be45 | 61 | m_id = 0; |
b3ddc4c2 | 62 | m_milli = 1000; |
4bb6408c JS |
63 | } |
64 | ||
65 | wxTimer::~wxTimer() | |
66 | { | |
4410d619 MB |
67 | Stop(); |
68 | s_timers.erase(this); | |
4bb6408c JS |
69 | } |
70 | ||
0d57be45 | 71 | bool wxTimer::Start(int milliseconds, bool mode) |
4bb6408c | 72 | { |
0d57be45 JS |
73 | Stop(); |
74 | ||
0470b1e6 | 75 | (void)wxTimerBase::Start(milliseconds, mode); |
0d57be45 | 76 | |
4410d619 MB |
77 | if (s_timers.find(this) == s_timers.end()) |
78 | s_timers[this] = this; | |
4bb6408c | 79 | |
0470b1e6 VZ |
80 | m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(), |
81 | m_milli, | |
82 | (XtTimerCallbackProc) wxTimerCallback, | |
83 | (XtPointer) this); | |
96be256b | 84 | return true; |
4bb6408c JS |
85 | } |
86 | ||
87 | void wxTimer::Stop() | |
88 | { | |
0d57be45 JS |
89 | if (m_id > 0) |
90 | { | |
91 | XtRemoveTimeOut (m_id); | |
92 | m_id = 0; | |
93 | } | |
4bb6408c JS |
94 | m_milli = 0 ; |
95 | } | |
96 | ||
97 |