Re: Getting widgets children



Vicki Stanfield wrote:
> I know that I can get the parent of a widget, but if I have only the
> parent widget, can I get the children? I need to unrealize most of the
> widgets to change the window.

Hi, if it's a subclass of container, you can loop over widget->children.
Something like:

/* Set a name for a widget and all its children.
 */
void 
set_name( GtkWidget *widget, const char *name )
{
        gtk_widget_set_name( widget, name );
        if( GTK_IS_CONTAINER( widget ) )
                gtk_container_foreach( GTK_CONTAINER( widget ), 
                           (GtkCallback) set_name, (char *) name );
}

You can do a for(;;) loop as well (slightly less clean):

if( GTK_IS_CONTAINER( widget ) ) {
	GSList *p;

	for( p = GTK_CONTAINER( widget )->children; p; p = p->next ) {
		GtkWidget *child = GTK_WIDGET( p->data );

		...
	}
}

That's what I do anyway.

John




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]