]> git.saurik.com Git - wxWidgets.git/blame - src/msw/timer.cpp
added several other accel strings
[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
73974df1 9// Licence: wxWindows license
2bda0e17
KB
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
0c589ad0
BM
23#include "wx/window.h"
24#include "wx/msw/private.h"
25
2bda0e17 26#ifndef WX_PRECOMP
c085e333
VZ
27 #include "wx/setup.h"
28 #include "wx/list.h"
2432b92d 29 #include "wx/event.h"
c085e333 30 #include "wx/app.h"
2bda0e17
KB
31#endif
32
c085e333
VZ
33#include "wx/intl.h"
34#include "wx/log.h"
35
2bda0e17 36#include "wx/timer.h"
2bda0e17
KB
37
38#include <time.h>
39#include <sys/types.h>
40
17dff81c 41#if !defined(__SC__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)
c085e333 42 #include <sys/timeb.h>
2bda0e17
KB
43#endif
44
c085e333
VZ
45// ----------------------------------------------------------------------------
46// private functions
47// ----------------------------------------------------------------------------
48
2bda0e17
KB
49wxList wxTimerList(wxKEY_INTEGER);
50UINT WINAPI _EXPORT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD);
51
c085e333
VZ
52// ----------------------------------------------------------------------------
53// macros
54// ----------------------------------------------------------------------------
55
56#ifdef __WIN32__
73974df1 57 #define _EXPORT
c085e333
VZ
58#else
59 #define _EXPORT _export
60#endif
61
2bda0e17 62#if !USE_SHARED_LIBRARY
c085e333 63 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
2bda0e17
KB
64#endif
65
c085e333
VZ
66// ============================================================================
67// implementation
68// ============================================================================
69
70// ----------------------------------------------------------------------------
71// wxTimer class
72// ----------------------------------------------------------------------------
73974df1
VZ
73
74wxTimer::wxTimer()
2bda0e17 75{
73974df1
VZ
76 milli = 0;
77 lastMilli = -1;
c085e333 78 id = 0;
2bda0e17
KB
79}
80
73974df1 81wxTimer::~wxTimer()
2bda0e17 82{
c085e333 83 Stop();
2bda0e17 84
c085e333 85 wxTimerList.DeleteObject(this);
2bda0e17
KB
86}
87
c085e333 88bool wxTimer::Start(int milliseconds, bool mode)
2bda0e17 89{
73974df1 90 oneShot = mode;
c085e333
VZ
91 if (milliseconds < 0)
92 milliseconds = lastMilli;
93
223d09f6 94 wxCHECK_MSG( milliseconds > 0, FALSE, wxT("invalid value for timer timeour") );
c085e333
VZ
95
96 lastMilli = milli = milliseconds;
97
98 wxTimerList.DeleteObject(this);
99 TIMERPROC wxTimerProcInst = (TIMERPROC)
100 MakeProcInstance((FARPROC)wxTimerProc, wxGetInstance());
101
102 id = SetTimer(NULL, (UINT)(id ? id : 1),
103 (UINT)milliseconds, wxTimerProcInst);
104 if (id > 0)
105 {
106 wxTimerList.Append(id, this);
107
108 return TRUE;
109 }
110 else
111 {
112 wxLogSysError(_("Couldn't create a timer"));
113
114 return FALSE;
115 }
2bda0e17
KB
116}
117
73974df1 118void wxTimer::Stop()
2bda0e17 119{
73974df1
VZ
120 if ( id )
121 {
c085e333 122 KillTimer(NULL, (UINT)id);
73974df1 123 wxTimerList.DeleteObject(this);
c085e333 124 }
73974df1
VZ
125 id = 0;
126 milli = 0;
2bda0e17
KB
127}
128
c085e333
VZ
129// ----------------------------------------------------------------------------
130// private functions
131// ----------------------------------------------------------------------------
73974df1 132
06e38c8e 133void wxProcessTimer(wxTimer& timer)
2bda0e17 134{
c085e333
VZ
135 // Avoid to process spurious timer events
136 if ( timer.id == 0)
137 return;
138
139 if ( timer.oneShot )
140 timer.Stop();
141
142 timer.Notify();
2bda0e17
KB
143}
144
c085e333
VZ
145UINT WINAPI _EXPORT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
146{
147 wxNode *node = wxTimerList.Find((long)idTimer);
148
223d09f6 149 wxCHECK_MSG( node, 0, wxT("bogus timer id in wxTimerProc") );
c085e333
VZ
150
151 wxProcessTimer(*(wxTimer *)node->Data());
152
153 return 0;
154}