]>
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 | 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 | 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 | wxTimer::wxTimer() | |
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 | m_info.m_task.tmAddr = NewTimerProc( MacTimerProc ) ; | |
76 | m_info.m_task.tmWakeUp = 0 ; | |
77 | m_info.m_task.tmReserved = 0 ; | |
78 | InsXTime((QElemPtr) &m_info.m_task ) ; | |
79 | PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ; | |
80 | return FALSE; | |
81 | } | |
82 | ||
83 | void wxTimer::Stop() | |
84 | { | |
85 | m_milli = 0 ; | |
86 | if ( m_info.m_task.tmAddr ) | |
87 | { | |
88 | RmvTime( (QElemPtr) &m_info.m_task ) ; | |
89 | DisposeTimerUPP(m_info.m_task.tmAddr) ; | |
90 | m_info.m_task.tmAddr = NULL ; | |
91 | } | |
92 | wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ; | |
93 | } | |
94 | ||
95 | ||
96 |