]> git.saurik.com Git - wxWidgets.git/blame - src/msw/timer.cpp
Compilaton 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$
6c9a19aa
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
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
1e6feb95
VZ
23#if wxUSE_TIMER
24
2bda0e17 25#ifndef WX_PRECOMP
0470b1e6 26 #include "wx/window.h"
c085e333 27 #include "wx/list.h"
2432b92d 28 #include "wx/event.h"
c085e333 29 #include "wx/app.h"
0470b1e6
VZ
30 #include "wx/intl.h"
31 #include "wx/log.h"
2bda0e17
KB
32#endif
33
dcc970af
VZ
34#include "wx/hashmap.h"
35
2bda0e17 36#include "wx/timer.h"
2bda0e17 37
0470b1e6 38#include "wx/msw/private.h"
2bda0e17 39
c085e333
VZ
40// ----------------------------------------------------------------------------
41// private functions
42// ----------------------------------------------------------------------------
43
222ed1d6 44WX_DECLARE_HASH_MAP( long,
dcc970af 45 wxTimer *,
222ed1d6
MB
46 wxIntegerHash,
47 wxIntegerEqual,
48 wxTimerMap );
49
50wxTimerMap wxTimerList;
4676948b
JS
51
52void WINAPI _EXPORT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD);
2bda0e17 53
c085e333
VZ
54// ----------------------------------------------------------------------------
55// macros
56// ----------------------------------------------------------------------------
57
58#ifdef __WIN32__
73974df1 59 #define _EXPORT
c085e333
VZ
60#else
61 #define _EXPORT _export
62#endif
63
62f17a18
VZ
64// should probably be in wx/msw/private.h
65#ifdef __WXMICROWIN__
66 #define MakeProcInstance(proc, hinst) proc
67#endif
68
ed791986 69IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
2bda0e17 70
c085e333
VZ
71// ============================================================================
72// implementation
73// ============================================================================
74
75// ----------------------------------------------------------------------------
76// wxTimer class
77// ----------------------------------------------------------------------------
73974df1 78
ed791986 79void wxTimer::Init()
2bda0e17 80{
0470b1e6 81 m_id = 0;
2bda0e17
KB
82}
83
73974df1 84wxTimer::~wxTimer()
2bda0e17 85{
222ed1d6
MB
86 long id = m_id;
87
0470b1e6 88 wxTimer::Stop();
2bda0e17 89
222ed1d6 90 wxTimerList.erase(id);
2bda0e17
KB
91}
92
0470b1e6 93bool wxTimer::Start(int milliseconds, bool oneShot)
2bda0e17 94{
0470b1e6 95 (void)wxTimerBase::Start(milliseconds, oneShot);
c085e333 96
04cd30de 97 wxCHECK_MSG( m_milli > 0, false, wxT("invalid value for timer timeour") );
c085e333 98
4676948b
JS
99#ifdef __WXWINCE__
100 m_id = ::SetTimer(NULL, (UINT)(m_id ? m_id : 1),
09785dd3 101 (UINT)m_milli, (TIMERPROC) wxTimerProc);
4676948b 102#else
c085e333
VZ
103 TIMERPROC wxTimerProcInst = (TIMERPROC)
104 MakeProcInstance((FARPROC)wxTimerProc, wxGetInstance());
105
62f17a18
VZ
106 m_id = ::SetTimer(NULL, (UINT)(m_id ? m_id : 1),
107 (UINT)m_milli, wxTimerProcInst);
4676948b 108#endif
04ef50df 109
0470b1e6 110 if ( m_id > 0 )
c085e333 111 {
222ed1d6 112 wxTimerList[m_id] = this;
c085e333 113
04cd30de 114 return true;
c085e333
VZ
115 }
116 else
117 {
118 wxLogSysError(_("Couldn't create a timer"));
119
04cd30de 120 return false;
c085e333 121 }
2bda0e17
KB
122}
123
73974df1 124void wxTimer::Stop()
2bda0e17 125{
0470b1e6 126 if ( m_id )
73974df1 127 {
62f17a18
VZ
128 ::KillTimer(NULL, (UINT)m_id);
129
222ed1d6 130 wxTimerList.erase(m_id);
c085e333 131 }
0470b1e6
VZ
132
133 m_id = 0;
2bda0e17
KB
134}
135
c085e333
VZ
136// ----------------------------------------------------------------------------
137// private functions
138// ----------------------------------------------------------------------------
73974df1 139
06e38c8e 140void wxProcessTimer(wxTimer& timer)
2bda0e17 141{
c085e333 142 // Avoid to process spurious timer events
0470b1e6 143 if ( timer.m_id == 0)
c085e333
VZ
144 return;
145
0470b1e6 146 if ( timer.IsOneShot() )
c085e333
VZ
147 timer.Stop();
148
149 timer.Notify();
2bda0e17
KB
150}
151
4676948b 152void WINAPI _EXPORT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
c085e333 153{
222ed1d6
MB
154
155 wxTimerMap::iterator node = wxTimerList.find((long)idTimer);
c085e333 156
4676948b 157 wxASSERT_MSG( node != wxTimerList.end(), wxT("bogus timer id in wxTimerProc") );
c085e333 158
222ed1d6 159 wxProcessTimer(*(node->second));
c085e333 160
4676948b 161 // return 0;
c085e333 162}
1e6feb95
VZ
163
164#endif // wxUSE_TIMER