]> git.saurik.com Git - wxWidgets.git/blame - src/os2/timer.cpp
added wxListBox styles
[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 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
272ebf16
SN
12#ifdef __GNUG__
13 #pragma implementation "timer.h"
14#endif
15
d90895ac
DW
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#include "wx/window.h"
20#include "wx/os2/private.h"
21
22#ifndef WX_PRECOMP
23 #include "wx/setup.h"
24 #include "wx/list.h"
25 #include "wx/event.h"
26 #include "wx/app.h"
0e320a79
DW
27#endif
28
d90895ac
DW
29#include "wx/intl.h"
30#include "wx/log.h"
31
0e320a79
DW
32#include "wx/timer.h"
33
d90895ac
DW
34#include <time.h>
35#include <sys/types.h>
36
37#include <sys/timeb.h>
d90895ac
DW
38// ----------------------------------------------------------------------------
39// private functions
40// ----------------------------------------------------------------------------
41
42wxList wxTimerList(wxKEY_INTEGER);
9ed0fac8 43ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG);
d90895ac
DW
44
45// ----------------------------------------------------------------------------
46// macros
47// ----------------------------------------------------------------------------
48
313feadc 49IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
0e320a79 50
496fd9fb 51void wxTimer::Init()
0e320a79 52{
9ed0fac8 53 m_ulId = 0;
0e320a79
DW
54}
55
56wxTimer::~wxTimer()
57{
05a8bfed 58 wxTimer::Stop();
272ebf16 59
d90895ac 60 wxTimerList.DeleteObject(this);
0e320a79
DW
61}
62
233d6db5
DW
63void wxTimer::Notify()
64{
65 //
66 // The base class version generates an event if it has owner - which it
67 // should because otherwise nobody can process timer events, but it does
68 // not use the OS's ID, which OS/2 must have to figure out which timer fired
69 //
70 wxCHECK_RET( m_owner, _T("wxTimer::Notify() should be overridden.") );
71
5d644707 72 wxTimerEvent vEvent( m_idTimer
233d6db5
DW
73 ,m_milli
74 );
75
76 (void)m_owner->ProcessEvent(vEvent);
77} // end of wxTimer::Notify
78
9ed0fac8
DW
79bool wxTimer::Start(
80 int nMilliseconds
81, bool bOneShot
82)
0e320a79 83{
9ed0fac8
DW
84 (void)wxTimerBase::Start( nMilliseconds
85 ,bOneShot
86 );
d90895ac 87
9ed0fac8 88 wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") );
d90895ac
DW
89
90 wxTimerList.DeleteObject(this);
0e320a79 91
5d644707
DW
92 wxWindow* pWin = NULL;
93
94 if (m_owner)
95 {
96 pWin = (wxWindow*)m_owner;
97 m_ulId = ::WinStartTimer( m_Hab
98 ,pWin->GetHWND()
99 ,m_idTimer
100 ,(ULONG)nMilliseconds
101 );
102 }
103 else
104 m_ulId = ::WinStartTimer( m_Hab
105 ,NULLHANDLE
106 ,0
107 ,(ULONG)nMilliseconds
108 );
9ed0fac8
DW
109 if (m_ulId > 0L)
110 {
111 wxTimerList.Append( m_ulId
112 ,this
113 );
114 return(TRUE);
d90895ac
DW
115 }
116 else
117 {
118 wxLogSysError(_("Couldn't create a timer"));
119
9ed0fac8 120 return(FALSE);
d90895ac 121 }
0e320a79
DW
122}
123
124void wxTimer::Stop()
125{
9ed0fac8 126 if ( m_ulId )
d90895ac 127 {
5d644707
DW
128 if (m_owner)
129 {
130 wxWindow* pWin = (wxWindow*)m_owner;
131
132 ::WinStopTimer(m_Hab, pWin->GetHWND(), m_ulId);
133 }
134 else
135 ::WinStopTimer(m_Hab, NULLHANDLE, m_ulId);
d90895ac
DW
136 wxTimerList.DeleteObject(this);
137 }
5d644707 138 m_ulId = 0L;
0e320a79
DW
139}
140
d90895ac
DW
141// ----------------------------------------------------------------------------
142// private functions
143// ----------------------------------------------------------------------------
144
9ed0fac8
DW
145void wxProcessTimer(
146 wxTimer& rTimer
147)
d90895ac 148{
9ed0fac8 149 //
d90895ac 150 // Avoid to process spurious timer events
9ed0fac8
DW
151 //
152 if (rTimer.m_ulId == 0L)
d90895ac
DW
153 return;
154
9ed0fac8
DW
155 if (rTimer.IsOneShot())
156 rTimer.Stop();
d90895ac 157
9ed0fac8 158 rTimer.Notify();
d90895ac
DW
159}
160
9ed0fac8
DW
161ULONG wxTimerProc(
162 HWND WXUNUSED(hwnd)
163, ULONG
164, int nIdTimer
165, ULONG
166)
d90895ac 167{
9ed0fac8 168 wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer);
d90895ac 169
9ed0fac8 170 wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") );
272ebf16 171 if (pNode)
9923c37d 172 wxProcessTimer(*(wxTimer *)pNode->GetData());
d90895ac
DW
173 return 0;
174}
0e320a79 175