Ryujinx-GtkSharp/glib/SimpleSignal.cs
Mike Kestner 25000abee7 2001-09-27 Mike Kestner <mkestner@speakeasy.net>
*.cs : Added .dll extension to a load of DllImports.
	* makefile : now can make the project with one make windows and on
	both NT and Win98.
	* gdk/Event.cs : Fixed some invalid symbol names and commented out a
	load of stuff.
	* gdk/SimpleEvent.cs : Relocated file from unnecessary subdir and fixed
	several event keyword clashing bugs. Need to relocate the EventArgs
	class out of here into its own file. Fixed loads of typos.
	* glib/Object.cs : Killed the Constructor, this should be a purely
	abstract class. made Events property public until I can fix the Signal
	proxying system's broken reliance on it.
	* glib/SimpleSignal.cs : Relocated, namespaces, and named this Class.
	Loads of bugfixes. Still doesn't work worth a damn, but it builds.
	* glib/TypeFundamentals.cs : New enum for use in the Value code.
	* glib/Value.cs : Implemented a more opaque approach with heap allocated
	memory and g_value_init and friends.  Still doesn't work.  Will probably
	switch to a more C# like approach and avoid GValues altogether.
	* gtk/Button.cs : Commented out some brokeness until I can get around
	to fixing it later.
	* gtk/Widget.cs : Commented out a bunch of the new signal stuff until
	I get around to it.
	* gtk/Window.cs (Title): using g_object_set until I work out the
	details of the new Value/SetProperty system.  It looks like g_object_set
	will end up being easier to use via PInvoke.

svn path=/trunk/gtk-sharp/; revision=1008
2001-09-27 17:17:33 +00:00

80 lines
1.6 KiB
C#

// GLib.Signals.Simple.cs - GLib Simple Signal implementation
//
// Authors: Bob Smith <bob@thestuff.net>
// Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001 Bob Smith & Mike Kestner
namespace GLib {
using System;
using System.Runtime.InteropServices;
using GLib;
/// <summary>
/// SimpleDelegate Delegate
/// </summary>
///
/// <remarks>
/// Used to connect to simple signals which contain no signal-
/// specific data.
/// </remarks>
public delegate void SimpleDelegate (IntPtr obj, String name);
/// <summary>
/// SimpleSignal Class
/// </summary>
///
/// <remarks>
/// Wraps a simple signal which contains no single-specific data.
/// </remarks>
public class SimpleSignal {
private static int _RefCount = 0;
private static SimpleDelegate _Delegate;
private static GCHandle _GCHandle;
private static void SimpleCallback(IntPtr obj, String name)
{
Object o = Object.GetObject(obj);
EventHandler eh = (EventHandler) o.Events[name];
if (eh != null)
{
eh(o, EventArgs.Empty);
}
}
public static SimpleDelegate Delegate
{
get
{
if (_Delegate == null)
{
_Delegate = new SimpleDelegate(SimpleCallback);
/* FIXME: Can't do this until a layout attribute is defined for SimpleCallback
* apparently, since this throws an ArgumentException:Type does not have a
* layout attribute.
*
* _GCHandle = GCHandle.Alloc (_Delegate, GCHandleType.Pinned);
*/
}
_RefCount++;
return _Delegate;
}
}
public static void Unref()
{
_RefCount--;
if (_RefCount < 1)
{
_RefCount = 0;
_GCHandle.Free();
_Delegate = null;
}
}
}
}