Test program for gtk bug



	Hi all,
here follows a small test program to demonstrate gtk bug : just run it 
and click on the button, you'll see tha the tree is scrolled down to 
the row 9 which is expanded, but the selected node is one step below. 
This is not what is intended by the code which should scroll to the 
first child of the "9" node. If you do the same after the "9" node has 
been expanded you'll see that gtk scrolles correclty to the first child 
of "9".
Is it OK for you that I post that to bugzilla?
Bye
Manu
/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
/* Balsa E-Mail Client
 * Copyright (C) 1997-2003 Stuart Parmenter and others,
 *                         See the file AUTHORS for a list.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option) 
 * any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
 * 02111-1307, USA.
 */

#include <gtk-2.0/gtk/gtk.h>

static void test_exit(void);

static void
test_exit(void)
{
    gtk_main_quit();
    return;
}

static void
button_pressed(GtkWidget * unused, gpointer data)
{
    GtkTreeView * tree = GTK_TREE_VIEW(data);
    GtkTreeSelection * selection = gtk_tree_view_get_selection(tree);

    gtk_tree_view_expand_row(tree, gtk_tree_path_new_from_string("9"),FALSE);
    gtk_tree_selection_unselect_all(selection);
    /* select path, and make sure this path gets the keyboard focus */
    gtk_tree_selection_select_path(selection, gtk_tree_path_new_from_string("9:0"));
    gtk_tree_view_set_cursor(tree, gtk_tree_path_new_from_string("9:0"), NULL, FALSE);
    gtk_tree_view_scroll_to_cell(tree,gtk_tree_path_new_from_string("9:0"),NULL,FALSE,0,0);
}

/* -------------------------- main --------------------------------- */
int
main(int argc, char *argv[])
{
    GtkWidget *window,* w, * tab, * button;
    GtkTreeStore * m;
    GtkTreeViewColumn * col;
    gint i;
    gchar * str;
    GtkTreeIter iter, *iter2;

    gtk_init_check(&argc, &argv);

    /* Prepare the tree store */
    m = gtk_tree_store_new(1, G_TYPE_STRING);
    for (i=0;i < 10; i++) {
	str = g_strdup_printf("string n=%d", i);
	gtk_tree_store_append(m, &iter, NULL);
	gtk_tree_store_set(m, &iter, 0, str, -1);
	g_free(str);
    }
    iter2 = gtk_tree_iter_copy(&iter);
    gtk_tree_store_append(m, &iter, iter2);
    gtk_tree_store_set(m, &iter, 0, "string n=9-1 ", -1);
    gtk_tree_store_append(m, &iter, iter2);
    gtk_tree_store_set(m, &iter, 0, "string n=9-2 ", -1);
    gtk_tree_iter_free(iter2);
    iter2 = gtk_tree_iter_copy(&iter);
    gtk_tree_store_append(m, &iter, iter2);
    gtk_tree_store_set(m, &iter, 0, "string n=9-2-1 ", -1);    
    gtk_tree_iter_free(iter2);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "destroy",
                     G_CALLBACK(test_exit), NULL);
    tab = gtk_vbox_new(FALSE, 5);
    button = gtk_button_new_with_label("Next in tree");
    gtk_box_pack_start(GTK_BOX(tab),button , FALSE, FALSE, 5);
    w = gtk_tree_view_new_with_model(GTK_TREE_MODEL(m));
    col = gtk_tree_view_column_new_with_attributes("TEXT", gtk_cell_renderer_text_new(),"text",0,NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(w), col);
    gtk_tree_view_set_expander_column(GTK_TREE_VIEW(w), col);
    gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(w)), GTK_SELECTION_MULTIPLE);
    gtk_widget_set_usize(w, 100,100);
    gtk_box_pack_start(GTK_BOX(tab),w, FALSE, FALSE, 5);
    g_signal_connect(G_OBJECT(button),"clicked",
		     G_CALLBACK(button_pressed), w);
    gtk_container_add(GTK_CONTAINER(window),tab);
    gtk_widget_show_all(window);
    gdk_threads_enter();
    gtk_main();
    gdk_threads_leave();
    return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]