]> git.saurik.com Git - wxWidgets.git/blob - src/motif/timer.cpp
Applied patch [ 1443707 ] kill "cast truncates constant value" warnings
[wxWidgets.git] / src / motif / timer.cpp
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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/timer.h"
16 #include "wx/app.h"
17 #include "wx/hashmap.h"
18
19 #ifdef __VMS__
20 #pragma message disable nosimpint
21 #endif
22 #include <Xm/Xm.h>
23 #ifdef __VMS__
24 #pragma message enable nosimpint
25 #endif
26
27 #include "wx/motif/private.h"
28
29 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
30
31 WX_DECLARE_VOIDPTR_HASH_MAP(wxTimer*, wxTimerHashMap);
32
33 static wxTimerHashMap s_timers;
34
35 void wxTimerCallback (wxTimer * timer)
36 {
37 // Check to see if it's still on
38 if (s_timers.find(timer) == s_timers.end())
39 return;
40
41 if (timer->m_id == 0)
42 return; // Avoid to process spurious timer events
43
44 if (!timer->m_oneShot)
45 timer->m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(),
46 timer->m_milli,
47 (XtTimerCallbackProc) wxTimerCallback,
48 (XtPointer) timer);
49 else
50 timer->m_id = 0;
51
52 timer->Notify();
53 }
54
55 void wxTimer::Init()
56 {
57 m_id = 0;
58 m_milli = 1000;
59 }
60
61 wxTimer::~wxTimer()
62 {
63 Stop();
64 s_timers.erase(this);
65 }
66
67 bool wxTimer::Start(int milliseconds, bool mode)
68 {
69 Stop();
70
71 (void)wxTimerBase::Start(milliseconds, mode);
72
73 if (s_timers.find(this) == s_timers.end())
74 s_timers[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