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