]> git.saurik.com Git - wxWidgets.git/blame - src/common/timercmn.cpp
Allow creating wxGraphicsBitmap and wxGraphicsContext from wxImage.
[wxWidgets.git] / src / common / timercmn.cpp
CommitLineData
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
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
e47859da 42IMPLEMENT_DYNAMIC_CLASS(wxTimerEvent, wxEvent)
c801d85f 43
3c778901
VZ
44wxDEFINE_EVENT(wxEVT_TIMER, wxTimerEvent);
45
0470b1e6 46// ============================================================================
e2478fde 47// wxTimerBase implementation
0470b1e6 48// ============================================================================
c801d85f 49
c2ca375c 50wxTimer::~wxTimer()
799ea011 51{
c2ca375c
VZ
52 Stop();
53
54 delete m_impl;
799ea011
GD
55}
56
c2ca375c
VZ
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 {
9a83f860 63 wxFAIL_MSG( wxT("No timer implementation for this platform") );
c2ca375c
VZ
64
65 }
66}
67
68// ============================================================================
69// rest of wxTimer implementation forwarded to wxTimerImpl
70// ============================================================================
71
72void wxTimer::SetOwner(wxEvtHandler *owner, int timerid)
73{
9a83f860 74 wxCHECK_RET( m_impl, wxT("uninitialized timer") );
c2ca375c
VZ
75
76 m_impl->SetOwner(owner, timerid);
77}
78
79wxEvtHandler *wxTimer::GetOwner() const
80{
9a83f860 81 wxCHECK_MSG( m_impl, NULL, wxT("uninitialized timer") );
c2ca375c
VZ
82
83 return m_impl->GetOwner();
84}
85
86bool wxTimer::Start(int milliseconds, bool oneShot)
87{
9a83f860 88 wxCHECK_MSG( m_impl, false, wxT("uninitialized timer") );
c2ca375c
VZ
89
90 return m_impl->Start(milliseconds, oneShot);
91}
92
93void wxTimer::Stop()
94{
9a83f860 95 wxCHECK_RET( m_impl, wxT("uninitialized timer") );
c2ca375c
VZ
96
97 if ( m_impl->IsRunning() )
98 m_impl->Stop();
99}
100
101void wxTimer::Notify()
ed791986
VZ
102{
103 // the base class version generates an event if it has owner - which it
104 // should because otherwise nobody can process timer events
9a83f860 105 wxCHECK_RET( GetOwner(), wxT("wxTimer::Notify() should be overridden.") );
ed791986 106
c2ca375c 107 m_impl->SendEvent();
ed791986 108}
b8f04990 109
c2ca375c 110bool wxTimer::IsRunning() const
99646f7e 111{
9a83f860 112 wxCHECK_MSG( m_impl, false, wxT("uninitialized timer") );
99646f7e 113
c2ca375c
VZ
114 return m_impl->IsRunning();
115}
116
117int wxTimer::GetId() const
118{
9a83f860 119 wxCHECK_MSG( m_impl, wxID_ANY, wxT("uninitialized timer") );
c2ca375c
VZ
120
121 return m_impl->GetId();
122}
99646f7e 123
c2ca375c
VZ
124int wxTimer::GetInterval() const
125{
9a83f860 126 wxCHECK_MSG( m_impl, -1, wxT("uninitialized timer") );
c2ca375c
VZ
127
128 return m_impl->GetInterval();
129}
130
131bool wxTimer::IsOneShot() const
132{
9a83f860 133 wxCHECK_MSG( m_impl, false, wxT("uninitialized timer") );
99646f7e 134
c2ca375c 135 return m_impl->IsOneShot();
99646f7e
VZ
136}
137
e2478fde 138#endif // wxUSE_TIMER
1e6feb95 139