How do I identifiy a widgets top level window or other
ancestor?
There are a couple of ways to find the top level parent
of a widget. The easier way is to call the
gtk_widget_get_toplevel() function that
returns pointer to a GtkWidget that is the top level
window.
A more complicated way to do this (but less limited, as
it allows the user to get the closest ancestor of a known type) is to use
gtk_widget_get_ancestor() as in:
GtkWidget *widget;
widget = gtk_widget_get_ancestor(w, GTK_TYPE_WINDOW); |
Since virtually all the GTK_TYPEs can be used as the
second parameter of this function, you can get any parent
widget of a particular widget. Suppose you have an hbox which
contains a vbox, which in turn contains some other atomic
widget (entry, label, etc. To find the master hbox using the
entry widget simply use:
GtkWidget *hbox;
hbox = gtk_widget_get_ancestor(w, GTK_TYPE_HBOX); |