]> git.saurik.com Git - wxWidgets.git/blob - src/motif/timer.cpp
Make mouse capture checking asserts stronger and more detailed.
[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 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #include "wx/motif/private/timer.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/app.h"
18 #include "wx/hashmap.h"
19 #endif
20
21 #ifdef __VMS__
22 #pragma message disable nosimpint
23 #endif
24 #include <Xm/Xm.h>
25 #ifdef __VMS__
26 #pragma message enable nosimpint
27 #endif
28
29 #include "wx/motif/private.h"
30
31 WX_DECLARE_VOIDPTR_HASH_MAP(wxMotifTimerImpl*, wxTimerHashMap);
32
33 static wxTimerHashMap gs_timers;
34
35 void wxTimerCallback (wxMotifTimerImpl *timer)
36 {
37 // Check to see if it's still on
38 if ( gs_timers.find(timer) == gs_timers.end() )
39 return;
40
41 if ( !timer->IsRunning() )
42 return; // Avoid to process spurious timer events
43
44 timer->Notify();
45 }
46
47 wxMotifTimerImpl::~wxMotifTimerImpl()
48 {
49 gs_timers.erase(this);
50 }
51
52 void wxMotifTimerImpl::DoStart()
53 {
54 m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(),
55 m_milli,
56 (XtTimerCallbackProc) wxTimerCallback,
57 (XtPointer) this);
58 }
59
60 bool wxMotifTimerImpl::Start(int milliseconds, bool mode)
61 {
62 if ( !wxTimerImpl::Start(milliseconds, mode) )
63 return false;
64
65 if ( gs_timers.find(this) == gs_timers.end() )
66 gs_timers[this] = this;
67
68 DoStart();
69
70 return true;
71 }
72
73 void wxMotifTimerImpl::Stop()
74 {
75 XtRemoveTimeOut (m_id);
76 m_id = 0;
77 }
78
79 void wxMotifTimerImpl::Notify()
80 {
81 if ( IsOneShot() )
82 {
83 // nothing to do, timeout is removed automatically by X
84 m_id = 0;
85 }
86 else // rearm the timer
87 {
88 DoStart();
89 }
90
91 wxTimerImpl::Notify();
92 }
93