1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "timer.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
34 #include "wx/msw/private.h"
37 #include <sys/types.h>
39 #if !defined(__SC__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)
40 #include <sys/timeb.h>
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 wxList
wxTimerList(wxKEY_INTEGER
);
48 UINT WINAPI _EXPORT
wxTimerProc(HWND hwnd
, WORD
, int idTimer
, DWORD
);
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
57 #define _EXPORT _export
60 #if !USE_SHARED_LIBRARY
61 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
64 // ============================================================================
66 // ============================================================================
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
71 wxTimer::wxTimer(void)
78 wxTimer::~wxTimer(void)
82 wxTimerList
.DeleteObject(this);
85 bool wxTimer::Start(int milliseconds
, bool mode
)
89 milliseconds
= lastMilli
;
91 wxCHECK_MSG( milliseconds
> 0, FALSE
, "invalid value for timer timeour" );
93 lastMilli
= milli
= milliseconds
;
95 wxTimerList
.DeleteObject(this);
96 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
97 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
99 id
= SetTimer(NULL
, (UINT
)(id
? id
: 1),
100 (UINT
)milliseconds
, wxTimerProcInst
);
103 wxTimerList
.Append(id
, this);
109 wxLogSysError(_("Couldn't create a timer"));
115 void wxTimer::Stop(void)
118 KillTimer(NULL
, (UINT
)id
);
119 wxTimerList
.DeleteObject(this); /* @@@@ */
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
128 void wxProcessTimer(wxTimer
& timer
)
130 // Avoid to process spurious timer events
140 UINT WINAPI _EXPORT
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
142 wxNode
*node
= wxTimerList
.Find((long)idTimer
);
144 wxCHECK_MSG( node
, 0, "bogus timer id in wxTimerProc" );
146 wxProcessTimer(*(wxTimer
*)node
->Data());