]>
Commit | Line | Data |
---|---|---|
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 | ||
18 | #if !USE_SHARED_LIBRARY | |
19 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) | |
20 | #endif | |
21 | ||
22 | static void wxProcessTimer( unsigned long event , void *data ) ; | |
23 | ||
24 | static pascal void MacTimerProc( TMTask * t ) | |
25 | { | |
26 | MacTimerInfo * tm = (MacTimerInfo*) t ; | |
27 | wxMacAddEvent( tm->m_table , wxProcessTimer, 0 , (void*) tm->m_timer , TRUE ) ; | |
28 | } | |
29 | ||
30 | static void wxProcessTimer( unsigned long event , void *data ) | |
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 | } | |
46 | ||
47 | void wxTimer::Init() | |
48 | { | |
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 ) ; | |
60 | } | |
61 | ||
62 | wxTimer::~wxTimer() | |
63 | { | |
64 | Stop(); | |
65 | } | |
66 | ||
67 | bool wxTimer::Start(int milliseconds,bool mode) | |
68 | { | |
69 | (void)wxTimerBase::Start(milliseconds, mode); | |
70 | ||
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") ); | |
73 | ||
74 | m_milli = milliseconds; | |
75 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) | |
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 ; | |
82 | InsXTime((QElemPtr) &m_info.m_task ) ; | |
83 | PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ; | |
84 | return FALSE; | |
85 | } | |
86 | ||
87 | void wxTimer::Stop() | |
88 | { | |
89 | m_milli = 0 ; | |
90 | if ( m_info.m_task.tmAddr ) | |
91 | { | |
92 | RmvTime( (QElemPtr) &m_info.m_task ) ; | |
93 | DisposeTimerUPP(m_info.m_task.tmAddr) ; | |
94 | m_info.m_task.tmAddr = NULL ; | |
95 | } | |
96 | wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ; | |
97 | } | |
98 | ||
99 | ||
100 |