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