]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/timer.cpp
Getting borders working
[wxWidgets.git] / src / gtk / timer.cpp
CommitLineData
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
c2ca375c 15#include "wx/gtk/private/timer.h"
c801d85f 16
855f31eb 17#include <gtk/gtk.h>
83624f79 18
1e6feb95 19// ----------------------------------------------------------------------------
c2ca375c 20// wxTimerImpl
1e6feb95 21// ----------------------------------------------------------------------------
c801d85f 22
865bb325 23extern "C" {
c2ca375c 24
855f31eb 25static gboolean timeout_callback(gpointer data)
c801d85f 26{
c2ca375c 27 wxGTKTimerImpl *timer = (wxGTKTimerImpl*)data;
3d257b8d 28
c2ca375c
VZ
29 const bool keepGoing = !timer->IsOneShot();
30 if ( !keepGoing )
7b14c561 31 timer->Stop();
3d257b8d 32
7b14c561
RR
33 // When getting called from GDK's timer handler we
34 // are no longer within GDK's grab on the GUI
35 // thread so we must lock it here ourselves.
924ef850 36 gdk_threads_enter();
e1393d82 37
83624f79 38 timer->Notify();
03f38c58 39
7b14c561 40 // Release lock again.
924ef850 41 gdk_threads_leave();
f6577bba 42
c2ca375c 43 return keepGoing;
ff7b1510 44}
c801d85f 45
c2ca375c 46} // extern "C"
c801d85f 47
c2ca375c 48bool wxGTKTimerImpl::Start(int millisecs, bool oneShot)
c801d85f 49{
c2ca375c
VZ
50 if ( !wxTimerImpl::Start(millisecs, oneShot) )
51 return false;
03f38c58 52
c2ca375c 53 wxASSERT_MSG( !m_sourceId, _T("shouldn't be still running") );
574bf507 54
855f31eb 55 m_sourceId = g_timeout_add(m_milli, timeout_callback, this);
03f38c58 56
855f31eb 57 return true;
ff7b1510 58}
c801d85f 59
c2ca375c 60void wxGTKTimerImpl::Stop()
c801d85f 61{
c2ca375c
VZ
62 wxASSERT_MSG( m_sourceId, _T("should be running") );
63
64 g_source_remove(m_sourceId);
65 m_sourceId = 0;
ff7b1510 66}
c801d85f 67
1e6feb95
VZ
68#endif // wxUSE_TIMER
69