]> git.saurik.com Git - wxWidgets.git/blob - src/motif/timer.cpp
Added function GetDefaultSize
[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 wxTimerList.DeleteObject(this);
59 }
60
61 bool wxTimer::Start(int milliseconds, bool mode)
62 {
63 Stop();
64
65 m_oneShot = mode;
66 if (milliseconds < 0)
67 milliseconds = m_lastMilli;
68
69 if (milliseconds <= 0)
70 return FALSE;
71
72 m_lastMilli = m_milli = milliseconds;
73
74 if (!wxTimerList.Find((long)this))
75 wxTimerList.Append((long)this, this);
76
77 m_id = XtAppAddTimeOut ((XtAppContext) wxTheApp->GetAppContext(), milliseconds,
78 (XtTimerCallbackProc) wxTimerCallback, (XtPointer) this);
79 return TRUE;
80 }
81
82 void wxTimer::Stop()
83 {
84 if (m_id > 0)
85 {
86 XtRemoveTimeOut (m_id);
87 m_id = 0;
88 }
89 m_milli = 0 ;
90 }
91
92