1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "timer.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/window.h"
34 #include "wx/hashmap.h"
38 #include "wx/msw/private.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 WX_DECLARE_HASH_MAP( long,
50 wxTimerMap wxTimerList
;
52 void WINAPI _EXPORT
wxTimerProc(HWND hwnd
, WORD
, int idTimer
, DWORD
);
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
61 #define _EXPORT _export
64 // should probably be in wx/msw/private.h
66 #define MakeProcInstance(proc, hinst) proc
69 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
71 // ============================================================================
73 // ============================================================================
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
90 wxTimerList
.erase(id
);
93 bool wxTimer::Start(int milliseconds
, bool oneShot
)
95 (void)wxTimerBase::Start(milliseconds
, oneShot
);
97 wxCHECK_MSG( m_milli
> 0, false, wxT("invalid value for timer timeour") );
100 m_id
= ::SetTimer(NULL
, (UINT
)(m_id
? m_id
: 1),
101 (UINT
)m_milli
, (TIMERPROC
) wxTimerProc
);
103 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
104 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
106 m_id
= ::SetTimer(NULL
, (UINT
)(m_id
? m_id
: 1),
107 (UINT
)m_milli
, wxTimerProcInst
);
112 wxTimerList
[m_id
] = this;
118 wxLogSysError(_("Couldn't create a timer"));
128 ::KillTimer(NULL
, (UINT
)m_id
);
130 wxTimerList
.erase(m_id
);
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
140 void wxProcessTimer(wxTimer
& timer
)
142 // Avoid to process spurious timer events
143 if ( timer
.m_id
== 0)
146 if ( timer
.IsOneShot() )
152 void WINAPI _EXPORT
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
155 wxTimerMap::iterator node
= wxTimerList
.find((long)idTimer
);
157 wxASSERT_MSG( node
!= wxTimerList
.end(), wxT("bogus timer id in wxTimerProc") );
159 wxProcessTimer(*(node
->second
));
164 #endif // wxUSE_TIMER