]> git.saurik.com Git - wxWidgets.git/blame - src/msw/timer.cpp
In wxApp::OnIdle() check to see if there is not a current menubar and if
[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
c085e333 26 #include "wx/setup.h"
0470b1e6 27 #include "wx/window.h"
c085e333 28 #include "wx/list.h"
2432b92d 29 #include "wx/event.h"
c085e333 30 #include "wx/app.h"
0470b1e6
VZ
31 #include "wx/intl.h"
32 #include "wx/log.h"
2bda0e17
KB
33#endif
34
35#include "wx/timer.h"
2bda0e17 36
0470b1e6 37#include "wx/msw/private.h"
2bda0e17 38
c085e333
VZ
39// ----------------------------------------------------------------------------
40// private functions
41// ----------------------------------------------------------------------------
42
2bda0e17
KB
43wxList wxTimerList(wxKEY_INTEGER);
44UINT WINAPI _EXPORT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD);
45
c085e333
VZ
46// ----------------------------------------------------------------------------
47// macros
48// ----------------------------------------------------------------------------
49
50#ifdef __WIN32__
73974df1 51 #define _EXPORT
c085e333
VZ
52#else
53 #define _EXPORT _export
54#endif
55
62f17a18
VZ
56// should probably be in wx/msw/private.h
57#ifdef __WXMICROWIN__
58 #define MakeProcInstance(proc, hinst) proc
59#endif
60
ed791986 61IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
2bda0e17 62
c085e333
VZ
63// ============================================================================
64// implementation
65// ============================================================================
66
67// ----------------------------------------------------------------------------
68// wxTimer class
69// ----------------------------------------------------------------------------
73974df1 70
ed791986 71void wxTimer::Init()
2bda0e17 72{
0470b1e6 73 m_id = 0;
2bda0e17
KB
74}
75
73974df1 76wxTimer::~wxTimer()
2bda0e17 77{
0470b1e6 78 wxTimer::Stop();
2bda0e17 79
c085e333 80 wxTimerList.DeleteObject(this);
2bda0e17
KB
81}
82
0470b1e6 83bool wxTimer::Start(int milliseconds, bool oneShot)
2bda0e17 84{
0470b1e6 85 (void)wxTimerBase::Start(milliseconds, oneShot);
c085e333 86
04cd30de 87 wxCHECK_MSG( m_milli > 0, false, wxT("invalid value for timer timeour") );
c085e333 88
c085e333
VZ
89 TIMERPROC wxTimerProcInst = (TIMERPROC)
90 MakeProcInstance((FARPROC)wxTimerProc, wxGetInstance());
91
62f17a18
VZ
92 m_id = ::SetTimer(NULL, (UINT)(m_id ? m_id : 1),
93 (UINT)m_milli, wxTimerProcInst);
04ef50df 94
0470b1e6 95 if ( m_id > 0 )
c085e333 96 {
0470b1e6 97 wxTimerList.Append(m_id, this);
c085e333 98
04cd30de 99 return true;
c085e333
VZ
100 }
101 else
102 {
103 wxLogSysError(_("Couldn't create a timer"));
104
04cd30de 105 return false;
c085e333 106 }
2bda0e17
KB
107}
108
73974df1 109void wxTimer::Stop()
2bda0e17 110{
0470b1e6 111 if ( m_id )
73974df1 112 {
62f17a18
VZ
113 ::KillTimer(NULL, (UINT)m_id);
114
73974df1 115 wxTimerList.DeleteObject(this);
c085e333 116 }
0470b1e6
VZ
117
118 m_id = 0;
2bda0e17
KB
119}
120
c085e333
VZ
121// ----------------------------------------------------------------------------
122// private functions
123// ----------------------------------------------------------------------------
73974df1 124
06e38c8e 125void wxProcessTimer(wxTimer& timer)
2bda0e17 126{
c085e333 127 // Avoid to process spurious timer events
0470b1e6 128 if ( timer.m_id == 0)
c085e333
VZ
129 return;
130
0470b1e6 131 if ( timer.IsOneShot() )
c085e333
VZ
132 timer.Stop();
133
134 timer.Notify();
2bda0e17
KB
135}
136
c085e333
VZ
137UINT WINAPI _EXPORT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
138{
139 wxNode *node = wxTimerList.Find((long)idTimer);
140
223d09f6 141 wxCHECK_MSG( node, 0, wxT("bogus timer id in wxTimerProc") );
c085e333 142
04cd30de 143 wxProcessTimer(*(wxTimer *)node->GetData());
c085e333
VZ
144
145 return 0;
146}
1e6feb95
VZ
147
148#endif // wxUSE_TIMER