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 // ----------------------------------------------------------------------------
85 wxTimerList
.DeleteObject(this);
88 bool wxTimer::Start(int milliseconds
, bool mode
)
92 milliseconds
= lastMilli
;
94 wxCHECK_MSG( milliseconds
> 0, FALSE
, wxT("invalid value for timer timeour") );
96 lastMilli
= milli
= milliseconds
;
98 wxTimerList
.DeleteObject(this);
99 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
100 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
102 id
= SetTimer(NULL
, (UINT
)(id
? id
: 1),
103 (UINT
)milliseconds
, wxTimerProcInst
);
106 wxTimerList
.Append(id
, this);
112 wxLogSysError(_("Couldn't create a timer"));
122 KillTimer(NULL
, (UINT
)id
);
123 wxTimerList
.DeleteObject(this);
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 void wxProcessTimer(wxTimer
& timer
)
135 // Avoid to process spurious timer events
145 UINT WINAPI _EXPORT
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
147 wxNode
*node
= wxTimerList
.Find((long)idTimer
);
149 wxCHECK_MSG( node
, 0, wxT("bogus timer id in wxTimerProc") );
151 wxProcessTimer(*(wxTimer
*)node
->Data());