preparation for allowing to use wxTimer in wxBase (heavily modified patch 1113088):

1. Changed wxTimer to use wxTimerImpl
2. Added Unix-specific generic timer implementation
3. Added wxAppTraits::CreateTimerImpl()


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45544 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-04-20 01:29:16 +00:00
parent a9c9588480
commit c2ca375c56
62 changed files with 1554 additions and 931 deletions

View File

@@ -24,6 +24,8 @@ class WXDLLIMPEXP_BASE wxLog;
class WXDLLIMPEXP_BASE wxMessageOutput;
class WXDLLEXPORT wxRendererNative;
class WXDLLIMPEXP_BASE wxString;
class WXDLLIMPEXP_BASE wxTimer;
class WXDLLIMPEXP_BASE wxTimerImpl;
class GSocketGUIFunctionsTable;
@@ -117,6 +119,10 @@ public:
virtual GSocketGUIFunctionsTable* GetSocketGUIFunctionsTable() = 0;
#endif
#if wxUSE_TIMER
// return platform and toolkit dependent wxTimer implementation
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) = 0;
#endif
// functions returning port-specific information
// ------------------------------------------------------------------------

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.h
// Name: wx/cocoa/private/timer.h
// Purpose: Cocoa wxTimer class
// Author: Ryan Norton
// Id: $Id$
@@ -7,9 +7,10 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_COCOA_PRIVATE_TIMER_H_
#define _WX_COCOA_PRIVATE_TIMER_H_
#ifndef __WX_TIMER_H__
#define __WX_TIMER_H__
#include "wx/private/timer.h"
#include "wx/cocoa/ObjcRef.h"
@@ -19,29 +20,24 @@
DECLARE_WXCOCOA_OBJC_CLASS(NSTimer);
class WXDLLEXPORT wxTimer : public wxTimerBase
class WXDLLEXPORT wxCocoaTimerImpl : public wxTimerImpl
{
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int timerid = -1) : wxTimerBase(owner, timerid)
{ Init(); }
virtual ~wxTimer();
wxCocoaTimerImpl(wxTimer* timer) : wxTimerImpl(timer) { Init(); }
virtual ~wxCocoaTimerImpl();
virtual bool Start(int millisecs = -1, bool oneShot = false);
virtual void Stop();
virtual bool IsRunning() const;
inline WX_NSTimer GetNSTimer()
{ return m_cocoaNSTimer; }
WX_NSTimer GetNSTimer() { return m_cocoaNSTimer; }
protected:
void Init();
private:
WX_NSTimer m_cocoaNSTimer;
DECLARE_ABSTRACT_CLASS(wxTimer)
};
#endif // __WX_TIMER_H__
#endif // _WX_COCOA_PRIVATE_TIMER_H_

View File

@@ -157,7 +157,7 @@ BEGIN_DECLARE_EVENT_TYPES()
// Sockets and timers send events, too
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_SOCKET, 50)
DECLARE_EVENT_TYPE(wxEVT_TIMER , 80)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_TIMER , 80)
// Mouse event types
DECLARE_EVENT_TYPE(wxEVT_LEFT_DOWN, 100)

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.h
// Name: wx/generic/private/timer.h
// Purpose: Generic implementation of wxTimer class
// Author: Vaclav Slavik
// Id: $Id$
@@ -8,8 +8,10 @@
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_TIMER_H__
#define __WX_TIMER_H__
#ifndef _WX_GENERIC_PRIVATE_TIMER_H_
#define _WX_GENERIC_PRIVATE_TIMER_H_
#include "wx/private/timer.h"
//-----------------------------------------------------------------------------
// wxTimer
@@ -17,13 +19,11 @@
class wxTimerDesc;
class WXDLLEXPORT wxTimer : public wxTimerBase
class WXDLLEXPORT wxGenericTimerImpl : public wxTimerImpl
{
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int timerid = -1) : wxTimerBase(owner, timerid)
{ Init(); }
virtual ~wxTimer();
wxGenericTimerImpl(wxTimer* timer) : wxTimerImpl(timer) { Init(); }
virtual ~wxGenericTimerImpl();
virtual bool Start(int millisecs = -1, bool oneShot = false);
virtual void Stop();
@@ -38,8 +38,6 @@ protected:
private:
wxTimerDesc *m_desc;
DECLARE_ABSTRACT_CLASS(wxTimer)
};
#endif // __WX_TIMER_H__
#endif // _WX_GENERIC_PRIVATE_TIMER_H_

View File

@@ -1,38 +1,32 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/timer.h
// Purpose:
// Name: wx/private/gtk/timer.h
// Purpose: wxTimerImpl for wxGTK
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_TIMER_H_
#define _WX_GTK_TIMER_H_
#ifndef _WX_GTK_PRIVATE_TIMER_H_
#define _WX_GTK_PRIVATE_TIMER_H_
#include "wx/private/timer.h"
//-----------------------------------------------------------------------------
// wxTimer
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxTimer : public wxTimerBase
class WXDLLIMPEXP_CORE wxGTKTimerImpl : public wxTimerImpl
{
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int id = -1) : wxTimerBase(owner, id)
{ Init(); }
virtual ~wxTimer();
wxGTKTimerImpl(wxTimer* timer) : wxTimerImpl(timer) { m_sourceId = 0; };
virtual bool Start(int millisecs = -1, bool oneShot = false);
virtual bool Start( int millisecs = -1, bool oneShot = false );
virtual void Stop();
virtual bool IsRunning() const { return m_sourceId != 0; }
private:
void Init();
unsigned m_sourceId;
DECLARE_ABSTRACT_CLASS(wxTimer)
protected:
int m_sourceId;
};
#endif // _WX_GTK_TIMER_H_
#endif // _WX_GTK_PRIVATE_TIMER_H_

View File

@@ -1,39 +1,34 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk1/timer.h
// Purpose:
// Name: wx/gtk1/private/timer.h
// Purpose: wxTimerImpl for wxGTK
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __GTKTIMERH__
#define __GTKTIMERH__
#ifndef _WX_GTK1_PRIVATE_TIMER_H_
#define _WX_GTK1_PRIVATE_TIMER_H_
#include "wx/private/timer.h"
//-----------------------------------------------------------------------------
// wxTimer
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxTimer : public wxTimerBase
class WXDLLIMPEXP_CORE wxGTKTimerImpl : public wxTimerImpl
{
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int id = -1) : wxTimerBase(owner, id)
{ Init(); }
virtual ~wxTimer();
wxGTKTimerImpl(wxTimer *timer) : wxTimerImpl(timer) { m_tag = -1; }
virtual bool Start( int millisecs = -1, bool oneShot = FALSE );
virtual bool Start(int millisecs = -1, bool oneShot = FALSE);
virtual void Stop();
virtual bool IsRunning() const { return m_tag != -1; }
protected:
void Init();
int m_tag;
private:
DECLARE_ABSTRACT_CLASS(wxTimer)
// registered timeout id, -1 if the timer isn't running
int m_tag;
};
#endif // __GTKTIMERH__
#endif // _WX_GTK1_PRIVATE_TIMER_H_

View File

@@ -19,6 +19,10 @@
class WXDLLEXPORT wxConsoleAppTraits : public wxConsoleAppTraitsBase
{
public:
// no timer support in wxBase yet
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) { return NULL; };
#endif
// other miscellaneous helpers
// ---------------------------
@@ -30,6 +34,9 @@ public:
class WXDLLEXPORT wxGUIAppTraits : public wxGUIAppTraitsBase
{
public:
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer);
#endif
// other miscellaneous helpers
// ---------------------------

View File

@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/mac/carbon/private/timer.h
// Purpose: wxTimer class
// Author: Stefan Csomor
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MAC_PRIVATE_TIMER_H_
#define _WX_MAC_PRIVATE_TIMER_H_
#include "wx/mac/macnotfy.h"
#include "wx/private/timer.h"
struct MacTimerInfo;
class WXDLLEXPORT wxCarbonTimerImpl : public wxTimerImpl
{
public:
wxCarbonTimerImpl(wxTimer *timer);
virtual ~wxCarbonTimerImpl();
virtual bool Start(int milliseconds = -1, bool one_shot = false);
virtual void Stop();
virtual bool IsRunning() const;
private:
MacTimerInfo *m_info;
};
#endif // _WX_MAC_PRIVATE_TIMER_H_

View File

@@ -1,44 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.h
// Purpose: wxTimer class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TIMER_H_
#define _WX_TIMER_H_
#include "wx/object.h"
#include "wx/mac/macnotfy.h"
class wxTimer ;
struct MacTimerInfo ;
class WXDLLEXPORT wxTimer: public wxTimerBase
{
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int id = -1) : wxTimerBase(owner, id) { Init(); }
virtual ~wxTimer();
virtual bool Start(int milliseconds = -1,
bool one_shot = FALSE); // Start timer
virtual void Stop(); // Stop timer
virtual bool IsRunning() const ;
MacTimerInfo* m_info;
protected :
void Init();
private:
DECLARE_ABSTRACT_CLASS(wxTimer)
};
#endif
// _WX_TIMER_H_

View File

@@ -0,0 +1,5 @@
#ifdef __WXMAC_CLASSIC__
#include "wx/mac/classic/private/timer.h"
#else
#include "wx/mac/carbon/private/timer.h"
#endif

View File

@@ -1,5 +0,0 @@
#ifdef __WXMAC_CLASSIC__
#include "wx/mac/classic/timer.h"
#else
#include "wx/mac/carbon/timer.h"
#endif

View File

@@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/motif/private/timer.h
// Purpose: wxTimer class
// Author: Julian Smart
// Created: 17/09/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MOTIF_PRIVATE_TIMER_H_
#define _WX_MOTIF_PRIVATE_TIMER_H_
#include "wx/private/timer.h"
class WXDLLEXPORT wxMotifTimerImpl : public wxTimerImpl
{
public:
wxMotifTimerImpl(wxTimer* timer) : wxTimerImpl(timer) { m_id = 0; }
virtual ~wxMotifTimerImpl();
virtual bool Start(int milliseconds = -1, bool oneShot = false);
virtual void Stop();
virtual bool IsRunning() const { return m_id != 0; }
// override this to rearm the timer if necessary (i.e. if not one shot) as
// X timeouts are removed automatically when they expire
virtual void Notify();
protected:
// common part of Start() and Notify()
void DoStart();
long m_id;
};
#endif // _WX_MOTIF_PRIVATE_TIMER_H_

View File

@@ -1,40 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/motif/timer.h
// Purpose: wxTimer class
// Author: Julian Smart
// Modified by:
// Created: 17/09/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TIMER_H_
#define _WX_TIMER_H_
class WXDLLEXPORT wxTimer : public wxTimerBase
{
friend void wxTimerCallback(wxTimer * timer);
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int id = -1) : wxTimerBase(owner, id)
{ Init(); }
virtual ~wxTimer();
virtual bool Start(int milliseconds = -1, bool oneShot = false);
virtual void Stop();
virtual bool IsRunning() const { return m_id != 0; }
protected:
void Init();
long m_id;
private:
DECLARE_DYNAMIC_CLASS(wxTimer)
};
#endif
// _WX_TIMER_H_

View File

@@ -22,7 +22,9 @@ public:
virtual void *BeforeChildWaitLoop();
virtual void AlwaysYield();
virtual void AfterChildWaitLoop(void *data);
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer);
#endif
virtual bool DoMessageFromThreadWait();
virtual WXDWORD WaitForThread(WXHANDLE hThread);
};
@@ -35,7 +37,9 @@ public:
virtual void *BeforeChildWaitLoop();
virtual void AlwaysYield();
virtual void AfterChildWaitLoop(void *data);
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer);
#endif
virtual bool DoMessageFromThreadWait();
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
virtual WXDWORD WaitForThread(WXHANDLE hThread);

View File

@@ -1,26 +1,22 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.h
// Name: wx/msw/private/timer.h
// Purpose: wxTimer class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TIMER_H_
#define _WX_TIMER_H_
#ifndef _WX_MSW_PRIVATE_TIMER_H_
#define _WX_MSW_PRIVATE_TIMER_H_
class WXDLLEXPORT wxTimer : public wxTimerBase
#include "wx/private/timer.h"
class WXDLLIMPEXP_BASE wxMSWTimerImpl : public wxTimerImpl
{
friend void wxProcessTimer(wxTimer& timer);
public:
wxTimer() { Init(); }
wxTimer(wxEvtHandler *owner, int id = wxID_ANY) : wxTimerBase(owner, id)
{ Init(); }
virtual ~wxTimer();
wxMSWTimerImpl(wxTimer *timer) : wxTimerImpl(timer) { m_id = 0; }
virtual bool Start(int milliseconds = -1, bool oneShot = false);
virtual void Stop();
@@ -28,13 +24,7 @@ public:
virtual bool IsRunning() const { return m_id != 0; }
protected:
void Init();
unsigned long m_id;
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxTimer)
};
#endif
// _WX_TIMERH_
#endif // _WX_TIMERH_

View File

@@ -19,6 +19,9 @@
class WXDLLIMPEXP_BASE wxConsoleAppTraits : public wxConsoleAppTraitsBase
{
public:
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) { return NULL; };
#endif
};
#if wxUSE_GUI
@@ -26,6 +29,9 @@ public:
class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase
{
public:
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer);
#endif
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
// wxThread helpers

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: timer.h
// Name: wx/os2/private/timer.h
// Purpose: wxTimer class
// Author: David Webster
// Modified by:
@@ -12,22 +12,15 @@
#ifndef _WX_TIMER_H_
#define _WX_TIMER_H_
#include "wx/object.h"
#include "wx/private/timerimpl.h"
class WXDLLEXPORT wxTimer: public wxTimerBase
class WXDLLEXPORT wxOS2TimerImpl: public wxTimerImpl
{
friend void wxProcessTimer(wxTimer& timer);
friend void wxProcessTimer(wxOS2TimerImpl& timer);
public:
wxTimer() { Init(); }
wxTimer( wxEvtHandler* pOwner
,int nId = -1
)
: wxTimerBase( pOwner
,nId
)
{ Init(); }
virtual ~wxTimer();
wxOS2TimerImpl(wxTimer *timer) : wxTimerImpl(timer) { Init(); }
virtual ~wxOS2TimerImpl();
virtual void Notify(void);
virtual bool Start( int nMilliseconds = -1
@@ -43,9 +36,6 @@ protected:
ULONG m_ulId;
HAB m_Hab;
private:
DECLARE_ABSTRACT_CLASS(wxTimer)
};
extern ULONG wxTimerProc( HWND WXUNUSED(hwnd)

View File

@@ -22,7 +22,9 @@ public:
virtual void *BeforeChildWaitLoop();
virtual void AlwaysYield();
virtual void AfterChildWaitLoop(void *data);
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) { return NULL; };
#endif
virtual bool DoMessageFromThreadWait();
};
@@ -34,7 +36,10 @@ public:
virtual void *BeforeChildWaitLoop();
virtual void AlwaysYield();
virtual void AfterChildWaitLoop(void *data);
#if wxUSE_TIMER
// there is no wxTimer support yet
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer);
#endif
virtual bool DoMessageFromThreadWait();
virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const;
};

View File

@@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/palmos/private/timer.h
// Purpose: wxTimer class
// Author: William Osborne - minimal working wxPalmOS port
// Modified by:
// Created: 10/13/04
// RCS-ID: $Id$
// Copyright: (c) William Osborne
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TIMER_H_
#define _WX_TIMER_H_
#include "wx/private/timerimpl.h"
class WXDLLEXPORT wxPalmOSTimerImpl : public wxTimerImpl
{
friend void wxProcessTimer(wxTimer& timer);
public:
wxPalmOSTimerImpl(wxTimer* timer) : wxTimerImpl(timer) { Init(); }
virtual ~wxPalmOSTimerImpl();
virtual bool Start(int milliseconds = -1, bool oneShot = FALSE);
virtual void Stop();
virtual bool IsRunning() const { return m_id != 0; }
protected:
void Init();
unsigned long m_id;
};
#endif
// _WX_TIMERH_

View File

@@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/private/timerimpl.h
// Purpose: Base class for wxTimer implementations
// Author: Lukasz Michalski <lmichalski@sf.net>
// Created: 31.10.2006
// RCS-ID: $Id$
// Copyright: (c) 2006-2007 wxWidgets dev team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TIMERIMPL_H_BASE_
#define _WX_TIMERIMPL_H_BASE_
#include "wx/defs.h"
#include "wx/event.h"
#include "wx/timer.h"
// ----------------------------------------------------------------------------
// wxTimerImpl: abstract base class for wxTimer implementations
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxTimerImpl
{
public:
// default ctor, SetOwner() must be called after it (wxTimer does it)
wxTimerImpl(wxTimer *owner);
// this must be called initially but may be also called later
void SetOwner(wxEvtHandler *owner, int timerid);
// empty but virtual base class dtor, the caller is responsible for
// stopping the timer before it's destroyed (it can't be done from here as
// it's too late)
virtual ~wxTimerImpl() { }
// start the timer. When overriding call base version first.
virtual bool Start(int milliseconds = -1, bool oneShot = false);
// stop the timer, only called if the timer is really running (unlike
// wxTimer::Stop())
virtual void Stop() = 0;
// return true if the timer is running
virtual bool IsRunning() const = 0;
// this should be called by the port-specific code when the timer expires
virtual void Notify() { m_timer->Notify(); }
// the default implementation of wxTimer::Notify(): generate a wxEVT_TIMER
void SendEvent();
// accessors for wxTimer:
wxEvtHandler *GetOwner() const { return m_owner; }
int GetId() const { return m_idTimer; }
int GetInterval() const { return m_milli; }
bool IsOneShot() const { return m_oneShot; }
protected:
wxTimer *m_timer;
wxEvtHandler *m_owner;
int m_idTimer; // id passed to wxTimerEvent
int m_milli; // the timer interval
bool m_oneShot; // true if one shot
DECLARE_NO_COPY_CLASS(wxTimerImpl);
};
#endif // _WX_TIMERIMPL_H_BASE_

View File

@@ -15,13 +15,13 @@
#include "wx/defs.h"
#if wxUSE_GUI && wxUSE_TIMER
#if wxUSE_TIMER
#include "wx/object.h"
#include "wx/longlong.h"
#include "wx/event.h"
#include "wx/stopwatch.h" // for backwards compatibility
#include "wx/window.h" // only for NewControlId()
#include "wx/utils.h"
// more readable flags for Start():
@@ -32,8 +32,10 @@
// only send the notification once and then stop the timer
#define wxTIMER_ONE_SHOT true
class WXDLLIMPEXP_BASE wxTimerImpl;
// the interface of wxTimer class
class WXDLLEXPORT wxTimerBase : public wxEvtHandler
class WXDLLIMPEXP_BASE wxTimer : public wxEvtHandler
{
public:
// ctors and initializers
@@ -41,29 +43,33 @@ public:
// default: if you don't call SetOwner(), your only chance to get timer
// notifications is to override Notify() in the derived class
wxTimerBase()
{ Init(); SetOwner(this); }
wxTimer()
{
Init();
SetOwner(this);
}
// ctor which allows to avoid having to override Notify() in the derived
// class: the owner will get timer notifications which can be handled with
// EVT_TIMER
wxTimerBase(wxEvtHandler *owner, int timerid = wxID_ANY)
{ Init(); SetOwner(owner, timerid); }
// same as ctor above
void SetOwner(wxEvtHandler *owner, int timerid = wxID_ANY)
wxTimer(wxEvtHandler *owner, int timerid = wxID_ANY)
{
m_owner = owner;
m_idTimer = timerid == wxID_ANY ? wxWindow::NewControlId() : timerid;
Init();
SetOwner(owner, timerid);
}
wxEvtHandler *GetOwner() const { return m_owner; }
// same as ctor above
void SetOwner(wxEvtHandler *owner, int timerid = wxID_ANY);
virtual ~wxTimer();
virtual ~wxTimerBase();
// working with the timer
// ----------------------
// NB: Start() and Stop() are not supposed to be overridden, they are only
// virtual for historical reasons, only Notify() can be overridden
// start the timer: if milliseconds == -1, use the same value as for the
// last Start()
//
@@ -71,63 +77,41 @@ public:
// timer if it is already running
virtual bool Start(int milliseconds = -1, bool oneShot = false);
// stop the timer
virtual void Stop() = 0;
// stop the timer, does nothing if the timer is not running
virtual void Stop();
// override this in your wxTimer-derived class if you want to process timer
// messages in it, use non default ctor or SetOwner() otherwise
virtual void Notify();
// getting info
// ------------
// accessors
// ---------
// get the object notified about the timer events
wxEvtHandler *GetOwner() const;
// return true if the timer is running
virtual bool IsRunning() const = 0;
bool IsRunning() const;
// return the timer ID
int GetId() const { return m_idTimer; }
int GetId() const;
// get the (last) timer interval in milliseconds
int GetInterval() const { return m_milli; }
int GetInterval() const;
// return true if the timer is one shot
bool IsOneShot() const { return m_oneShot; }
bool IsOneShot() const;
protected:
// common part of all ctors
void Init()
{ m_owner = NULL; m_idTimer = wxID_ANY; m_milli = 0; m_oneShot = false; }
void Init();
wxEvtHandler *m_owner;
int m_idTimer;
int m_milli; // the timer interval
bool m_oneShot; // true if one shot
wxTimerImpl *m_impl;
DECLARE_NO_COPY_CLASS(wxTimerBase)
DECLARE_NO_COPY_CLASS(wxTimer)
};
// ----------------------------------------------------------------------------
// wxTimer itself
// ----------------------------------------------------------------------------
#if defined(__WXMSW__)
#include "wx/msw/timer.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/timer.h"
#elif defined(__WXGTK20__)
#include "wx/gtk/timer.h"
#elif defined(__WXGTK__)
#include "wx/gtk1/timer.h"
#elif defined(__WXX11__) || defined(__WXMGL__) || defined(__WXDFB__)
#include "wx/generic/timer.h"
#elif defined (__WXCOCOA__)
#include "wx/cocoa/timer.h"
#elif defined(__WXMAC__)
#include "wx/mac/timer.h"
#elif defined(__WXPM__)
#include "wx/os2/timer.h"
#endif
// ----------------------------------------------------------------------------
// wxTimerRunner: starts the timer in its ctor, stops in the dtor
// ----------------------------------------------------------------------------
@@ -195,7 +179,6 @@ typedef void (wxEvtHandler::*wxTimerEventFunction)(wxTimerEvent&);
#define EVT_TIMER(timerid, func) \
wx__DECLARE_EVT1(wxEVT_TIMER, timerid, wxTimerEventHandler(func))
#endif // wxUSE_GUI && wxUSE_TIMER
#endif // wxUSE_TIMER
#endif
// _WX_TIMER_H_BASE_
#endif // _WX_TIMER_H_BASE_

View File

@@ -23,6 +23,9 @@ public:
virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd);
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
virtual int WaitForChild(wxExecuteData& execData);
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer);
#endif
};
#if wxUSE_GUI
@@ -34,6 +37,9 @@ public:
virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd);
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
virtual int WaitForChild(wxExecuteData& execData);
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer);
#endif
#if defined(__WXMAC__) || defined(__WXCOCOA__)
virtual wxStandardPathsBase& GetStandardPaths();

View File

@@ -0,0 +1,131 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/timer.h
// Purpose: wxTimer for wxBase (unix)
// Author: Lukasz Michalski
// Created: 15/01/2005
// RCS-ID: $Id$
// Copyright: (c) Lukasz Michalski
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_TIMER_H_
#define _WX_UNIX_PRIVATE_TIMER_H_
#include "wx/private/timer.h"
// the type used for milliseconds is large enough for microseconds too but
// introduce a synonym for it to avoid confusion
typedef wxMilliClock_t wxUsecClock_t;
// ----------------------------------------------------------------------------
// wxTimer implementation class for Unix platforms
// ----------------------------------------------------------------------------
class wxUnixTimerImpl : public wxTimerImpl
{
public:
wxUnixTimerImpl(wxTimer *timer);
virtual ~wxUnixTimerImpl();
virtual bool IsRunning() const;
virtual bool Start(int milliseconds = -1, bool oneShot = false);
virtual void Stop();
private:
bool m_isRunning;
friend class wxTimerScheduler;
};
// ----------------------------------------------------------------------------
// wxTimerSchedule: information about a single timer, used by wxTimerScheduler
// ----------------------------------------------------------------------------
struct wxTimerSchedule
{
wxTimerSchedule(wxUnixTimerImpl *timer, wxUsecClock_t expiration)
: m_timer(timer),
m_expiration(expiration)
{
}
// the timer itself (we don't own this pointer)
wxUnixTimerImpl *m_timer;
// the time of its next expiration, in usec
wxUsecClock_t m_expiration;
};
// the linked list of all active timers, we keep it sorted by expiration time
WX_DECLARE_LIST(wxTimerSchedule, wxTimerList);
// ----------------------------------------------------------------------------
// wxTimerScheduler: class responsible for updating all timers
// ----------------------------------------------------------------------------
class wxTimerScheduler
{
public:
// get the unique timer scheduler instance
static wxTimerScheduler& Get()
{
if ( !ms_instance )
ms_instance = new wxTimerScheduler;
return *ms_instance;
}
// must be called on shutdown to delete the global timer scheduler
static void Shutdown()
{
if ( ms_instance )
{
delete ms_instance;
ms_instance = NULL;
}
}
// adds timer which should expire at the given absolute time to the list
void AddTimer(wxUnixTimerImpl *timer, wxUsecClock_t expiration);
// remove timer from the list, called automatically from timer dtor
void RemoveTimer(wxUnixTimerImpl *timer);
// the functions below are used by the event loop implementation to monitor
// and notify timers:
// if this function returns true, the time remaining until the next time
// expiration is returned in the provided parameter (always positive or 0)
//
// it returns false if there are no timers
bool GetNext(wxUsecClock_t *remaining) const;
// trigger the timer event for all timers which have expired
void NotifyExpired();
private:
// ctor and dtor are private, this is a singleton class only created by
// Get() and destroyed by Shutdown()
wxTimerScheduler() { }
~wxTimerScheduler();
// add the given timer schedule to the list in the right place
//
// we take ownership of the pointer "s" which must be heap-allocated
void DoAddTimer(wxTimerSchedule *s);
// the list of all currently active timers sorted by expiration
wxTimerList m_timers;
static wxTimerScheduler *ms_instance;
};
// this helper function currently only exists for Unix platforms but could be
// moved to wx/stopwatch.h if it turns out to be useful elsewhere
//
// returns the number of microseconds since the Epoch
extern wxUsecClock_t wxGetLocalTimeUsec();
#endif // _WX_UNIX_PRIVATE_TIMER_H_

View File

@@ -266,21 +266,20 @@ private:
// Returns the current state of the mouse position, buttons and modifers
WXDLLEXPORT wxMouseState wxGetMouseState();
#endif // wxUSE_GUI
// ----------------------------------------------------------------------------
// Window ID management
// ----------------------------------------------------------------------------
// Generate a unique ID
WXDLLEXPORT long wxNewId();
// Ensure subsequent IDs don't clash with this one
WXDLLEXPORT void wxRegisterId(long id);
WXDLLIMPEXP_BASE void wxRegisterId(long id);
// Return the current ID
WXDLLEXPORT long wxGetCurrentId();
WXDLLIMPEXP_BASE long wxGetCurrentId();
#endif // wxUSE_GUI
// Generate a unique ID
WXDLLIMPEXP_BASE long wxNewId();
// ----------------------------------------------------------------------------
// Various conversions