]> git.saurik.com Git - wxWidgets.git/blame - src/msw/timer.cpp
VisualAge C++ V4.0 configuration files
[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
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__
57 #define _EXPORT /**/
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// ----------------------------------------------------------------------------
2bda0e17
KB
73wxTimer::wxTimer(void)
74{
c085e333
VZ
75 milli = 0 ;
76 lastMilli = -1 ;
77 id = 0;
2bda0e17
KB
78}
79
80wxTimer::~wxTimer(void)
81{
c085e333 82 Stop();
2bda0e17 83
c085e333 84 wxTimerList.DeleteObject(this);
2bda0e17
KB
85}
86
c085e333 87bool wxTimer::Start(int milliseconds, bool mode)
2bda0e17 88{
c085e333
VZ
89 oneShot = mode ;
90 if (milliseconds < 0)
91 milliseconds = lastMilli;
92
837e5743 93 wxCHECK_MSG( milliseconds > 0, FALSE, _T("invalid value for timer timeour") );
c085e333
VZ
94
95 lastMilli = milli = milliseconds;
96
97 wxTimerList.DeleteObject(this);
98 TIMERPROC wxTimerProcInst = (TIMERPROC)
99 MakeProcInstance((FARPROC)wxTimerProc, wxGetInstance());
100
101 id = SetTimer(NULL, (UINT)(id ? id : 1),
102 (UINT)milliseconds, wxTimerProcInst);
103 if (id > 0)
104 {
105 wxTimerList.Append(id, this);
106
107 return TRUE;
108 }
109 else
110 {
111 wxLogSysError(_("Couldn't create a timer"));
112
113 return FALSE;
114 }
2bda0e17
KB
115}
116
117void wxTimer::Stop(void)
118{
c085e333
VZ
119 if (id) {
120 KillTimer(NULL, (UINT)id);
121 wxTimerList.DeleteObject(this); /* @@@@ */
122 }
123 id = 0 ;
124 milli = 0 ;
2bda0e17
KB
125}
126
c085e333
VZ
127// ----------------------------------------------------------------------------
128// private functions
129// ----------------------------------------------------------------------------
06e38c8e 130void wxProcessTimer(wxTimer& timer)
2bda0e17 131{
c085e333
VZ
132 // Avoid to process spurious timer events
133 if ( timer.id == 0)
134 return;
135
136 if ( timer.oneShot )
137 timer.Stop();
138
139 timer.Notify();
2bda0e17
KB
140}
141
c085e333
VZ
142UINT WINAPI _EXPORT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
143{
144 wxNode *node = wxTimerList.Find((long)idTimer);
145
837e5743 146 wxCHECK_MSG( node, 0, _T("bogus timer id in wxTimerProc") );
c085e333
VZ
147
148 wxProcessTimer(*(wxTimer *)node->Data());
149
150 return 0;
151}