Hi, long time ago I posted a patch that allows one to resize a column in a gtkclììÿ¿6Ê ist to the optimal width by double clicking the resize window. Since I find that this a useful feature and that there was no answer I will repost the patch. It is fully outdated right now. I do not have a lot time left playing with my linux box. So someone with more deep gtk+ knowledge could reimplement the feature? Thanks Dirk
--- gtk+-1.2.2/gtk/gtkclist.c Tue Mar 23 22:ììÿ¿6Ê 59:43 1999 +++ gtk+-1.2.2.local/gtk/gtkclist.c Thu Aug 26 01:13:19 1999 @@ -1030,6 +1030,8 @@ { GTK_CLIST_UNSET_FLAG (clist, CLIST_SHOW_TITLES); } + + GTK_CLIST_UNSET_FLAG (clist, CLIST_XOR_VISIBLE); } /* GTKCLIST PUBLIC INTERFACE @@ -1868,13 +1870,16 @@ return; GTK_CLIST_UNSET_FLAG (clist, CLIST_IN_DRAG); + GTK_CLIST_UNSET_FLAG (clist, CLIST_OPTIMAL_WIDTH); gtk_grab_remove (GTK_WIDGET (clist)); gdk_pointer_ungrab (GDK_CURRENT_TIME); clist->drag_pos = -1ììÿ¿6Ê ; - if (clist->x_drag >= 0 && clist->x_drag <= clist->clist_window_width - 1) + if (clist->x_drag >= 0 && clist->x_drag <= clist->clist_window_width - 1 && +GTK_CLIST_XOR_VISIBLE(clist)) draw_xor_line (clist); + GTK_CLIST_UNSET_FLAG (clist, CLIST_XOR_VISIBLE); + if (GTK_CLIST_ADD_MODE(clist)) { gdk_gc_set_line_attributes (clist->xor_gc, 1, GDK_LINE_ON_OFF_DASH, 0,0); @@ -5081,7 +5086,17 @@ if (GTK_CLIST_ADD_MODE(clist)) gdk_gc_set_line_attributes (clist->xor_gc,ììÿ¿6Ê 1, GDK_LINE_SOLID, 0, 0); - draw_xor_line (clist); + + GTK_CLIST_UNSET_FLAG (clist, CLIST_XOR_VISIBLE); + + if (event->type == GDK_2BUTTON_PRESS) { + gint optimal_width; + + GTK_CLIST_SET_FLAG (clist, CLIST_OPTIMAL_WIDTH); + + optimal_width = gtk_clist_optimal_column_width (clist, i); + gtk_clist_set_column_width (clist, i, optimal_width); + } } return FALSE; } @@ -5124,7 +5139,7 @@ gtk_grab_remove (widget); gdk_pointer_ungrab (event->time); - if (clist->ììÿ¿6Ê x_drag >= 0) + if (clist->x_drag >= 0 && GTK_CLIST_XOR_VISIBLE(clist)) draw_xor_line (clist); if (GTK_CLIST_ADD_MODE(clist)) @@ -5134,8 +5149,13 @@ gdk_gc_set_dashes (clist->xor_gc, 0, "\4\4", 2); } - width = new_column_width (clist, i, &x); - gtk_clist_set_column_width (clist, i, width); + if (!GTK_CLIST_OPTIMAL_WIDTH(clist)) { + width = new_column_width (clist, i, &x); + gtk_clist_set_column_width (clist, i, width); + } + + GTK_CLIST_UNSET_FLAG ììÿ¿6Ê (clist, CLIST_OPTIMAL_WIDTH); + return FALSE; } @@ -5200,7 +5220,7 @@ if (clist->drag_button > 0) button_actions = clist->button_actions[clist->drag_button - 1]; - if (GTK_CLIST_IN_DRAG(clist)) + if (GTK_CLIST_IN_DRAG(clist) && !GTK_CLIST_OPTIMAL_WIDTH(clist)) { if (event->is_hint || event->window != widget->window) gtk_widget_get_pointer (widget, &x, NULL); @@ -5211,13 +5231,14 @@ if (x != clist->x_drag) { /* x_drag < 0 indicates that the xorììÿ¿6Ê line is already invisible */ - if (clist->x_drag >= 0) + if (clist->x_drag >= 0 && GTK_CLIST_XOR_VISIBLE(clist)) draw_xor_line (clist); clist->x_drag = x; if (clist->x_drag >= 0) draw_xor_line (clist); + GTK_CLIST_SET_FLAG (clist, CLIST_XOR_VISIBLE); } if (new_width <= MAX (COLUMN_MIN_WIDTH + 1,
--- gtk+-1.2.2/gtk/gtkclist.h Sun Maììÿ¿6Ê r 21 08:07:03 1999 +++ gtk+-1.2.2.local/gtk/gtkclist.h Wed Aug 25 23:10:30 1999 @@ -54,7 +54,9 @@ GTK_CLIST_REORDERABLE = 1 << 7, GTK_CLIST_USE_DRAG_ICONS = 1 << 8, GTK_CLIST_DRAW_DRAG_LINE = 1 << 9, - GTK_CLIST_DRAW_DRAG_RECT = 1 << 10 + GTK_CLIST_DRAW_DRAG_RECT = 1 << 10, + GTK_CLIST_XOR_VISIBLE = 1 << 11, + GTK_CLIST_OPTIMAL_WIDTH = 1 << 12 }; /* cell types */ @@ -94,6 +96,7 @@ #define GTK_CLIST_UNSET_FLAG(clist,flag) (GTK_CLISììÿ¿6Ê T_FLAGS (clist) &= ~(GTK_ ## flag)) #define GTK_CLIST_IN_DRAG(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_IN_DRAG) +#define GTK_CLIST_OPTIMAL_DRAG(clist) (GTK_CLIST_FLAGS (clist) & +GTK_CLIST_OPTIMAL_DRAG) #define GTK_CLIST_ROW_HEIGHT_SET(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ROW_HEIGHT_SET) #define GTK_CLIST_SHOW_TITLES(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_SHOW_TITLES) #define GTK_CLIST_CHILD_HAS_FOCUS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_CHILDììÿ¿6Ê _HAS_FOCUS) @@ -104,6 +107,8 @@ #define GTK_CLIST_USE_DRAG_ICONS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_USE_DRAG_ICONS) #define GTK_CLIST_DRAW_DRAG_LINE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_LINE) #define GTK_CLIST_DRAW_DRAG_RECT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_RECT) +#define GTK_CLIST_XOR_VISIBLE(clist) (GTK_CLIST_FLAGS (clist) & +GTK_CLIST_XOR_VISIBLE) +#define GTK_CLIST_OPTIMAL_WIDTH(clist) (GTK_CLIST_FLAGS (clist) & +GTK_CLIST_OPììÿ¿6Ê TIMAL_WIDTH) #define GTK_CLIST_ROW(_glist_) ((GtkCListRow *)((_glist_)->data))