scroll bars and sorted tree views
- From: James Pelletier <jamesp trdlnk com>
- To: gtk-list gnome org
- Subject: scroll bars and sorted tree views
- Date: Fri, 09 Jul 2004 14:50:26 -0500
I'm having trouble getting the vertical scroll bar of a sorted tree view
to clamp to the top while adding new data. When the slider is at the top
I want the slider to stay at the top after the new data is added. When
the slider is not at the top, it should stay where it is after the new
data is added. (Basically I want it to act like Mozilla Mail sorted by
descending date.) I've tried playing with the "changed" and
"value-changed" callbacks of the adjustment, but I haven't gotten
anything to work properly.
Any advice?
James
Below is the code that I used to emulate adding dynamic data to the tree
view.
#include <gtk/gtk.h>
struct info {
GtkTreeStore *store;
int val;
};
gboolean addval( gpointer data )
{
struct info *i = (struct info *)data;
GtkTreeIter iter;
gtk_tree_store_append( i->store, &iter, NULL );
gtk_tree_store_set( i->store, &iter, 0, i->val, -1 );
if( i->val < 50 )
{
i->val += 1;
return TRUE;
}
return FALSE;
}
int main( int argc, char **argv )
{
GtkWidget *window;
GtkScrolledWindow *scroll;
GtkTreeStore *store;
GtkTreeView *view;
struct info i;
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
g_signal_connect( G_OBJECT(window), "delete_event",
G_CALLBACK(gtk_main_quit), NULL );
scroll = GTK_SCROLLED_WINDOW( gtk_scrolled_window_new(NULL, NULL) );
store = gtk_tree_store_new( 1, G_TYPE_INT );
view = gtk_tree_view_new_with_model(store);
gtk_tree_view_insert_column_with_attributes( view, 0, "Value",
gtk_cell_renderer_text_new(), "text", 0, NULL );
gtk_tree_sortable_set_sort_column_id( store, 0, GTK_SORT_DESCENDING );
gtk_container_add( scroll, view );
gtk_container_add( window, scroll );
i.store = store;
i.val = 0;
gtk_timeout_add( 2000, addval, &i );
gtk_widget_show_all( window );
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]