]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/timer.cpp
correction for memory leak
[wxWidgets.git] / src / mac / carbon / timer.cpp
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 m_info.m_task.qType = 0 ;
83 m_info.m_timer = this ;
84 InsXTime((QElemPtr) &m_info.m_task ) ;
85 PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ;
86 return FALSE;
87 }
88
89 void wxTimer::Stop()
90 {
91 m_milli = 0 ;
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 ) ;
99 }
100
101
102