diff --git a/gtk_treeview_example b/gtk_treeview_example index b156cd3..b431899 100755 Binary files a/gtk_treeview_example and b/gtk_treeview_example differ diff --git a/main.c b/main.c index edc2dcb..76168d9 100644 --- a/main.c +++ b/main.c @@ -119,6 +119,15 @@ GListModel* create_model_func(GObject *item, gpointer user_data) return get_children_model(cur); } +void on_expander_toggled(GtkExpander *expander, gpointer user_data) { + // This is a conceptual callback for when an expander is toggled + GtkTreeListRow *row = GTK_TREE_LIST_ROW(user_data); + gboolean is_expanded = gtk_tree_list_row_get_expanded(row); + gtk_tree_list_row_set_expanded(row, !is_expanded); + // Assuming you have a way to update your model's is_expanded property + // Update your model here based on the new state +} + void setup_factory (GtkListItemFactory *factory, GtkListItem *list_item, gpointer user_data) { GtkWidget* expander = gtk_expander_new (NULL); @@ -139,7 +148,7 @@ void bind_factory (GtkListItemFactory *factory, GtkListItem *list_item, gpointer gtk_expander_set_label(GTK_EXPANDER(expander), text); - gtk_tree_list_row_set_expanded(row, !is_expanded); + //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); @@ -147,6 +156,12 @@ void bind_factory (GtkListItemFactory *factory, GtkListItem *list_item, gpointer printf("[bind_factory] here is %s content (no childs)\n", text); } + // Disconnect previous signal handlers to avoid stacking them + g_signal_handlers_disconnect_by_func(expander, G_CALLBACK(on_expander_toggled), row); + + // Connect the signal handler + g_signal_connect(expander, "activate", G_CALLBACK(on_expander_toggled), row); + gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20); //g_object_unref(row); // Decrease the reference count when done