]> git.saurik.com Git - wxWidgets.git/blob - src/common/timercmn.cpp
Clear grid selection more consistently prior clear operations; improved Clear() tests...
[wxWidgets.git] / src / common / timercmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/timercmn.cpp
3 // Purpose: wxTimerBase implementation
4 // Author: Julian Smart, Guillermo Rodriguez, Vadim Zeitlin
5 // Modified by: VZ: extracted all non-wxTimer stuff in stopwatch.cpp (20.06.03)
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // (c) 1999 Guillermo Rodriguez <guille@iies.es>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 // ============================================================================
14 // declarations
15 // ============================================================================
16
17 // ----------------------------------------------------------------------------
18 // wxWin headers
19 // ----------------------------------------------------------------------------
20
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
23
24 #ifdef __BORLANDC__
25 #pragma hdrstop
26 #endif
27
28 #if wxUSE_TIMER
29
30 #ifndef WX_PRECOMP
31 #include "wx/app.h"
32 #endif
33
34 #include "wx/timer.h"
35 #include "wx/apptrait.h"
36 #include "wx/private/timer.h"
37
38 // ----------------------------------------------------------------------------
39 // wxWin macros
40 // ----------------------------------------------------------------------------
41
42 IMPLEMENT_DYNAMIC_CLASS(wxTimerEvent, wxEvent)
43
44 wxDEFINE_EVENT(wxEVT_TIMER, wxTimerEvent);
45
46 // ============================================================================
47 // wxTimerBase implementation
48 // ============================================================================
49
50 wxTimer::~wxTimer()
51 {
52 Stop();
53
54 delete m_impl;
55 }
56
57 void wxTimer::Init()
58 {
59 wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
60 m_impl = traits ? traits->CreateTimerImpl(this) : NULL;
61 if ( !m_impl )
62 {
63 wxFAIL_MSG( _T("No timer implementation for this platform") );
64
65 }
66 }
67
68 // ============================================================================
69 // rest of wxTimer implementation forwarded to wxTimerImpl
70 // ============================================================================
71
72 void wxTimer::SetOwner(wxEvtHandler *owner, int timerid)
73 {
74 wxCHECK_RET( m_impl, _T("uninitialized timer") );
75
76 m_impl->SetOwner(owner, timerid);
77 }
78
79 wxEvtHandler *wxTimer::GetOwner() const
80 {
81 wxCHECK_MSG( m_impl, NULL, _T("uninitialized timer") );
82
83 return m_impl->GetOwner();
84 }
85
86 bool wxTimer::Start(int milliseconds, bool oneShot)
87 {
88 wxCHECK_MSG( m_impl, false, _T("uninitialized timer") );
89
90 return m_impl->Start(milliseconds, oneShot);
91 }
92
93 void wxTimer::Stop()
94 {
95 wxCHECK_RET( m_impl, _T("uninitialized timer") );
96
97 if ( m_impl->IsRunning() )
98 m_impl->Stop();
99 }
100
101 void wxTimer::Notify()
102 {
103 // the base class version generates an event if it has owner - which it
104 // should because otherwise nobody can process timer events
105 wxCHECK_RET( GetOwner(), _T("wxTimer::Notify() should be overridden.") );
106
107 m_impl->SendEvent();
108 }
109
110 bool wxTimer::IsRunning() const
111 {
112 wxCHECK_MSG( m_impl, false, _T("uninitialized timer") );
113
114 return m_impl->IsRunning();
115 }
116
117 int wxTimer::GetId() const
118 {
119 wxCHECK_MSG( m_impl, wxID_ANY, _T("uninitialized timer") );
120
121 return m_impl->GetId();
122 }
123
124 int wxTimer::GetInterval() const
125 {
126 wxCHECK_MSG( m_impl, -1, _T("uninitialized timer") );
127
128 return m_impl->GetInterval();
129 }
130
131 bool wxTimer::IsOneShot() const
132 {
133 wxCHECK_MSG( m_impl, false, _T("uninitialized timer") );
134
135 return m_impl->IsOneShot();
136 }
137
138 #endif // wxUSE_TIMER
139