]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/timer.cpp
don't reset the selection after event was vetoed if there is no old selection
[wxWidgets.git] / src / mac / classic / timer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/timer.cpp
3 // Purpose: wxTimer implementation
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/timer.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/dynarray.h"
19 #endif
20
21 IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler)
22
23 #ifdef __WXMAC__
24 #include "wx/mac/private.h"
25 #endif
26 #ifndef __DARWIN__
27 #include <Timer.h>
28 #endif
29
30 typedef struct MacTimerInfo
31 {
32 TMTask m_task;
33 wxMacNotifierTableRef m_table ;
34 wxTimer* m_timer ;
35 } ;
36
37 static void wxProcessTimer( unsigned long event , void *data ) ;
38
39 static pascal void MacTimerProc( TMTask * t )
40 {
41 MacTimerInfo * tm = (MacTimerInfo*) t ;
42 wxMacAddEvent( tm->m_table , wxProcessTimer, 0 , (void*) tm->m_timer , TRUE ) ;
43 }
44
45 // we need this array to track timers that are being deleted within the Notify procedure
46 // adding the timer before the Notify call and checking after whether it still is in there
47 // as the destructor would have removed it from the array
48
49 wxArrayPtrVoid gTimersInProcess ;
50
51 static void wxProcessTimer( unsigned long event , void *data )
52 {
53 if ( !data )
54 return ;
55
56 wxTimer* timer = (wxTimer*) data ;
57
58 if ( timer->IsOneShot() )
59 timer->Stop() ;
60
61 gTimersInProcess.Add( timer ) ;
62
63 timer->Notify();
64
65 int index = gTimersInProcess.Index( timer ) ;
66
67 if ( index != wxNOT_FOUND )
68 {
69 gTimersInProcess.RemoveAt( index ) ;
70
71 if ( !timer->IsOneShot() && timer->m_info->m_task.tmAddr )
72 {
73 PrimeTime( (QElemPtr) &timer->m_info->m_task , timer->GetInterval() ) ;
74 }
75 }
76 }
77
78 void wxTimer::Init()
79 {
80 m_info = new MacTimerInfo() ;
81 m_info->m_task.tmAddr = NULL ;
82 m_info->m_task.tmWakeUp = 0 ;
83 m_info->m_task.tmReserved = 0 ;
84 m_info->m_task.qType = 0 ;
85 m_info->m_table = wxMacGetNotifierTable() ;
86 m_info->m_timer = this ;
87 }
88
89 bool wxTimer::IsRunning() const
90 {
91 // as the qType may already indicate it is elapsed, but it
92 // was not handled internally yet
93 return ( m_info->m_task.tmAddr != NULL ) ;
94 }
95
96 wxTimer::~wxTimer()
97 {
98 Stop();
99 if (m_info != NULL) {
100 delete m_info ;
101 m_info = NULL ;
102 }
103 int index = gTimersInProcess.Index( this ) ;
104 if ( index != wxNOT_FOUND )
105 gTimersInProcess.RemoveAt( index ) ;
106 }
107
108 bool wxTimer::Start(int milliseconds,bool mode)
109 {
110 (void)wxTimerBase::Start(milliseconds, mode);
111
112 wxCHECK_MSG( m_milli > 0, false, wxT("invalid value for timer timeout") );
113 wxCHECK_MSG( m_info->m_task.tmAddr == NULL , false, wxT("attempting to restart a timer") );
114
115 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
116 m_info->m_task.tmAddr = NewTimerUPP( MacTimerProc ) ;
117 #else
118 m_info->m_task.tmAddr = NewTimerProc( MacTimerProc ) ;
119 #endif
120 m_info->m_task.tmWakeUp = 0 ;
121 m_info->m_task.tmReserved = 0 ;
122 m_info->m_task.qType = 0 ;
123 m_info->m_timer = this ;
124 InsXTime((QElemPtr) &m_info->m_task ) ;
125 PrimeTime( (QElemPtr) &m_info->m_task , m_milli ) ;
126 return true;
127 }
128
129 void wxTimer::Stop()
130 {
131 if ( m_info->m_task.tmAddr )
132 {
133 RmvTime( (QElemPtr) &m_info->m_task ) ;
134 DisposeTimerUPP(m_info->m_task.tmAddr) ;
135 m_info->m_task.tmAddr = NULL ;
136 }
137 wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;
138 }