fixed compilation error
[wxWidgets.git] / src / motif / timer.cpp
CommitLineData
4bb6408c
JS
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"
0d57be45
JS
17#include "wx/app.h"
18#include "wx/list.h"
19
20#include <Xm/Xm.h>
21
22#include "wx/motif/private.h"
4bb6408c
JS
23
24#if !USE_SHARED_LIBRARY
25IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
26#endif
27
0d57be45
JS
28static wxList wxTimerList(wxKEY_INTEGER);
29
30void 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
4bb6408c
JS
47wxTimer::wxTimer()
48{
0d57be45 49 m_id = 0;
4bb6408c
JS
50 m_milli = 0 ;
51 m_id = 0;
52 m_oneShot = FALSE;
53}
54
55wxTimer::~wxTimer()
56{
57 Stop();
1a3ac83f 58 wxTimerList.DeleteObject(this);
4bb6408c
JS
59}
60
0d57be45 61bool wxTimer::Start(int milliseconds, bool mode)
4bb6408c 62{
0d57be45
JS
63 Stop();
64
65 m_oneShot = mode;
66 if (milliseconds < 0)
67 milliseconds = m_lastMilli;
68
4bb6408c
JS
69 if (milliseconds <= 0)
70 return FALSE;
71
0d57be45
JS
72 m_lastMilli = m_milli = milliseconds;
73
74 if (!wxTimerList.Find((long)this))
75 wxTimerList.Append((long)this, this);
4bb6408c 76
0d57be45
JS
77 m_id = XtAppAddTimeOut ((XtAppContext) wxTheApp->GetAppContext(), milliseconds,
78 (XtTimerCallbackProc) wxTimerCallback, (XtPointer) this);
79 return TRUE;
4bb6408c
JS
80}
81
82void wxTimer::Stop()
83{
0d57be45
JS
84 if (m_id > 0)
85 {
86 XtRemoveTimeOut (m_id);
87 m_id = 0;
88 }
4bb6408c
JS
89 m_milli = 0 ;
90}
91
92