From 4b150c5f7c13ef5b8611e3fe72cef7f8e7854e4f Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Sun, 25 Nov 2012 20:26:25 +1100 Subject: [PATCH] Add new type: gtk-widget. It represents pointer to GtkWidget. --- lib/gtk/gtk.h | 12 ++++++++++++ lib/gtk/gtkwidget.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/gtk/gtk.h b/lib/gtk/gtk.h index 51e6aa5..6d04028 100644 --- a/lib/gtk/gtk.h +++ b/lib/gtk/gtk.h @@ -32,8 +32,20 @@ #include #include "config.h" +extern int T_GtkWidget; + +#define GTKWIDGET(x) ((struct S_GtkWidget *)POINTER(x)) + +struct S_GtkWidget { + Object tag; + GtkWidget *widget; +}; + C_LINKAGE_BEGIN +extern GtkWidget *Get_GtkWidget (Object w); +extern Object Make_GtkWidget (GtkWidget *w); + extern void elk_init_gtk_gtkmain (void); extern void elk_init_gtk_gtkwidget (void); diff --git a/lib/gtk/gtkwidget.c b/lib/gtk/gtkwidget.c index 80f8e86..2be6309 100644 --- a/lib/gtk/gtkwidget.c +++ b/lib/gtk/gtkwidget.c @@ -30,5 +30,38 @@ #include "gtk.h" -void elk_init_gtk_gtkwidget () { +int T_GtkWidget; + +GtkWidget *Get_GtkWidget (Object w) { + Check_Type (w, T_GtkWidget); + return GTKWIDGET(w)->widget; +} + +Object Make_GtkWidget (GtkWidget *w) { + Object yield; + + yield = Alloc_Object (sizeof (struct S_GtkWidget), T_GtkWidget, 0); + GTKWIDGET(yield)->widget = w; + return yield; +} + +static int GtkWidget_Equal (Object x, Object y) { + return GTKWIDGET(x)->widget == GTKWIDGET(y)->widget; +} + +static int GtkWidget_Print (Object x, Object port, int raw, int depth, + int len) { + Printf (port, "#[gtk-widget %lu]", (unsigned long)GTKWIDGET(x)->widget); + return 0; +} + +static Object GtkWidgetp (Object x) { + return TYPE(x) == T_GtkWidget ? True : False; +} + +void elk_init_gtk_gtkwidget () { + T_GtkWidget = Define_Type (0, "gtk-widget", NOFUNC, + sizeof (struct S_GtkWidget), GtkWidget_Equal, GtkWidget_Equal, + GtkWidget_Print, NOFUNC); + Define_Primitive (GtkWidgetp, "gtk-widget?", 1, 1, EVAL); }