From e91a71949a93b195d9162510edf57b9b60060a9d Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 7 May 2009 01:22:41 +0000 Subject: [PATCH] 2009-05-06 Mike Kestner * glib/Idle.cs: add a Remove overload for consistency. * glib/Timeout.cs: add a Remove overload for consistency. [Fixes #356138] svn path=/trunk/gtk-sharp/; revision=133702 --- ChangeLog | 6 ++++++ glib/Idle.cs | 5 +++++ glib/Timeout.cs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/ChangeLog b/ChangeLog index f9671acd8..3d45c934e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-05-06 Mike Kestner + + * glib/Idle.cs: add a Remove overload for consistency. + * glib/Timeout.cs: add a Remove overload for consistency. + [Fixes #356138] + 2009-05-06 Mike Kestner * generator/EnumGen.cs: support 1L long values or explicit types. diff --git a/glib/Idle.cs b/glib/Idle.cs index 965270957..1bf8aa006 100755 --- a/glib/Idle.cs +++ b/glib/Idle.cs @@ -94,6 +94,11 @@ namespace GLib { [DllImport("libglib-2.0-0.dll")] static extern bool g_source_remove_by_funcs_user_data (Delegate d, IntPtr data); + public static void Remove (uint id) + { + Source.Remove (id); + } + public static bool Remove (IdleHandler hndlr) { bool result = false; diff --git a/glib/Timeout.cs b/glib/Timeout.cs index 4a51ebeab..082e6f7da 100755 --- a/glib/Timeout.cs +++ b/glib/Timeout.cs @@ -25,6 +25,7 @@ namespace GLib { using System; + using System.Collections; using System.Runtime.InteropServices; public delegate bool TimeoutHandler (); @@ -99,6 +100,36 @@ namespace GLib { return p.ID; } + + public static void Remove (uint id) + { + Source.Remove (id); + } + + [DllImport("libglib-2.0-0.dll")] + static extern bool g_source_remove_by_funcs_user_data (Delegate d, IntPtr data); + + public static bool Remove (TimeoutHandler hndlr) + { + bool result = false; + ArrayList keys = new ArrayList (); + + lock (Source.source_handlers) { + foreach (uint code in Source.source_handlers.Keys) { + TimeoutProxy p = Source.source_handlers [code] as TimeoutProxy; + + if (p != null && p.real_handler == hndlr) { + keys.Add (code); + result = g_source_remove_by_funcs_user_data (p.proxy_handler, IntPtr.Zero); + } + } + + foreach (object key in keys) + Source.source_handlers.Remove (key); + } + + return result; + } } }