]> git.saurik.com Git - wxWidgets.git/blame - src/os2/timer.cpp
Distrib corrections,
[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>
34
35// ----------------------------------------------------------------------------
36// private functions
37// ----------------------------------------------------------------------------
38
39wxList wxTimerList(wxKEY_INTEGER);
40UINT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD);
41
42// ----------------------------------------------------------------------------
43// macros
44// ----------------------------------------------------------------------------
45
0e320a79
DW
46#if !USE_SHARED_LIBRARY
47IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
48#endif
49
50wxTimer::wxTimer()
51{
d90895ac
DW
52 milli = 0 ;
53 id = 0;
54 oneShot = FALSE;
0e320a79
DW
55}
56
57wxTimer::~wxTimer()
58{
59 Stop();
d90895ac
DW
60
61 wxTimerList.DeleteObject(this);
0e320a79
DW
62}
63
64bool wxTimer::Start(int milliseconds,bool mode)
65{
d90895ac
DW
66 oneShot = mode;
67 if (milliseconds < 0)
68 milliseconds = lastMilli;
69
70 wxCHECK_MSG( milliseconds > 0, FALSE, wxT("invalid value for timer timeour") );
71
72 lastMilli = milli = milliseconds;
73
74 wxTimerList.DeleteObject(this);
75// TODO:
76/*
77 TIMERPROC wxTimerProcInst = (TIMERPROC)
78 MakeProcInstance((FARPROC)wxTimerProc, wxGetInstance());
0e320a79 79
d90895ac
DW
80 id = SetTimer(NULL, (UINT)(id ? id : 1),
81 (UINT)milliseconds, wxTimerProcInst);
82*/
83 if (id > 0)
84 {
85 wxTimerList.Append(id, this);
0e320a79 86
d90895ac
DW
87 return TRUE;
88 }
89 else
90 {
91 wxLogSysError(_("Couldn't create a timer"));
92
93 return FALSE;
94 }
0e320a79
DW
95}
96
97void wxTimer::Stop()
98{
d90895ac
DW
99 if ( id )
100 {
101// KillTimer(NULL, (UINT)id);
102 wxTimerList.DeleteObject(this);
103 }
104 id = 0;
105 milli = 0;
0e320a79
DW
106}
107
d90895ac
DW
108// ----------------------------------------------------------------------------
109// private functions
110// ----------------------------------------------------------------------------
111
112void wxProcessTimer(wxTimer& timer)
113{
114 // Avoid to process spurious timer events
115 if ( timer.id == 0)
116 return;
117
118 if ( timer.oneShot )
119 timer.Stop();
120
121 timer.Notify();
122}
123
124UINT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
125{
126 wxNode *node = wxTimerList.Find((long)idTimer);
127
128 wxCHECK_MSG( node, 0, wxT("bogus timer id in wxTimerProc") );
129
130 wxProcessTimer(*(wxTimer *)node->Data());
131
132 return 0;
133}
0e320a79 134