]>
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 | ||
76a5e5d2 SC |
22 | #ifdef __WXMAC__ |
23 | #include "wx/mac/private.h" | |
24 | #endif | |
66a09d47 SC |
25 | #ifndef __DARWIN__ |
26 | #include <Timer.h> | |
27 | #endif | |
76a5e5d2 SC |
28 | |
29 | typedef struct MacTimerInfo | |
30 | { | |
31 | TMTask m_task; | |
32 | wxMacNotifierTableRef m_table ; | |
33 | wxTimer* m_timer ; | |
34 | } ; | |
35 | ||
2f1ae414 SC |
36 | static void wxProcessTimer( unsigned long event , void *data ) ; |
37 | ||
d015713e | 38 | static pascal void MacTimerProc( TMTask * t ) |
2f1ae414 SC |
39 | { |
40 | MacTimerInfo * tm = (MacTimerInfo*) t ; | |
41 | wxMacAddEvent( tm->m_table , wxProcessTimer, 0 , (void*) tm->m_timer , TRUE ) ; | |
42 | } | |
43 | ||
d015713e | 44 | static void wxProcessTimer( unsigned long event , void *data ) |
2f1ae414 SC |
45 | { |
46 | if ( !data ) | |
47 | return ; | |
48 | ||
49 | wxTimer* timer = (wxTimer*) data ; | |
50 | if ( timer->IsOneShot() ) | |
51 | timer->Stop() ; | |
52 | ||
53 | timer->Notify(); | |
54 | ||
76a5e5d2 | 55 | if ( timer->m_info->m_task.tmAddr && !timer->IsOneShot() ) |
2f1ae414 | 56 | { |
76a5e5d2 | 57 | PrimeTime( (QElemPtr) &timer->m_info->m_task , timer->GetInterval() ) ; |
2f1ae414 SC |
58 | } |
59 | } | |
e9576ca5 | 60 | |
d015713e | 61 | void wxTimer::Init() |
e9576ca5 | 62 | { |
76a5e5d2 SC |
63 | m_info = new MacTimerInfo() ; |
64 | m_info->m_task.tmAddr = NULL ; | |
65 | m_info->m_task.tmWakeUp = 0 ; | |
66 | m_info->m_task.tmReserved = 0 ; | |
67 | m_info->m_task.qType = 0 ; | |
68 | m_info->m_table = wxMacGetNotifierTable() ; | |
69 | m_info->m_timer = this ; | |
2f1ae414 SC |
70 | } |
71 | ||
72 | bool wxTimer::IsRunning() const | |
73 | { | |
76a5e5d2 | 74 | return ( m_info->m_task.qType & kTMTaskActive ) ; |
e9576ca5 SC |
75 | } |
76 | ||
77 | wxTimer::~wxTimer() | |
78 | { | |
79 | Stop(); | |
76a5e5d2 SC |
80 | delete m_info ; |
81 | m_info = NULL ; | |
e9576ca5 SC |
82 | } |
83 | ||
84 | bool wxTimer::Start(int milliseconds,bool mode) | |
85 | { | |
2f1ae414 | 86 | (void)wxTimerBase::Start(milliseconds, mode); |
e9576ca5 | 87 | |
2f1ae414 | 88 | wxCHECK_MSG( m_milli > 0, FALSE, wxT("invalid value for timer timeour") ); |
76a5e5d2 | 89 | wxCHECK_MSG( m_info->m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") ); |
e9576ca5 | 90 | |
2f1ae414 | 91 | m_milli = milliseconds; |
4114d0af | 92 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) |
76a5e5d2 | 93 | m_info->m_task.tmAddr = NewTimerUPP( MacTimerProc ) ; |
03e11df5 | 94 | #else |
76a5e5d2 | 95 | m_info->m_task.tmAddr = NewTimerProc( MacTimerProc ) ; |
03e11df5 | 96 | #endif |
76a5e5d2 SC |
97 | m_info->m_task.tmWakeUp = 0 ; |
98 | m_info->m_task.tmReserved = 0 ; | |
99 | m_info->m_task.qType = 0 ; | |
100 | m_info->m_timer = this ; | |
101 | InsXTime((QElemPtr) &m_info->m_task ) ; | |
102 | PrimeTime( (QElemPtr) &m_info->m_task , m_milli ) ; | |
e9576ca5 SC |
103 | return FALSE; |
104 | } | |
105 | ||
106 | void wxTimer::Stop() | |
107 | { | |
e9576ca5 | 108 | m_milli = 0 ; |
76a5e5d2 | 109 | if ( m_info->m_task.tmAddr ) |
2f1ae414 | 110 | { |
76a5e5d2 SC |
111 | RmvTime( (QElemPtr) &m_info->m_task ) ; |
112 | DisposeTimerUPP(m_info->m_task.tmAddr) ; | |
113 | m_info->m_task.tmAddr = NULL ; | |
2f1ae414 SC |
114 | } |
115 | wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ; | |
e9576ca5 SC |
116 | } |
117 | ||
118 | ||
2f1ae414 | 119 |