]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: timer.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
c801d85f KB |
7 | // Licence: wxWindows licence |
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 | /* | |
27 | static GTimer *g_timer = (GTimer*) NULL; | |
28 | ||
29 | void 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 | ||
42 | long wxGetElapsedTime( bool resetTimer ) | |
43 | { | |
44 | gulong res = 0; | |
45 | if (g_timer) | |
46 | { | |
47 | g_timer_elapsed( g_timer, &res ); | |
48 | if (resetTimer) g_timer_reset( g_timer ); | |
49 | } | |
50 | ||
51 | return res; | |
52 | } | |
53 | ||
54 | bool wxGetLocalTime( long *timeZone, int *dstObserved ) | |
55 | { | |
56 | } | |
57 | ||
58 | long wxGetCurrentTime() | |
59 | { | |
60 | } | |
61 | */ | |
62 | ||
83624f79 | 63 | |
c801d85f KB |
64 | //----------------------------------------------------------------------------- |
65 | // wxTimer | |
66 | //----------------------------------------------------------------------------- | |
67 | ||
03f38c58 | 68 | IMPLEMENT_ABSTRACT_CLASS(wxTimer,wxObject) |
c801d85f | 69 | |
7b90a8f2 | 70 | static gint timeout_callback( gpointer data ) |
c801d85f | 71 | { |
83624f79 RR |
72 | wxTimer *timer = (wxTimer*)data; |
73 | timer->Notify(); | |
03f38c58 | 74 | |
83624f79 RR |
75 | if (timer->OneShot()) |
76 | { | |
77 | timer->Stop(); | |
78 | } | |
03f38c58 | 79 | |
83624f79 | 80 | return TRUE; |
ff7b1510 | 81 | } |
c801d85f | 82 | |
03f38c58 | 83 | wxTimer::wxTimer() |
c801d85f | 84 | { |
83624f79 RR |
85 | m_tag = -1; |
86 | m_time = 1000; | |
87 | m_oneShot = FALSE; | |
ff7b1510 | 88 | } |
c801d85f | 89 | |
03f38c58 | 90 | wxTimer::~wxTimer() |
c801d85f | 91 | { |
83624f79 | 92 | Stop(); |
ff7b1510 | 93 | } |
c801d85f | 94 | |
03f38c58 | 95 | bool wxTimer::Start( int millisecs, bool oneShot ) |
c801d85f | 96 | { |
83624f79 RR |
97 | if (millisecs != -1) |
98 | { | |
99 | m_time = millisecs; | |
100 | } | |
c801d85f | 101 | |
83624f79 | 102 | m_oneShot = oneShot; |
03f38c58 | 103 | |
83624f79 | 104 | m_tag = gtk_timeout_add( millisecs, timeout_callback, this ); |
03f38c58 | 105 | |
83624f79 | 106 | return TRUE; |
ff7b1510 | 107 | } |
c801d85f | 108 | |
03f38c58 | 109 | void wxTimer::Stop() |
c801d85f | 110 | { |
83624f79 RR |
111 | if (m_tag != -1) |
112 | { | |
113 | gtk_timeout_remove( m_tag ); | |
114 | m_tag = -1; | |
115 | } | |
ff7b1510 | 116 | } |
c801d85f | 117 |