mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-01-09 01:15:40 +00:00
ObjectManager.cs nuked, Glib.Object now keeps track of the wrapper class, and Gtk.Object should have a better signal handling system.
svn path=/trunk/gtk-sharp/; revision=894
This commit is contained in:
parent
91c58501fa
commit
3d40a27630
|
@ -1,3 +1,10 @@
|
|||
2001-09-20
|
||||
|
||||
* glib/ObjectManager.cs: Nuked.
|
||||
* glib/Object.cs: Keep track of wrapper.
|
||||
* gtk/Object: First stab at better signal system. Should reduce
|
||||
number of pins nessisary.
|
||||
|
||||
2001-09-19 Mike Kestner <mkestner@speakeasy.net>
|
||||
|
||||
* HACKING : New rulez.
|
||||
|
|
|
@ -7,25 +7,31 @@
|
|||
namespace GLib {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class Object {
|
||||
|
||||
/*
|
||||
protected static Hashtable Objects = new Hashtable();
|
||||
protected const String GOBJECTKEY = "gobject#-object";
|
||||
public static Object GetObject(IntPtr o)
|
||||
{
|
||||
if (o == null) throw new ArgumentNullException ();
|
||||
IntPtr obj = g_object_get_data (o, "gobject#-object-manager");
|
||||
if (obj == null) return new Object(o);
|
||||
else return ((GCHandle)obj).Target();
|
||||
IntPtr key = g_object_get_data (o, GOBJECTKEY);
|
||||
Object obj;
|
||||
if((int)key != 0)
|
||||
{
|
||||
obj = (Object)Objects[(int)key];
|
||||
if (obj != null) return obj;
|
||||
}
|
||||
obj = new Object(o); //FIXME: Cast up when we know how.
|
||||
return obj;
|
||||
}
|
||||
GCHandle gh;
|
||||
|
||||
public Object(IntPtr o)
|
||||
{
|
||||
Object = o;
|
||||
RawObject = o;
|
||||
}
|
||||
*/
|
||||
|
||||
private IntPtr _obj;
|
||||
|
||||
protected IntPtr RawObject
|
||||
|
@ -34,6 +40,15 @@ namespace GLib {
|
|||
return _obj;
|
||||
}
|
||||
set {
|
||||
IntPtr key = g_object_get_data (value, GOBJECTKEY);
|
||||
if ((int)key != 0)
|
||||
{
|
||||
Object obj = (Object)Objects[(int)key];
|
||||
if (obj != null) Objects.Remove((int)key);
|
||||
}
|
||||
key = new IntPtr(this.GetHashCode());
|
||||
Objects[(int)key] = this;
|
||||
g_object_set_data (value, GOBJECTKEY, key);
|
||||
_obj = value;
|
||||
}
|
||||
}
|
||||
|
@ -48,31 +63,31 @@ namespace GLib {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
[DllImport("gobject-1.3")]
|
||||
static extern IntPtr g_object_get_data (
|
||||
IntPtr object,
|
||||
IntPtr obj,
|
||||
String key );
|
||||
|
||||
public IntPtr GetRawData (String key)
|
||||
{
|
||||
return g_object_get_data (_obj, key);
|
||||
}
|
||||
|
||||
[DllImport("gobject-1.3")]
|
||||
static extern void g_object_set_data (
|
||||
IntPtr object,
|
||||
IntPtr obj,
|
||||
String key,
|
||||
IntPtr data );
|
||||
|
||||
public IntPtr Data [String key]
|
||||
public void SetRawData (String key, IntPtr value)
|
||||
{
|
||||
get
|
||||
{
|
||||
return g_object_get_data (Object, key);
|
||||
}
|
||||
set
|
||||
{
|
||||
g_object_set_data (Object, key, value);
|
||||
}
|
||||
g_object_set_data (_obj, key, value);
|
||||
}
|
||||
[DllImport("gtk-1.3")]
|
||||
|
||||
/* [DllImport("gtk-1.3")]
|
||||
static extern void g_object_set_data_full (
|
||||
IntPtr object,
|
||||
IntPtr obj,
|
||||
String key,
|
||||
IntPtr data,
|
||||
DestroyNotify destroy );
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
// ObjectManager.cs - GObject class wrapper helper implementation
|
||||
//
|
||||
// Author: Bob Smith <bob@thestuff.net>
|
||||
//
|
||||
// (c) 2001 Bob Smith
|
||||
|
||||
namespace GLib {
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/*
|
||||
public class ObjectManager {
|
||||
public ObjectManager(IntPtr o, Object go)
|
||||
{
|
||||
if (o == null || go -- null) throw new ArgumentNullException ();
|
||||
_gobj = go;
|
||||
_gobj.gh = GCHandle.Alloc (this, GCHandleType.Pinned);
|
||||
Glib.Object.g_object_set_data_full(o, "gobject#-object-manager",
|
||||
gh.AddrOfPinnedObject (), new DestroyNotify(DestroyNotifyEvent));
|
||||
|
||||
}
|
||||
public Glib.Object gobj;
|
||||
|
||||
protected delegate void DestroyNotify (IntPtr data);
|
||||
|
||||
private void DestroyNotifyEvent (IntPtr data)
|
||||
{
|
||||
gobj.gh.Free();
|
||||
_gobj = null;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -12,6 +12,43 @@ namespace Gtk {
|
|||
|
||||
public abstract class Object : GLib.Object {
|
||||
|
||||
/// <summary>
|
||||
/// Destroy Event
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Occurs when the Object is destroyed.
|
||||
/// </remarks>
|
||||
|
||||
private static readonly object DestroyEvent = new object ();
|
||||
|
||||
public event EventHandler Destroy
|
||||
{
|
||||
add
|
||||
{
|
||||
if (Events[DestroyEvent] == null)
|
||||
{
|
||||
ConnectSignal ("destroy", new SimpleSignal (EmitDestroyEvent));
|
||||
}
|
||||
Events.AddHandler (DeleteEvent, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
Events.RemoveHandler (DeleteEvent, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void EmitDestroyEvent (IntPtr obj, IntPtr data)
|
||||
{
|
||||
Glib.Object o = Glib.Object.GetObject(obj);
|
||||
EventHandler eh = (EventHandler)(o.Events[DeleteEvent]);
|
||||
if (eh != null)
|
||||
{
|
||||
EventArgs args = new EventArgs ();
|
||||
eh(this, args);
|
||||
}
|
||||
}
|
||||
|
||||
protected delegate void SimpleCallback (IntPtr obj);
|
||||
|
||||
[DllImport("gtk-1.3")]
|
||||
|
|
11
gtk/SimpleSignal.cs
Normal file
11
gtk/SimpleSignal.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
// SimpleSignal.cs - Simple callback delegate.
|
||||
//
|
||||
// Author: Bob Smith <bob@thestuff.net>
|
||||
//
|
||||
// (c) 2001 Bob Smith
|
||||
|
||||
namespace Gtk {
|
||||
using System;
|
||||
|
||||
public delegate void SimpleSignal (IntPtr obj, IntPtr data);
|
||||
}
|
Loading…
Reference in a new issue