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"
33 #include "wx/msw/private.h"
36 #include <sys/types.h>
38 #if !defined(__SC__) && !defined(__GNUWIN32__)
39 #include <sys/timeb.h>
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 wxList
wxTimerList(wxKEY_INTEGER
);
47 UINT WINAPI _EXPORT
wxTimerProc(HWND hwnd
, WORD
, int idTimer
, DWORD
);
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
56 #define _EXPORT _export
59 #if !USE_SHARED_LIBRARY
60 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
63 // ============================================================================
65 // ============================================================================
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
70 wxTimer::wxTimer(void)
77 wxTimer::~wxTimer(void)
81 wxTimerList
.DeleteObject(this);
84 bool wxTimer::Start(int milliseconds
, bool mode
)
88 milliseconds
= lastMilli
;
90 wxCHECK_MSG( milliseconds
> 0, FALSE
, "invalid value for timer timeour" );
92 lastMilli
= milli
= milliseconds
;
94 wxTimerList
.DeleteObject(this);
95 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
96 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
98 id
= SetTimer(NULL
, (UINT
)(id
? id
: 1),
99 (UINT
)milliseconds
, wxTimerProcInst
);
102 wxTimerList
.Append(id
, this);
108 wxLogSysError(_("Couldn't create a timer"));
114 void wxTimer::Stop(void)
117 KillTimer(NULL
, (UINT
)id
);
118 wxTimerList
.DeleteObject(this); /* @@@@ */
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
127 static void wxProcessTimer(wxTimer
& timer
)
129 // Avoid to process spurious timer events
139 UINT WINAPI _EXPORT
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
141 wxNode
*node
= wxTimerList
.Find((long)idTimer
);
143 wxCHECK_MSG( node
, 0, "bogus timer id in wxTimerProc" );
145 wxProcessTimer(*(wxTimer
*)node
->Data());