]> git.saurik.com Git - wxWidgets.git/blame - src/os2/timer.cpp
Adaptions for new redrawing
[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 45IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
0e320a79 46
496fd9fb 47void wxTimer::Init()
0e320a79 48{
9ed0fac8 49 m_ulId = 0;
0e320a79
DW
50}
51
52wxTimer::~wxTimer()
53{
54 Stop();
05a8bfed 55 wxTimer::Stop();
d90895ac 56 wxTimerList.DeleteObject(this);
0e320a79
DW
57}
58
9ed0fac8
DW
59bool wxTimer::Start(
60 int nMilliseconds
61, bool bOneShot
62)
0e320a79 63{
9ed0fac8
DW
64 (void)wxTimerBase::Start( nMilliseconds
65 ,bOneShot
66 );
d90895ac 67
9ed0fac8 68 wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") );
d90895ac
DW
69
70 wxTimerList.DeleteObject(this);
0e320a79 71
9ed0fac8
DW
72 //
73 // Create a windowless timer
74 //
75 m_ulId = ::WinStartTimer( m_Hab
76 ,NULL
77 ,(m_ulId ? m_ulId : 1L)
78 ,(ULONG)nMilliseconds
79 );
80 if (m_ulId > 0L)
81 {
82 wxTimerList.Append( m_ulId
83 ,this
84 );
85 return(TRUE);
d90895ac
DW
86 }
87 else
88 {
89 wxLogSysError(_("Couldn't create a timer"));
90
9ed0fac8 91 return(FALSE);
d90895ac 92 }
0e320a79
DW
93}
94
95void wxTimer::Stop()
96{
9ed0fac8 97 if ( m_ulId )
d90895ac 98 {
9ed0fac8 99 ::WinStopTimer(m_Hab, NULL, m_ulId);
d90895ac
DW
100 wxTimerList.DeleteObject(this);
101 }
9ed0fac8 102 m_ulId = 0L;
0e320a79
DW
103}
104
d90895ac
DW
105// ----------------------------------------------------------------------------
106// private functions
107// ----------------------------------------------------------------------------
108
9ed0fac8
DW
109void wxProcessTimer(
110 wxTimer& rTimer
111)
d90895ac 112{
9ed0fac8 113 //
d90895ac 114 // Avoid to process spurious timer events
9ed0fac8
DW
115 //
116 if (rTimer.m_ulId == 0L)
d90895ac
DW
117 return;
118
9ed0fac8
DW
119 if (rTimer.IsOneShot())
120 rTimer.Stop();
d90895ac 121
9ed0fac8 122 rTimer.Notify();
d90895ac
DW
123}
124
9ed0fac8
DW
125ULONG wxTimerProc(
126 HWND WXUNUSED(hwnd)
127, ULONG
128, int nIdTimer
129, ULONG
130)
d90895ac 131{
9ed0fac8 132 wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer);
d90895ac 133
9ed0fac8 134 wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") );
d90895ac 135
9ed0fac8 136 wxProcessTimer(*(wxTimer *)pNode->Data());
d90895ac
DW
137 return 0;
138}
0e320a79 139