2001-11-25 00:25:47 +00:00
|
|
|
// GtkSharp.SignalCallback.cs - Signal callback base class implementation
|
|
|
|
//
|
|
|
|
// Authors: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
|
|
|
namespace GtkSharp {
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using GLib;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// SignalCallback Class
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Base Class for GSignal to C# event marshalling.
|
|
|
|
/// </remarks>
|
|
|
|
|
2003-02-26 02:16:38 +00:00
|
|
|
public abstract class SignalCallback : IDisposable {
|
2001-11-25 00:25:47 +00:00
|
|
|
|
|
|
|
// 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;
|
2003-02-06 00:58:02 +00:00
|
|
|
protected Delegate _handler;
|
2001-11-25 00:25:47 +00:00
|
|
|
protected int _key;
|
2003-02-24 06:39:30 +00:00
|
|
|
protected System.Type _argstype;
|
2001-11-25 00:25:47 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// SignalCallback Constructor
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// Initializes instance data.
|
|
|
|
/// </remarks>
|
|
|
|
|
2003-11-28 05:29:34 +00:00
|
|
|
protected SignalCallback (GLib.Object obj, Delegate eh, System.Type argstype)
|
2001-11-25 00:25:47 +00:00
|
|
|
{
|
|
|
|
_key = _NextKey++;
|
|
|
|
_obj = obj;
|
|
|
|
_handler = eh;
|
2002-07-16 23:14:35 +00:00
|
|
|
_argstype = argstype;
|
2001-11-25 00:25:47 +00:00
|
|
|
_Instances [_key] = this;
|
|
|
|
}
|
|
|
|
|
2003-02-06 00:58:02 +00:00
|
|
|
public void AddDelegate (Delegate d)
|
|
|
|
{
|
|
|
|
_handler = Delegate.Combine (_handler, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveDelegate (Delegate d)
|
|
|
|
{
|
|
|
|
_handler = Delegate.Remove (_handler, d);
|
|
|
|
}
|
2003-02-26 02:16:38 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2001-11-25 00:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-26 02:16:38 +00:00
|
|
|
|