2004-05-05 18:24:04 +00:00
|
|
|
// GLib.SignalCallback.cs - Signal callback base class implementation
|
2001-11-25 00:25:47 +00:00
|
|
|
//
|
2004-05-05 18:24:04 +00:00
|
|
|
// Authors: Mike Kestner <mkestner@ximian.com>
|
2001-11-25 00:25:47 +00:00
|
|
|
//
|
2004-05-05 18:24:04 +00:00
|
|
|
// Copyright (c) 2001 Mike Kestner
|
|
|
|
// Copyright (c) 2004 Novell, Inc.
|
2004-06-25 18:42:19 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of version 2 of the Lesser GNU General
|
|
|
|
// Public License as published by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this program; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
// Boston, MA 02111-1307, USA.
|
|
|
|
|
2001-11-25 00:25:47 +00:00
|
|
|
|
2004-05-05 18:24:04 +00:00
|
|
|
namespace GLib {
|
2001-11-25 00:25:47 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
2005-02-02 21:57:15 +00:00
|
|
|
[Obsolete ("Replaced by GLib.Signal.")]
|
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;
|
2004-05-05 18:24:04 +00:00
|
|
|
protected uint _HandlerID;
|
2001-11-25 00:25:47 +00:00
|
|
|
|
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
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2005-03-08 21:28:08 +00:00
|
|
|
static extern uint g_signal_connect_data(IntPtr obj, IntPtr name, Delegate cb, int key, IntPtr p, int flags);
|
2004-05-05 18:24:04 +00:00
|
|
|
|
|
|
|
protected void Connect (string name, Delegate cb, int flags)
|
|
|
|
{
|
2005-03-08 21:28:08 +00:00
|
|
|
IntPtr native_name = Marshaller.StringToPtrGStrdup (name);
|
|
|
|
_HandlerID = g_signal_connect_data(_obj.Handle, native_name, cb, _key, new IntPtr(0), flags);
|
|
|
|
Marshaller.Free (native_name);
|
2004-05-05 18:24:04 +00:00
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2004-05-05 18:24:04 +00:00
|
|
|
static extern void g_signal_handler_disconnect (IntPtr instance, uint handler);
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2004-05-05 18:24:04 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|