]> git.saurik.com Git - wxWidgets.git/blame - src/os2/timer.cpp
corrected scrolling problems for controls, switched to separate wxSpinCtrl implementa...
[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
233d6db5
DW
59void wxTimer::Notify()
60{
61 //
62 // The base class version generates an event if it has owner - which it
63 // should because otherwise nobody can process timer events, but it does
64 // not use the OS's ID, which OS/2 must have to figure out which timer fired
65 //
66 wxCHECK_RET( m_owner, _T("wxTimer::Notify() should be overridden.") );
67
5d644707 68 wxTimerEvent vEvent( m_idTimer
233d6db5
DW
69 ,m_milli
70 );
71
72 (void)m_owner->ProcessEvent(vEvent);
73} // end of wxTimer::Notify
74
9ed0fac8
DW
75bool wxTimer::Start(
76 int nMilliseconds
77, bool bOneShot
78)
0e320a79 79{
9ed0fac8
DW
80 (void)wxTimerBase::Start( nMilliseconds
81 ,bOneShot
82 );
d90895ac 83
9ed0fac8 84 wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") );
d90895ac
DW
85
86 wxTimerList.DeleteObject(this);
0e320a79 87
5d644707
DW
88 wxWindow* pWin = NULL;
89
90 if (m_owner)
91 {
92 pWin = (wxWindow*)m_owner;
93 m_ulId = ::WinStartTimer( m_Hab
94 ,pWin->GetHWND()
95 ,m_idTimer
96 ,(ULONG)nMilliseconds
97 );
98 }
99 else
100 m_ulId = ::WinStartTimer( m_Hab
101 ,NULLHANDLE
102 ,0
103 ,(ULONG)nMilliseconds
104 );
9ed0fac8
DW
105 if (m_ulId > 0L)
106 {
107 wxTimerList.Append( m_ulId
108 ,this
109 );
110 return(TRUE);
d90895ac
DW
111 }
112 else
113 {
114 wxLogSysError(_("Couldn't create a timer"));
115
9ed0fac8 116 return(FALSE);
d90895ac 117 }
0e320a79
DW
118}
119
120void wxTimer::Stop()
121{
9ed0fac8 122 if ( m_ulId )
d90895ac 123 {
5d644707
DW
124 if (m_owner)
125 {
126 wxWindow* pWin = (wxWindow*)m_owner;
127
128 ::WinStopTimer(m_Hab, pWin->GetHWND(), m_ulId);
129 }
130 else
131 ::WinStopTimer(m_Hab, NULLHANDLE, m_ulId);
d90895ac
DW
132 wxTimerList.DeleteObject(this);
133 }
5d644707 134 m_ulId = 0L;
0e320a79
DW
135}
136
d90895ac
DW
137// ----------------------------------------------------------------------------
138// private functions
139// ----------------------------------------------------------------------------
140
9ed0fac8
DW
141void wxProcessTimer(
142 wxTimer& rTimer
143)
d90895ac 144{
9ed0fac8 145 //
d90895ac 146 // Avoid to process spurious timer events
9ed0fac8
DW
147 //
148 if (rTimer.m_ulId == 0L)
d90895ac
DW
149 return;
150
9ed0fac8
DW
151 if (rTimer.IsOneShot())
152 rTimer.Stop();
d90895ac 153
9ed0fac8 154 rTimer.Notify();
d90895ac
DW
155}
156
9ed0fac8
DW
157ULONG wxTimerProc(
158 HWND WXUNUSED(hwnd)
159, ULONG
160, int nIdTimer
161, ULONG
162)
d90895ac 163{
9ed0fac8 164 wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer);
d90895ac 165
9ed0fac8 166 wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") );
d90895ac 167
9ed0fac8 168 wxProcessTimer(*(wxTimer *)pNode->Data());
d90895ac
DW
169 return 0;
170}
0e320a79 171