/
timerimpl.cpp
84 lines (67 loc) · 2.28 KB
/
timerimpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/////////////////////////////////////////////////////////////////////////////
// Name: src/common/timerimpl.cpp
// Purpose: wxTimerBase implementation
// Author: Julian Smart, Guillermo Rodriguez, Vadim Zeitlin
// Modified by: VZ: extracted all non-wxTimer stuff in stopwatch.cpp (20.06.03)
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// (c) 1999 Guillermo Rodriguez <guille@iies.es>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// wxWin headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_TIMER
#include "wx/private/timer.h"
#include "wx/utils.h" // for wxNewId()
#include "wx/thread.h"
wxTimerImpl::wxTimerImpl(wxTimer *timer)
{
m_timer = timer;
m_owner = NULL;
m_idTimer = wxID_ANY;
m_milli = 0;
m_oneShot = false;
}
void wxTimerImpl::SetOwner(wxEvtHandler *owner, int timerid)
{
m_owner = owner;
m_idTimer = timerid == wxID_ANY ? wxNewId() : timerid;
}
void wxTimerImpl::SendEvent()
{
wxTimerEvent event(*m_timer);
(void)m_owner->SafelyProcessEvent(event);
}
bool wxTimerImpl::Start(int milliseconds, bool oneShot)
{
// under MSW timers only work when they're started from the main thread so
// let the caller know about it
#if wxUSE_THREADS
wxASSERT_MSG( wxThread::IsMain(),
wxT("timer can only be started from the main thread") );
#endif // wxUSE_THREADS
if ( IsRunning() )
{
// not stopping the already running timer might work for some
// platforms (no problems under MSW) but leads to mysterious crashes
// on the others (GTK), so to be on the safe side do it here
Stop();
}
if ( milliseconds != -1 )
{
m_milli = milliseconds;
}
m_oneShot = oneShot;
return true;
}
#endif // wxUSE_TIMER