]> git.saurik.com Git - wxWidgets.git/blob - src/os2/timer.cpp
using Theme layout for measuring as well
[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 bool wxTimer::Start(
60 int nMilliseconds
61 , bool bOneShot
62 )
63 {
64 (void)wxTimerBase::Start( nMilliseconds
65 ,bOneShot
66 );
67
68 wxCHECK_MSG( m_milli > 0L, FALSE, wxT("invalid value for timer") );
69
70 wxTimerList.DeleteObject(this);
71
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);
86 }
87 else
88 {
89 wxLogSysError(_("Couldn't create a timer"));
90
91 return(FALSE);
92 }
93 }
94
95 void wxTimer::Stop()
96 {
97 if ( m_ulId )
98 {
99 ::WinStopTimer(m_Hab, NULL, m_ulId);
100 wxTimerList.DeleteObject(this);
101 }
102 m_ulId = 0L;
103 }
104
105 // ----------------------------------------------------------------------------
106 // private functions
107 // ----------------------------------------------------------------------------
108
109 void wxProcessTimer(
110 wxTimer& rTimer
111 )
112 {
113 //
114 // Avoid to process spurious timer events
115 //
116 if (rTimer.m_ulId == 0L)
117 return;
118
119 if (rTimer.IsOneShot())
120 rTimer.Stop();
121
122 rTimer.Notify();
123 }
124
125 ULONG wxTimerProc(
126 HWND WXUNUSED(hwnd)
127 , ULONG
128 , int nIdTimer
129 , ULONG
130 )
131 {
132 wxNode* pNode = wxTimerList.Find((ULONG)nIdTimer);
133
134 wxCHECK_MSG(pNode, 0, wxT("bogus timer id in wxTimerProc") );
135
136 wxProcessTimer(*(wxTimer *)pNode->Data());
137 return 0;
138 }
139