]> git.saurik.com Git - wxWidgets.git/blame - src/msw/timer.cpp
Compilation fixes
[wxWidgets.git] / src / msw / timer.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: timer.cpp
3// Purpose: wxTimer implementation
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
c085e333 13 #pragma implementation "timer.h"
2bda0e17
KB
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
c085e333 20 #pragma hdrstop
2bda0e17
KB
21#endif
22
23#ifndef WX_PRECOMP
c085e333
VZ
24 #include "wx/setup.h"
25 #include "wx/list.h"
26 #include "wx/app.h"
2bda0e17
KB
27#endif
28
c085e333
VZ
29#include "wx/intl.h"
30#include "wx/log.h"
31
2bda0e17
KB
32#include "wx/timer.h"
33#include "wx/msw/private.h"
34
35#include <time.h>
36#include <sys/types.h>
37
17dff81c 38#if !defined(__SC__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)
c085e333 39 #include <sys/timeb.h>
2bda0e17
KB
40#endif
41
c085e333
VZ
42// ----------------------------------------------------------------------------
43// private functions
44// ----------------------------------------------------------------------------
45
2bda0e17
KB
46wxList wxTimerList(wxKEY_INTEGER);
47UINT WINAPI _EXPORT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD);
48
c085e333
VZ
49// ----------------------------------------------------------------------------
50// macros
51// ----------------------------------------------------------------------------
52
53#ifdef __WIN32__
54 #define _EXPORT /**/
55#else
56 #define _EXPORT _export
57#endif
58
2bda0e17 59#if !USE_SHARED_LIBRARY
c085e333 60 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
2bda0e17
KB
61#endif
62
c085e333
VZ
63// ============================================================================
64// implementation
65// ============================================================================
66
67// ----------------------------------------------------------------------------
68// wxTimer class
69// ----------------------------------------------------------------------------
2bda0e17
KB
70wxTimer::wxTimer(void)
71{
c085e333
VZ
72 milli = 0 ;
73 lastMilli = -1 ;
74 id = 0;
2bda0e17
KB
75}
76
77wxTimer::~wxTimer(void)
78{
c085e333 79 Stop();
2bda0e17 80
c085e333 81 wxTimerList.DeleteObject(this);
2bda0e17
KB
82}
83
c085e333 84bool wxTimer::Start(int milliseconds, bool mode)
2bda0e17 85{
c085e333
VZ
86 oneShot = mode ;
87 if (milliseconds < 0)
88 milliseconds = lastMilli;
89
90 wxCHECK_MSG( milliseconds > 0, FALSE, "invalid value for timer timeour" );
91
92 lastMilli = milli = milliseconds;
93
94 wxTimerList.DeleteObject(this);
95 TIMERPROC wxTimerProcInst = (TIMERPROC)
96 MakeProcInstance((FARPROC)wxTimerProc, wxGetInstance());
97
98 id = SetTimer(NULL, (UINT)(id ? id : 1),
99 (UINT)milliseconds, wxTimerProcInst);
100 if (id > 0)
101 {
102 wxTimerList.Append(id, this);
103
104 return TRUE;
105 }
106 else
107 {
108 wxLogSysError(_("Couldn't create a timer"));
109
110 return FALSE;
111 }
2bda0e17
KB
112}
113
114void wxTimer::Stop(void)
115{
c085e333
VZ
116 if (id) {
117 KillTimer(NULL, (UINT)id);
118 wxTimerList.DeleteObject(this); /* @@@@ */
119 }
120 id = 0 ;
121 milli = 0 ;
2bda0e17
KB
122}
123
c085e333
VZ
124// ----------------------------------------------------------------------------
125// private functions
126// ----------------------------------------------------------------------------
06e38c8e 127void wxProcessTimer(wxTimer& timer)
2bda0e17 128{
c085e333
VZ
129 // Avoid to process spurious timer events
130 if ( timer.id == 0)
131 return;
132
133 if ( timer.oneShot )
134 timer.Stop();
135
136 timer.Notify();
2bda0e17
KB
137}
138
c085e333
VZ
139UINT WINAPI _EXPORT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
140{
141 wxNode *node = wxTimerList.Find((long)idTimer);
142
143 wxCHECK_MSG( node, 0, "bogus timer id in wxTimerProc" );
144
145 wxProcessTimer(*(wxTimer *)node->Data());
146
147 return 0;
148}