diff options
author | Tim Janik <timj@src.gnome.org> | 1998-01-16 05:11:10 +0000 |
---|---|---|
committer | Tim Janik <timj@src.gnome.org> | 1998-01-16 05:11:10 +0000 |
commit | 97f11c694c2f9e43a26dc733c18a19a3c12173fa (patch) | |
tree | 4c77cdf70b1335c5e0c62c4e189133628df9ee17 | |
parent | aed02304eba9488e6008436f364ec588f1cd0e6f (diff) | |
download | gtk+-97f11c694c2f9e43a26dc733c18a19a3c12173fa.tar.gz |
implementation of gtk_widget_get()
-timj
-rw-r--r-- | gtk/gtkbutton.c | 2 | ||||
-rw-r--r-- | gtk/gtkcontainer.c | 26 | ||||
-rw-r--r-- | gtk/gtkobject.c | 100 | ||||
-rw-r--r-- | gtk/gtkobject.h | 56 | ||||
-rw-r--r-- | gtk/gtktypeutils.c | 25 | ||||
-rw-r--r-- | gtk/gtktypeutils.h | 4 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 46 | ||||
-rw-r--r-- | gtk/gtkwidget.h | 9 | ||||
-rw-r--r-- | gtk/gtkwindow.c | 2 |
9 files changed, 219 insertions, 51 deletions
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index f85ddf0fbb..f86275c19a 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -231,8 +231,6 @@ gtk_button_set_arg (GtkButton *button, gtk_container_add (GTK_CONTAINER (button), label); gtk_container_enable_resize (GTK_CONTAINER (button)); break; - default: - g_assert_not_reached (); } } diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index 77bee5964d..1fbfa1aacd 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -71,6 +71,9 @@ static void gtk_container_marshal_signal_4 (GtkObject *object, static void gtk_container_class_init (GtkContainerClass *klass); static void gtk_container_init (GtkContainer *container); +static void gtk_container_get_arg (GtkContainer *container, + GtkArg *arg, + guint arg_id); static void gtk_container_set_arg (GtkContainer *container, GtkArg *arg, guint arg_id); @@ -114,7 +117,7 @@ gtk_container_get_type () (GtkClassInitFunc) gtk_container_class_init, (GtkObjectInitFunc) gtk_container_init, (GtkArgSetFunc) gtk_container_set_arg, - (GtkArgGetFunc) NULL, + (GtkArgGetFunc) gtk_container_get_arg, }; container_type = gtk_type_unique (gtk_widget_get_type (), &container_info); @@ -226,8 +229,27 @@ gtk_container_set_arg (GtkContainer *container, case ARG_CHILD: gtk_container_add (container, GTK_WIDGET (GTK_VALUE_OBJECT (*arg))); break; + } +} + +static void +gtk_container_get_arg (GtkContainer *container, + GtkArg *arg, + guint arg_id) +{ + switch (arg_id) + { + case ARG_BORDER_WIDTH: + GTK_VALUE_LONG (*arg) = container->border_width; + break; + case ARG_AUTO_RESIZE: + GTK_VALUE_BOOL (*arg) = container->auto_resize; + break; + case ARG_BLOCK_RESIZE: + GTK_VALUE_BOOL (*arg) = container->block_resize; + break; default: - g_assert_not_reached (); + arg->type = GTK_TYPE_INVALID; } } diff --git a/gtk/gtkobject.c b/gtk/gtkobject.c index d61a73ede7..8d76b6d9f5 100644 --- a/gtk/gtkobject.c +++ b/gtk/gtkobject.c @@ -64,7 +64,7 @@ static void gtk_object_data_init (void); static GtkObjectData* gtk_object_data_new (void); static void gtk_object_data_destroy (GtkObjectData *odata); static guint* gtk_object_data_id_alloc (void); -GtkArg* gtk_object_collect_args (gint *nargs, +GtkArg* gtk_object_collect_args (guint *nargs, va_list args1, va_list args2); @@ -220,6 +220,7 @@ gtk_object_class_add_signals (GtkObjectClass *class, for (i = 0; i < nsignals; i++) new_signals[class->nsignals + i] = signals[i]; + /* g_free (class->signals); FIXME freeing here causes a segfault */ class->signals = new_signals; class->nsignals += nsignals; } @@ -273,7 +274,7 @@ gtk_object_new (guint type, { GtkObject *obj; GtkArg *args; - gint nargs; + guint nargs; va_list args1; va_list args2; @@ -302,7 +303,7 @@ gtk_object_new (guint type, GtkObject* gtk_object_newv (guint type, - gint nargs, + guint nargs, GtkArg *args) { gpointer obj; @@ -314,6 +315,63 @@ gtk_object_newv (guint type, } /***************************************** + * gtk_object_getv: + * + * arguments: + * + * results: + *****************************************/ + +void +gtk_object_getv (GtkObject *object, + guint nargs, + GtkArg *args) +{ + int i; + + g_return_if_fail (object != NULL); + + if (!arg_info_ht) + return; + + for (i = 0; i < nargs; i++) + { + GtkArgInfo *info; + gchar *lookup_name; + gchar *d; + + + /* hm, the name cutting shouldn't be needed on gets, but what the heck... + */ + lookup_name = g_strdup (args[i].name); + d = strchr (lookup_name, ':'); + if (d && d[1] == ':') + { + d = strchr (d + 2, ':'); + if (d) + *d = 0; + + info = g_hash_table_lookup (arg_info_ht, lookup_name); + } + else + info = NULL; + + if (!info) + { + g_warning ("invalid arg name: \"%s\"\n", lookup_name); + args[i].type = GTK_TYPE_INVALID; + g_free (lookup_name); + continue; + } + else + g_free (lookup_name); + + args[i].type = info->type; + gtk_type_get_arg (object, info->class_type, &args[i], info->arg_id); + } +} + +/***************************************** * gtk_object_set: * * arguments: @@ -322,21 +380,21 @@ gtk_object_newv (guint type, *****************************************/ void -gtk_object_set (GtkObject *obj, +gtk_object_set (GtkObject *object, ...) { GtkArg *args; - gint nargs; + guint nargs; va_list args1; va_list args2; - g_return_if_fail (obj != NULL); + g_return_if_fail (object != NULL); - va_start (args1, obj); - va_start (args2, obj); + va_start (args1, object); + va_start (args2, object); args = gtk_object_collect_args (&nargs, args1, args2); - gtk_object_setv (obj, nargs, args); + gtk_object_setv (object, nargs, args); g_free (args); va_end (args1); @@ -353,7 +411,7 @@ gtk_object_set (GtkObject *obj, void gtk_object_setv (GtkObject *obj, - gint nargs, + guint nargs, GtkArg *args) { int i; @@ -368,6 +426,7 @@ gtk_object_setv (GtkObject *obj, GtkArgInfo *info; gchar *lookup_name; gchar *d; + gboolean arg_ok; lookup_name = g_strdup (args[i].name); d = strchr (lookup_name, ':'); @@ -382,13 +441,24 @@ gtk_object_setv (GtkObject *obj, else info = NULL; + arg_ok = TRUE; + if (!info) { g_warning ("invalid arg name: \"%s\"\n", lookup_name); - continue; + arg_ok = FALSE; + } + else if (info->type != args[i].type) + { + g_warning ("invalid arg type for: \"%s\"\n", lookup_name); + arg_ok = FALSE; } + g_free (lookup_name); + if (!arg_ok) + continue; + gtk_type_set_arg (obj, info->class_type, &args[i], info->arg_id); } } @@ -857,15 +927,15 @@ gtk_object_data_id_alloc () *****************************************/ GtkArg* -gtk_object_collect_args (gint *nargs, +gtk_object_collect_args (guint *nargs, va_list args1, va_list args2) { GtkArg *args; GtkType type; - char *name; - int done; - int i, n; + gchar *name; + gint done; + gint i, n; n = 0; done = FALSE; diff --git a/gtk/gtkobject.h b/gtk/gtkobject.h index 16bcafa876..40edb8d66b 100644 --- a/gtk/gtkobject.h +++ b/gtk/gtkobject.h @@ -159,37 +159,51 @@ struct _GtkObjectClass /* Get the type identifier for GtkObject's. */ -guint gtk_object_get_type (void); +guint gtk_object_get_type (void); /* Append "signals" to those already defined in "class". */ -void gtk_object_class_add_signals (GtkObjectClass *klass, - gint *signals, - gint nsignals); +void gtk_object_class_add_signals (GtkObjectClass *klass, + gint *signals, + gint nsignals); -void gtk_object_ref (GtkObject *object); +GtkObject* gtk_object_new (guint type, + ...); -void gtk_object_unref (GtkObject *object); +GtkObject* gtk_object_newv (guint type, + guint nargs, + GtkArg *args); -GtkObject* gtk_object_new (guint type, - ...); +void gtk_object_ref (GtkObject *object); -GtkObject* gtk_object_newv (guint type, - gint nargs, - GtkArg *args); +void gtk_object_unref (GtkObject *object); -void gtk_object_set (GtkObject *obj, - ...); +/* gtk_object_getv() sets an arguments type and value, or just + * its type to GTK_TYPE_INVALID. + * if arg->type == GTK_TYPE_STRING, it's the callers response to + * do a g_free (GTK_VALUE_STRING (arg)); + */ +void gtk_object_getv (GtkObject *object, + guint nargs, + GtkArg *args); + +/* gtk_object_set() takes a variable argument list of the form: + * (..., gchar *arg_name, ARG_VALUES, [repeatedly name/value pairs,] NULL) + * where ARG_VALUES type depend on the argument and can consist of + * more than one c-function argument. + */ +void gtk_object_set (GtkObject *object, + ...); -void gtk_object_setv (GtkObject *obj, - gint nargs, - GtkArg *args); +void gtk_object_setv (GtkObject *object, + guint nargs, + GtkArg *args); -void gtk_object_add_arg_type (const char *arg_name, - GtkType arg_type, - guint arg_id); +void gtk_object_add_arg_type (const gchar *arg_name, + GtkType arg_type, + guint arg_id); -GtkType gtk_object_get_arg_type (const char *arg_name); +GtkType gtk_object_get_arg_type (const gchar *arg_name); /* Emit the "destroy" signal for "object". Normally it is * permissible to emit a signal for an object instead of @@ -200,7 +214,7 @@ GtkType gtk_object_get_arg_type (const char *arg_name); * and sets the GTK_NEED_DESTROY flag which tells the object * to be destroyed when it is done handling the signal emittion. */ -void gtk_object_destroy (GtkObject *object); +void gtk_object_destroy (GtkObject *object); /* Set 'data' to the "object_data" field of the object. The * data is indexed by the "key". If there is already data diff --git a/gtk/gtktypeutils.c b/gtk/gtktypeutils.c index 79e049156f..fa4605d547 100644 --- a/gtk/gtktypeutils.c +++ b/gtk/gtktypeutils.c @@ -270,6 +270,28 @@ gtk_type_is_a (GtkType type, } void +gtk_type_get_arg (GtkObject *object, + GtkType type, + GtkArg *arg, + guint arg_id) +{ + GtkTypeNode *node; + + g_return_if_fail (object != NULL); + g_return_if_fail (arg != NULL); + + if (initialize) + gtk_type_init (); + + node = g_hash_table_lookup (type_hash_table, &type); + + if (node && node->type_info.arg_get_func) + (* node->type_info.arg_get_func) (object, arg, arg_id); + else + arg->type = GTK_TYPE_INVALID; +} + +void gtk_type_set_arg (GtkObject *object, GtkType type, GtkArg *arg, @@ -277,6 +299,9 @@ gtk_type_set_arg (GtkObject *object, { GtkTypeNode *node; + g_return_if_fail (object != NULL); + g_return_if_fail (arg != NULL); + if (initialize) gtk_type_init (); diff --git a/gtk/gtktypeutils.h b/gtk/gtktypeutils.h index d6e398f0e5..f2f976a2e4 100644 --- a/gtk/gtktypeutils.h +++ b/gtk/gtktypeutils.h @@ -185,6 +185,10 @@ void gtk_type_describe_tree (GtkType type, gint show_size); gint gtk_type_is_a (GtkType type, GtkType is_a_type); +void gtk_type_get_arg (GtkObject *object, + GtkType type, + GtkArg *arg, + guint arg_id); void gtk_type_set_arg (GtkObject *object, GtkType type, GtkArg *arg, diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 9dbde0d43b..ba8524d51e 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -167,7 +167,7 @@ static void gtk_widget_set_style_internal (GtkWidget *widget, static void gtk_widget_set_style_recurse (GtkWidget *widget, gpointer client_data); -extern GtkArg* gtk_object_collect_args (gint *nargs, +extern GtkArg* gtk_object_collect_args (guint *nargs, va_list args1, va_list args2); @@ -718,8 +718,6 @@ gtk_widget_set_arg (GtkWidget *widget, case ARG_PARENT: gtk_container_add (GTK_CONTAINER (GTK_VALUE_OBJECT(*arg)), widget); break; - default: - g_assert_not_reached (); } } @@ -785,7 +783,7 @@ gtk_widget_new (guint type, { GtkObject *obj; GtkArg *args; - gint nargs; + guint nargs; va_list args1; va_list args2; @@ -816,7 +814,7 @@ gtk_widget_new (guint type, GtkWidget* gtk_widget_newv (guint type, - gint nargs, + guint nargs, GtkArg *args) { g_return_val_if_fail (gtk_type_is_a (type, gtk_widget_get_type ()), NULL); @@ -825,6 +823,40 @@ gtk_widget_newv (guint type, } /***************************************** + * gtk_widget_get: + * + * arguments: + * + * results: + *****************************************/ + +void +gtk_widget_get (GtkWidget *widget, + GtkArg *arg) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (arg != NULL); + + gtk_object_getv (GTK_OBJECT (widget), 1, arg); +} + +/***************************************** + * gtk_widget_getv: + * + * arguments: + * + * results: + *****************************************/ + +void +gtk_widget_getv (GtkWidget *widget, + guint nargs, + GtkArg *args) +{ + gtk_object_getv (GTK_OBJECT (widget), nargs, args); +} + +/***************************************** * gtk_widget_set: * * arguments: @@ -837,7 +869,7 @@ gtk_widget_set (GtkWidget *widget, ...) { GtkArg *args; - gint nargs; + guint nargs; va_list args1; va_list args2; @@ -864,7 +896,7 @@ gtk_widget_set (GtkWidget *widget, void gtk_widget_setv (GtkWidget *widget, - gint nargs, + guint nargs, GtkArg *args) { gtk_object_setv (GTK_OBJECT (widget), nargs, args); diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 5b80ffda0b..f84e481539 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -355,12 +355,17 @@ guint gtk_widget_get_type (void); GtkWidget* gtk_widget_new (guint type, ...); GtkWidget* gtk_widget_newv (guint type, - gint nargs, + guint nargs, + GtkArg *args); +void gtk_widget_get (GtkWidget *widget, + GtkArg *arg); +void gtk_widget_getv (GtkWidget *widget, + guint nargs, GtkArg *args); void gtk_widget_set (GtkWidget *widget, ...); void gtk_widget_setv (GtkWidget *widget, - gint nargs, + guint nargs, GtkArg *args); void gtk_widget_destroy (GtkWidget *widget); void gtk_widget_unparent (GtkWidget *widget); diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 163ade09a4..1ab8d70647 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -242,8 +242,6 @@ gtk_window_set_arg (GtkWindow *window, case ARG_ALLOW_GROW: window->allow_grow = (GTK_VALUE_BOOL(*arg) != FALSE); break; - default: - g_assert_not_reached (); } } |