]> git.saurik.com Git - wxWidgets.git/blob - src/msw/timer.cpp
no message
[wxWidgets.git] / src / msw / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: timer.cpp
3 // Purpose: wxTimer implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "timer.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/setup.h"
25 #include "wx/list.h"
26 #include "wx/app.h"
27 #endif
28
29 #include "wx/timer.h"
30 #include "wx/msw/private.h"
31
32 #include <time.h>
33 #include <sys/types.h>
34
35 #if !defined(__SC__) && !defined(__GNUWIN32__)
36 #include <sys/timeb.h>
37 #endif
38 #ifdef __WIN32__
39 #define _EXPORT /**/
40 #else
41 #define _EXPORT _export
42 #endif
43
44 wxList wxTimerList(wxKEY_INTEGER);
45 UINT WINAPI _EXPORT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD);
46
47 #if !USE_SHARED_LIBRARY
48 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
49 #endif
50
51 wxTimer::wxTimer(void)
52 {
53 milli = 0 ;
54 lastMilli = -1 ;
55 id = 0;
56 }
57
58 wxTimer::~wxTimer(void)
59 {
60 Stop();
61
62 wxTimerList.DeleteObject(this);
63 }
64
65 bool wxTimer::Start(int milliseconds,bool mode)
66 {
67 oneShot = mode ;
68 if (milliseconds < 0)
69 milliseconds = lastMilli;
70
71 if (milliseconds <= 0)
72 return FALSE;
73
74 lastMilli = milli = milliseconds;
75
76 wxTimerList.DeleteObject(this);
77 TIMERPROC wxTimerProcInst = (TIMERPROC) MakeProcInstance((FARPROC)wxTimerProc,
78 wxGetInstance());
79
80 id = SetTimer(NULL, (UINT)(id ? id : 1), (UINT)milliseconds, wxTimerProcInst);
81 if (id > 0)
82 {
83 wxTimerList.Append(id, this);
84 return TRUE;
85 }
86 else return FALSE;
87 }
88
89 void wxTimer::Stop(void)
90 {
91 if (id) {
92 KillTimer(NULL, (UINT)id);
93 wxTimerList.DeleteObject(this); /* @@@@ */
94 }
95 id = 0 ;
96 milli = 0 ;
97 }
98
99 UINT WINAPI _EXPORT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD)
100 {
101 wxNode *node = wxTimerList.Find((long)idTimer);
102 if (node)
103 {
104 wxTimer *timer = (wxTimer *)node->Data();
105 if (timer->id==0)
106 return(0) ; // Avoid to process spurious timer events
107 if (timer->oneShot)
108 timer->Stop() ;
109 timer->Notify();
110 }
111 return 0;
112 }
113