A cleaner approach than using a struct is to subclass your toplevel and add all other widgets that you may need to access as class members. Though you can do it in plain C, I prefer using gob2 (a c-preprocessor) for this, in which you can simply do the following:
Code:
class My:Applic from Gtk:Window
{
private GtkWidget *w_menubox = NULL;
private GtkWidget *w_text_view = NULL;
private GtkWidget *w_image_dir = NULL;
private GtkWidget *w_output_dir = NULL;
:
public GtkWidget *
new (int argc, char *argv[])
{
MyApplic *self = PA_WIDGET(GET_NEW);
selfp->w_menubox = new_...();
:
return GTK_WIDGET(self);
}
}
All you then need to do is to pass the self pointer around as userdata and you can access all your widgets from the whole application.
Another uglier approach is to use the g_object_set_data() to assign the other widgets to the data hash table that is part of all g_objects.