Re: [gtk-list] Re: Argument handling
- From: Tim Janik <timj gtk org>
- To: "J.A.M. Molenaar" <Klem Prod net HCC nl>
- cc: Gtk+ MList <gtk-list redhat com>, Federico Mena <federico nuclecu unam mx>
- Subject: Re: [gtk-list] Re: Argument handling
- Date: Thu, 4 Feb 1999 03:37:14 +0100 (CET)
On Wed, 3 Feb 1999, J.A.M. Molenaar wrote:
> Federico Mena Quintero wrote:
> >
> > > I've been coding for a while an ran up to a (minor) question. I'm
> > > creating some GnomeCanvas things that use the GTK Argument System. It
> > > allows me to set attributes on creation and set them after I have
> > > created them. The problem is that I can't figure out what function is
> > > used to retrieve information. gtk_object_get ()? I dunno...
> >
> > You can use the gtk_object_getv() function. Here is a small example
> > from the Gnomecal sources:
> >
> > GtkArg args[3];
> > double text_height;
> > double clip_height;
> > double y_offset;
> >
> > args[0].name = "text_height";
> > args[1].name = "clip_height";
> > args[2].name = "y_offset";
> > gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 3, args);
> >
> > text_height = GTK_VALUE_DOUBLE (args[0]);
> > clip_height = GTK_VALUE_DOUBLE (args[1]);
> > y_offset = GTK_VALUE_DOUBLE (args[2]);
> >
> > In this case, mv->text[day_index] is a GnomeCanvasText item.
> >
> > Federico
> >
>
> Thanx!!! This will simplify my program a lot!
it should be noted, that string-like values that are retrived this way need
an explicit call to g_free to not leak memory:
for (i = 0; i < 3; i++)
{
if (GTK_FUNDAMENTAL_TYPE (args[i].type) == GTK_TYPE_STRING)
g_free (GTK_VALUE_STRING (args[i]));
}
i also wonder whether people would be interested in an elipsis type
interface to query such values, so you could write the above as:
gdouble text_height;
gdouble clip_height;
gdouble y_offset;
gtk_object_get (GTK_OBJECT (mv->text[day_index]),
"text_height", &text_height,
"clip_height", &clip_height,
"y_offset", &y_offset,
NULL);
of course, this lacks type safety as much as the current _set() interface
does, and certain constrains have to be taken care about, e.g.
fundamental type var arg collected
GTK_TYPE_DOUBLE expects: gdouble*
GTK_TYPE_FLOAT expects: gdouble*
GTK_TYPE_INT expects: gint*
GTK_TYPE_CHAR expects: gint*
GTK_TYPE_UCHAR expects: guint*
GTK_TYPE_LONG expects: glong*
etc...
(the actuall mappings of fundamental types to var arg types can be
found in the guts of gtkargcollector.c).
>
> _A_
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]