GtkTable resize problem and a minor contribution



Hi,

I had a long fight with GtkTable and resizes.  I wanted to make a little
image browser like guash, ie to present the user with a tabular,
resizable display of image thumbnails, with a vertical scrollbar. 
Obviously the GtkTable I use have to reformat when the window is
resized, but how do I do it the right way?

To get the window resizes, I connect_after to configure_event on the
top-level widget.

Within the configure_event handler, I tried to remove all widgets from
the table with gtk_container_remove, then resize the table and attach
the widgets  again in the new positions, but then gtk_table_resize
dumped core. How does one remove something from a GtkTable? 

Here is what works for me:

On a configure_event, I manually move all elements within the table to
the new positions.  I do this by finding the GtkTableChild* on the
table->children list, and then modifying the
{left,right,top,bottom}_attach fields directly.  When this is done, I
resize the table.

This works, but doesn't redisplay the table correctly immediately.  When
something else triggers a redisplay of the table, everything is in
order.  This problem was solved, after hours of studying docs and
sources, by adding
the call gtk_widget_queue_resize(GTK_WIDGET(table)) after the table
resize. 

Now my browser works well, but this way seems too contorted.

Here is what I have been missing:
	gtk_table_detach(table, widget);
	gtk_table_clear(table);
	gtk_table_move( <like attach but moves an existing element>  );
	gtk_table_resize that redisplays
	maybe gtk_table_{freeze,thaw} too.

BTW, what does GtkPacker do? I have tried to read the code, play with
the examples and with glade, but I just don't get it. It GtkPacker what
I needed in the first place?

My application also uses GtkCTree and GtkCList a lot, so I have added
these little helpers (they're simple, though the last one cost me some
time):

GList *
gtk_clist_get_selection(GtkCList *list)
{
    g_return_val_if_fail(list != NULL, NULL);

    return list->selection;
}

void
gtk_clist_set_focus_row(GtkCList *list, guint row)
{
    g_return_if_fail(list != NULL);
    g_return_if_fail(row >= 0);
    g_return_if_fail(row < list->rows);

    list->focus_row = row;
}

GList *
gtk_ctree_get_selection(GtkCTree *tree)
{
    g_return_val_if_fail(tree != NULL, NULL);

    return GTK_CLIST(tree)->selection;
}

void
gtk_ctree_set_focus_node(GtkCTree *tree, GtkCTreeNode *node)
{
    g_return_if_fail(tree != NULL);
    g_return_if_fail(node != NULL);

    GTK_CLIST(tree)->focus_row
	= g_list_position(GTK_CLIST(tree)->row_list, (GList *)node);
}



-- 
René Seindal (rene@seindal.dk)			http://www.seindal.dk/rene/



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