1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "timer.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
41 #include "wx/msw/private.h"
44 #include <sys/types.h>
46 #if !defined(__SC__) && !defined(__GNUWIN32__)
47 #include <sys/timeb.h>
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 wxList
wxTimerList(wxKEY_INTEGER
);
55 UINT WINAPI _EXPORT
wxTimerProc(HWND hwnd
, WORD
, int idTimer
, DWORD
);
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
64 #define _EXPORT _export
67 #if !USE_SHARED_LIBRARY
68 IMPLEMENT_ABSTRACT_CLASS(wxTimer
, wxObject
)
71 // ============================================================================
73 // ============================================================================
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
78 wxTimer::wxTimer(void)
85 wxTimer::~wxTimer(void)
89 wxTimerList
.DeleteObject(this);
92 bool wxTimer::Start(int milliseconds
, bool mode
)
96 milliseconds
= lastMilli
;
98 wxCHECK_MSG( milliseconds
> 0, FALSE
, "invalid value for timer timeour" );
100 lastMilli
= milli
= milliseconds
;
102 wxTimerList
.DeleteObject(this);
103 TIMERPROC wxTimerProcInst
= (TIMERPROC
)
104 MakeProcInstance((FARPROC
)wxTimerProc
, wxGetInstance());
106 id
= SetTimer(NULL
, (UINT
)(id
? id
: 1),
107 (UINT
)milliseconds
, wxTimerProcInst
);
110 wxTimerList
.Append(id
, this);
116 wxLogSysError(_("Couldn't create a timer"));
122 void wxTimer::Stop(void)
125 KillTimer(NULL
, (UINT
)id
);
126 wxTimerList
.DeleteObject(this); /* @@@@ */
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
135 static void wxProcessTimer(wxTimer
& timer
)
137 // Avoid to process spurious timer events
147 UINT WINAPI _EXPORT
wxTimerProc(HWND
WXUNUSED(hwnd
), WORD
, int idTimer
, DWORD
)
149 wxNode
*node
= wxTimerList
.Find((long)idTimer
);
151 wxCHECK_MSG( node
, 0, "bogus timer id in wxTimerProc" );
153 wxProcessTimer(*(wxTimer
*)node
->Data());