]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
ed791986 | 2 | // Name: gtk/timer.cpp |
1e6feb95 | 3 | // Purpose: wxTimer implementation |
c801d85f | 4 | // Author: Robert Roebling |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
1e6feb95 VZ |
12 | |
13 | #if wxUSE_TIMER | |
14 | ||
c801d85f KB |
15 | #include "wx/timer.h" |
16 | ||
855f31eb | 17 | #include <gtk/gtk.h> |
83624f79 | 18 | |
1e6feb95 | 19 | // ---------------------------------------------------------------------------- |
c801d85f | 20 | // wxTimer |
1e6feb95 | 21 | // ---------------------------------------------------------------------------- |
c801d85f | 22 | |
313feadc | 23 | IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxEvtHandler) |
c801d85f | 24 | |
865bb325 | 25 | extern "C" { |
855f31eb | 26 | static gboolean timeout_callback(gpointer data) |
c801d85f | 27 | { |
83624f79 | 28 | wxTimer *timer = (wxTimer*)data; |
e1393d82 | 29 | |
7b14c561 | 30 | // Don't change the order of anything in this callback! |
3d257b8d | 31 | |
7b14c561 RR |
32 | if (timer->IsOneShot()) |
33 | { | |
34 | // This sets m_tag to -1 | |
35 | timer->Stop(); | |
36 | } | |
3d257b8d | 37 | |
7b14c561 RR |
38 | // When getting called from GDK's timer handler we |
39 | // are no longer within GDK's grab on the GUI | |
40 | // thread so we must lock it here ourselves. | |
924ef850 | 41 | gdk_threads_enter(); |
e1393d82 | 42 | |
83624f79 | 43 | timer->Notify(); |
03f38c58 | 44 | |
7b14c561 | 45 | // Release lock again. |
924ef850 | 46 | gdk_threads_leave(); |
f6577bba | 47 | |
855f31eb | 48 | return !timer->IsOneShot(); |
ff7b1510 | 49 | } |
865bb325 | 50 | } |
c801d85f | 51 | |
ed791986 | 52 | void wxTimer::Init() |
c801d85f | 53 | { |
855f31eb | 54 | m_sourceId = 0; |
0470b1e6 | 55 | m_milli = 1000; |
ff7b1510 | 56 | } |
c801d85f | 57 | |
03f38c58 | 58 | wxTimer::~wxTimer() |
c801d85f | 59 | { |
855f31eb | 60 | Stop(); |
ff7b1510 | 61 | } |
c801d85f | 62 | |
03f38c58 | 63 | bool wxTimer::Start( int millisecs, bool oneShot ) |
c801d85f | 64 | { |
0470b1e6 | 65 | (void)wxTimerBase::Start(millisecs, oneShot); |
03f38c58 | 66 | |
855f31eb PC |
67 | if (m_sourceId != 0) |
68 | g_source_remove(m_sourceId); | |
574bf507 | 69 | |
855f31eb | 70 | m_sourceId = g_timeout_add(m_milli, timeout_callback, this); |
03f38c58 | 71 | |
855f31eb | 72 | return true; |
ff7b1510 | 73 | } |
c801d85f | 74 | |
03f38c58 | 75 | void wxTimer::Stop() |
c801d85f | 76 | { |
855f31eb | 77 | if (m_sourceId != 0) |
83624f79 | 78 | { |
855f31eb PC |
79 | g_source_remove(m_sourceId); |
80 | m_sourceId = 0; | |
83624f79 | 81 | } |
ff7b1510 | 82 | } |
c801d85f | 83 | |
1e6feb95 VZ |
84 | #endif // wxUSE_TIMER |
85 |