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