1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
wxTimerProc(HWND hwnd
, WORD
, int idTimer
, DWORD
);
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // should probably be in wx/msw/missing.h
60 #define MakeProcInstance(proc, hinst) proc
63 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
65 // ============================================================================
67 // ============================================================================
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
84 wxTimerList
.erase(id
);
87 bool wxTimer::Start(int milliseconds
, bool oneShot
)
89 (void)wxTimerBase::Start(milliseconds
, oneShot
);
91 wxCHECK_MSG( m_milli
> 0, false, wxT("invalid value for timer timeour") );
94 m_id
= ::SetTimer(NULL
, (UINT
)(m_id
? m_id
: 1),
95 (UINT
)m_milli
, (TIMERPROC
) wxTimerProc
);
97 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
98 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
100 m_id
= ::SetTimer(NULL
, (UINT
)(m_id
? m_id
: 1),
101 (UINT
)m_milli
, wxTimerProcInst
);
106 wxTimerList
[m_id
] = this;
112 wxLogSysError(_("Couldn't create a timer"));
122 ::KillTimer(NULL
, (UINT
)m_id
);
124 wxTimerList
.erase(m_id
);
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
134 void wxProcessTimer(wxTimer
& timer
)
136 // Avoid to process spurious timer events
137 if ( timer
.m_id
== 0)
140 if ( timer
.IsOneShot() )
146 void WINAPI
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
149 wxTimerMap::iterator node
= wxTimerList
.find((long)idTimer
);
151 wxASSERT_MSG( node
!= wxTimerList
.end(), wxT("bogus timer id in wxTimerProc") );
153 wxProcessTimer(*(node
->second
));
156 #endif // wxUSE_TIMER