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"
23 #include "wx/window.h"
24 #include "wx/msw/private.h"
39 #include <sys/types.h>
41 #if !defined(__SC__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)
42 #include <sys/timeb.h>
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 wxList
wxTimerList(wxKEY_INTEGER
);
50 UINT WINAPI _EXPORT
wxTimerProc(HWND hwnd
, WORD
, int idTimer
, DWORD
);
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
59 #define _EXPORT _export
62 #if !USE_SHARED_LIBRARY
63 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
66 // ============================================================================
68 // ============================================================================
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
73 wxTimer::wxTimer(void)
80 wxTimer::~wxTimer(void)
84 wxTimerList
.DeleteObject(this);
87 bool wxTimer::Start(int milliseconds
, bool mode
)
91 milliseconds
= lastMilli
;
93 wxCHECK_MSG( milliseconds
> 0, FALSE
, _T("invalid value for timer timeour") );
95 lastMilli
= milli
= milliseconds
;
97 wxTimerList
.DeleteObject(this);
98 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
99 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
101 id
= SetTimer(NULL
, (UINT
)(id
? id
: 1),
102 (UINT
)milliseconds
, wxTimerProcInst
);
105 wxTimerList
.Append(id
, this);
111 wxLogSysError(_("Couldn't create a timer"));
117 void wxTimer::Stop(void)
120 KillTimer(NULL
, (UINT
)id
);
121 wxTimerList
.DeleteObject(this); /* @@@@ */
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
130 void wxProcessTimer(wxTimer
& timer
)
132 // Avoid to process spurious timer events
142 UINT WINAPI _EXPORT
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
144 wxNode
*node
= wxTimerList
.Find((long)idTimer
);
146 wxCHECK_MSG( node
, 0, _T("bogus timer id in wxTimerProc") );
148 wxProcessTimer(*(wxTimer
*)node
->Data());