]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: src/gtk1/timer.cpp |
1e6feb95 | 3 | // Purpose: wxTimer implementation |
c801d85f | 4 | // Author: Robert Roebling |
01111366 | 5 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 6 | // Licence: wxWindows licence |
c801d85f KB |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
14f355c2 | 9 | #include "wx/wxprec.h" |
1e6feb95 VZ |
10 | |
11 | #if wxUSE_TIMER | |
12 | ||
c2ca375c | 13 | #include "wx/gtk1/private/timer.h" |
c801d85f | 14 | |
83624f79 RR |
15 | #include "gtk/gtk.h" |
16 | ||
1e6feb95 | 17 | // ---------------------------------------------------------------------------- |
c801d85f | 18 | // wxTimer |
1e6feb95 | 19 | // ---------------------------------------------------------------------------- |
c801d85f | 20 | |
865bb325 | 21 | extern "C" { |
c2ca375c | 22 | static gint timeout_callback(void *data) |
c801d85f | 23 | { |
c2ca375c | 24 | wxTimerImpl * const timer = (wxTimerImpl *)data; |
3d257b8d | 25 | |
c2ca375c VZ |
26 | const bool keepGoing = !timer->IsOneShot(); |
27 | if ( !keepGoing ) | |
7b14c561 | 28 | timer->Stop(); |
3d257b8d | 29 | |
7b14c561 RR |
30 | // When getting called from GDK's timer handler we |
31 | // are no longer within GDK's grab on the GUI | |
32 | // thread so we must lock it here ourselves. | |
924ef850 | 33 | gdk_threads_enter(); |
e1393d82 | 34 | |
83624f79 | 35 | timer->Notify(); |
03f38c58 | 36 | |
7b14c561 | 37 | // Release lock again. |
924ef850 | 38 | gdk_threads_leave(); |
f6577bba | 39 | |
c2ca375c | 40 | return keepGoing; |
ff7b1510 | 41 | } |
ff7b1510 | 42 | } |
c801d85f | 43 | |
c2ca375c | 44 | bool wxGTKTimerImpl::Start(int millisecs, bool oneShot) |
c801d85f | 45 | { |
c2ca375c VZ |
46 | if ( !wxTimerImpl::Start(millisecs, oneShot) ) |
47 | return false; | |
03f38c58 | 48 | |
9a83f860 | 49 | wxASSERT_MSG( m_tag == -1, wxT("shouldn't be still running") ); |
574bf507 | 50 | |
0470b1e6 | 51 | m_tag = gtk_timeout_add( m_milli, timeout_callback, this ); |
03f38c58 | 52 | |
c2ca375c | 53 | return true; |
ff7b1510 | 54 | } |
c801d85f | 55 | |
c2ca375c | 56 | void wxGTKTimerImpl::Stop() |
c801d85f | 57 | { |
9a83f860 | 58 | wxASSERT_MSG( m_tag != -1, wxT("should be running") ); |
c2ca375c VZ |
59 | |
60 | gtk_timeout_remove( m_tag ); | |
61 | m_tag = -1; | |
ff7b1510 | 62 | } |
c801d85f | 63 | |
1e6feb95 VZ |
64 | #endif // wxUSE_TIMER |
65 |