]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/timer.cpp
libpng vulnerability CAN-2004-0421
[wxWidgets.git] / src / motif / timer.cpp
... / ...
CommitLineData
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#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13#pragma implementation "timer.h"
14#endif
15
16#include "wx/timer.h"
17#include "wx/app.h"
18#include "wx/hashmap.h"
19
20#ifdef __VMS__
21#pragma message disable nosimpint
22#endif
23#include <Xm/Xm.h>
24#ifdef __VMS__
25#pragma message enable nosimpint
26#endif
27
28#include "wx/motif/private.h"
29
30IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject);
31
32WX_DECLARE_VOIDPTR_HASH_MAP(wxTimer*, wxTimerHashMap);
33
34static wxTimerHashMap s_timers;
35
36void wxTimerCallback (wxTimer * timer)
37{
38 // Check to see if it's still on
39 if (s_timers.find(timer) == s_timers.end())
40 return;
41
42 if (timer->m_id == 0)
43 return; // Avoid to process spurious timer events
44
45 if (!timer->m_oneShot)
46 timer->m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(),
47 timer->m_milli,
48 (XtTimerCallbackProc) wxTimerCallback,
49 (XtPointer) timer);
50 else
51 timer->m_id = 0;
52
53 timer->Notify();
54}
55
56void wxTimer::Init()
57{
58 m_id = 0;
59 m_milli = 1000;
60}
61
62wxTimer::~wxTimer()
63{
64 Stop();
65 s_timers.erase(this);
66}
67
68bool wxTimer::Start(int milliseconds, bool mode)
69{
70 Stop();
71
72 (void)wxTimerBase::Start(milliseconds, mode);
73
74 if (s_timers.find(this) == s_timers.end())
75 s_timers[this] = this;
76
77 m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(),
78 m_milli,
79 (XtTimerCallbackProc) wxTimerCallback,
80 (XtPointer) this);
81 return TRUE;
82}
83
84void wxTimer::Stop()
85{
86 if (m_id > 0)
87 {
88 XtRemoveTimeOut (m_id);
89 m_id = 0;
90 }
91 m_milli = 0 ;
92}
93
94