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