Tooltip updates
[wxWidgets.git] / src / os2 / timer.cpp
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
38 wxList wxTimerList(wxKEY_INTEGER);
39 ULONG wxTimerProc(HWND hwnd, ULONG, int nIdTimer, ULONG);
40
41 // ----------------------------------------------------------------------------
42 // macros
43 // ----------------------------------------------------------------------------
44
45 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
46
47 void wxTimer::Init()
48 {
49 m_ulId = 0;
50 }
51
52 wxTimer::~wxTimer()
53 {
54 Stop();
55 wxTimer::Stop();
56 wxTimerList.DeleteObject(this);
57 }
58
59 void 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_ulId
69 ,m_milli
70 );
71
72 (void)m_owner->ProcessEvent(vEvent);
73 } // end of wxTimer::Notify
74
75 bool 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 //
89 // Create a windowless timer
90 //
91 m_ulId = ::WinStartTimer( m_Hab
92 ,NULL
93 ,(m_ulId ? m_ulId : 1L)
94 ,(ULONG)nMilliseconds
95 );
96 if (m_ulId > 0L)
97 {
98 wxTimerList.Append( m_ulId
99 ,this
100 );
101 return(TRUE);
102 }
103 else
104 {
105 wxLogSysError(_("Couldn't create a timer"));
106
107 return(FALSE);
108 }
109 }
110
111 void wxTimer::Stop()
112 {
113 if ( m_ulId )
114 {
115 ::WinStopTimer(m_Hab, NULL, m_ulId);
116 wxTimerList.DeleteObject(this);
117 }
118 m_ulId = 0L;
119 }
120
121 // ----------------------------------------------------------------------------
122 // private functions
123 // ----------------------------------------------------------------------------
124
125 void wxProcessTimer(
126 wxTimer& rTimer
127 )
128 {
129 //
130 // Avoid to process spurious timer events
131 //
132 if (rTimer.m_ulId == 0L)
133 return;
134
135 if (rTimer.IsOneShot())
136 rTimer.Stop();
137
138 rTimer.Notify();
139 }
140
141 ULONG wxTimerProc(
142 HWND WXUNUSED(hwnd)
143 , ULONG
144 , int nIdTimer
145 , ULONG
146 )
147 {
148 wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer);
149
150 wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") );
151
152 wxProcessTimer(*(wxTimer *)pNode->Data());
153 return 0;
154 }
155