Patch for GtkPaned



Hi

This patch contains some small modifications I've made to the GtkPaned
widget.

The changes are:

* Vertical and horizontal length of the handle can be set independently
of each other.
* 'gtk_paned_set_handle_size_xy ' function added for this purpose.
* 'gtk_paned_set_handle_size' defined in terms of *_xy.
* The default size of the handle is 8x24 (horiz.) and 24x8 (vertical).
* The handle is painted as a handle, not as a button.

Right now, if the window is small enough the handle will not be drawn. I
added a check for this situation, and in such a case, the handle will be
painted exactly in the middle of the gutter.

* If you set the handle size with 'gtk_paned_set_handle_size', right now
the handle is enlarged in both directions, so it could easily  cover
some part of the paned child window. With the patch, the handle is
enlarged only in the wider direction,  no both. You can use
'gtk_paned_set_handle_size_xy' to set the handle size whatever size you
want.

The reason for these changes is that I find very uncomfortable to drag
the little button at 1024x768. I also think it is more consistent to
draw a handle as a handle, no as a button.

I've put a screenshot at
<http://www.geocities.com/SiliconValley/Lab/8325/new-panes.png>


    Juan Pablo

PS: I don't know if this is the right place to send a patch, hope nobody
gets angry.
diff -C 2 -r gtk+-1.2.3.orig/gtk/gtkhpaned.c gtk+-1.2.3/gtk/gtkhpaned.c
*** gtk+-1.2.3.orig/gtk/gtkhpaned.c	Wed Feb 24 04:15:09 1999
--- gtk+-1.2.3/gtk/gtkhpaned.c	Tue Aug 10 05:01:55 1999
***************
*** 83,86 ****
--- 83,87 ----
    widget_class->button_release_event = gtk_hpaned_button_release;
    widget_class->motion_notify_event = gtk_hpaned_motion;
+ 
  }
  
***************
*** 88,91 ****
--- 89,94 ----
  gtk_hpaned_init (GtkHPaned *hpaned)
  {
+     hpaned->handle_size_x = 8;
+     hpaned->handle_size_y = 24;
  }
  
***************
*** 137,241 ****
  static void
  gtk_hpaned_size_allocate (GtkWidget     *widget,
! 			  GtkAllocation *allocation)
  {
!   GtkPaned *paned;
!   GtkRequisition child1_requisition;
!   GtkRequisition child2_requisition;
!   GtkAllocation child1_allocation;
!   GtkAllocation child2_allocation;
!   GdkRectangle old_groove_rectangle;
!   guint16 border_width;
  
-   g_return_if_fail (widget != NULL);
-   g_return_if_fail (GTK_IS_HPANED (widget));
-   g_return_if_fail (allocation != NULL);
  
!   widget->allocation = *allocation;
  
!   paned = GTK_PANED (widget);
!   border_width = GTK_CONTAINER (paned)->border_width;
  
!   if (paned->child1)
!     gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
!   else
!     child1_requisition.width = 0;
! 
!   if (paned->child2)
!     gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
!   else
!     child2_requisition.width = 0;
!     
!   gtk_paned_compute_position (paned,
! 			      widget->allocation.width
! 			        - paned->gutter_size
! 			        - 2 * border_width,
! 			      child1_requisition.width,
! 			      child2_requisition.width);
!   
!   /* Move the handle before the children so we don't get extra expose events */
! 
!   paned->handle_xpos = paned->child1_size + border_width + paned->gutter_size / 2 - paned->handle_size / 2;
!   paned->handle_ypos = allocation->height - border_width - 2*paned->handle_size;
! 
!   if (GTK_WIDGET_REALIZED (widget))
!     {
!       gdk_window_move_resize (widget->window,
! 			      allocation->x, allocation->y,
! 			      allocation->width, allocation->height);
!       
!       gdk_window_move (paned->handle, paned->handle_xpos, paned->handle_ypos);
!     }
! 
!   child1_allocation.height = child2_allocation.height = MAX (1, (gint)allocation->height - border_width * 2);
!   child1_allocation.width = paned->child1_size;
!   child1_allocation.x = border_width;
!   child1_allocation.y = child2_allocation.y = border_width;
!   
!   old_groove_rectangle = paned->groove_rectangle;
! 
!   paned->groove_rectangle.x = child1_allocation.x 
!     + child1_allocation.width + paned->gutter_size / 2 - 1;
!   paned->groove_rectangle.y = 0;
!   paned->groove_rectangle.width = 2;
!   paned->groove_rectangle.height = allocation->height;
!       
!   if (GTK_WIDGET_DRAWABLE (widget) &&
!       ((paned->groove_rectangle.x != old_groove_rectangle.x) ||
!        (paned->groove_rectangle.y != old_groove_rectangle.y) ||
!        (paned->groove_rectangle.width != old_groove_rectangle.width) ||
!        (paned->groove_rectangle.height != old_groove_rectangle.height)))
!     {
!       gtk_widget_queue_clear_area (widget,
! 				   old_groove_rectangle.x,
! 				   old_groove_rectangle.y,
! 				   old_groove_rectangle.width,
! 				   old_groove_rectangle.height);
!       gtk_widget_queue_draw_area (widget,
! 				  paned->groove_rectangle.x,
! 				  paned->groove_rectangle.y,
! 				  paned->groove_rectangle.width,
! 				  paned->groove_rectangle.height);
!     }
!   
!   child2_allocation.x = paned->groove_rectangle.x + paned->gutter_size / 2 + 1;
!   child2_allocation.width = MAX (1, (gint)allocation->width
!     - child2_allocation.x - border_width);
!   
!   /* Now allocate the childen, making sure, when resizing not to
!    * overlap the windows */
!   if (GTK_WIDGET_MAPPED(widget) &&
!       paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
!       paned->child1->allocation.width < child1_allocation.width)
!     {
!       if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
! 	gtk_widget_size_allocate (paned->child2, &child2_allocation);
!       gtk_widget_size_allocate (paned->child1, &child1_allocation);      
!     }
!   else
!     {
!       if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
! 	gtk_widget_size_allocate (paned->child1, &child1_allocation);
!       if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
! 	gtk_widget_size_allocate (paned->child2, &child2_allocation);
      }
  }
--- 140,277 ----
  static void
  gtk_hpaned_size_allocate (GtkWidget     *widget,
!                           GtkAllocation *allocation)
  {
!     GtkPaned *paned;
!     GtkRequisition child1_requisition;
!     GtkRequisition child2_requisition;
!     GtkAllocation child1_allocation;
!     GtkAllocation child2_allocation;
!     GdkRectangle old_groove_rectangle;
!     guint16 border_width;
! 
! 
!     g_return_if_fail (widget != NULL);
!     g_return_if_fail (GTK_IS_HPANED (widget));
!     g_return_if_fail (allocation != NULL);
! 
!     widget->allocation = *allocation;
! 
!     paned = GTK_PANED (widget);
!     border_width = GTK_CONTAINER (paned)->border_width;
! 
!     if (paned->child1)
!         gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
!     else
!         child1_requisition.width = 0;
! 
!     if (paned->child2)
!         gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
!     else
!         child2_requisition.width = 0;
! 
!     gtk_paned_compute_position (paned,
!                                 widget->allocation.width
!                                 - paned->gutter_size
!                                 - 2 * border_width,
!                                 child1_requisition.width,
!                                 child2_requisition.width);
! 
!     /* Move the handle before the children so we don't get extra expose events */
! 
!     paned->handle_xpos =
!         paned->child1_size +
!         border_width +
!         paned->gutter_size / 2 -
!         (GTK_HPANED(widget)->handle_size_x) / 2;
! 
! 
!     /* first try to calculate the position (this is the original behaviour) */
!     paned->handle_ypos =
!         allocation->height - border_width -
!         2 * (GTK_HPANED(widget)->handle_size_y);
! 
!     /* if the space before the handle is going to be smaller than the space after the handle,
!      * for example:
!      *  -----
!      *    |
!      *    |
!      *    #  <-- handle
!      *    #
!      *    |
!      *    |
!      *    |
!      *  -----
!      */
! 
!     if( paned->handle_ypos <
!         allocation->height - (paned->handle_ypos + (GTK_HPANED(widget)->handle_size_y))
!       )
!     { /* put the handle in the center of the groove */
!         paned->handle_ypos =
!             allocation->height * 1/2 -
!             (GTK_HPANED(widget)->handle_size_y) / 2;
!     }
  
  
!     if (GTK_WIDGET_REALIZED (widget))
!     {
!         gdk_window_move_resize (widget->window,
!                                 allocation->x, allocation->y,
!                                 allocation->width, allocation->height);
  
!         gdk_window_move (paned->handle, paned->handle_xpos, paned->handle_ypos);
!     }
! 
!     child1_allocation.height = child2_allocation.height = MAX (1, (gint)allocation->height - border_width * 2);
!     child1_allocation.width = paned->child1_size;
!     child1_allocation.x = border_width;
!     child1_allocation.y = child2_allocation.y = border_width;
! 
!     old_groove_rectangle = paned->groove_rectangle;
! 
!     paned->groove_rectangle.x = child1_allocation.x
!         + child1_allocation.width + paned->gutter_size / 2 - 1;
!     paned->groove_rectangle.y = 0;
!     paned->groove_rectangle.width = 2;
!     paned->groove_rectangle.height = allocation->height;
! 
!     if (GTK_WIDGET_DRAWABLE (widget) &&
!         ((paned->groove_rectangle.x != old_groove_rectangle.x) ||
!          (paned->groove_rectangle.y != old_groove_rectangle.y) ||
!          (paned->groove_rectangle.width != old_groove_rectangle.width) ||
!          (paned->groove_rectangle.height != old_groove_rectangle.height)))
!     {
!         gtk_widget_queue_clear_area (widget,
!                                      old_groove_rectangle.x,
!                                      old_groove_rectangle.y,
!                                      old_groove_rectangle.width,
!                                      old_groove_rectangle.height);
!         gtk_widget_queue_draw_area (widget,
!                                     paned->groove_rectangle.x,
!                                     paned->groove_rectangle.y,
!                                     paned->groove_rectangle.width,
!                                     paned->groove_rectangle.height);
!     }
  
!     child2_allocation.x = paned->groove_rectangle.x + paned->gutter_size / 2 + 1;
!     child2_allocation.width = MAX (1, (gint)allocation->width
!                                    - child2_allocation.x - border_width);
! 
!     /* Now allocate the childen, making sure, when resizing not to
!      * overlap the windows */
!     if (GTK_WIDGET_MAPPED(widget) &&
!         paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
!         paned->child1->allocation.width < child1_allocation.width)
!     {
!         if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
!             gtk_widget_size_allocate (paned->child2, &child2_allocation);
!         gtk_widget_size_allocate (paned->child1, &child1_allocation);
!     }
!     else
!     {
!         if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
!             gtk_widget_size_allocate (paned->child1, &child1_allocation);
!         if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
!             gtk_widget_size_allocate (paned->child2, &child2_allocation);
      }
  }
***************
*** 301,305 ****
  		 0,
  		 xpos,
! 		 widget->allocation.height - 1);
  }
  
--- 337,342 ----
  		 0,
  		 xpos,
!                  widget->allocation.height - 1);
! 
  }
  
***************
*** 325,329 ****
  			| GDK_BUTTON_RELEASE_MASK,
  			NULL, NULL, event->time);
!       paned->child1_size += event->x - paned->handle_size / 2;
        paned->child1_size = CLAMP (paned->child1_size, 0,
                                    widget->allocation.width - paned->gutter_size
--- 362,366 ----
  			| GDK_BUTTON_RELEASE_MASK,
  			NULL, NULL, event->time);
!       paned->child1_size += event->x - (GTK_HPANED(widget)->handle_size_x) / 2;
        paned->child1_size = CLAMP (paned->child1_size, 0,
                                    widget->allocation.width - paned->gutter_size
diff -C 2 -r gtk+-1.2.3.orig/gtk/gtkhpaned.h gtk+-1.2.3/gtk/gtkhpaned.h
*** gtk+-1.2.3.orig/gtk/gtkhpaned.h	Wed Feb 24 04:15:09 1999
--- gtk+-1.2.3/gtk/gtkhpaned.h	Tue Aug 10 05:01:55 1999
***************
*** 37,41 ****
  #endif /* __cplusplus */
  
! 
  #define GTK_HPANED(obj)          GTK_CHECK_CAST (obj, gtk_hpaned_get_type (), GtkHPaned)
  #define GTK_HPANED_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_hpaned_get_type (), GtkHPanedClass)
--- 37,41 ----
  #endif /* __cplusplus */
  
! #define GTK_TYPE_HPANED          (gtk_hpaned_get_type ())
  #define GTK_HPANED(obj)          GTK_CHECK_CAST (obj, gtk_hpaned_get_type (), GtkHPaned)
  #define GTK_HPANED_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_hpaned_get_type (), GtkHPanedClass)
***************
*** 49,52 ****
--- 49,55 ----
  {
    GtkPaned paned;
+ 
+   guint16 handle_size_x;
+   guint16 handle_size_y;
  };
  
diff -C 2 -r gtk+-1.2.3.orig/gtk/gtkpaned.c gtk+-1.2.3/gtk/gtkpaned.c
*** gtk+-1.2.3.orig/gtk/gtkpaned.c	Mon May 10 21:31:09 1999
--- gtk+-1.2.3/gtk/gtkpaned.c	Tue Aug 10 05:01:55 1999
***************
*** 26,29 ****
--- 26,31 ----
  
  #include "gtkpaned.h"
+ #include "gtkvpaned.h"
+ #include "gtkhpaned.h"
  
  
***************
*** 41,47 ****
  				  GtkWidget      *widget);
  static void gtk_paned_forall     (GtkContainer   *container,
! 			   	  gboolean	  include_internals,
! 			          GtkCallback     callback,
! 			          gpointer        callback_data);
  static GtkType gtk_paned_child_type (GtkContainer *container);
  
--- 43,49 ----
  				  GtkWidget      *widget);
  static void gtk_paned_forall     (GtkContainer   *container,
!                                   gboolean	  include_internals,
!                                   GtkCallback     callback,
!                                   gpointer        callback_data);
  static GtkType gtk_paned_child_type (GtkContainer *container);
  
***************
*** 49,52 ****
--- 51,76 ----
  static GtkContainerClass *parent_class = NULL;
  
+ #define READ_HANDLE_SIZE_XY(widget, x, y) \
+     if( GTK_CHECK_TYPE(widget, GTK_TYPE_VPANED) ) {\
+     x = GTK_VPANED(widget)->handle_size_x;\
+     y = GTK_VPANED(widget)->handle_size_y;\
+     }                                          \
+     else if( GTK_CHECK_TYPE(widget, GTK_TYPE_HPANED) ) {\
+     x = GTK_HPANED(widget)->handle_size_x;          \
+     y = GTK_HPANED(widget)->handle_size_y;          \
+     }
+ 
+ 
+ #define SET_HANDLE_SIZE_XY(widget, x, y) \
+     if( GTK_CHECK_TYPE(widget, GTK_TYPE_VPANED) ) {\
+     GTK_VPANED(widget)->handle_size_x = x;\
+     GTK_VPANED(widget)->handle_size_y = y;\
+     }                                          \
+     else if( GTK_CHECK_TYPE(widget, GTK_TYPE_HPANED) ) {\
+     GTK_HPANED(widget)->handle_size_x = x;          \
+     GTK_HPANED(widget)->handle_size_y = y;          \
+     }
+ 
+ 
  
  GtkType
***************
*** 119,124 ****
    paned->xor_gc = NULL;
    
!   paned->handle_size = 10;
!   paned->gutter_size = 6;
    paned->position_set = FALSE;
    paned->last_allocation = -1;
--- 143,147 ----
    paned->xor_gc = NULL;
    
!   paned->gutter_size = 10;
    paned->position_set = FALSE;
    paned->last_allocation = -1;
***************
*** 133,185 ****
  gtk_paned_realize (GtkWidget *widget)
  {
!   GtkPaned *paned;
!   GdkWindowAttr attributes;
!   gint attributes_mask;
!   
!   g_return_if_fail (widget != NULL);
!   g_return_if_fail (GTK_IS_PANED (widget));
!   
!   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
!   paned = GTK_PANED (widget);
!   
!   attributes.x = widget->allocation.x;
!   attributes.y = widget->allocation.y;
!   attributes.width = widget->allocation.width;
!   attributes.height = widget->allocation.height;
!   attributes.window_type = GDK_WINDOW_CHILD;
!   attributes.wclass = GDK_INPUT_OUTPUT;
!   attributes.visual = gtk_widget_get_visual (widget);
!   attributes.colormap = gtk_widget_get_colormap (widget);
!   attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
!   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
!   
!   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
! 				   &attributes, attributes_mask);
!   gdk_window_set_user_data (widget->window, paned);
!   
!   attributes.x = paned->handle_xpos;
!   attributes.y = paned->handle_ypos;
!   attributes.width = paned->handle_size;
!   attributes.height = paned->handle_size;
!   attributes.cursor = gdk_cursor_new (GDK_CROSS);
!   attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
! 			    GDK_BUTTON_RELEASE_MASK |
! 			    GDK_POINTER_MOTION_MASK |
! 			    GDK_POINTER_MOTION_HINT_MASK);
!   attributes_mask |= GDK_WA_CURSOR;
!   
!   paned->handle = gdk_window_new (widget->window,
! 				  &attributes, attributes_mask);
!   gdk_window_set_user_data (paned->handle, paned);
!   gdk_cursor_destroy (attributes.cursor);
!   
!   widget->style = gtk_style_attach (widget->style, widget->window);
!   
!   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
!   gtk_style_set_background (widget->style, paned->handle, GTK_STATE_NORMAL);
  
!   gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
!   
!   gdk_window_show (paned->handle);
  }
  
--- 156,210 ----
  gtk_paned_realize (GtkWidget *widget)
  {
!     GtkPaned *paned;
  
!     GdkWindowAttr attributes;
!     gint attributes_mask;
! 
!     g_return_if_fail (widget != NULL);
!     g_return_if_fail (GTK_IS_PANED (widget));
! 
!     GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
!     paned = GTK_PANED (widget);
! 
!     attributes.x = widget->allocation.x;
!     attributes.y = widget->allocation.y;
!     attributes.width = widget->allocation.width;
!     attributes.height = widget->allocation.height;
!     attributes.window_type = GDK_WINDOW_CHILD;
!     attributes.wclass = GDK_INPUT_OUTPUT;
!     attributes.visual = gtk_widget_get_visual (widget);
!     attributes.colormap = gtk_widget_get_colormap (widget);
!     attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
!     attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
! 
!     widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
!                                      &attributes, attributes_mask);
!     gdk_window_set_user_data (widget->window, paned);
! 
!     attributes.x = paned->handle_xpos;
!     attributes.y = paned->handle_ypos;
! 
!     READ_HANDLE_SIZE_XY(widget, attributes.width, attributes.height);
! 
!     attributes.cursor = gdk_cursor_new (GDK_CROSS);
!     attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
!                               GDK_BUTTON_RELEASE_MASK |
!                               GDK_POINTER_MOTION_MASK |
!                               GDK_POINTER_MOTION_HINT_MASK);
!     attributes_mask |= GDK_WA_CURSOR;
! 
!     paned->handle = gdk_window_new (widget->window,
!                                     &attributes, attributes_mask);
!     gdk_window_set_user_data (paned->handle, paned);
!     gdk_cursor_destroy (attributes.cursor);
! 
!     widget->style = gtk_style_attach (widget->style, widget->window);
! 
!     gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
!     gtk_style_set_background (widget->style, paned->handle, GTK_STATE_NORMAL);
! 
!     gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
! 
!     gdk_window_show (paned->handle);
  }
  
***************
*** 247,294 ****
  static gint
  gtk_paned_expose (GtkWidget      *widget,
! 		  GdkEventExpose *event)
  {
!   GtkPaned *paned;
!   GdkEventExpose child_event;
!   
!   g_return_val_if_fail (widget != NULL, FALSE);
!   g_return_val_if_fail (GTK_IS_PANED (widget), FALSE);
!   g_return_val_if_fail (event != NULL, FALSE);
!   
!   if (GTK_WIDGET_DRAWABLE (widget))
      {
!       paned = GTK_PANED (widget);
!       
!       /* An expose event for the handle */
!       if (event->window == paned->handle)
! 	{
! 	   gtk_paint_box (widget->style, paned->handle,
! 			  GTK_WIDGET_STATE(widget),
! 			  GTK_SHADOW_OUT, 
! 			  &event->area, widget, "paned",
! 			  0, 0,
! 			  paned->handle_size, paned->handle_size);
! 	}
!       else
! 	{
! 	  child_event = *event;
! 	  if (paned->child1 &&
! 	      GTK_WIDGET_NO_WINDOW (paned->child1) &&
! 	      gtk_widget_intersect (paned->child1, &event->area, &child_event.area))
! 	    gtk_widget_event (paned->child1, (GdkEvent*) &child_event);
! 	  
! 	  if (paned->child2 &&
! 	      GTK_WIDGET_NO_WINDOW (paned->child2) &&
! 	      gtk_widget_intersect (paned->child2, &event->area, &child_event.area))
! 	    gtk_widget_event (paned->child2, (GdkEvent*) &child_event);
! 	  
! 	  /* redraw the groove if necessary */
! 	  if (gdk_rectangle_intersect (&paned->groove_rectangle, 
! 				       &event->area, 
! 				       &child_event.area))
! 	    gtk_widget_draw (widget, &child_event.area);
! 	}
      }
!   return FALSE;
  }
  
--- 272,330 ----
  static gint
  gtk_paned_expose (GtkWidget      *widget,
!                   GdkEventExpose *event)
  {
!     GtkPaned *paned;
!     GdkEventExpose child_event;
!     GtkOrientation orientation;
!     guint16 hszx, hszy;
! 
!     g_return_val_if_fail (widget != NULL, FALSE);
!     g_return_val_if_fail (GTK_IS_PANED (widget), FALSE);
!     g_return_val_if_fail (event != NULL, FALSE);
! 
!     READ_HANDLE_SIZE_XY(widget, hszx, hszy);
! 
!     if( GTK_CHECK_TYPE(widget, GTK_TYPE_VPANED) )
!         orientation = GTK_ORIENTATION_HORIZONTAL;
!     else /* it must be HPANED, right? */
!         orientation = GTK_ORIENTATION_VERTICAL;
! 
! 
!     if (GTK_WIDGET_DRAWABLE (widget))
      {
!         paned = GTK_PANED (widget);
! 
!         /* An expose event for the handle */
!         if (event->window == paned->handle)
!         {
!             gtk_paint_handle (widget->style, paned->handle,
!                               GTK_WIDGET_STATE(widget),
!                               GTK_SHADOW_OUT,
!                               &event->area, widget, "paned",
!                               0, 0,
!                               hszx, hszy,
!                               orientation);
!         }
!         else
!         {
!             child_event = *event;
!             if (paned->child1 &&
!                 GTK_WIDGET_NO_WINDOW (paned->child1) &&
!                 gtk_widget_intersect (paned->child1, &event->area, &child_event.area))
!                 gtk_widget_event (paned->child1, (GdkEvent*) &child_event);
! 
!             if (paned->child2 &&
!                 GTK_WIDGET_NO_WINDOW (paned->child2) &&
!                 gtk_widget_intersect (paned->child2, &event->area, &child_event.area))
!                 gtk_widget_event (paned->child2, (GdkEvent*) &child_event);
! 
!             /* redraw the groove if necessary */
!             if (gdk_rectangle_intersect (&paned->groove_rectangle,
!                                          &event->area,
!                                          &child_event.area))
!                 gtk_widget_draw (widget, &child_event.area);
!         }
      }
!     return FALSE;
  }
  
***************
*** 467,487 ****
  void
  gtk_paned_set_handle_size (GtkPaned *paned,
! 			   guint16   size)
  {
    gint x,y;
!   
    g_return_if_fail (paned != NULL);
    g_return_if_fail (GTK_IS_PANED (paned));
  
    if (paned->handle)
      {
        gdk_window_get_geometry (paned->handle, &x, &y, NULL, NULL, NULL);
        gdk_window_move_resize (paned->handle,
!                               x + paned->handle_size / 2 - size / 2,
!                               y + paned->handle_size / 2 - size / 2,
!                               size, size);
      }
!   paned->handle_size = size;
  }
  
  void
--- 503,544 ----
  void
  gtk_paned_set_handle_size (GtkPaned *paned,
!                            guint16   size)
! {
!     /* This way the handle will not overlap with the paned's window.
!      * If you actually want that, use 'gtk_paned_set_handle_size_xy'
!      */
! 
!     if( GTK_CHECK_TYPE(paned, GTK_TYPE_VPANED) )
!         gtk_paned_set_handle_size_xy (paned, size, GTK_VPANED(paned)->handle_size_y);
! 
!     else if( GTK_CHECK_TYPE(paned, GTK_TYPE_HPANED) )
!         gtk_paned_set_handle_size_xy (paned, GTK_HPANED(paned)->handle_size_x, size);
! }
! 
! void
! gtk_paned_set_handle_size_xy (GtkPaned *paned,
!                               guint16   sizex,
!                               guint16   sizey)
  {
    gint x,y;
!   guint16 hszx, hszy;
! 
    g_return_if_fail (paned != NULL);
    g_return_if_fail (GTK_IS_PANED (paned));
  
+   READ_HANDLE_SIZE_XY(paned, hszx, hszy);
+ 
    if (paned->handle)
      {
        gdk_window_get_geometry (paned->handle, &x, &y, NULL, NULL, NULL);
        gdk_window_move_resize (paned->handle,
!                               x + hszx / 2 - sizex / 2,
!                               y + hszy / 2 - sizey / 2,
!                               sizex, sizey);
      }
! 
!   SET_HANDLE_SIZE_XY(paned, sizex, sizey);
  }
+ 
  
  void
diff -C 2 -r gtk+-1.2.3.orig/gtk/gtkpaned.h gtk+-1.2.3/gtk/gtkpaned.h
*** gtk+-1.2.3.orig/gtk/gtkpaned.h	Wed Feb 24 04:15:10 1999
--- gtk+-1.2.3/gtk/gtkpaned.h	Tue Aug 10 05:01:55 1999
***************
*** 61,64 ****
--- 61,65 ----
    /*< public >*/
    guint16 handle_size;
+ 
    guint16 gutter_size;
  
***************
*** 103,106 ****
--- 104,111 ----
  void    gtk_paned_set_handle_size (GtkPaned *paned,
  				   guint16   size);
+ void    gtk_paned_set_handle_size_xy (GtkPaned *paned,
+                                       guint16   sizex,
+                                       guint16   sizey);
+ 
  void    gtk_paned_set_gutter_size (GtkPaned *paned,
  				   guint16   size);
diff -C 2 -r gtk+-1.2.3.orig/gtk/gtkvpaned.c gtk+-1.2.3/gtk/gtkvpaned.c
*** gtk+-1.2.3.orig/gtk/gtkvpaned.c	Wed Feb 24 04:15:18 1999
--- gtk+-1.2.3/gtk/gtkvpaned.c	Tue Aug 10 05:01:55 1999
***************
*** 83,86 ****
--- 83,87 ----
    widget_class->button_release_event = gtk_vpaned_button_release;
    widget_class->motion_notify_event = gtk_vpaned_motion;
+ 
  }
  
***************
*** 88,91 ****
--- 89,94 ----
  gtk_vpaned_init (GtkVPaned *vpaned)
  {
+     vpaned->handle_size_x = 24;
+     vpaned->handle_size_y = 8;
  }
  
***************
*** 137,241 ****
  static void
  gtk_vpaned_size_allocate (GtkWidget     *widget,
! 			  GtkAllocation *allocation)
  {
!   GtkPaned *paned;
!   GtkRequisition child1_requisition;
!   GtkRequisition child2_requisition;
!   GtkAllocation child1_allocation;
!   GtkAllocation child2_allocation;
!   GdkRectangle old_groove_rectangle;
!   guint16 border_width;
  
-   g_return_if_fail (widget != NULL);
-   g_return_if_fail (GTK_IS_VPANED (widget));
-   g_return_if_fail (allocation != NULL);
  
-   widget->allocation = *allocation;
  
!   paned = GTK_PANED (widget);
!   border_width = GTK_CONTAINER (widget)->border_width;
  
!   if (paned->child1)
!     gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
!   else
!     child1_requisition.height = 0;
! 
!   if (paned->child2)
!     gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
!   else
!     child2_requisition.height = 0;
!     
!   gtk_paned_compute_position (paned,
! 			      widget->allocation.height
! 			        - paned->gutter_size
! 			        - 2 * border_width,
! 			      child1_requisition.height,
! 			      child2_requisition.height);
! 
!   /* Move the handle before the children so we don't get extra expose events */
! 
!   paned->handle_xpos = allocation->width - border_width - 2 * paned->handle_size;
!   paned->handle_ypos = paned->child1_size + border_width + paned->gutter_size / 2 - paned->handle_size / 2;
! 
!   if (GTK_WIDGET_REALIZED (widget))
!     {
!       gdk_window_move_resize (widget->window,
! 			      allocation->x, allocation->y,
! 			      allocation->width, allocation->height);
!       
!       gdk_window_move (paned->handle, paned->handle_xpos, paned->handle_ypos);
!     }
! 
!   child1_allocation.width = child2_allocation.width = MAX (1, (gint)allocation->width - border_width * 2);
!   child1_allocation.height = paned->child1_size;
!   child1_allocation.x = child2_allocation.x = border_width;
!   child1_allocation.y = border_width;
!   
!   old_groove_rectangle = paned->groove_rectangle;
! 
!   paned->groove_rectangle.y = child1_allocation.y 
!     + child1_allocation.height + paned->gutter_size / 2 - 1;
!   paned->groove_rectangle.x = 0;
!   paned->groove_rectangle.height = 2;
!   paned->groove_rectangle.width = allocation->width;
!   
!   if (GTK_WIDGET_DRAWABLE (widget) &&
!       ((paned->groove_rectangle.x != old_groove_rectangle.x) ||
!        (paned->groove_rectangle.y != old_groove_rectangle.y) ||
!        (paned->groove_rectangle.width != old_groove_rectangle.width) ||
!        (paned->groove_rectangle.height != old_groove_rectangle.height)))
!     {
!       gtk_widget_queue_clear_area (widget,
! 				   old_groove_rectangle.x,
! 				   old_groove_rectangle.y,
! 				   old_groove_rectangle.width,
! 				   old_groove_rectangle.height);
!       gtk_widget_queue_draw_area (widget,
! 				  paned->groove_rectangle.x,
! 				  paned->groove_rectangle.y,
! 				  paned->groove_rectangle.width,
! 				  paned->groove_rectangle.height);
!     }
!   
!   child2_allocation.y = paned->groove_rectangle.y + paned->gutter_size / 2 + 1;
!   child2_allocation.height = MAX (1, (gint)allocation->height 
!     - child2_allocation.y - border_width);
!   
!   /* Now allocate the childen, making sure, when resizing not to
!    * overlap the windows */
!   if (GTK_WIDGET_MAPPED(widget) &&
!       paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
!       paned->child1->allocation.height < child1_allocation.height)
!     {
!       if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
! 	gtk_widget_size_allocate (paned->child2, &child2_allocation);
!       gtk_widget_size_allocate (paned->child1, &child1_allocation);      
!     }
!   else
!     {
!       if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
! 	gtk_widget_size_allocate (paned->child1, &child1_allocation);
!       if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
! 	gtk_widget_size_allocate (paned->child2, &child2_allocation);
      }
  }
--- 140,261 ----
  static void
  gtk_vpaned_size_allocate (GtkWidget     *widget,
!                           GtkAllocation *allocation)
  {
!     GtkPaned *paned;
!     GtkRequisition child1_requisition;
!     GtkRequisition child2_requisition;
!     GtkAllocation child1_allocation;
!     GtkAllocation child2_allocation;
!     GdkRectangle old_groove_rectangle;
!     guint16 border_width;
! 
!     g_return_if_fail (widget != NULL);
!     g_return_if_fail (GTK_IS_VPANED (widget));
!     g_return_if_fail (allocation != NULL);
! 
!     widget->allocation = *allocation;
! 
!     paned = GTK_PANED (widget);
!     border_width = GTK_CONTAINER (widget)->border_width;
! 
!     if (paned->child1)
!         gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
!     else
!         child1_requisition.height = 0;
! 
!     if (paned->child2)
!         gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
!     else
!         child2_requisition.height = 0;
! 
!     gtk_paned_compute_position (paned,
!                                 widget->allocation.height
!                                 - paned->gutter_size
!                                 - 2 * border_width,
!                                 child1_requisition.height,
!                                 child2_requisition.height);
! 
!     /* Move the handle before the children so we don't get extra expose events */
! 
!     paned->handle_xpos =
!         allocation->width - border_width -
!         2 * (GTK_VPANED(widget)->handle_size_x);
! 
!     /* if the space before the handle is going to be smaller than the
!      * space after the handle
!      */
!     if( paned->handle_xpos <
!         allocation->width - ( paned->handle_xpos + GTK_VPANED(widget)->handle_size_x )
!       )
!     { /* put the handle in the center of the groove */
!         paned->handle_xpos =
!             allocation->width * 1/2 -
!             GTK_VPANED(widget)->handle_size_x / 2;
!     }
  
  
  
!     paned->handle_ypos = paned->child1_size + border_width + paned->gutter_size / 2 - (GTK_VPANED(widget)->handle_size_y) / 2;
! 
!     if (GTK_WIDGET_REALIZED (widget))
!     {
!         gdk_window_move_resize (widget->window,
!                                 allocation->x, allocation->y,
!                                 allocation->width, allocation->height);
  
!         gdk_window_move (paned->handle, paned->handle_xpos, paned->handle_ypos);
!     }
! 
!     child1_allocation.width = child2_allocation.width = MAX (1, (gint)allocation->width - border_width * 2);
!     child1_allocation.height = paned->child1_size;
!     child1_allocation.x = child2_allocation.x = border_width;
!     child1_allocation.y = border_width;
! 
!     old_groove_rectangle = paned->groove_rectangle;
! 
!     paned->groove_rectangle.y = child1_allocation.y
!         + child1_allocation.height + paned->gutter_size / 2 - 1;
!     paned->groove_rectangle.x = 0;
!     paned->groove_rectangle.height = 2;
!     paned->groove_rectangle.width = allocation->width;
! 
!     if (GTK_WIDGET_DRAWABLE (widget) &&
!         ((paned->groove_rectangle.x != old_groove_rectangle.x) ||
!          (paned->groove_rectangle.y != old_groove_rectangle.y) ||
!          (paned->groove_rectangle.width != old_groove_rectangle.width) ||
!          (paned->groove_rectangle.height != old_groove_rectangle.height)))
!     {
!         gtk_widget_queue_clear_area (widget,
!                                      old_groove_rectangle.x,
!                                      old_groove_rectangle.y,
!                                      old_groove_rectangle.width,
!                                      old_groove_rectangle.height);
!         gtk_widget_queue_draw_area (widget,
!                                     paned->groove_rectangle.x,
!                                     paned->groove_rectangle.y,
!                                     paned->groove_rectangle.width,
!                                     paned->groove_rectangle.height);
!     }
! 
!     child2_allocation.y = paned->groove_rectangle.y + paned->gutter_size / 2 + 1;
!     child2_allocation.height = MAX (1, (gint)allocation->height
!                                     - child2_allocation.y - border_width);
! 
!     /* Now allocate the childen, making sure, when resizing not to
!      * overlap the windows */
!     if (GTK_WIDGET_MAPPED(widget) &&
!         paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
!         paned->child1->allocation.height < child1_allocation.height)
!     {
!         if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
!             gtk_widget_size_allocate (paned->child2, &child2_allocation);
!         gtk_widget_size_allocate (paned->child1, &child1_allocation);
!     }
!     else
!     {
!         if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
!             gtk_widget_size_allocate (paned->child1, &child1_allocation);
!         if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
!             gtk_widget_size_allocate (paned->child2, &child2_allocation);
      }
  }
***************
*** 325,329 ****
  			| GDK_BUTTON_RELEASE_MASK,
  			NULL, NULL, event->time);
!       paned->child1_size += event->y - paned->handle_size / 2;
        paned->child1_size = CLAMP (paned->child1_size, 0,
                                    widget->allocation.height - paned->gutter_size
--- 345,349 ----
  			| GDK_BUTTON_RELEASE_MASK,
  			NULL, NULL, event->time);
!       paned->child1_size += event->y - (GTK_VPANED(widget)->handle_size_y) / 2;
        paned->child1_size = CLAMP (paned->child1_size, 0,
                                    widget->allocation.height - paned->gutter_size
diff -C 2 -r gtk+-1.2.3.orig/gtk/gtkvpaned.h gtk+-1.2.3/gtk/gtkvpaned.h
*** gtk+-1.2.3.orig/gtk/gtkvpaned.h	Wed Feb 24 04:15:18 1999
--- gtk+-1.2.3/gtk/gtkvpaned.h	Tue Aug 10 05:01:55 1999
***************
*** 38,41 ****
--- 38,42 ----
  
  
+ #define GTK_TYPE_VPANED          (gtk_vpaned_get_type ())
  #define GTK_VPANED(obj)          GTK_CHECK_CAST (obj, gtk_vpaned_get_type (), GtkVPaned)
  #define GTK_VPANED_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_vpaned_get_type (), GtkVPanedClass)
***************
*** 49,52 ****
--- 50,57 ----
  {
    GtkPaned paned;
+ 
+   guint16 handle_size_x;
+   guint16 handle_size_y;
+ 
  };
  


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