A question about gtk_tree_view_get_visible_rect



Title: A question about gtk_tree_view_get_visible_rect

Hello

I have a question about the function below.

void        gtk_tree_view_get_visible_rect  (GtkTreeView *tree_view,
                                             GdkRectangle *visible_rect);

Documentation says that it fills visible_rect with the currently-visible region of the buffer, in tree coordinates.

I've written a test case which inserts a bunch of data into a tree store and puts the tree view into a scrolled window. The scrolled window is resized to be pretty small and all nodes in the tree view are expanded so that the limited window does not have enough space to show all nodes of the tree view. Then I use gtk_tree_view_scroll_to_cell to move the alignments of tree to somewhere else and call gtk_tree_view_get_visible_rect to get the currently-visible region. The problem is that the currently-visible regions returned by gtk_tree_view_get_visible_rect are always the same wherever I move the alignments although the alignments are moved on my screen. Is this a bug of gtk_tree_view_get_visible_rect or not?

Test case is as below and you guys can try to move the alignments to wherever you like by modifying the value of PATH and COL_POSITION:

#include <gtk/gtk.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;

static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int main (int argc, char *argv[])
{
    #define PATH "2:3"
    #define COL_POSITION 1
    #define USE_ALIGN TRUE
    #define ROW_ALIGN 0.1
    #define COL_ALIGN 0.1

    GtkWidget* container;
    GtkWidget* window;
    GtkWidget *tree_view;
    GtkTreeStore *tree_store;
    GtkTreeIter iter;
    GtkTreeIter child_iter;
    GtkTreePath* path = NULL;
    GtkTreeViewColumn* column;
    GdkRectangle rect;
    GdkRectangle cell;
    guint i, j;


    gtk_init(&argc, &argv);

    container = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (G_OBJECT (container), "destroy",
                      G_CALLBACK (destroy), NULL);

    tree_store = gtk_tree_store_new (2, G_TYPE_UINT, G_TYPE_UINT);
    if (!tree_store)
    {
        printf ("cannot create tree store\n");
    }

    for (i = 0; i < NUM_TREE_ELEMS; i++)
    {
        gint j;

        gtk_tree_store_append (GTK_TREE_STORE (tree_store), &iter, NULL);
        gtk_tree_store_set (GTK_TREE_STORE (tree_store), &iter,
                            0, data[i].number1,
                            1, data[i].number2,
                            -1);
        for (j = 0; j < NUM_TREE_ELEMS; j++)
        {
            gtk_tree_store_append (GTK_TREE_STORE (tree_store), &child_iter, &iter);
            gtk_tree_store_set (GTK_TREE_STORE (tree_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 (tree_store));
    if (!tree_view)
    {
        printf ("cannot create tree view\n");
        return;
    }
    if (!GTK_IS_TREE_VIEW (tree_view))
    {
        printf ("tree view is invalide\n");
        return;
    }

    column = gtk_tree_view_column_new_with_attributes ("Number 1", gtk_cell_renderer_text_new (), "text", 0, NULL);
    gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

    column = gtk_tree_view_column_new_with_attributes ("Number 2", gtk_cell_renderer_text_new (), "text", 1,  NULL);
    gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

    column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), COL_POSITION);
    path = gtk_tree_path_new_from_string (PATH);

    gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));

    window = gtk_scrolled_window_new (NULL, NULL);
    gtk_container_add (GTK_CONTAINER (window), tree_view);
    gtk_container_add (GTK_CONTAINER (container), window);
    gtk_window_resize (GTK_WINDOW (container), 200, 200);
    gtk_widget_show_all (container);
    gtk_tree_view_get_cell_area (GTK_TREE_VIEW (tree_view), path, column, &cell);

    gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), path, column, USE_ALIGN, ROW_ALIGN, COL_ALIGN);

    gtk_tree_view_get_visible_rect (GTK_TREE_VIEW (tree_view), &rect);

    printf ("visible rect = (%d, %d, %d, %d)\n", rect.x, rect.y, rect.width, rect.height);
    printf ("cell         = (%d, %d, %d, %d)\n", cell.x, cell.y, cell.width, cell.height);

    if (path)
        gtk_tree_path_free (path);

    //gtk_widget_show_all (container);

    gtk_main ();

    #undef PATH
    #undef COL_POSITION
    #undef USE_ALIGN
    #undef ROW_ALIGN
    #undef COL_ALIGN

    return 0;
}

Thanks
Yong



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