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