Ryujinx-GtkSharp/glib/SignalCallback.cs
Mike Kestner 01acd7f576 2004-05-05 Mike Kestner <mkestner@ximian.com>
* generator/Signal.cs : rmv Handle param to SignalCallback ctor calls.
	s/GtkSharp.Signal*/GLib.Signal*.
	* generator/SignalHandler.cs : rmv Handle param to ctors as it's
	redundant.  s/GtkSharp.Signal*/GLib.Signal*. Use new Connect/Disconnect
	instead of generating DllImports into libgobject directly.
	* glib/SignalArgs.cs : move the the GLib namespace.
	* glib/SignalCallback.cs : expose Connect and Disconnect methods to
	hide some pinvokes that were previously generated. Also move to the
	GLib namespace.
	gnome/*Handler.cs : update to new SignalHandler API.
	gnome/CanvasProxy.cs : ditto
	gnome/void*Signal.cs : ditto

svn path=/trunk/gtk-sharp/; revision=26778
2004-05-05 18:24:04 +00:00

89 lines
2.1 KiB
C#

// GLib.SignalCallback.cs - Signal callback base class implementation
//
// Authors: Mike Kestner <mkestner@ximian.com>
//
// Copyright (c) 2001 Mike Kestner
// Copyright (c) 2004 Novell, Inc.
namespace GLib {
using System;
using System.Collections;
using System.Runtime.InteropServices;
public abstract class SignalCallback : IDisposable {
// A counter used to produce unique keys for instances.
protected static int _NextKey = 0;
// Hashtable containing refs to all current instances.
protected static Hashtable _Instances = new Hashtable ();
// protected instance members
protected GLib.Object _obj;
protected Delegate _handler;
protected int _key;
protected System.Type _argstype;
protected uint _HandlerID;
protected SignalCallback (GLib.Object obj, Delegate eh, System.Type argstype)
{
_key = _NextKey++;
_obj = obj;
_handler = eh;
_argstype = argstype;
_Instances [_key] = this;
}
public void AddDelegate (Delegate d)
{
_handler = Delegate.Combine (_handler, d);
}
public void RemoveDelegate (Delegate d)
{
_handler = Delegate.Remove (_handler, d);
}
[DllImport("libgobject-2.0-0.dll")]
static extern uint g_signal_connect_data(IntPtr obj, string name, Delegate cb, int key, IntPtr p, int flags);
protected void Connect (string name, Delegate cb, int flags)
{
_HandlerID = g_signal_connect_data(_obj.Handle, name, cb, _key, new IntPtr(0), flags);
}
[DllImport("libgobject-2.0-0.dll")]
static extern void g_signal_handler_disconnect (IntPtr instance, uint handler);
[DllImport("libgobject-2.0-0.dll")]
static extern bool g_signal_handler_is_connected (IntPtr instance, uint handler);
protected void Disconnect ()
{
if (g_signal_handler_is_connected (_obj.Handle, _HandlerID))
g_signal_handler_disconnect (_obj.Handle, _HandlerID);
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
if (disposing) {
_obj = null;
_handler = null;
_argstype = null;
}
}
~SignalCallback ()
{
Dispose (false);
}
}
}