]> git.saurik.com Git - wxWidgets.git/blame - src/mac/timer.cpp
correction to maintain data array in synch with string array
[wxWidgets.git] / src / mac / timer.cpp
CommitLineData
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 19IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject)
2f1ae414
SC
20#endif
21
22static void wxProcessTimer( unsigned long event , void *data ) ;
23
d015713e 24static pascal void MacTimerProc( TMTask * t )
2f1ae414
SC
25{
26 MacTimerInfo * tm = (MacTimerInfo*) t ;
27 wxMacAddEvent( tm->m_table , wxProcessTimer, 0 , (void*) tm->m_timer , TRUE ) ;
28}
29
d015713e 30static void wxProcessTimer( unsigned long event , void *data )
2f1ae414
SC
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}
e9576ca5 46
d015713e 47void wxTimer::Init()
e9576ca5 48{
2f1ae414
SC
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
57bool wxTimer::IsRunning() const
58{
59 return ( m_info.m_task.qType & kTMTaskActive ) ;
e9576ca5
SC
60}
61
62wxTimer::~wxTimer()
63{
64 Stop();
65}
66
67bool wxTimer::Start(int milliseconds,bool mode)
68{
2f1ae414 69 (void)wxTimerBase::Start(milliseconds, mode);
e9576ca5 70
2f1ae414
SC
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") );
e9576ca5 73
2f1ae414
SC
74 m_milli = milliseconds;
75 m_info.m_task.tmAddr = NewTimerProc( MacTimerProc ) ;
76 m_info.m_task.tmWakeUp = 0 ;
77 m_info.m_task.tmReserved = 0 ;
78 InsXTime((QElemPtr) &m_info.m_task ) ;
79 PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ;
e9576ca5
SC
80 return FALSE;
81}
82
83void wxTimer::Stop()
84{
e9576ca5 85 m_milli = 0 ;
2f1ae414
SC
86 if ( m_info.m_task.tmAddr )
87 {
88 RmvTime( (QElemPtr) &m_info.m_task ) ;
89 DisposeTimerUPP(m_info.m_task.tmAddr) ;
90 m_info.m_task.tmAddr = NULL ;
91 }
92 wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ;
e9576ca5
SC
93}
94
95
2f1ae414 96