Finding children of a GtkWidget

前端 未结 2 1161
执笔经年
执笔经年 2021-02-13 01:33

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

2条回答
  •  没有蜡笔的小新
    2021-02-13 01:53

    Yes, there are macros for every GObject type to check whether an object is of that type:

    if(GTK_IS_CONTAINER(widget)) {
        GList *children = gtk_container_get_children(GTK_CONTAINER(widget));
        ...
    }
    

    If the widget is a GtkBin it has only one child. In that case, the following is simpler than dealing with a GList:

    if(GTK_IS_BIN(widget)) {
        GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget));
        ...
    }
    

提交回复
热议问题