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