]> git.saurik.com Git - wxWidgets.git/blob - src/motif/timer.cpp
cleanup
[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/motif/private/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 WX_DECLARE_VOIDPTR_HASH_MAP(wxMotifTimerImpl*, wxTimerHashMap);
33
34 static wxTimerHashMap gs_timers;
35
36 void wxTimerCallback (wxMotifTimerImpl *timer)
37 {
38 // Check to see if it's still on
39 if ( gs_timers.find(timer) == gs_timers.end() )
40 return;
41
42 if ( !timer->IsRunning() )
43 return; // Avoid to process spurious timer events
44
45 timer->Notify();
46 }
47
48 wxMotifTimerImpl::~wxMotifTimerImpl()
49 {
50 gs_timers.erase(this);
51 }
52
53 void wxMotifTimerImpl::DoStart()
54 {
55 m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(),
56 m_milli,
57 (XtTimerCallbackProc) wxTimerCallback,
58 (XtPointer) this);
59 }
60
61 bool wxMotifTimerImpl::Start(int milliseconds, bool mode)
62 {
63 if ( !wxTimerImpl::Start(milliseconds, mode) )
64 return false;
65
66 if ( gs_timers.find(this) == gs_timers.end() )
67 gs_timers[this] = this;
68
69 DoStart();
70
71 return true;
72 }
73
74 void wxMotifTimerImpl::Stop()
75 {
76 XtRemoveTimeOut (m_id);
77 m_id = 0;
78 }
79
80 void wxMotifTimerImpl::Notify()
81 {
82 if ( IsOneShot() )
83 {
84 // nothing to do, timeout is removed automatically by X
85 m_id = 0;
86 }
87 else // rearm the timer
88 {
89 DoStart();
90 }
91
92 wxTimerImpl::Notify();
93 }
94