]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/timercmn.cpp
simplify code so it always returns the same object
[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// 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
42IMPLEMENT_DYNAMIC_CLASS(wxTimerEvent, wxEvent)
43
44wxDEFINE_EVENT(wxEVT_TIMER, wxTimerEvent);
45
46// ============================================================================
47// wxTimerBase implementation
48// ============================================================================
49
50wxTimer::~wxTimer()
51{
52 Stop();
53
54 delete m_impl;
55}
56
57void 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( wxT("No timer implementation for this platform") );
64
65 }
66}
67
68// ============================================================================
69// rest of wxTimer implementation forwarded to wxTimerImpl
70// ============================================================================
71
72void wxTimer::SetOwner(wxEvtHandler *owner, int timerid)
73{
74 wxCHECK_RET( m_impl, wxT("uninitialized timer") );
75
76 m_impl->SetOwner(owner, timerid);
77}
78
79wxEvtHandler *wxTimer::GetOwner() const
80{
81 wxCHECK_MSG( m_impl, NULL, wxT("uninitialized timer") );
82
83 return m_impl->GetOwner();
84}
85
86bool wxTimer::Start(int milliseconds, bool oneShot)
87{
88 wxCHECK_MSG( m_impl, false, wxT("uninitialized timer") );
89
90 return m_impl->Start(milliseconds, oneShot);
91}
92
93void wxTimer::Stop()
94{
95 wxCHECK_RET( m_impl, wxT("uninitialized timer") );
96
97 if ( m_impl->IsRunning() )
98 m_impl->Stop();
99}
100
101void 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(), wxT("wxTimer::Notify() should be overridden.") );
106
107 m_impl->SendEvent();
108}
109
110bool wxTimer::IsRunning() const
111{
112 wxCHECK_MSG( m_impl, false, wxT("uninitialized timer") );
113
114 return m_impl->IsRunning();
115}
116
117int wxTimer::GetId() const
118{
119 wxCHECK_MSG( m_impl, wxID_ANY, wxT("uninitialized timer") );
120
121 return m_impl->GetId();
122}
123
124int wxTimer::GetInterval() const
125{
126 wxCHECK_MSG( m_impl, -1, wxT("uninitialized timer") );
127
128 return m_impl->GetInterval();
129}
130
131bool wxTimer::IsOneShot() const
132{
133 wxCHECK_MSG( m_impl, false, wxT("uninitialized timer") );
134
135 return m_impl->IsOneShot();
136}
137
138#endif // wxUSE_TIMER
139