GNOME Bugzilla – Bug 97428
gtk_tree_vew_expand_to_path() doesn't work or has wrong documentation
Last modified: 2004-12-22 21:47:04 UTC
if you call gtk_tree_view_expand_to_path (view, path), gtk_tree_view_row_expanded (view, path) returns FALSE. It means that gtk_tree_view_expand_to_path() doesn't work or has wrong documentation. Test case. ---------- #include <string.h> #include <stdlib.h> #include <stdio.h> struct ListSort { gint number1; gint number2; }; struct ListSort data[] = { { 3, 4 }, { 2, 6 }, { 0, 49 }, { 856856, 965 }, { 1, 34663 }, }; struct ListSort child_data[] = { { 10, 149 }, { 12, 13 }, { 1856856, 1965 }, { 11, 15 }, { 14, 14 }, }; const gint NUM_TREE_ELEMS = 5; int main (int argc, char** argv) { GtkTreeStore* store; GtkTreeViewColumn* column0; GtkTreeViewColumn* column1; GtkCellRenderer* renderer; GtkWidget* tree_view; GtkTreeIter iter; GtkTreeIter child_iter; gint i; gint j; gtk_init (&argc, &argv); store = gtk_tree_store_new (2, G_TYPE_UINT, G_TYPE_UINT); for (i = 0; i < NUM_TREE_ELEMS; i++) { gint j; gtk_tree_store_append (store, &iter, NULL); gtk_tree_store_set (store, &iter, 0, data[i].number1, 1, data[i].number2, -1); for (j = 0; j < NUM_TREE_ELEMS; j++) { gtk_tree_store_append (store, &child_iter, &iter); gtk_tree_store_set (store, &child_iter, 0, child_data[j].number1, 1, child_data[j].number2, -1); } } tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); renderer = gtk_cell_renderer_text_new (); column0 = gtk_tree_view_column_new_with_attributes ("Number 1", renderer, "text", 0, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column0); gtk_tree_view_column_set_sort_column_id (column0, 0); renderer = gtk_cell_renderer_text_new (); column1 = gtk_tree_view_column_new_with_attributes ("Number 2", renderer, "text", 1, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column1); gtk_tree_view_column_set_sort_column_id (column1, 1); { GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_add (GTK_CONTAINER (window), tree_view); gtk_widget_show_all (window); } { const char* str = "2:2"; GtkTreePath* expand_to_path = gtk_tree_path_new_from_string (str); gtk_tree_view_expand_to_path (GTK_TREE_VIEW (tree_view), expand_to_path); printf ("--- path = '%s', expanded = %d\n", str, gtk_tree_view_row_expanded (GTK_TREE_VIEW (tree_view), expand_to_path)); } gtk_main(); } Output. ------- --- path = '2:2', expanded = 0
You call gtk_tree_view_row_expanded on path "2:2". In the treestore in this testcase, 2:2 is a leaf, in other words it is a node without children. That implies that 2:2 can never be expanded. So the return value FALSE is correct.
Err...today's cvs code for gtk_tree_vew_expand_to_path looks suspicious. There's a GtkTreePath `*tmp' that's created but never used, and an argument `path' that's modified and finally freed!
I know, a fix will be committed tomorrow or so.
See #97927. That patch is probably going in.
Sure. Definately not a bug. Thanks for the explanation.
BTW, should the path "2" (parent for tested "2:2") be expanded?
gtk_tree_view_expand_to_path will work for both "2" and "2:2". But gtk_tree_view_row_expanded will only return TRUE for "2".
Replace the string containing 'printf' with printf ("--- path = '%s', expanded = %d\n", str, gtk_tree_view_row_expanded (GTK_TREE_VIEW (tree_view), gtk_tree_path_new_from_string ("2"))); and get this output: --- path = '2:2', expanded = 0 Is this a bug?
Don't pay attention to '--- path = '2:2'' in the patched test case output. The actual path tested is "2". Probably, a separate bug should be submitted or the summary of this one should be modified...
I get: --- path = '2:2', expanded = 1 which is correct. Prolly related to bug #97927, from which the patch just went in (on HEAD).