Patch for clist auto-resize



Howdy...

I got used to being able to double-click (as well as drag) on the
resize-line between the buttons at the top of a clist under a certain
other unmentionable interface... This has the effect of setting the
width of the column to the left of the line to the width of its widest
item.  After some poking around, I saw that this was pretty easy to
implement in GTK's clist as well.  Here's the patch that does it...  I
also made it so that holding down SHIFT while double-clicking the line
resizes ALL of the columns in the clist the same way.  The code uses
functions that were already in the file which make sure to ignore
columns that can't be resized, etc.  Let me know if this gets rolled
in... 

Thanks!

Bret

PS: Whooohooo, after years of just plain advocacy, this is the first
time I've actually contributed code to an open source project...
*** gtkclist.c	Thu Apr  1 03:15:51 1999
--- gtkclist.patched	Thu Apr  1 03:39:21 1999
***************
*** 5088,5093 ****
--- 5088,5116 ----
  			if (clist->column[i].resizeable && clist->column[i].window &&
  					event->window == clist->column[i].window)
  			{
+ 				 if(event->type == GDK_2BUTTON_PRESS)
+ 				 {
+ 						/* On a double-click, try to resize the column.  If SHIFT is
+ 							 down, try to resize ALL columns. */
+ 						if (event->state & GDK_SHIFT_MASK)
+ 						{
+ 							 gtk_clist_columns_autosize (clist);
+ 						}
+ 						else
+ 						{
+ 							 gtk_clist_set_column_width(clist, i,
+ 																					gtk_clist_optimal_column_width
+ 																					(clist, i));
+ 						}
+ 						abort_column_resize(clist);
+ 
+ 						/* Have to get rid of the xor'd line that'll be left over from the drag. */
+ 						if (clist->x_drag >= 0 && clist->x_drag <= clist->clist_window_width - 1)
+ 							 draw_xor_line (clist);
+ 
+ 				 }
+ 				 else
+ 				 {
  						gpointer drag_data;
  
  						if (gdk_pointer_grab (clist->column[i].window, FALSE,
***************
*** 5116,5121 ****
--- 5139,5145 ----
  							 gdk_gc_set_line_attributes (clist->xor_gc, 1, GDK_LINE_SOLID, 0, 0);
  						draw_xor_line (clist);
  				 }
+ 			}
  	 return FALSE;
  }
  
***************
*** 5145,5171 ****
        gint i;
  
        i = clist->drag_pos;
!       clist->drag_pos = -1;
  
        /* unblock attached dnd signal handler */
        drag_data = gtk_object_get_data (GTK_OBJECT (clist), "gtk-site-data");
        if (drag_data)
  	gtk_signal_handler_unblock_by_data (GTK_OBJECT (clist), drag_data);
  
-       GTK_CLIST_UNSET_FLAG (clist, CLIST_IN_DRAG);
        gtk_widget_get_pointer (widget, &x, NULL);
-       gtk_grab_remove (widget);
-       gdk_pointer_ungrab (event->time);
- 
-       if (clist->x_drag >= 0)
- 	draw_xor_line (clist);
  
-       if (GTK_CLIST_ADD_MODE(clist))
- 	{
- 	  gdk_gc_set_line_attributes (clist->xor_gc, 1,
- 				      GDK_LINE_ON_OFF_DASH, 0, 0);
- 	  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);
--- 5169,5183 ----
  			 gint i;
  
  			 i = clist->drag_pos;
! 			 abort_column_resize(clist);
  
        /* unblock attached dnd signal handler */
        drag_data = gtk_object_get_data (GTK_OBJECT (clist), "gtk-site-data");
        if (drag_data)
  	gtk_signal_handler_unblock_by_data (GTK_OBJECT (clist), drag_data);
  
        gtk_widget_get_pointer (widget, &x, NULL);
  
  
        width = new_column_width (clist, i, &x);
        gtk_clist_set_column_width (clist, i, width);


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