I need to be able to explore a GTK GUI's structure programmatically. I have the GtkWidget and I want to find any children of that widget. Now I know that GtkContainer's have a function to find children and that GtkContainer is derived from GtkWidget.
Is there anyway I can check if a widget is a GtkContainer and then perform the cast? If not, is there any other way I can discover the GtkWidget's that are children of the one I have?
In the following code I have implemented
find_child
function which recursively searches for the widget by name. Ideas build on the answer of @ptomato and from the following PHP example:Yes, there are macros for every GObject type to check whether an object is of that type:
If the widget is a
GtkBin
it has only one child. In that case, the following is simpler than dealing with aGList
: