More implementation

svn path=/trunk/gtk-sharp/; revision=876
This commit is contained in:
Bob Smith 2001-09-19 02:04:57 +00:00
parent 073970c120
commit 22b77037ed
8 changed files with 286 additions and 32 deletions

183
glib/Object.cs Normal file
View file

@ -0,0 +1,183 @@
// Object.cs - GObject class wrapper implementation
//
// Author: Bob Smith <bob@thestuff.net>
//
// (c) 2001 Bob Smith
namespace Glib {
using System;
using System.Runtime.InteropServices;
public class Object {
public Object(IntPtr o)
{
Object=o;
}
protected IntPtr _obj;
private IntPtr Object
{
get
{
return _obj;
}
set
{
if (value == null) throw new ArgumentNullException ();
_objectManager = null;
_obj = value;
}
}
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;
}
}
protected EventHandlerList Events
{
get
{
return ObjectManager.Events;
}
}
[DllImport("gtk-1.3")]
static extern IntPtr g_object_get_data (
IntPtr object,
String key );
[DllImport("gtk-1.3")]
static extern void g_object_set_data (
IntPtr object,
String key,
IntPtr data );
public IntPtr Data [String key]
{
get
{
return g_object_get_data (Object, key);
}
set
{
g_object_set_data (Object, key, value);
}
}
/*
void (*GObjectGetPropertyFunc) (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
void (*GObjectSetPropertyFunc) (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
void (*GObjectFinalizeFunc) (GObject *object);
#define G_TYPE_IS_OBJECT (type)
#define G_OBJECT (object)
#define G_IS_OBJECT (object)
#define G_OBJECT_CLASS (class)
#define G_IS_OBJECT_CLASS (class)
#define G_OBJECT_GET_CLASS (object)
#define G_OBJECT_TYPE (object)
#define G_OBJECT_TYPE_NAME (object)
#define G_OBJECT_CLASS_TYPE (class)
#define G_OBJECT_CLASS_NAME (class)
#define G_VALUE_HOLDS_OBJECT (value)
void g_object_class_install_property (GObjectClass *oclass,
guint property_id,
GParamSpec *pspec);
GParamSpec* g_object_class_find_property (GObjectClass *oclass,
const gchar *property_name);
GParamSpec** g_object_class_list_properties (GObjectClass *oclass,
guint *n_properties);
gpointer g_object_new (GType object_type,
const gchar *first_property_name,
...);
gpointer g_object_newv (GType object_type,
guint n_parameters,
GParameter *parameters);
gpointer g_object_ref (gpointer object);
void g_object_unref (gpointer object);
void g_object_weak_ref (GObject *object,
GWeakNotify notify,
gpointer data);
void g_object_weak_unref (GObject *object,
GWeakNotify notify,
gpointer data);
void g_object_add_weak_pointer (GObject *object,
gpointer *weak_pointer_location);
void g_object_remove_weak_pointer (GObject *object,
gpointer *weak_pointer_location);
gpointer g_object_connect (gpointer object,
const gchar *signal_spec,
...);
void g_object_disconnect (gpointer object,
const gchar *signal_spec,
...);
void g_object_set (gpointer object,
const gchar *first_property_name,
...);
void g_object_get (gpointer object,
const gchar *first_property_name,
...);
void g_object_notify (GObject *object,
const gchar *property_name);
void g_object_freeze_notify (GObject *object);
void g_object_thaw_notify (GObject *object);
void g_object_set_data_full (GObject *object,
const gchar *key,
gpointer data,
GDestroyNotify destroy);
gpointer g_object_steal_data (GObject *object,
const gchar *key);
gpointer g_object_get_qdata (GObject *object,
GQuark quark);
void g_object_set_qdata (GObject *object,
GQuark quark,
gpointer data);
void g_object_set_qdata_full (GObject *object,
GQuark quark,
gpointer data,
GDestroyNotify destroy);
gpointer g_object_steal_qdata (GObject *object,
GQuark quark);
void g_object_set_property (GObject *object,
const gchar *property_name,
const GValue *value);
void g_object_get_property (GObject *object,
const gchar *property_name,
GValue *value);
GObject* g_object_new_valist (GType object_type,
const gchar *first_property_name,
va_list var_args);
void g_object_set_valist (GObject *object,
const gchar *first_property_name,
va_list var_args);
void g_object_get_valist (GObject *object,
const gchar *first_property_name,
va_list var_args);
void g_object_watch_closure (GObject *object,
GClosure *closure);
void g_object_run_dispose (GObject *object);
void g_value_set_object (GValue *value,
gpointer v_object);
gpointer g_value_get_object (const GValue *value);
GObject* g_value_dup_object (const GValue *value);
#define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec)
*/
}
}

94
glib/ObjectManager.cs Normal file
View file

@ -0,0 +1,94 @@
// 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;
protected delegate void SignalFunc ();
protected delegate void DestroyNotify (IntPtr data);
public class ObjectManager {
public ObjectManager(IntPtr o)
{
if (o == null) throw new ArgumentNullException ();
Object=o;
g_object_set_data_full(Object, "gobject#-object-manager",
this, 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 );
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);
}
}
}

View file

@ -4,7 +4,7 @@
//
// (c) 2001 Mike Kestner
namespace GTK {
namespace Gtk {
using System;
using System.Runtime.InteropServices;

View file

@ -4,7 +4,7 @@
//
// (c) 2001 Bob Smith
namespace GTK {
namespace Gtk {
using System;
using System.Runtime.InteropServices;
@ -30,7 +30,7 @@ namespace GTK {
private void EmitClickedEvent (IntPtr obj)
{
EventHandler eh = (EventHandler)(_events[ClickedEvent]);
EventHandler eh = (EventHandler)(Events[ClickedEvent]);
if (eh != null)
{
EventArgs args = new EventArgs ();

View file

@ -4,7 +4,7 @@
//
// (c) 2001 Bob Smith
namespace GTK {
namespace Gtk {
using System;
using System.Runtime.InteropServices;

View file

@ -4,37 +4,14 @@
//
// (c) 2001 Mike Kestner
namespace GTK {
namespace Gtk {
using System;
using System.Drawing;
using System.Runtime.InteropServices;
public abstract class Object {
private EventHandlerList _events;
protected EventHandlerList Events
{
get
{
if (_events != null) return _events;
_events = new EventHandlerList ();
}
}
private IntPtr _obj;
IntPtr Object
{
get
{
return _obj;
}
set
{
_events = null;
_obj = value;
}
}
public abstract class Object : Glib.Object {
protected delegate void SimpleCallback (IntPtr obj);

View file

@ -4,7 +4,7 @@
//
// (c) 2001 Mike Kestner
namespace GTK {
namespace Gtk {
using System;
using System.Runtime.InteropServices;
@ -40,7 +40,7 @@ namespace GTK {
private void EmitDeleteEvent (IntPtr obj)
{
EventHandler eh = (EventHandler)(_events[DeleteEvent]);
EventHandler eh = (EventHandler)(Events[DeleteEvent]);
if (eh != null)
{
EventArgs args = new EventArgs ();

View file

@ -4,7 +4,7 @@
//
// (c) 2001 Mike Kestner
namespace GTK {
namespace Gtk {
using System;
using System.Drawing;