]>
Commit | Line | Data |
---|---|---|
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 | #include "wx/thread.h" | |
33 | ||
34 | wxTimerImpl::wxTimerImpl(wxTimer *timer) | |
35 | { | |
36 | m_timer = timer; | |
37 | m_owner = NULL; | |
38 | m_idTimer = wxID_ANY; | |
39 | m_milli = 0; | |
40 | m_oneShot = false; | |
41 | } | |
42 | ||
43 | void wxTimerImpl::SetOwner(wxEvtHandler *owner, int timerid) | |
44 | { | |
45 | m_owner = owner; | |
46 | m_idTimer = timerid == wxID_ANY ? wxNewId() : timerid; | |
47 | } | |
48 | ||
49 | void wxTimerImpl::SendEvent() | |
50 | { | |
51 | wxTimerEvent event(*m_timer); | |
52 | (void)m_owner->SafelyProcessEvent(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 | wxT("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 |