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