hover effect in a treeview
- From: todd <toddf simosoftware com>
- To: GTK AppDev <gtk-app-devel-list gnome org>
- Subject: hover effect in a treeview
- Date: Wed, 13 Oct 2004 21:03:19 -0700
Hi,
I'm trying to add a hover effect to a treeview, without using the
selection, because I use the selection to indicate which row
the user is currently using. So, I have it working; but it uses more
cpu power then I'd like. Heres a the mouse motion routine:
The commented out section is how one thing I tried to do to only update
part of the widget.
// connected to motion-notify-event
static void
sidebar_highlight( GtkWidget *widget, GdkEventMotion *event, SimoSidebar
*sidebar )
{
gint x, y;
GdkWindow *window = gtk_tree_view_get_bin_window( sidebar->view );
x = event->x;
y = event->y;
if( window == event->window ){
/*GdkRectangle cell_area;
gtk_cell_renderer_get_size( sidebar->cell_renderer,
GTK_WIDGET( sidebar->view ),
&cell_area, 0, 0, 0, 0 );
cell_area.x = x;
cell_area.y = y;
//gdk_window_invalidate_rect( window, &cell_area, 0 );
g_print( "update region: %d, %d\n", x, y );
gtk_widget_queue_draw_area(
GTK_WIDGET( sidebar->view ),
cell_area.x, cell_area.y, cell_area.width + 100,
cell_area.height + 100 );*/
gtk_widget_queue_draw( GTK_WIDGET( sidebar->view ) );
}
}
// connected leave-notify-event
static void
mouse_leave( GtkWidget *widget, GdkEvent *event, SimoSidebar *sidebar )
{
gtk_widget_queue_draw( GTK_WIDGET( sidebar->view ) );
}
This triggers a cell renderer data function I connected to a column
static void
name_column_render( GtkTreeViewColumn *col, GtkCellRenderer *cell,
GtkTreeModel *model, GtkTreeIter
*iter, SimoSidebar *sidebar )
{
int val;
GtkTreePath *cur_path;
GtkTreeViewColumn *cur_col;
//gtk_tree_view_get_cursor( sidebar->view, &cur_path, &cur_col );
gtk_tree_model_get( model, iter, COL_TYPE, &val, -1 );
switch( val ){
case SIDEBAR_PEOPLE:
case SIDEBAR_PROVIDERS:
case SIDEBAR_PHARMACIES:
case SIDEBAR_PLANS:
case SIDEBAR_FLEX_SPENDING:
case SIDEBAR_MEDICAL_SAVINGS:
g_object_set( G_OBJECT( cell ), //"cell-background", "#ececee",
//"cell-background-set", TRUE,
"weight-set", TRUE,
"foreground", "white",
"foreground-set", TRUE,
"size-points", (double)8,
NULL );
break;
case SIDEBAR_GROUP:
g_object_set( G_OBJECT( cell ), //"cell-background",
//"#7788ee", "cell-background-set", TRUE,
"weight", 500,
"weight-set", TRUE,
"foreground", "#34547b",
"foreground-set", TRUE,
"size-points", (double)9,
NULL );
break;
case SIDEBAR_PROVIDER_HEADER:
case SIDEBAR_PHARMACY_HEADER:
case SIDEBAR_PLAN_HEADER:
case SIDEBAR_FLEX_SPENDING_HEADER:
case SIDEBAR_MEDICAL_SAVINGS_HEADER:
case SIDEBAR_PEOPLE_HEADER:
g_object_set( G_OBJECT( cell ), //"cell-background", "#4362c5",
//"cell-background-set", TRUE,
"weight", 1000,
"weight-set", TRUE,
"foreground", "#123259",//"#34547b",
"foreground-set", TRUE,
"size-points", (double)9,
//
"size-set", TRUE,
NULL );
break;
}
// highlight the row with the mouse over it
gint x, y;
GdkWindow *window = gtk_tree_view_get_bin_window( sidebar->view );
gdk_window_get_pointer( window, &x, &y, 0 );
if( gtk_tree_view_get_path_at_pos( sidebar->view, x, y,
&cur_path, &cur_col, 0, 0 ) ){
if( cur_col == col ){
GtkTreePath *rpath = gtk_tree_model_get_path( model, iter );
if( !gtk_tree_path_compare( cur_path, rpath ) ){
//g_print( "render column: SET FOREGROUND COLOR\n" );
g_object_set( G_OBJECT( cell ), "foreground", "#F4547b", 0 );
}
else{
}
if( rpath )
gtk_tree_path_free( rpath );
}
gtk_tree_path_free( cur_path );
}
else{
// g_print( "cur path is null\n" );
}
}
any thoughts or comments on how to make this work a little more
efficently would be welcome :-)
-todd
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]