diff --git a/gtk_treeview_example b/gtk_treeview_example index 4f010f5..b156cd3 100755 Binary files a/gtk_treeview_example and b/gtk_treeview_example differ diff --git a/main.c b/main.c index 34a7cd7..edc2dcb 100644 --- a/main.c +++ b/main.c @@ -75,12 +75,16 @@ GListModel* get_children_model (struct TreeNode_t *parent) { struct TreeNode_t *child; - GtkStringList *list = gtk_string_list_new(NULL); + GtkStringList *list = NULL; if (parent) { printf("[get_children_model] here is %s content : ", parent->text); child = parent->child; + + if (child) { + list = gtk_string_list_new(NULL); + } while(child) { gtk_string_list_append(list, child->text); printf("%s ", child->text); @@ -133,8 +137,18 @@ void bind_factory (GtkListItemFactory *factory, GtkListItem *list_item, gpointer text = gtk_string_object_get_string(GTK_STRING_OBJECT(gtk_tree_list_row_get_item(row))); GtkWidget *expander = gtk_list_item_get_child(list_item); gtk_expander_set_label(GTK_EXPANDER(expander), text); - printf("[bind_factory] here is %s content\n", text); + + gtk_tree_list_row_set_expanded(row, !is_expanded); + + if (gtk_tree_list_row_get_children(row)) { + printf("[bind_factory] here is %s content (childs)\n", text); + } else { + printf("[bind_factory] here is %s content (no childs)\n", text); + } + + gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20); + //g_object_unref(row); // Decrease the reference count when done } else { printf("[bind_factory] here is NON %s content\n", text); @@ -182,6 +196,7 @@ int main (int argc, char **argv) root = create_tree_node("Root"); add_child_node(root, create_tree_node("Child 1")); add_child_node(root, create_tree_node("Child 2")); + GtkApplication *app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE); g_signal_connect(app, "activate", G_CALLBACK(app_activate), NULL); int status = g_application_run(G_APPLICATION(app), argc, argv);