wxBase/GUI separation: 1st step, wxMSW should build, all the rest is broken
[wxWidgets.git] / src / common / timercmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #ifdef __GNUG__
22 #pragma implementation "timerbase.h"
23 #endif
24
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
27
28 #ifdef __BORLANDC__
29 #pragma hdrstop
30 #endif
31
32 #if wxUSE_TIMER
33
34 #ifndef WX_PRECOMP
35 #endif
36
37 // ----------------------------------------------------------------------------
38 // wxWin macros
39 // ----------------------------------------------------------------------------
40
41 IMPLEMENT_DYNAMIC_CLASS(wxTimerEvent, wxEvent)
42
43 // ============================================================================
44 // wxTimerBase implementation
45 // ============================================================================
46
47 wxTimerBase::~wxTimerBase()
48 {
49 // this destructor is required for Darwin
50 }
51
52 void wxTimerBase::Notify()
53 {
54 // the base class version generates an event if it has owner - which it
55 // should because otherwise nobody can process timer events
56 wxCHECK_RET( m_owner, _T("wxTimer::Notify() should be overridden.") );
57
58 wxTimerEvent event(m_idTimer, m_milli);
59 (void)m_owner->ProcessEvent(event);
60 }
61
62 bool wxTimerBase::Start(int milliseconds, bool oneShot)
63 {
64 // under MSW timers only work when they're started from the main thread so
65 // let the caller know about it
66 #if wxUSE_THREADS
67 wxASSERT_MSG( wxThread::IsMain(),
68 _T("timer can only be started from the main thread") );
69 #endif // wxUSE_THREADS
70
71 if ( IsRunning() )
72 {
73 // not stopping the already running timer might work for some
74 // platforms (no problems under MSW) but leads to mysterious crashes
75 // on the others (GTK), so to be on the safe side do it here
76 Stop();
77 }
78
79 if ( milliseconds != -1 )
80 {
81 m_milli = milliseconds;
82 }
83
84 m_oneShot = oneShot;
85
86 return TRUE;
87 }
88
89 #endif // wxUSE_TIMER
90