From ed085ca8241ea9077436940cf7ccabb5c89b6086 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 2 Apr 2008 17:04:21 +0000 Subject: [PATCH] Another tedious chore off the to-do list. I've just checked over my custom Columns layout class to see what fiddly details of GTK2isation were yet to be done. It turns out that all the basic object management got moved out of GTK into a separate library, so that all the gtk_object_* calls are deprecated and g_object_* should be used instead; having done that, though, it all looks perfectly fine. [originally from svn r7962] --- unix/GTK2.TODO | 6 ------ unix/gtkcols.c | 56 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/unix/GTK2.TODO b/unix/GTK2.TODO index 524458d7..0453c475 100644 --- a/unix/GTK2.TODO +++ b/unix/GTK2.TODO @@ -3,12 +3,6 @@ TODO for PuTTY GTK2 port before merging back into main trunk code Things to do before deciding a merge is feasible: - - gtkcols.c is currently a minimal-work GTK2 port of my original - GTK1 implementation. Someone should go through it and compare it - to a real GTK2 container class, to make sure there aren't any - large chunks we should have reimplemented and haven't, or indeed - that we shouldn't have reimplemented and have. - - Update the autoconf build. Richard B says he had to replace AM_PATH_GTK([1.2.0], with diff --git a/unix/gtkcols.c b/unix/gtkcols.c index e70400de..cb654b03 100644 --- a/unix/gtkcols.c +++ b/unix/gtkcols.c @@ -26,6 +26,7 @@ static void columns_size_allocate(GtkWidget *widget, GtkAllocation *alloc); static GtkContainerClass *parent_class = NULL; +#if !GTK_CHECK_VERSION(2,0,0) GtkType columns_get_type(void) { static GtkType columns_type = 0; @@ -47,6 +48,31 @@ GtkType columns_get_type(void) return columns_type; } +#else +GType columns_get_type(void) +{ + static GType columns_type = 0; + + if (!columns_type) { + static const GTypeInfo columns_info = { + sizeof(ColumnsClass), + NULL, + NULL, + (GClassInitFunc) columns_class_init, + NULL, + NULL, + sizeof(Columns), + 0, + (GInstanceInitFunc)columns_init, + }; + + columns_type = g_type_register_static(GTK_TYPE_CONTAINER, "Columns", + &columns_info, 0); + } + + return columns_type; +} +#endif #if !GTK_CHECK_VERSION(2,0,0) static gint (*columns_inherited_focus)(GtkContainer *container, @@ -55,20 +81,21 @@ static gint (*columns_inherited_focus)(GtkContainer *container, static void columns_class_init(ColumnsClass *klass) { - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *)klass; - widget_class = (GtkWidgetClass *)klass; - container_class = (GtkContainerClass *)klass; +#if !GTK_CHECK_VERSION(2,0,0) + GtkObjectClass *object_class = (GtkObjectClass *)klass; + GtkWidgetClass *widget_class = (GtkWidgetClass *)klass; + GtkContainerClass *container_class = (GtkContainerClass *)klass; +#else + /* GObjectClass *object_class = G_OBJECT_CLASS(klass); */ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + GtkContainerClass *container_class = GTK_CONTAINER_CLASS(klass); +#endif +#if !GTK_CHECK_VERSION(2,0,0) + parent_class = g_type_class_peek_parent(klass); +#else parent_class = gtk_type_class(GTK_TYPE_CONTAINER); - - /* - * FIXME: do we have to do all this faffing with set_arg, - * get_arg and child_arg_type? Ick. - */ +#endif widget_class->map = columns_map; widget_class->unmap = columns_unmap; @@ -300,7 +327,12 @@ GtkWidget *columns_new(gint spacing) { Columns *cols; +#if !GTK_CHECK_VERSION(2,0,0) cols = gtk_type_new(columns_get_type()); +#else + cols = g_object_new(TYPE_COLUMNS, NULL); +#endif + cols->spacing = spacing; return GTK_WIDGET(cols);