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