]>
Commit | Line | Data |
---|---|---|
c2ca375c VZ |
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 | // 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 | #include "wx/private/timer.h" | |
31 | #include "wx/utils.h" // for wxNewId() | |
32 | ||
33 | wxTimerImpl::wxTimerImpl(wxTimer *timer) | |
34 | { | |
35 | m_timer = timer; | |
36 | m_owner = NULL; | |
37 | m_idTimer = wxID_ANY; | |
38 | m_milli = 0; | |
39 | m_oneShot = false; | |
40 | } | |
41 | ||
42 | void wxTimerImpl::SetOwner(wxEvtHandler *owner, int timerid) | |
43 | { | |
44 | m_owner = owner; | |
45 | m_idTimer = timerid == wxID_ANY ? wxNewId() : timerid; | |
46 | } | |
47 | ||
48 | void wxTimerImpl::SendEvent() | |
49 | { | |
50 | wxTimerEvent event(m_idTimer, m_milli); | |
51 | event.SetEventObject(m_owner); | |
52 | (void)m_owner->ProcessEvent(event); | |
53 | } | |
54 | ||
55 | bool wxTimerImpl::Start(int milliseconds, bool oneShot) | |
56 | { | |
57 | // under MSW timers only work when they're started from the main thread so | |
58 | // let the caller know about it | |
59 | #if wxUSE_THREADS | |
60 | wxASSERT_MSG( wxThread::IsMain(), | |
61 | _T("timer can only be started from the main thread") ); | |
62 | #endif // wxUSE_THREADS | |
63 | ||
64 | if ( IsRunning() ) | |
65 | { | |
66 | // not stopping the already running timer might work for some | |
67 | // platforms (no problems under MSW) but leads to mysterious crashes | |
68 | // on the others (GTK), so to be on the safe side do it here | |
69 | Stop(); | |
70 | } | |
71 | ||
72 | if ( milliseconds != -1 ) | |
73 | { | |
74 | m_milli = milliseconds; | |
75 | } | |
76 | ||
77 | m_oneShot = oneShot; | |
78 | ||
79 | return true; | |
80 | } | |
81 | ||
82 | ||
83 | #endif // wxUSE_TIMER | |
84 |