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