Include wx/hashmap.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / motif / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/timer.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/hashmap.h"
20 #endif
21
22 #ifdef __VMS__
23 #pragma message disable nosimpint
24 #endif
25 #include <Xm/Xm.h>
26 #ifdef __VMS__
27 #pragma message enable nosimpint
28 #endif
29
30 #include "wx/motif/private.h"
31
32 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
33
34 WX_DECLARE_VOIDPTR_HASH_MAP(wxTimer*, wxTimerHashMap);
35
36 static wxTimerHashMap s_timers;
37
38 void wxTimerCallback (wxTimer * timer)
39 {
40 // Check to see if it's still on
41 if (s_timers.find(timer) == s_timers.end())
42 return;
43
44 if (timer->m_id == 0)
45 return; // Avoid to process spurious timer events
46
47 if (!timer->m_oneShot)
48 timer->m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(),
49 timer->m_milli,
50 (XtTimerCallbackProc) wxTimerCallback,
51 (XtPointer) timer);
52 else
53 timer->m_id = 0;
54
55 timer->Notify();
56 }
57
58 void wxTimer::Init()
59 {
60 m_id = 0;
61 m_milli = 1000;
62 }
63
64 wxTimer::~wxTimer()
65 {
66 Stop();
67 s_timers.erase(this);
68 }
69
70 bool wxTimer::Start(int milliseconds, bool mode)
71 {
72 Stop();
73
74 (void)wxTimerBase::Start(milliseconds, mode);
75
76 if (s_timers.find(this) == s_timers.end())
77 s_timers[this] = this;
78
79 m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(),
80 m_milli,
81 (XtTimerCallbackProc) wxTimerCallback,
82 (XtPointer) this);
83 return true;
84 }
85
86 void wxTimer::Stop()
87 {
88 if (m_id > 0)
89 {
90 XtRemoveTimeOut (m_id);
91 m_id = 0;
92 }
93 m_milli = 0 ;
94 }