]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin (use hash map instead of list, global rewrite)
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 // define a hash containing all the timers: it is indexed by timer id and
45 // contains the corresponding timer
46 WX_DECLARE_HASH_MAP(unsigned long, wxTimer
*, wxIntegerHash
, wxIntegerEqual
,
49 static wxTimerMap g_timerMap
;
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // timer callback used for all timers
56 void WINAPI
wxTimerProc(HWND hwnd
, UINT msg
, UINT idTimer
, DWORD dwTime
);
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxEvtHandler
)
64 // ============================================================================
66 // ============================================================================
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
82 bool wxTimer::Start(int milliseconds
, bool oneShot
)
84 (void)wxTimerBase::Start(milliseconds
, oneShot
);
86 wxCHECK_MSG( m_milli
> 0, false, wxT("invalid value for timer timeour") );
90 NULL
, // don't use window
91 1, // id ignored with NULL hwnd anyhow
92 (UINT
)m_milli
, // delay
93 wxTimerProc
// timer proc to call
98 wxLogSysError(_("Couldn't create a timer"));
103 // check that SetTimer() didn't reuse an existing id: according to the MSDN
104 // this can happen and this would be catastrophic to us as we rely on ids
105 // uniquely identifying the timers because we use them as keys in the hash
106 if ( g_timerMap
.find(m_id
) != g_timerMap
.end() )
108 wxLogError(_("Timer creation failed."));
110 ::KillTimer(NULL
, m_id
);
116 g_timerMap
[m_id
] = this;
125 ::KillTimer(NULL
, m_id
);
127 g_timerMap
.erase(m_id
);
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 void wxProcessTimer(wxTimer
& timer
)
139 wxASSERT_MSG( timer
.m_id
!= 0, _T("bogus timer id") );
141 if ( timer
.IsOneShot() )
148 wxTimerProc(HWND
WXUNUSED(hwnd
),
151 DWORD
WXUNUSED(dwTime
))
153 wxTimerMap::iterator node
= g_timerMap
.find(idTimer
);
155 wxCHECK_RET( node
!= g_timerMap
.end(), wxT("bogus timer id in wxTimerProc") );
157 wxProcessTimer(*(node
->second
));
160 #endif // wxUSE_TIMER