GObject fixes.
svn path=/trunk/gtk-sharp/; revision=878
This commit is contained in:
parent
22b77037ed
commit
b4c11b3210
2 changed files with 28 additions and 87 deletions
|
@ -10,6 +10,14 @@ 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;
|
||||
|
@ -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 );
|
||||
|
||||
/*
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue