]> git.saurik.com Git - wxWidgets.git/blame - src/os2/timer.cpp
Visualage C++ V4.0 updates
[wxWidgets.git] / src / os2 / timer.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: timer.cpp
3// Purpose: wxTimer implementation
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
0e320a79 7// RCS-ID: $Id$
d90895ac
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
d90895ac
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#include "wx/window.h"
16#include "wx/os2/private.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/setup.h"
20 #include "wx/list.h"
21 #include "wx/event.h"
22 #include "wx/app.h"
0e320a79
DW
23#endif
24
d90895ac
DW
25#include "wx/intl.h"
26#include "wx/log.h"
27
0e320a79
DW
28#include "wx/timer.h"
29
d90895ac
DW
30#include <time.h>
31#include <sys/types.h>
32
33#include <sys/timeb.h>
d90895ac
DW
34// ----------------------------------------------------------------------------
35// private functions
36// ----------------------------------------------------------------------------
37
38wxList wxTimerList(wxKEY_INTEGER);
9ed0fac8 39ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG);
d90895ac
DW
40
41// ----------------------------------------------------------------------------
42// macros
43// ----------------------------------------------------------------------------
44
0e320a79
DW
45#if !USE_SHARED_LIBRARY
46IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
47#endif
48
49wxTimer::wxTimer()
50{
9ed0fac8 51 m_ulId = 0;
0e320a79
DW
52}
53
54wxTimer::~wxTimer()
55{
56 Stop();
d90895ac
DW
57
58 wxTimerList.DeleteObject(this);
0e320a79
DW
59}
60
9ed0fac8
DW
61bool wxTimer::Start(
62 int nMilliseconds
63, bool bOneShot
64)
0e320a79 65{
9ed0fac8
DW
66 (void)wxTimerBase::Start( nMilliseconds
67 ,bOneShot
68 );
d90895ac 69
9ed0fac8 70 wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") );
d90895ac
DW
71
72 wxTimerList.DeleteObject(this);
0e320a79 73
9ed0fac8
DW
74 //
75 // Create a windowless timer
76 //
77 m_ulId = ::WinStartTimer( m_Hab
78 ,NULL
79 ,(m_ulId ? m_ulId : 1L)
80 ,(ULONG)nMilliseconds
81 );
82 if (m_ulId > 0L)
83 {
84 wxTimerList.Append( m_ulId
85 ,this
86 );
87 return(TRUE);
d90895ac
DW
88 }
89 else
90 {
91 wxLogSysError(_("Couldn't create a timer"));
92
9ed0fac8 93 return(FALSE);
d90895ac 94 }
0e320a79
DW
95}
96
97void wxTimer::Stop()
98{
9ed0fac8 99 if ( m_ulId )
d90895ac 100 {
9ed0fac8 101 ::WinStopTimer(m_Hab, NULL, m_ulId);
d90895ac
DW
102 wxTimerList.DeleteObject(this);
103 }
9ed0fac8 104 m_ulId = 0L;
0e320a79
DW
105}
106
d90895ac
DW
107// ----------------------------------------------------------------------------
108// private functions
109// ----------------------------------------------------------------------------
110
9ed0fac8
DW
111void wxProcessTimer(
112 wxTimer& rTimer
113)
d90895ac 114{
9ed0fac8 115 //
d90895ac 116 // Avoid to process spurious timer events
9ed0fac8
DW
117 //
118 if (rTimer.m_ulId == 0L)
d90895ac
DW
119 return;
120
9ed0fac8
DW
121 if (rTimer.IsOneShot())
122 rTimer.Stop();
d90895ac 123
9ed0fac8 124 rTimer.Notify();
d90895ac
DW
125}
126
9ed0fac8
DW
127ULONG wxTimerProc(
128 HWND WXUNUSED(hwnd)
129, ULONG
130, int nIdTimer
131, ULONG
132)
d90895ac 133{
9ed0fac8 134 wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer);
d90895ac 135
9ed0fac8 136 wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") );
d90895ac 137
9ed0fac8 138 wxProcessTimer(*(wxTimer *)pNode->Data());
d90895ac
DW
139 return 0;
140}
0e320a79 141