move wxMGL's wxTimer to src/generic

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14275 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2002-02-17 14:55:41 +00:00
parent 1aee06c5b7
commit a0cb0ba509
27 changed files with 120 additions and 294 deletions

View File

@ -111,6 +111,7 @@ statusbr.cpp Generic NotMGL,NotX11,NotMicro
tabg.cpp Generic NotWin32,NotOS2
tbarsmpl.cpp Generic
textdlgg.cpp Generic
timer.cpp Generic LowLevel,NotMSW,NotX,NotGTK,NotOS2,NotMac,NotMicro
tipdlg.cpp Generic
tipwin.cpp Generic
treectlg.cpp Generic
@ -630,7 +631,6 @@ popupwin.cpp X11
region.cpp X11
settings.cpp X11
toplevel.cpp X11
timer.cpp X11
utils.cpp X11
window.cpp X11
@ -1203,7 +1203,6 @@ print.h X11H
private.h X11H
region.h X11H
settings.h X11H
timer.h X11H
toolbar.h X11H
toplevel.h X11H
window.h X11H
@ -1472,6 +1471,7 @@ splitter.h GenericH
statusbr.h GenericH
tabg.h GenericH NotWin32
textdlgg.h GenericH
timer.h GenericH
treectlg.h GenericH NotWin32
wizard.h GenericH
@ -1537,7 +1537,6 @@ dcscreen.cpp MGL LowLevel
toplevel.cpp MGL LowLevel
icon.cpp MGL LowLevel
settings.cpp MGL LowLevel
timer.cpp MGL LowLevel
window.cpp MGL LowLevel
utils.cpp MGL LowLevel

View File

@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.h
// Purpose: wxTimer class
// Purpose: Generic implementation of wxTimer class
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)

View File

@ -1,49 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.h
// Purpose: wxTimer class
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_TIMER_H__
#define __WX_TIMER_H__
#ifdef __GNUG__
#pragma interface "timer.h"
#endif
//-----------------------------------------------------------------------------
// wxTimer
//-----------------------------------------------------------------------------
class wxTimerDesc;
class WXDLLEXPORT wxTimer : public wxTimerBase
{
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int id = -1) : wxTimerBase(owner, id)
{ Init(); }
~wxTimer();
virtual bool Start(int millisecs = -1, bool oneShot = FALSE);
virtual void Stop();
virtual bool IsRunning() const;
// implementation
static void NotifyTimers();
protected:
void Init();
private:
wxTimerDesc *m_desc;
DECLARE_ABSTRACT_CLASS(wxTimer)
};
#endif // __WX_TIMER_H__

View File

@ -83,7 +83,8 @@ ALL_SOURCES = \
msw/snglinst.cpp \
msw/thread.cpp \
msw/utils.cpp \
msw/utilsexc.cpp
msw/utilsexc.cpp \
msw/volume.cpp
ALL_HEADERS = \
app.h \
@ -163,6 +164,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wfstream.h \
wx.h \
wxchar.h \
@ -266,6 +268,7 @@ BASE_MSW_OBJS = \
snglinst.o \
thread.o \
utils.o \
utilsexc.o
utilsexc.o \
volume.o

View File

@ -7,7 +7,6 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "timer.h"
#endif
@ -19,15 +18,33 @@
#pragma hdrstop
#endif
// ----------------------------------------------------------------------------
// NB: when using generic wxTimer implementation in your port, you *must* call
// wxTimer::NotifyTimers() often enough. The ideal place for this
// is in wxEventLoop::Dispatch().
// ----------------------------------------------------------------------------
#include "wx/timer.h"
#if wxUSE_TIMER
#include "wx/log.h"
#include "wx/module.h"
#include "wx/mgl/private.h"
extern "C" ulong _EVT_getTicks();
// ----------------------------------------------------------------------------
// Time input function
// ----------------------------------------------------------------------------
#ifdef __WXMGL__
// We take advantage of wxMGL's _EVT_getTicks because it is faster
// (especially under MS-DOS!) and more precise than wxGetLocalTimeMillis
// if we are unlucky and the latter combines information from two sources.
#include "wx/mgl/private.h"
extern "C" ulong _EVT_getTicks();
#define GetMillisecondsTime() _EVT_getTicks()
#else
#define GetMillisecondsTime() wxGetLocalTimeMillis().ToLong()
#endif
// ----------------------------------------------------------------------------
// helper structures and wxTimerScheduler
@ -66,11 +83,11 @@ void wxTimerScheduler::QueueTimer(wxTimerDesc *desc, unsigned long when)
return; // already scheduled
if ( when == 0 )
when = _EVT_getTicks() + desc->timer->GetInterval();
when = GetMillisecondsTime() + desc->timer->GetInterval();
desc->shotTime = when;
desc->running = TRUE;
wxLogTrace("mgl_timer", "queued timer %p at tick %i",
wxLogTrace("timer", "queued timer %p at tick %i",
desc->timer, when);
if ( m_timers )
@ -108,7 +125,7 @@ void wxTimerScheduler::NotifyTimers()
{
bool oneShot;
volatile bool timerDeleted;
unsigned long now = _EVT_getTicks();
unsigned long now = GetMillisecondsTime();
wxTimerDesc *desc;
while ( m_timers && m_timers->shotTime <= now )
@ -123,7 +140,7 @@ void wxTimerScheduler::NotifyTimers()
if ( !timerDeleted )
{
wxLogTrace("mgl_timer", "notified timer %p sheduled for %i",
wxLogTrace("timer", "notified timer %p sheduled for %i",
desc->timer, desc->shotTime);
desc->deleteFlag = NULL;
@ -135,7 +152,6 @@ void wxTimerScheduler::NotifyTimers()
}
// ----------------------------------------------------------------------------
// wxTimer
// ----------------------------------------------------------------------------
@ -153,7 +169,7 @@ void wxTimer::Init()
wxTimer::~wxTimer()
{
wxLogTrace("mgl_timer", "destroying timer %p...", this);
wxLogTrace("timer", "destroying timer %p...", this);
if ( IsRunning() )
Stop();
@ -165,7 +181,7 @@ wxTimer::~wxTimer()
*m_desc->deleteFlag = TRUE;
delete m_desc;
wxLogTrace("mgl_timer", " ...done destroying timer %p...", this);
wxLogTrace("timer", " ...done destroying timer %p...", this);
}
bool wxTimer::IsRunning() const
@ -175,7 +191,7 @@ bool wxTimer::IsRunning() const
bool wxTimer::Start(int millisecs, bool oneShot)
{
wxLogTrace("mgl_timer", "started timer %p: %i ms, oneshot=%i",
wxLogTrace("timer", "started timer %p: %i ms, oneshot=%i",
this, millisecs, oneShot);
if ( !wxTimerBase::Start(millisecs, oneShot) )

View File

@ -479,6 +479,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -592,6 +593,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \

View File

@ -479,6 +479,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -592,6 +593,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \

View File

@ -486,6 +486,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -619,6 +620,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \

View File

@ -486,6 +486,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -619,6 +620,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \

View File

@ -41,6 +41,7 @@ ALL_SOURCES = \
generic/tabg.cpp \
generic/tbarsmpl.cpp \
generic/textdlgg.cpp \
generic/timer.cpp \
generic/tipdlg.cpp \
generic/tipwin.cpp \
generic/treectlg.cpp \
@ -193,7 +194,6 @@ ALL_SOURCES = \
mgl/pen.cpp \
mgl/region.cpp \
mgl/settings.cpp \
mgl/timer.cpp \
mgl/toplevel.cpp \
mgl/utils.cpp \
mgl/window.cpp \
@ -441,6 +441,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -492,6 +493,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \
@ -685,6 +687,7 @@ GENERICOBJS = \
tabg.o \
tbarsmpl.o \
textdlgg.o \
timer.o \
tipdlg.o \
tipwin.o \
treectlg.o \
@ -714,7 +717,6 @@ GUI_LOWLEVEL_OBJS = \
pen.o \
region.o \
settings.o \
timer.o \
toplevel.o \
utils.o \
window.o

View File

@ -80,6 +80,7 @@ GENERICOBJS= accel.obj &
tabg.obj &
tbarsmpl.obj &
textdlgg.obj &
timer.obj &
tipdlg.obj &
tipwin.obj &
treectlg.obj &
@ -236,7 +237,6 @@ MGLOBJS = app.obj &
pen.obj &
region.obj &
settings.obj &
timer.obj &
toplevel.obj &
utils.obj &
window.obj
@ -394,9 +394,6 @@ region.obj: $(MGLDIR)\region.cpp
settings.obj: $(MGLDIR)\settings.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
timer.obj: $(MGLDIR)\timer.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
toplevel.obj: $(MGLDIR)\toplevel.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
@ -1035,6 +1032,9 @@ tbarsmpl.obj: $(GENDIR)\tbarsmpl.cpp
textdlgg.obj: $(GENDIR)\textdlgg.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
timer.obj: $(GENDIR)\timer.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
tipdlg.obj: $(GENDIR)\tipdlg.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<

View File

@ -441,6 +441,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -585,6 +586,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \

View File

@ -470,6 +470,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -580,6 +581,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \

View File

@ -259,6 +259,7 @@ ALL_SOURCES = \
msw/utils.cpp \
msw/utilsexc.cpp \
msw/ole/uuid.cpp \
msw/volume.cpp \
msw/wave.cpp \
msw/window.cpp \
html/helpctrl.cpp \
@ -498,6 +499,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -650,6 +652,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \
@ -932,6 +935,7 @@ GUIOBJS = \
treectrl.o \
utils.o \
utilsexc.o \
volume.o \
wave.o \
window.o

View File

@ -343,6 +343,7 @@ MSWOBJS = $(MSWDIR)\accel.obj \
$(MSWDIR)\utils.obj \
$(MSWDIR)\utilsexc.obj \
$(MSWDIR)\uuid.obj \
$(MSWDIR)\volume.obj \
$(MSWDIR)\wave.obj \
$(MSWDIR)\window.obj
@ -633,6 +634,8 @@ $(MSWDIR)\utilsexc.obj: $(MSWDIR)\utilsexc.$(SRCSUFF)
$(MSWDIR)\uuid.obj: $(OLEDIR)\uuid.$(SRCSUFF)
$(MSWDIR)\volume.obj: $(MSWDIR)\volume.$(SRCSUFF)
$(MSWDIR)\wave.obj: $(MSWDIR)\wave.$(SRCSUFF)
$(MSWDIR)\window.obj: $(MSWDIR)\window.$(SRCSUFF)

View File

@ -294,6 +294,7 @@ MSWOBJS = $(MSWDIR)\accel.obj \
$(MSWDIR)\toplevel.obj \
$(MSWDIR)\utils.obj \
$(MSWDIR)\utilsexc.obj \
$(MSWDIR)\volume.obj \
$(MSWDIR)\wave.obj \
$(MSWDIR)\window.obj
@ -495,6 +496,8 @@ $(MSWDIR)\utils.obj: $(MSWDIR)\utils.$(SRCSUFF)
$(MSWDIR)\utilsexc.obj: $(MSWDIR)\utilsexc.$(SRCSUFF)
$(MSWDIR)\volume.obj: $(MSWDIR)\volume.$(SRCSUFF)
$(MSWDIR)\wave.obj: $(MSWDIR)\wave.$(SRCSUFF)
$(MSWDIR)\window.obj: $(MSWDIR)\window.$(SRCSUFF)

View File

@ -283,6 +283,7 @@ MSWOBJS2 = $(MSWDIR)\palette.obj \
$(MSWDIR)\toplevel.obj \
$(MSWDIR)\utils.obj \
$(MSWDIR)\utilsexc.obj \
$(MSWDIR)\volume.obj \
$(MSWDIR)\wave.obj \
$(MSWDIR)\window.obj
@ -772,6 +773,11 @@ $(MSWDIR)/utilsexc.obj: $*.$(SRCSUFF)
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
<<
$(MSWDIR)/volume.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
<<
$(MSWDIR)/wave.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)

View File

@ -277,7 +277,8 @@ MSWOBJS_BASE = \
$(MSWDIR)/snglinst.$(OBJSUFF) \
$(MSWDIR)/thread.$(OBJSUFF) \
$(MSWDIR)/utils.$(OBJSUFF) \
$(MSWDIR)/utilsexc.$(OBJSUFF)
$(MSWDIR)/utilsexc.$(OBJSUFF) \
$(MSWDIR)/volume.$(OBJSUFF)
MSWOBJS = \
$(MSWOBJS_BASE) \

View File

@ -287,6 +287,7 @@ MSWOBJS = $(MSWDIR)\accel.obj \
$(MSWDIR)\utils.obj \
$(MSWDIR)\utilsexc.obj \
$(MSWDIR)\ole\uuid.obj \
$(MSWDIR)\volume.obj \
$(MSWDIR)\wave.obj \
$(MSWDIR)\window.obj

View File

@ -364,6 +364,7 @@ MSWOBJS = $(MSWDIR)\$D\accel.obj \
$(MSWDIR)\$D\utils.obj \
$(MSWDIR)\$D\utilsexc.obj \
$(OLEDIR)\$D\uuid.obj \
$(MSWDIR)\$D\volume.obj \
$(MSWDIR)\$D\wave.obj \
$(MSWDIR)\$D\window.obj

View File

@ -92,7 +92,8 @@ NONESSENTIALOBJS= accel.obj &
printps.obj &
prntdlgg.obj &
statline.obj &
tabg.obj
tabg.obj &
timer.obj
COMMONOBJS = &
y_tab.obj &
@ -329,6 +330,7 @@ MSWOBJS = accel.obj &
utils.obj &
utilsexc.obj &
uuid.obj &
volume.obj &
wave.obj &
window.obj
@ -713,6 +715,9 @@ utilsexc.obj: $(MSWDIR)\utilsexc.cpp
uuid.obj: $(OLEDIR)\uuid.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
volume.obj: $(MSWDIR)\volume.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
wave.obj: $(MSWDIR)\wave.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<

View File

@ -47,6 +47,7 @@ UNIV_HEADERS = \
univ/colschem.h \
univ/combobox.h \
univ/control.h \
univ/dialog.h \
univ/frame.h \
univ/gauge.h \
univ/inpcons.h \

View File

@ -560,6 +560,10 @@ SOURCE=.\msw\utils.cpp
SOURCE=.\msw\utilsexc.cpp
# End Source File
# Begin Source File
SOURCE=.\msw\volume.cpp
# End Source File
# Begin Source File
@ -953,6 +957,10 @@ SOURCE=..\include\wx\version.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\volume.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\wfstream.h
# End Source File
# Begin Source File

View File

@ -1016,6 +1016,10 @@ SOURCE=.\msw\utilsexc.cpp
# End Source File
# Begin Source File
SOURCE=.\msw\volume.cpp
# End Source File
# Begin Source File
SOURCE=.\msw\window.cpp
# End Source File
@ -2062,6 +2066,10 @@ SOURCE=..\include\wx\version.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\volume.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\wave.h
# End Source File
# Begin Source File
@ -2275,6 +2283,10 @@ SOURCE=..\include\wx\generic\textdlgg.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\generic\timer.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\generic\treectlg.h
# End Source File
# Begin Source File

View File

@ -1361,6 +1361,10 @@ SOURCE=.\msw\utilsexc.cpp
# End Source File
# Begin Source File
SOURCE=.\msw\volume.cpp
# End Source File
# Begin Source File
SOURCE=.\msw\wave.cpp
# End Source File
# Begin Source File
@ -2338,6 +2342,10 @@ SOURCE=..\include\wx\version.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\volume.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\wave.h
# End Source File
# Begin Source File
@ -2920,6 +2928,10 @@ SOURCE=..\include\wx\generic\textdlgg.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\generic\timer.h
# End Source File
# Begin Source File
SOURCE=..\include\wx\generic\treectlg.h
# End Source File
# Begin Source File

View File

@ -22,12 +22,12 @@ ALL_SOURCES = \
x11/joystick.cpp \
x11/main.cpp \
x11/minifram.cpp \
x11/nanox.c \
x11/palette.cpp \
x11/pen.cpp \
x11/popupwin.cpp \
x11/region.cpp \
x11/settings.cpp \
x11/timer.cpp \
x11/toplevel.cpp \
x11/utils.cpp \
x11/window.cpp \
@ -71,6 +71,7 @@ ALL_SOURCES = \
generic/tabg.cpp \
generic/tbarsmpl.cpp \
generic/textdlgg.cpp \
generic/timer.cpp \
generic/tipdlg.cpp \
generic/tipwin.cpp \
generic/treectlg.cpp \
@ -447,6 +448,7 @@ ALL_HEADERS = \
variant.h \
vector.h \
version.h \
volume.h \
wave.h \
wfstream.h \
window.h \
@ -490,7 +492,6 @@ ALL_HEADERS = \
x11/private.h \
x11/region.h \
x11/settings.h \
x11/timer.h \
x11/toolbar.h \
x11/toplevel.h \
x11/window.h \
@ -567,6 +568,7 @@ ALL_HEADERS = \
generic/statusbr.h \
generic/tabg.h \
generic/textdlgg.h \
generic/timer.h \
generic/treectlg.h \
generic/wizard.h \
unix/execute.h \
@ -613,12 +615,12 @@ GUI_LOWLEVEL_OBJS = \
joystick.o \
main.o \
minifram.o \
nanox.o \
palette.o \
pen.o \
popupwin.o \
region.o \
settings.o \
timer.o \
toplevel.o \
utils.o \
window.o
@ -792,6 +794,7 @@ GENERICOBJS = \
tabg.o \
tbarsmpl.o \
textdlgg.o \
timer.o \
tipdlg.o \
tipwin.o \
treectlg.o \

View File

@ -1,217 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: x11/timer.cpp
// Purpose: wxTimer implementation
// Author: Vaclav Slavik
// Id: $Id$
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "timer.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/timer.h"
#if wxUSE_TIMER
#include "wx/log.h"
#include "wx/module.h"
#include "wx/x11/private.h"
// ----------------------------------------------------------------------------
// helper structures and wxTimerScheduler
// ----------------------------------------------------------------------------
class wxTimerDesc
{
public:
wxTimerDesc(wxTimer *t) :
timer(t), running(FALSE), next(NULL), prev(NULL),
shotTime(0), deleteFlag(NULL) {}
wxTimer *timer;
bool running;
wxTimerDesc *next, *prev;
unsigned long shotTime;
volatile bool *deleteFlag; // see comment in ~wxTimer
};
class wxTimerScheduler
{
public:
wxTimerScheduler() : m_timers(NULL) {}
void QueueTimer(wxTimerDesc *desc, unsigned long when = 0);
void RemoveTimer(wxTimerDesc *desc);
void NotifyTimers();
private:
wxTimerDesc *m_timers;
};
void wxTimerScheduler::QueueTimer(wxTimerDesc *desc, unsigned long when)
{
if ( desc->running )
return; // already scheduled
if ( when == 0 )
{
unsigned long local = wxGetLocalTimeMillis().ToLong();
when = local + desc->timer->GetInterval();
}
desc->shotTime = when;
desc->running = TRUE;
wxLogTrace("mgl_timer", "queued timer %p at tick %i",
desc->timer, when);
if ( m_timers )
{
wxTimerDesc *d = m_timers;
while ( d->next && d->next->shotTime < when ) d = d->next;
desc->next = d->next;
desc->prev = d;
if ( d->next )
d->next->prev = desc;
d->next = desc;
}
else
{
m_timers = desc;
desc->prev = desc->next = NULL;
}
}
void wxTimerScheduler::RemoveTimer(wxTimerDesc *desc)
{
desc->running = FALSE;
if ( desc == m_timers )
m_timers = desc->next;
if ( desc->prev )
desc->prev->next = desc->next;
if ( desc->next )
desc->next->prev = desc->prev;
desc->prev = desc->next = NULL;
}
void wxTimerScheduler::NotifyTimers()
{
if ( m_timers )
{
bool oneShot;
volatile bool timerDeleted;
unsigned long now = wxGetLocalTimeMillis().ToLong();
wxTimerDesc *desc;
while ( m_timers && m_timers->shotTime <= now )
{
desc = m_timers;
oneShot = desc->timer->IsOneShot();
RemoveTimer(desc);
timerDeleted = FALSE;
desc->deleteFlag = &timerDeleted;
desc->timer->Notify();
if ( !timerDeleted )
{
wxLogTrace("mgl_timer", "notified timer %p sheduled for %i",
desc->timer, desc->shotTime);
desc->deleteFlag = NULL;
if ( !oneShot )
QueueTimer(desc, now + desc->timer->GetInterval());
}
}
}
}
// ----------------------------------------------------------------------------
// wxTimer
// ----------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
wxTimerScheduler *gs_scheduler = NULL;
void wxTimer::Init()
{
if ( !gs_scheduler )
gs_scheduler = new wxTimerScheduler;
m_desc = new wxTimerDesc(this);
}
wxTimer::~wxTimer()
{
wxLogTrace("mgl_timer", "destroying timer %p...", this);
if ( IsRunning() )
Stop();
// NB: this is a hack: wxTimerScheduler must have some way of knowing
// that wxTimer object was deleted under its hands -- this may
// happen if somebody is really nasty and deletes the timer
// from wxTimer::Notify()
if ( m_desc->deleteFlag != NULL )
*m_desc->deleteFlag = TRUE;
delete m_desc;
wxLogTrace("mgl_timer", " ...done destroying timer %p...", this);
}
bool wxTimer::IsRunning() const
{
return m_desc->running;
}
bool wxTimer::Start(int millisecs, bool oneShot)
{
wxLogTrace("mgl_timer", "started timer %p: %i ms, oneshot=%i",
this, millisecs, oneShot);
if ( !wxTimerBase::Start(millisecs, oneShot) )
return FALSE;
gs_scheduler->QueueTimer(m_desc);
return TRUE;
}
void wxTimer::Stop()
{
if ( !m_desc->running ) return;
gs_scheduler->RemoveTimer(m_desc);
}
/*static*/ void wxTimer::NotifyTimers()
{
if ( gs_scheduler )
gs_scheduler->NotifyTimers();
}
// A module to deallocate memory properly:
class wxTimerModule: public wxModule
{
DECLARE_DYNAMIC_CLASS(wxTimerModule)
public:
wxTimerModule() {}
bool OnInit() { return TRUE; }
void OnExit() { delete gs_scheduler; gs_scheduler = NULL; }
};
IMPLEMENT_DYNAMIC_CLASS(wxTimerModule, wxModule)
#endif //wxUSE_TIMER