Commit 97f11c69 authored by Tim Janik's avatar Tim Janik

implementation of gtk_widget_get()

-timj
parent aed02304
......@@ -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 ();
}
}
......
......@@ -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;
}
}
......
......@@ -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;
......@@ -313,6 +314,63 @@ gtk_object_newv (guint type,
return obj;
}
/*****************************************
* 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:
*
......@@ -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;
......
......@@ -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
......
......@@ -269,6 +269,28 @@ gtk_type_is_a (GtkType type,
return FALSE;
}
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,
......@@ -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 ();
......
......@@ -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,
......
......@@ -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);
......@@ -824,6 +822,40 @@ gtk_widget_newv (guint type,
return GTK_WIDGET (gtk_object_newv (type, nargs, args));
}
/*****************************************
* 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:
*
......@@ -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);
......
......@@ -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);
......
......@@ -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 ();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment