]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: timer.cpp | |
3 | // Purpose: wxTimer implementation | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "timer.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/timer.h" | |
17 | ||
2f1ae414 | 18 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 19 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) |
2f1ae414 SC |
20 | #endif |
21 | ||
22 | static void wxProcessTimer( unsigned long event , void *data ) ; | |
23 | ||
d015713e | 24 | static pascal void MacTimerProc( TMTask * t ) |
2f1ae414 SC |
25 | { |
26 | MacTimerInfo * tm = (MacTimerInfo*) t ; | |
27 | wxMacAddEvent( tm->m_table , wxProcessTimer, 0 , (void*) tm->m_timer , TRUE ) ; | |
28 | } | |
29 | ||
d015713e | 30 | static void wxProcessTimer( unsigned long event , void *data ) |
2f1ae414 SC |
31 | { |
32 | if ( !data ) | |
33 | return ; | |
34 | ||
35 | wxTimer* timer = (wxTimer*) data ; | |
36 | if ( timer->IsOneShot() ) | |
37 | timer->Stop() ; | |
38 | ||
39 | timer->Notify(); | |
40 | ||
41 | if ( timer->m_info.m_task.tmAddr && !timer->IsOneShot() ) | |
42 | { | |
43 | PrimeTime( (QElemPtr) &timer->m_info.m_task , timer->GetInterval() ) ; | |
44 | } | |
45 | } | |
e9576ca5 | 46 | |
d015713e | 47 | void wxTimer::Init() |
e9576ca5 | 48 | { |
2f1ae414 SC |
49 | m_info.m_task.tmAddr = NULL ; |
50 | m_info.m_task.tmWakeUp = 0 ; | |
51 | m_info.m_task.tmReserved = 0 ; | |
52 | m_info.m_task.qType = 0 ; | |
53 | m_info.m_table = wxMacGetNotifierTable() ; | |
54 | m_info.m_timer = this ; | |
55 | } | |
56 | ||
57 | bool wxTimer::IsRunning() const | |
58 | { | |
59 | return ( m_info.m_task.qType & kTMTaskActive ) ; | |
e9576ca5 SC |
60 | } |
61 | ||
62 | wxTimer::~wxTimer() | |
63 | { | |
64 | Stop(); | |
65 | } | |
66 | ||
67 | bool wxTimer::Start(int milliseconds,bool mode) | |
68 | { | |
2f1ae414 | 69 | (void)wxTimerBase::Start(milliseconds, mode); |
e9576ca5 | 70 | |
2f1ae414 SC |
71 | wxCHECK_MSG( m_milli > 0, FALSE, wxT("invalid value for timer timeour") ); |
72 | wxCHECK_MSG( m_info.m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") ); | |
e9576ca5 | 73 | |
2f1ae414 | 74 | m_milli = milliseconds; |
4114d0af | 75 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) |
03e11df5 GD |
76 | m_info.m_task.tmAddr = NewTimerUPP( MacTimerProc ) ; |
77 | #else | |
78 | m_info.m_task.tmAddr = NewTimerProc( MacTimerProc ) ; | |
79 | #endif | |
80 | m_info.m_task.tmWakeUp = 0 ; | |
81 | m_info.m_task.tmReserved = 0 ; | |
ba7eb0a5 SC |
82 | m_info.m_task.qType = 0 ; |
83 | m_info.m_timer = this ; | |
2f1ae414 SC |
84 | InsXTime((QElemPtr) &m_info.m_task ) ; |
85 | PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ; | |
e9576ca5 SC |
86 | return FALSE; |
87 | } | |
88 | ||
89 | void wxTimer::Stop() | |
90 | { | |
e9576ca5 | 91 | m_milli = 0 ; |
2f1ae414 SC |
92 | if ( m_info.m_task.tmAddr ) |
93 | { | |
94 | RmvTime( (QElemPtr) &m_info.m_task ) ; | |
95 | DisposeTimerUPP(m_info.m_task.tmAddr) ; | |
96 | m_info.m_task.tmAddr = NULL ; | |
97 | } | |
98 | wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ; | |
e9576ca5 SC |
99 | } |
100 | ||
101 | ||
2f1ae414 | 102 |