]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/timer.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / gtk1 / timer.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: timer.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
e1393d82 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "timer.h"
13#endif
14
15#include "wx/timer.h"
16
83624f79 17#include "gtk/gtk.h"
bbe0af5b
RR
18/*
19#include "glib.h"
20*/
21
22//-----------------------------------------------------------------------------
23// global functions
24//-----------------------------------------------------------------------------
25
26/*
27static GTimer *g_timer = (GTimer*) NULL;
28
29void wxStartTimer()
30{
31 if (g_timer)
32 {
33 g_timer_rest( g_timer );
34 }
35 else
36 {
37 g_timer = g_timer_new();
38 g_timer_start( g_timer );
39 }
40}
41
42long wxGetElapsedTime( bool resetTimer )
43{
44 gulong res = 0;
45 if (g_timer)
46 {
47 g_timer_elapsed( g_timer, &res );
e1393d82 48 if (resetTimer) g_timer_reset( g_timer );
bbe0af5b 49 }
e1393d82 50
bbe0af5b
RR
51 return res;
52}
53
54bool wxGetLocalTime( long *timeZone, int *dstObserved )
55{
56}
57
58long wxGetCurrentTime()
59{
60}
61*/
62
83624f79 63
c801d85f
KB
64//-----------------------------------------------------------------------------
65// wxTimer
66//-----------------------------------------------------------------------------
67
03f38c58 68IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject)
c801d85f 69
7b90a8f2 70static gint timeout_callback( gpointer data )
c801d85f 71{
83624f79 72 wxTimer *timer = (wxTimer*)data;
e1393d82 73
f6577bba
RR
74#if (GTK_MINOR_VERSION > 0)
75 /* when getting called from GDK's timer handler we
76 are no longer within GDK's grab on the GUI
77 thread so we must lock it here ourselves */
78 GDK_THREADS_ENTER ();
79#endif
e1393d82 80
83624f79 81 timer->Notify();
03f38c58 82
f6577bba
RR
83#if (GTK_MINOR_VERSION > 0)
84 /* release lock again */
85 GDK_THREADS_LEAVE ();
86#endif
87
0470b1e6 88 if ( timer->IsOneShot() )
e1393d82 89 return FALSE;
03f38c58 90
83624f79 91 return TRUE;
ff7b1510 92}
c801d85f 93
03f38c58 94wxTimer::wxTimer()
c801d85f 95{
83624f79 96 m_tag = -1;
0470b1e6 97 m_milli = 1000;
83624f79 98 m_oneShot = FALSE;
ff7b1510 99}
c801d85f 100
03f38c58 101wxTimer::~wxTimer()
c801d85f 102{
0470b1e6 103 wxTimer::Stop();
ff7b1510 104}
c801d85f 105
03f38c58 106bool wxTimer::Start( int millisecs, bool oneShot )
c801d85f 107{
0470b1e6 108 (void)wxTimerBase::Start(millisecs, oneShot);
03f38c58 109
0470b1e6 110 m_tag = gtk_timeout_add( m_milli, timeout_callback, this );
03f38c58 111
83624f79 112 return TRUE;
ff7b1510 113}
c801d85f 114
03f38c58 115void wxTimer::Stop()
c801d85f 116{
83624f79
RR
117 if (m_tag != -1)
118 {
119 gtk_timeout_remove( m_tag );
120 m_tag = -1;
121 }
ff7b1510 122}
c801d85f 123