diff --git a/glib/Object.cs b/glib/Object.cs index 43bd4f838..a41b6b03d 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -10,9 +10,17 @@ namespace Glib { using System.Runtime.InteropServices; public class 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(); + } + GCHandle gh; public Object(IntPtr o) { - Object=o; + Object = o; } protected IntPtr _obj; @@ -30,28 +38,16 @@ namespace Glib { } } - protected ObjectManager _objectManager; - - private ObjectManager ObjectManager - { - get - { - if (_objectManager == null) - { - IntPtr o = Data["gobject#-object-manager"]; - if (o == null) _objectManager = new ObjectManager(_obj); - else _objectManager = o; - } - return _objectManager; - } - } + private EventHandlerList _events; protected EventHandlerList Events { get { - return ObjectManager.Events; + if (_events != null) return _events; + _events = new EventHandlerList (); } } + [DllImport("gtk-1.3")] static extern IntPtr g_object_get_data ( IntPtr object, @@ -73,6 +69,12 @@ namespace Glib { g_object_set_data (Object, key, value); } } + [DllImport("gtk-1.3")] + static extern void g_object_set_data_full ( + IntPtr object, + String key, + IntPtr data, + DestroyNotify destroy ); /* diff --git a/glib/ObjectManager.cs b/glib/ObjectManager.cs index 1ebe73a63..c251ee201 100644 --- a/glib/ObjectManager.cs +++ b/glib/ObjectManager.cs @@ -9,85 +9,24 @@ namespace Glib { using System; using System.Runtime.InteropServices; - protected delegate void SignalFunc (); protected delegate void DestroyNotify (IntPtr data); public class ObjectManager { - public ObjectManager(IntPtr o) + public ObjectManager(IntPtr o, Glib.Object go) { - if (o == null) throw new ArgumentNullException (); - Object=o; - g_object_set_data_full(Object, "gobject#-object-manager", - this, new DestroyNotify(DestroyNotifyEvent)); + 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)); } - private IntPtr _obj; - - IntPtr Object - { - get - { - return _obj; - } - set - { - _obj = value; - } - } - private EventHandlerList _events; - protected EventHandlerList Events - { - get - { - if (_events != null) return _events; - _events = new EventHandlerList (); - } - } - - [DllImport("gtk-1.3")] - static extern void g_object_set_data_full ( - IntPtr object, - String key, - IntPtr data, - DestroyNotify destroy ); + public Glib.Object gobj; private void DestroyNotifyEvent (IntPtr data) { - _events = null; - } -//TODO: Replace IntPtr's with Types. - [DllImport("gtk-1.3")] - static extern long g_signal_connect_closure_by_id ( - IntPtr instance, - int signalID, - IntPtr detail, - IntPtr closure, - bool after ); - [DllImport("gtk-1.3")] - static extern int g_signal_lookup ( - String name, - IntPtr itype ); - [DllImport("gtk-1.3")] - static extern IntPtr g_cclosure_new ( - IntPtr callback_func, - IntPtr user_data, - IntPtr destroy_data ); - - [DllImport("gtk-1.3")] - static extern IntPtr g_cclosure_new_swap ( - IntPtr callback_func, - IntPtr user_data, - IntPtr destroy_data ); - public long SignalConnect(String name, SignalFunc func, IntPtr data){ - SignalConnectFull(name, func, data, null, 0, 0); - } - public long SignalConnectFull(String name, SignalFunc func, IntPtr data, DestroyNotify destroy, int objectSignal, int after){ - return g_signal_connect_closure_by_id (Object, - g_signal_lookup (name, Object), 0, //Need to cast object? - (object_signal ? g_cclosure_new_swap(func, data, destroy) - : g_cclosure_new(func, data, destroy), - after); - + gobj.gh.Free(); + _gobj = null; } }