After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 97428 - gtk_tree_vew_expand_to_path() doesn't work or has wrong documentation
gtk_tree_vew_expand_to_path() doesn't work or has wrong documentation
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
2.1.x
Other All
: Normal normal
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
Depends on:
Blocks: 97233
 
 
Reported: 2002-11-01 19:03 UTC by Vitaly Tishkov
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: 2.0



Description Vitaly Tishkov 2002-11-01 19:03:52 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
Comment 1 Kristian Rietveld 2002-11-11 22:28:05 UTC
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.
Comment 2 PeterBloomfield 2002-11-11 22:54:10 UTC
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!
Comment 3 Kristian Rietveld 2002-11-11 22:57:23 UTC
I know, a fix will be committed tomorrow or so.
Comment 4 Kristian Rietveld 2002-11-11 22:58:05 UTC
See #97927. That patch is probably going in.
Comment 5 Vitaly Tishkov 2002-11-13 13:28:53 UTC
Sure. Definately not a bug. Thanks for the explanation.
Comment 6 Vitaly Tishkov 2002-11-13 15:51:12 UTC
BTW, should the path "2" (parent for tested "2:2") be expanded?
Comment 7 Kristian Rietveld 2002-11-13 16:02:50 UTC
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".
Comment 8 Vitaly Tishkov 2002-11-13 16:06:28 UTC
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?
Comment 9 Vitaly Tishkov 2002-11-14 15:28:51 UTC
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...
Comment 10 Kristian Rietveld 2002-11-18 19:52:26 UTC
I get:

--- path = '2:2', expanded = 1

which is correct. Prolly related to bug #97927, from which the patch
just went in (on HEAD).