]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/gtk/timer.cpp | |
3 | // Purpose: wxTimer implementation | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // For compilers that support precompilation, includes "wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #if wxUSE_TIMER | |
14 | ||
15 | #include "wx/gtk/private/timer.h" | |
16 | #include "wx/app.h" | |
17 | ||
18 | #include <gtk/gtk.h> | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // wxTimerImpl | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
24 | extern "C" { | |
25 | ||
26 | static gboolean timeout_callback(gpointer data) | |
27 | { | |
28 | wxGTKTimerImpl *timer = (wxGTKTimerImpl*)data; | |
29 | ||
30 | const bool keepGoing = !timer->IsOneShot(); | |
31 | if ( !keepGoing ) | |
32 | timer->Stop(); | |
33 | ||
34 | // When getting called from GDK's timer handler we | |
35 | // are no longer within GDK's grab on the GUI | |
36 | // thread so we must lock it here ourselves. | |
37 | gdk_threads_enter(); | |
38 | ||
39 | timer->Notify(); | |
40 | ||
41 | // Release lock again. | |
42 | gdk_threads_leave(); | |
43 | ||
44 | wxApp* app = wxTheApp; | |
45 | if (app) | |
46 | app->WakeUpIdle(); | |
47 | ||
48 | return keepGoing; | |
49 | } | |
50 | ||
51 | } // extern "C" | |
52 | ||
53 | bool wxGTKTimerImpl::Start(int millisecs, bool oneShot) | |
54 | { | |
55 | if ( !wxTimerImpl::Start(millisecs, oneShot) ) | |
56 | return false; | |
57 | ||
58 | wxASSERT_MSG( !m_sourceId, wxT("shouldn't be still running") ); | |
59 | ||
60 | m_sourceId = g_timeout_add(m_milli, timeout_callback, this); | |
61 | ||
62 | return true; | |
63 | } | |
64 | ||
65 | void wxGTKTimerImpl::Stop() | |
66 | { | |
67 | wxASSERT_MSG( m_sourceId, wxT("should be running") ); | |
68 | ||
69 | g_source_remove(m_sourceId); | |
70 | m_sourceId = 0; | |
71 | } | |
72 | ||
73 | #endif // wxUSE_TIMER | |
74 |