More Motif stuff incl. beginnings of wxToolBar
[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 #ifdef __GNUG__
13 #pragma implementation "timer.h"
14 #endif
15
16 #include "wx/timer.h"
17 #include "wx/app.h"
18 #include "wx/list.h"
19
20 #include <Xm/Xm.h>
21
22 #include "wx/motif/private.h"
23
24 #if !USE_SHARED_LIBRARY
25 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
26 #endif
27
28 static wxList wxTimerList(wxKEY_INTEGER);
29
30 void wxTimerCallback (wxTimer * timer)
31 {
32 // Check to see if it's still on
33 if (!wxTimerList.Find((long)timer))
34 return;
35
36 if (timer->m_id == 0)
37 return; // Avoid to process spurious timer events
38
39 if (!timer->m_oneShot)
40 timer->m_id = XtAppAddTimeOut ((XtAppContext) wxTheApp->GetAppContext(), timer->m_milli,
41 (XtTimerCallbackProc) wxTimerCallback, (XtPointer) timer);
42 else
43 timer->m_id = 0;
44 timer->Notify ();
45 }
46
47 wxTimer::wxTimer()
48 {
49 m_id = 0;
50 m_milli = 0 ;
51 m_id = 0;
52 m_oneShot = FALSE;
53 }
54
55 wxTimer::~wxTimer()
56 {
57 Stop();
58 }
59
60 bool wxTimer::Start(int milliseconds, bool mode)
61 {
62 Stop();
63
64 m_oneShot = mode;
65 if (milliseconds < 0)
66 milliseconds = m_lastMilli;
67
68 if (milliseconds <= 0)
69 return FALSE;
70
71 m_lastMilli = m_milli = milliseconds;
72
73 if (!wxTimerList.Find((long)this))
74 wxTimerList.Append((long)this, this);
75
76 m_id = XtAppAddTimeOut ((XtAppContext) wxTheApp->GetAppContext(), milliseconds,
77 (XtTimerCallbackProc) wxTimerCallback, (XtPointer) this);
78 return TRUE;
79 }
80
81 void wxTimer::Stop()
82 {
83 if (m_id > 0)
84 {
85 XtRemoveTimeOut (m_id);
86 m_id = 0;
87 }
88 m_milli = 0 ;
89 }
90
91