]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
0470b1e6 | 2 | // Name: 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> |
55d99c7a | 10 | // Licence: wxWindows licence |
c801d85f KB |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
0470b1e6 VZ |
13 | // ============================================================================ |
14 | // declarations | |
15 | // ============================================================================ | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
91ff98b7 | 18 | // wxWin headers |
0470b1e6 VZ |
19 | // ---------------------------------------------------------------------------- |
20 | ||
14f355c2 | 21 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
0470b1e6 | 22 | #pragma implementation "timerbase.h" |
c801d85f KB |
23 | #endif |
24 | ||
25 | // For compilers that support precompilation, includes "wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
0470b1e6 | 29 | #pragma hdrstop |
c801d85f KB |
30 | #endif |
31 | ||
e2478fde | 32 | #if wxUSE_TIMER |
07cf98cb | 33 | |
e2478fde | 34 | #ifndef WX_PRECOMP |
46446cc2 | 35 | #include "wx/timer.h" |
c801d85f KB |
36 | #endif |
37 | ||
ed791986 VZ |
38 | // ---------------------------------------------------------------------------- |
39 | // wxWin macros | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
e2478fde | 42 | IMPLEMENT_DYNAMIC_CLASS(wxTimerEvent, wxEvent) |
c801d85f | 43 | |
0470b1e6 | 44 | // ============================================================================ |
e2478fde | 45 | // wxTimerBase implementation |
0470b1e6 | 46 | // ============================================================================ |
c801d85f | 47 | |
799ea011 GD |
48 | wxTimerBase::~wxTimerBase() |
49 | { | |
50 | // this destructor is required for Darwin | |
51 | } | |
52 | ||
ed791986 VZ |
53 | void wxTimerBase::Notify() |
54 | { | |
55 | // the base class version generates an event if it has owner - which it | |
56 | // should because otherwise nobody can process timer events | |
57 | wxCHECK_RET( m_owner, _T("wxTimer::Notify() should be overridden.") ); | |
58 | ||
59 | wxTimerEvent event(m_idTimer, m_milli); | |
60 | (void)m_owner->ProcessEvent(event); | |
61 | } | |
b8f04990 | 62 | |
99646f7e VZ |
63 | bool wxTimerBase::Start(int milliseconds, bool oneShot) |
64 | { | |
2b5f62a0 VZ |
65 | // under MSW timers only work when they're started from the main thread so |
66 | // let the caller know about it | |
67 | #if wxUSE_THREADS | |
68 | wxASSERT_MSG( wxThread::IsMain(), | |
69 | _T("timer can only be started from the main thread") ); | |
70 | #endif // wxUSE_THREADS | |
71 | ||
99646f7e VZ |
72 | if ( IsRunning() ) |
73 | { | |
74 | // not stopping the already running timer might work for some | |
75 | // platforms (no problems under MSW) but leads to mysterious crashes | |
76 | // on the others (GTK), so to be on the safe side do it here | |
77 | Stop(); | |
78 | } | |
79 | ||
80 | if ( milliseconds != -1 ) | |
81 | { | |
82 | m_milli = milliseconds; | |
83 | } | |
84 | ||
85 | m_oneShot = oneShot; | |
86 | ||
87 | return TRUE; | |
88 | } | |
89 | ||
e2478fde | 90 | #endif // wxUSE_TIMER |
1e6feb95 | 91 |