diff options
author | Michael Meeks <michael.meeks@suse.com> | 2011-10-03 20:00:17 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2011-10-25 13:41:52 +0100 |
commit | caccd13297506fad6b528617c6a53adcda79267a (patch) | |
tree | 167bcb4328cf7b518889cc232a1c6b92a7627089 /vcl | |
parent | c529623457889a67473f773d080941903e2784fc (diff) |
gtk3: try to improve AnyInput (absent toolkit support for it)
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/unx/gtk/gtkdata.hxx | 4 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtkinst.hxx | 6 | ||||
-rw-r--r-- | vcl/unx/gtk/app/gtkdata.cxx | 14 | ||||
-rw-r--r-- | vcl/unx/gtk/app/gtkinst.cxx | 46 |
4 files changed, 61 insertions, 9 deletions
diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx index 4e5f7b68f3f2..0c9af2ae508e 100644 --- a/vcl/inc/unx/gtk/gtkdata.hxx +++ b/vcl/inc/unx/gtk/gtkdata.hxx @@ -86,9 +86,11 @@ class GtkSalTimer : public SalTimer public: GtkSalTimer(); ~GtkSalTimer(); - sal_uLong m_nTimeoutMS; virtual void Start( sal_uLong nMS ); virtual void Stop(); + bool Expired(); + + sal_uLong m_nTimeoutMS; }; class GtkData : public SalGenericData diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx index e27042aa9f6a..3df521822877 100644 --- a/vcl/inc/unx/gtk/gtkinst.hxx +++ b/vcl/inc/unx/gtk/gtkinst.hxx @@ -79,6 +79,7 @@ public: #define GTK_YIELD_GRAB() GtkYieldMutex::GtkYieldGuard aLocalGtkYieldGuard( static_cast<GtkYieldMutex*>(GetSalData()->m_pInstance->GetYieldMutex()) ) +class GtkSalTimer; #if GTK_CHECK_VERSION(3,0,0) class GtkInstance : public SvpSalInstance { @@ -109,6 +110,11 @@ public: virtual void Yield( bool bWait, bool bHandleAllCurrentEvents ); virtual bool AnyInput( sal_uInt16 nType ); + + void RemoveTimer (SalTimer *pTimer); + private: + std::vector<GtkSalTimer *> m_aTimers; + bool IsTimerExpired(); }; #endif // _VCL_GTKINST_HXX diff --git a/vcl/unx/gtk/app/gtkdata.cxx b/vcl/unx/gtk/app/gtkdata.cxx index 52b7166c2899..3b02af709ee9 100644 --- a/vcl/unx/gtk/app/gtkdata.cxx +++ b/vcl/unx/gtk/app/gtkdata.cxx @@ -785,9 +785,23 @@ GtkSalTimer::GtkSalTimer() GtkSalTimer::~GtkSalTimer() { + GtkInstance *pInstance = static_cast<GtkInstance *>(GetSalData()->m_pInstance); + pInstance->RemoveTimer( this ); Stop(); } +bool GtkSalTimer::Expired() +{ + if( !m_pTimeout ) + return false; + GSourceFuncs *pKlass = m_pTimeout->source_funcs; + gint timeout = 0; + if( pKlass && pKlass->prepare ) + return !!pKlass->prepare( m_pTimeout, &timeout ); + else + return false; +} + extern "C" { gboolean call_timeoutFn( gpointer pData ) diff --git a/vcl/unx/gtk/app/gtkinst.cxx b/vcl/unx/gtk/app/gtkinst.cxx index 301e6f029bea..fbc96fca0c7e 100644 --- a/vcl/unx/gtk/app/gtkinst.cxx +++ b/vcl/unx/gtk/app/gtkinst.cxx @@ -38,6 +38,7 @@ #include <unx/gtk/atkbridge.hxx> #include <headless/svpvd.hxx> #include <headless/svpbmp.hxx> +#include <vcl/apptypes.hxx> #include <rtl/strbuf.hxx> @@ -200,6 +201,8 @@ extern "C" GtkInstance::~GtkInstance() { + while( !m_aTimers.empty() ) + delete *m_aTimers.begin(); DeInitAtkBridge(); } @@ -443,7 +446,17 @@ SalBitmap* GtkInstance::CreateSalBitmap() SalTimer* GtkInstance::CreateSalTimer() { - return new GtkSalTimer(); + GtkSalTimer *pTimer = new GtkSalTimer(); + m_aTimers.push_back( pTimer ); + return pTimer; +} + +void GtkInstance::RemoveTimer (SalTimer *pTimer) +{ + std::vector<GtkSalTimer *>::iterator it; + it = std::find( m_aTimers.begin(), m_aTimers.end(), pTimer ); + if( it != m_aTimers.end() ) + m_aTimers.erase( it ); } void GtkInstance::Yield( bool bWait, bool bHandleAllCurrentEvents ) @@ -451,19 +464,36 @@ void GtkInstance::Yield( bool bWait, bool bHandleAllCurrentEvents ) GetGtkSalData()->Yield( bWait, bHandleAllCurrentEvents ); } -bool GtkInstance::AnyInput( sal_uInt16 nType ) +bool GtkInstance::IsTimerExpired() { -#if GTK_CHECK_VERSION(3,0,0) - g_warning ("any input returning false"); + gint nPriority; + GMainContext *pCtx = g_main_context_default(); + // sets time_is_fresh to FALSE + if( !g_main_context_prepare( pCtx, &nPriority ) ) + return false; + for( std::vector<GtkSalTimer *>::iterator it = m_aTimers.begin(); + it != m_aTimers.end(); ++it ) + { + if( (*it)->Expired() ) + return true; + } return false; -#else +} + +bool GtkInstance::AnyInput( sal_uInt16 nType ) +{ + if( (nType & INPUT_TIMER) && IsTimerExpired() ) + return true; + else +#warning FIXME: this is really not ideal - we should snoop for misc. types + /* FIXME: AnyInput is also extremely fragile ... if we just return + !!gtk_events_pending(); we hang on start [!] ... amazing ...*/ + return false; +#if 0 return X11SalInstance::AnyInput( nType ); #endif } -// FIXME: these above should all be in a more generic, shared base of unix's salinst.cxx - - #if GTK_CHECK_VERSION(3,0,0) #define GTK3_INCLUDED #include "../../headless/svpinst.cxx" |