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
5 changed files with 93 additions and 58 deletions
|
@ -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>
|
2001-09-19 Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
|
||||||
* HACKING : New rulez.
|
* HACKING : New rulez.
|
||||||
|
|
|
@ -7,25 +7,31 @@
|
||||||
namespace GLib {
|
namespace GLib {
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
public class Object {
|
public class Object {
|
||||||
|
protected static Hashtable Objects = new Hashtable();
|
||||||
/*
|
protected const String GOBJECTKEY = "gobject#-object";
|
||||||
public static Object GetObject(IntPtr o)
|
public static Object GetObject(IntPtr o)
|
||||||
{
|
{
|
||||||
if (o == null) throw new ArgumentNullException ();
|
IntPtr key = g_object_get_data (o, GOBJECTKEY);
|
||||||
IntPtr obj = g_object_get_data (o, "gobject#-object-manager");
|
Object obj;
|
||||||
if (obj == null) return new Object(o);
|
if((int)key != 0)
|
||||||
else return ((GCHandle)obj).Target();
|
{
|
||||||
|
obj = (Object)Objects[(int)key];
|
||||||
|
if (obj != null) return obj;
|
||||||
}
|
}
|
||||||
GCHandle gh;
|
obj = new Object(o); //FIXME: Cast up when we know how.
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
public Object(IntPtr o)
|
public Object(IntPtr o)
|
||||||
{
|
{
|
||||||
Object = o;
|
RawObject = o;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
private IntPtr _obj;
|
private IntPtr _obj;
|
||||||
|
|
||||||
protected IntPtr RawObject
|
protected IntPtr RawObject
|
||||||
|
@ -34,6 +40,15 @@ namespace GLib {
|
||||||
return _obj;
|
return _obj;
|
||||||
}
|
}
|
||||||
set {
|
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;
|
_obj = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,31 +63,31 @@ namespace GLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
[DllImport("gobject-1.3")]
|
[DllImport("gobject-1.3")]
|
||||||
static extern IntPtr g_object_get_data (
|
static extern IntPtr g_object_get_data (
|
||||||
IntPtr object,
|
IntPtr obj,
|
||||||
String key );
|
String key );
|
||||||
|
|
||||||
|
public IntPtr GetRawData (String key)
|
||||||
|
{
|
||||||
|
return g_object_get_data (_obj, key);
|
||||||
|
}
|
||||||
|
|
||||||
[DllImport("gobject-1.3")]
|
[DllImport("gobject-1.3")]
|
||||||
static extern void g_object_set_data (
|
static extern void g_object_set_data (
|
||||||
IntPtr object,
|
IntPtr obj,
|
||||||
String key,
|
String key,
|
||||||
IntPtr data );
|
IntPtr data );
|
||||||
|
|
||||||
public IntPtr Data [String key]
|
public void SetRawData (String key, IntPtr value)
|
||||||
{
|
{
|
||||||
get
|
g_object_set_data (_obj, key, value);
|
||||||
{
|
|
||||||
return g_object_get_data (Object, key);
|
|
||||||
}
|
}
|
||||||
set
|
|
||||||
{
|
/* [DllImport("gtk-1.3")]
|
||||||
g_object_set_data (Object, key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[DllImport("gtk-1.3")]
|
|
||||||
static extern void g_object_set_data_full (
|
static extern void g_object_set_data_full (
|
||||||
IntPtr object,
|
IntPtr obj,
|
||||||
String key,
|
String key,
|
||||||
IntPtr data,
|
IntPtr data,
|
||||||
DestroyNotify destroy );
|
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 {
|
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);
|
protected delegate void SimpleCallback (IntPtr obj);
|
||||||
|
|
||||||
[DllImport("gtk-1.3")]
|
[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