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