GObject fixes.

svn path=/trunk/gtk-sharp/; revision=878
This commit is contained in:
Bob Smith 2001-09-19 04:47:48 +00:00
parent 22b77037ed
commit b4c11b3210
2 changed files with 28 additions and 87 deletions

View file

@ -10,9 +10,17 @@ namespace Glib {
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public class Object { 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) public Object(IntPtr o)
{ {
Object=o; Object = o;
} }
protected IntPtr _obj; protected IntPtr _obj;
@ -30,28 +38,16 @@ namespace Glib {
} }
} }
protected ObjectManager _objectManager; private EventHandlerList _events;
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;
}
}
protected EventHandlerList Events protected EventHandlerList Events
{ {
get get
{ {
return ObjectManager.Events; if (_events != null) return _events;
_events = new EventHandlerList ();
} }
} }
[DllImport("gtk-1.3")] [DllImport("gtk-1.3")]
static extern IntPtr g_object_get_data ( static extern IntPtr g_object_get_data (
IntPtr object, IntPtr object,
@ -73,6 +69,12 @@ namespace Glib {
g_object_set_data (Object, key, value); 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 );
/* /*

View file

@ -9,85 +9,24 @@ namespace Glib {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
protected delegate void SignalFunc ();
protected delegate void DestroyNotify (IntPtr data); protected delegate void DestroyNotify (IntPtr data);
public class ObjectManager { public class ObjectManager {
public ObjectManager(IntPtr o) public ObjectManager(IntPtr o, Glib.Object go)
{ {
if (o == null) throw new ArgumentNullException (); if (o == null || go -- null) throw new ArgumentNullException ();
Object=o; _gobj = go;
g_object_set_data_full(Object, "gobject#-object-manager", _gobj.gh = GCHandle.Alloc (this, GCHandleType.Pinned);
this, new DestroyNotify(DestroyNotifyEvent)); Glib.Object.g_object_set_data_full(o, "gobject#-object-manager",
gh.AddrOfPinnedObject (), new DestroyNotify(DestroyNotifyEvent));
} }
private IntPtr _obj; public Glib.Object gobj;
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 );
private void DestroyNotifyEvent (IntPtr data) private void DestroyNotifyEvent (IntPtr data)
{ {
_events = null; gobj.gh.Free();
} _gobj = 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);
} }
} }