]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/timer.cpp
corrected scrolling problems for controls, switched to separate wxSpinCtrl implementa...
[wxWidgets.git] / src / os2 / timer.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: timer.cpp
3// Purpose: wxTimer implementation
4// Author: David Webster
5// Modified by:
6// Created: 10/17/99
7// RCS-ID: $Id$
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
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"
23#endif
24
25#include "wx/intl.h"
26#include "wx/log.h"
27
28#include "wx/timer.h"
29
30#include <time.h>
31#include <sys/types.h>
32
33#include <sys/timeb.h>
34// ----------------------------------------------------------------------------
35// private functions
36// ----------------------------------------------------------------------------
37
38wxList wxTimerList(wxKEY_INTEGER);
39ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG);
40
41// ----------------------------------------------------------------------------
42// macros
43// ----------------------------------------------------------------------------
44
45IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
46
47void wxTimer::Init()
48{
49 m_ulId = 0;
50}
51
52wxTimer::~wxTimer()
53{
54 Stop();
55 wxTimer::Stop();
56 wxTimerList.DeleteObject(this);
57}
58
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
68 wxTimerEvent vEvent( m_idTimer
69 ,m_milli
70 );
71
72 (void)m_owner->ProcessEvent(vEvent);
73} // end of wxTimer::Notify
74
75bool wxTimer::Start(
76 int nMilliseconds
77, bool bOneShot
78)
79{
80 (void)wxTimerBase::Start( nMilliseconds
81 ,bOneShot
82 );
83
84 wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") );
85
86 wxTimerList.DeleteObject(this);
87
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 );
105 if (m_ulId > 0L)
106 {
107 wxTimerList.Append( m_ulId
108 ,this
109 );
110 return(TRUE);
111 }
112 else
113 {
114 wxLogSysError(_("Couldn't create a timer"));
115
116 return(FALSE);
117 }
118}
119
120void wxTimer::Stop()
121{
122 if ( m_ulId )
123 {
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);
132 wxTimerList.DeleteObject(this);
133 }
134 m_ulId = 0L;
135}
136
137// ----------------------------------------------------------------------------
138// private functions
139// ----------------------------------------------------------------------------
140
141void wxProcessTimer(
142 wxTimer& rTimer
143)
144{
145 //
146 // Avoid to process spurious timer events
147 //
148 if (rTimer.m_ulId == 0L)
149 return;
150
151 if (rTimer.IsOneShot())
152 rTimer.Stop();
153
154 rTimer.Notify();
155}
156
157ULONG wxTimerProc(
158 HWND WXUNUSED(hwnd)
159, ULONG
160, int nIdTimer
161, ULONG
162)
163{
164 wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer);
165
166 wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") );
167
168 wxProcessTimer(*(wxTimer *)pNode->Data());
169 return 0;
170}
171