]>
Commit | Line | Data |
---|---|---|
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 | #include <windows.h> | |
45 | ||
46 | wxList wxTimerList(wxKEY_INTEGER); | |
47 | UINT WINAPI _EXPORT wxTimerProc(HWND hwnd, WORD, int idTimer, DWORD); | |
48 | ||
49 | #if !USE_SHARED_LIBRARY | |
50 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) | |
51 | #endif | |
52 | ||
53 | wxTimer::wxTimer(void) | |
54 | { | |
55 | milli = 0 ; | |
56 | lastMilli = -1 ; | |
57 | id = 0; | |
58 | } | |
59 | ||
60 | wxTimer::~wxTimer(void) | |
61 | { | |
62 | Stop(); | |
63 | ||
64 | wxTimerList.DeleteObject(this); | |
65 | } | |
66 | ||
67 | bool wxTimer::Start(int milliseconds,bool mode) | |
68 | { | |
69 | oneShot = mode ; | |
70 | if (milliseconds < 0) | |
71 | milliseconds = lastMilli; | |
72 | ||
73 | if (milliseconds <= 0) | |
74 | return FALSE; | |
75 | ||
76 | lastMilli = milli = milliseconds; | |
77 | ||
78 | wxTimerList.DeleteObject(this); | |
79 | TIMERPROC wxTimerProcInst = (TIMERPROC) MakeProcInstance((FARPROC)wxTimerProc, | |
80 | wxGetInstance()); | |
81 | ||
82 | id = SetTimer(NULL, (UINT)(id ? id : 1), (UINT)milliseconds, wxTimerProcInst); | |
83 | if (id > 0) | |
84 | { | |
85 | wxTimerList.Append(id, this); | |
86 | return TRUE; | |
87 | } | |
88 | else return FALSE; | |
89 | } | |
90 | ||
91 | void wxTimer::Stop(void) | |
92 | { | |
93 | if (id) { | |
94 | KillTimer(NULL, (UINT)id); | |
95 | wxTimerList.DeleteObject(this); /* @@@@ */ | |
96 | } | |
97 | id = 0 ; | |
98 | milli = 0 ; | |
99 | } | |
100 | ||
101 | UINT WINAPI _EXPORT wxTimerProc(HWND WXUNUSED(hwnd), WORD, int idTimer, DWORD) | |
102 | { | |
103 | wxNode *node = wxTimerList.Find((long)idTimer); | |
104 | if (node) | |
105 | { | |
106 | wxTimer *timer = (wxTimer *)node->Data(); | |
107 | if (timer->id==0) | |
108 | return(0) ; // Avoid to process spurious timer events | |
109 | if (timer->oneShot) | |
110 | timer->Stop() ; | |
111 | timer->Notify(); | |
112 | } | |
113 | return 0; | |
114 | } | |
115 |