Re: Iterating through children
- From: Tristan Van Berkom <vantr touchtunes com>
- To: Dimitar Haralanov <mitko keyresearch com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Iterating through children
- Date: Fri, 17 Oct 2003 13:47:58 -0400
Ok, so you want a function to be called for *every* child widget of the
toplevel window ?
With or without glade, you're going to need a reference to the toplevel.
If you want to reference the toplevel without useing a global pointer,
then you could use something like:
http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#gtk-widget-get-toplevel
within whatever callback you want.
The following example shows "a way" to "itterate through children" without
naming your widgets or anything like that.
Regards,
-Tristan
PS:
You might want to note the complete irrelevence of the name
you choose for your 4 byte address space used to reference a UI object
and the dynamicly allocated charachter array stored in
GTK_WIDGET(object)->name which is used by the theeme engine
to associate graphic files to UI objects.
/******************************************************/
gtk_container_foreach(GTK_CONTAINER(toplevel_window),
GTK_CALLBACK(ui_itterator), NULL);
void ui_itterator(GtkWidget *wid, gpointer unused)
{
if (GTK_IS_CONTAINER(wid)) {
gtk_container_foreach(GTK_CONTAINER(wid),
GTK_CALLBACK(ui_itterator), NULL);
}
my_func(wid);
}
void my_func(GtkWidget *wid)
{
/* this func gets called for every widget that is child of
"toplevel_window" */
}
/******************************************************/
Dimitar Haralanov wrote:
On Fri, 17 Oct 2003 12:05:35 +0200
Gus Koppel <gtk spamkiller bytechase cx> wrote:
That's basically the same thing my function does. There are just two
main differences:
1. my function operates independently from Glade, has no particular
external references and doesn't need any extra precautions like
Glade's GLADE_HOOKUP_OBJECT lists.
This is not entirely accurate, unfortunately (at least in my case).
Using your function, I can't just find any widget! gtk_widget_get_name
() returns the type of the widget that I am passing to it and not the
name of the variable which points to the widget. For instance, if I have
the following;
GtkWidget *widget;
gchar *name;
widget = gtk_check_button_new ();
name = gtk_widget_get_name (widget);
Now name will contain 'GtkCheckButton' and not 'widget'. Therefore, I
can use it as I can use the libglade function. To use an example, I need
something that will do the following:
GtkWidget *this;
GtkWidget *that;
....
(in some callback)
GtkWidget *widget = <lookup_function> (that, "this");
And at that point widget will be a pointer to this.
I personally dislike such ideas.
Me too and that is why I am trying to figure out a way to do this but
so far nothing!!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]