Patch to Gtk?Pane




Hello all!

I have made a patch that allow to move a pane with all the handler.
I have redone the allocation code too.

There is some bug when your child is a NO_WINDOW widget and it wants some 
events(i have removed the handle window frome GtkPane, so paned->window is now
receiving button and motion events). I don't know how to deal with events
repartition and I think some gtk gurus could find the matter.

a+

--
Utilisateur de Gyptis (33-491604361) - Shell/PPP/UUCP/Usenet/E-Mail
E-Mail: feanor@cassis.gyptis.frmug.org (UUCP)
        feanor@easynet.fr (POP3)
Fido:   2:323/28.17 (Point du Phocea Marseille)
Apply this patch in gtk+ directory.

diff -u -r /mnt/hdc7/gnome/gnome-cvs/gtk+/gtk/gtkhpaned.c gtk/gtkhpaned.c
--- /mnt/hdc7/gnome/gnome-cvs/gtk+/gtk/gtkhpaned.c	Fri Apr 17 00:58:30 1998
+++ gtk/gtkhpaned.c	Fri Apr 17 02:36:15 1998
@@ -36,6 +36,12 @@
 static gint gtk_hpaned_motion           (GtkWidget *widget,
 					 GdkEventMotion *event);
 
+
+#define POINT_IN_RECTANGLE(rect, w, h) ((w > rect.x) \
+    && ( w < rect.x+rect.width) && (h > rect.y) \
+    && ( h < rect.y+rect.height))
+
+
 guint
 gtk_hpaned_get_type ()
 {
@@ -121,7 +127,7 @@
       requisition->width += paned->child2->requisition.width;
     }
 
-  requisition->width += GTK_CONTAINER (paned)->border_width * 2 + paned->gutter_size;
+  requisition->width += GTK_CONTAINER (paned)->border_width * 2 + paned->handle_size;
   requisition->height += GTK_CONTAINER (paned)->border_width * 2;
 }
 
@@ -143,22 +149,24 @@
   paned = GTK_PANED (widget);
   border_width = GTK_CONTAINER (paned)->border_width;
 
+
   if (!paned->position_set)
     {
-      if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
-	paned->child1_size = paned->child1->requisition.width;
-      else
-	paned->child1_size = 0;
+      
+      paned->child1_size = 0;
+      if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) 
+	{
+		paned->child1_size += (allocation->width - paned->handle_size) 
+		  / 2 - border_width;
+		if ((!paned->child2 || !GTK_WIDGET_VISIBLE (paned->child2)) )
+		  paned->child1_size += (allocation->width - paned->handle_size)                 
+		    / 2 - border_width;
+	}    
     }
   else
     paned->child1_size = CLAMP (paned->child1_size, 0,
-				allocation->width - paned->gutter_size
-				- 2 * GTK_CONTAINER (paned)->border_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;
+				allocation->width - paned->handle_size
+				- 2 * border_width);
 
   if (GTK_WIDGET_REALIZED (widget))
     {
@@ -166,7 +174,6 @@
 			      allocation->x, allocation->y,
 			      allocation->width, allocation->height);
       
-      gdk_window_move (paned->handle, paned->handle_xpos, paned->handle_ypos);
     }
 
   if (GTK_WIDGET_MAPPED (widget))
@@ -178,20 +185,22 @@
 			     paned->groove_rectangle.height);
     }
   
-  child1_allocation.height = child2_allocation.height = MAX (1, allocation->height - border_width * 2);
+  child1_allocation.height = child2_allocation.height = MAX (1, 
+    allocation->height - border_width * 2);
   child1_allocation.width = paned->child1_size;
   child1_allocation.x = border_width;
   child1_allocation.y = child2_allocation.y = border_width;
+	
   
-  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;
+  paned->groove_rectangle.width = paned->handle_size;
+  paned->groove_rectangle.x = child1_allocation.x + child1_allocation.width;   
+  paned->groove_rectangle.y = border_width;
+  paned->groove_rectangle.height = allocation->height - 2 * border_width;
       
-  child2_allocation.x = paned->groove_rectangle.x + paned->gutter_size / 2 + 1;
-  child2_allocation.width = MAX (1, allocation->width
-    - child2_allocation.x - border_width);
+  child2_allocation.x = child1_allocation.x + child1_allocation.width 
+    + paned->handle_size;
+  child2_allocation.width = allocation->width - 2 * border_width - paned->handle_size - paned->child1_size;
+
   
   /* Now allocate the childen, making sure, when resizing not to
    * overlap the windows */
@@ -235,18 +244,9 @@
 	  gtk_widget_intersect (paned->child2, area, &child_area))
         gtk_widget_draw (paned->child2, &child_area);
 
-      gdk_draw_line (widget->window,
-		     widget->style->dark_gc[widget->state],
-		     border_width + paned->child1_size + paned->gutter_size / 2 - 1,
-		     0,
-		     border_width + paned->child1_size + paned->gutter_size / 2 - 1,
-		     widget->allocation.height - 1);
-      gdk_draw_line (widget->window,
-		     widget->style->light_gc[widget->state],
-		     border_width + paned->child1_size + paned->gutter_size / 2,
-		     0,
-		     border_width + paned->child1_size + paned->gutter_size / 2,
-		     widget->allocation.height - 1);
+/* I wait for gtk_draw_oval so it could look like NextStep */
+
+
     }
 }
 
@@ -272,13 +272,13 @@
     }
 
   xpos = paned->child1_size
-    + GTK_CONTAINER(paned)->border_width + paned->gutter_size / 2;
+    + GTK_CONTAINER(paned)->border_width + paned->handle_size / 2;
 
   gdk_draw_line (widget->window, paned->xor_gc,
 		 xpos,
-		 0,
+		 GTK_CONTAINER(paned)->border_width,
 		 xpos,
-		 widget->allocation.height - 1);
+		 widget->allocation.height - GTK_CONTAINER(paned)->border_width);
 }
 
 static gint
@@ -290,23 +290,26 @@
   g_return_val_if_fail (GTK_IS_PANED (widget),FALSE);
 
   paned = GTK_PANED (widget);
-
-  if (!paned->in_drag &&
-      (event->window == paned->handle) && (event->button == 1))
+  
+  if ((!paned->in_drag) && 
+      (event->window == widget->window) && 
+      (POINT_IN_RECTANGLE(paned->groove_rectangle, event->x, event->y)) && 
+      (event->button == 1))
     {
       paned->in_drag = TRUE;
       /* We need a server grab here, not gtk_grab_add(), since
        * we don't want to pass events on to the widget's children */
-      gdk_pointer_grab (paned->handle, FALSE,
+      gdk_pointer_grab (widget->window, FALSE,
 			GDK_POINTER_MOTION_HINT_MASK 
 			| GDK_BUTTON1_MOTION_MASK 
 			| GDK_BUTTON_RELEASE_MASK,
 			NULL, NULL, event->time);
-      paned->child1_size += event->x - paned->handle_size / 2;
+      paned->child1_size = event->x - GTK_CONTAINER (paned)->border_width - paned->handle_size / 2;
       paned->child1_size = CLAMP (paned->child1_size, 0,
-                                  widget->allocation.width - paned->gutter_size
+                                  widget->allocation.width - paned->handle_size
                                   - 2 * GTK_CONTAINER (paned)->border_width);
       gtk_hpaned_xor_line (paned);
+      return TRUE;
     }
 
   return FALSE;
@@ -329,9 +332,10 @@
       paned->position_set = TRUE;
       gdk_pointer_ungrab (event->time);
       gtk_widget_queue_resize (GTK_WIDGET (paned));
+      return TRUE;
     }
 
-  return TRUE;
+  return FALSE;
 }
 
 static gint
@@ -353,10 +357,11 @@
   if (paned->in_drag)
     {
       gtk_hpaned_xor_line (paned);
-      paned->child1_size = x - GTK_CONTAINER (paned)->border_width - paned->gutter_size / 2;
+      paned->child1_size = x - GTK_CONTAINER (paned)->border_width - paned->handle_size / 2;
       paned->child1_size = CLAMP (paned->child1_size, 0,
-                                  widget->allocation.width - paned->gutter_size
-                                  - 2 * GTK_CONTAINER (paned)->border_width);
+                                  widget->allocation.width 
+                                  - paned->handle_size
+                                  - 2*GTK_CONTAINER (paned)->border_width);
       gtk_hpaned_xor_line (paned);
     }
 
diff -u -r /mnt/hdc7/gnome/gnome-cvs/gtk+/gtk/gtkpaned.c gtk/gtkpaned.c
--- /mnt/hdc7/gnome/gnome-cvs/gtk+/gtk/gtkpaned.c	Mon Apr 13 15:47:56 1998
+++ gtk/gtkpaned.c	Fri Apr 17 02:36:15 1998
@@ -94,16 +94,11 @@
 
   paned->child1 = NULL;
   paned->child2 = NULL;
-  paned->handle = NULL;
   paned->xor_gc = NULL;
 
-  paned->handle_size = 10;
-  paned->gutter_size = 6;
+  paned->handle_size = 6;
   paned->position_set = FALSE;
   paned->in_drag = FALSE;
-
-  paned->handle_xpos = -1;
-  paned->handle_ypos = -1;
 }
 
 
@@ -128,34 +123,20 @@
   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.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK |
+			GDK_BUTTON_PRESS_MASK |
+                        GDK_BUTTON_RELEASE_MASK |
+                        GDK_POINTER_MOTION_MASK |
+                        GDK_POINTER_MOTION_HINT_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 = paned->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);
-
   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_show (paned->handle);
 }
   
 static void
@@ -208,15 +189,6 @@
       paned->xor_gc = NULL;
     }
 
-  if (paned->handle)
-    {
-      gdk_window_set_user_data (paned->handle, NULL);
-      gdk_window_destroy (paned->handle);
-      paned->handle = NULL;
-      gdk_cursor_destroy (paned->cursor);
-      paned->cursor = NULL;
-    }
-
   if (GTK_WIDGET_CLASS (parent_class)->unrealize)
     (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
 }
@@ -237,17 +209,7 @@
       paned = GTK_PANED (widget);
 
       /* An expose event for the handle */
-      if (event->window == paned->handle)
-	{
-	  gdk_window_set_background (paned->handle,
-				     &widget->style->bg[widget->state]);
-	  gdk_window_clear (paned->handle);
-	  gtk_draw_shadow (widget->style, paned->handle,
-			   GTK_WIDGET_STATE(widget),
-			   GTK_SHADOW_OUT, 0, 0,
-			   paned->handle_size, paned->handle_size);
-	}
-      else
+
 	{
 	  child_event = *event;
 	  if (paned->child1 &&
@@ -395,27 +357,11 @@
     (* callback) (paned->child2, callback_data);
 }
 
-void
-gtk_paned_handle_size (GtkPaned *paned, guint16 size)
-{
-  gint x,y;
-
-  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
-gtk_paned_gutter_size (GtkPaned *paned, guint16 size)
+gtk_paned_handle_size (GtkPaned *paned, guint16 size)
 {
-  paned->gutter_size = size;
+  paned->handle_size = MAX(size, 6);
 
   if (GTK_WIDGET_VISIBLE (GTK_WIDGET (paned)))
     gtk_widget_queue_resize (GTK_WIDGET (paned));
diff -u -r /mnt/hdc7/gnome/gnome-cvs/gtk+/gtk/gtkpaned.h gtk/gtkpaned.h
--- /mnt/hdc7/gnome/gnome-cvs/gtk+/gtk/gtkpaned.h	Mon Apr 13 15:47:56 1998
+++ gtk/gtkpaned.h	Fri Apr 17 02:36:15 1998
@@ -44,20 +44,14 @@
   GtkWidget *child1;
   GtkWidget *child2;
 
-  GdkWindow *handle;
-  GdkCursor *cursor;
   GdkRectangle groove_rectangle;
   GdkGC *xor_gc;
 
   guint16 handle_size;
-  guint16 gutter_size;
-  
+
   gint child1_size;
   guint position_set : 1;
   guint in_drag : 1;
-
-  gint16 handle_xpos;
-  gint16 handle_ypos;
 };
 
 struct _GtkPanedClass
@@ -70,7 +64,7 @@
 void gtk_paned_add1 (GtkPaned *paned, GtkWidget *child);
 void gtk_paned_add2 (GtkPaned *paned, GtkWidget *child);
 void gtk_paned_handle_size (GtkPaned *paned, guint16 size);
-void gtk_paned_gutter_size (GtkPaned *paned, guint16 size);
+
 
 #ifdef __cplusplus
 }
diff -u -r /mnt/hdc7/gnome/gnome-cvs/gtk+/gtk/gtkvpaned.c gtk/gtkvpaned.c
--- /mnt/hdc7/gnome/gnome-cvs/gtk+/gtk/gtkvpaned.c	Fri Apr 17 00:58:47 1998
+++ gtk/gtkvpaned.c	Fri Apr 17 02:36:15 1998
@@ -36,6 +36,12 @@
 static gint gtk_vpaned_motion           (GtkWidget *widget,
 					 GdkEventMotion *event);
 
+
+#define POINT_IN_RECTANGLE(rect, w, h) ((w > rect.x) \
+    && ( w < rect.x+rect.width) && (h > rect.y) \
+    && ( h < rect.y+rect.height))
+	
+	
 guint
 gtk_vpaned_get_type ()
 {
@@ -121,7 +127,7 @@
       requisition->height += paned->child2->requisition.height;
     }
 
-  requisition->height += GTK_CONTAINER (paned)->border_width * 2 + paned->gutter_size;
+  requisition->height += GTK_CONTAINER (paned)->border_width * 2 + paned->handle_size;
   requisition->width += GTK_CONTAINER (paned)->border_width * 2;
 }
 
@@ -145,28 +151,28 @@
 
   if (!paned->position_set)
     {
-      if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
-	paned->child1_size = paned->child1->requisition.height;
-      else
-	paned->child1_size = 0;
+      paned->child1_size = 0;
+      if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))                  
+              {                                                                       
+		paned->child1_size += (allocation->height - paned->handle_size)  
+	          / 2 - border_width;                                           
+		if ((!paned->child2 || !GTK_WIDGET_VISIBLE (paned->child2)) )   
+		 paned->child1_size += (allocation->height - paned->handle_size)
+	          / 2 - border_width;                                         
+	      }                              
+
     }
   else
     paned->child1_size = CLAMP (paned->child1_size, 0,
-				allocation->height - paned->gutter_size
+				allocation->height - paned->handle_size
 				- 2 * GTK_CONTAINER (paned)->border_width);
 
-  /* 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);
     }
 
   if (GTK_WIDGET_MAPPED (widget))
@@ -183,16 +189,15 @@
   child1_allocation.x = child2_allocation.x = border_width;
   child1_allocation.y = border_width;
   
-  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;
+  paned->groove_rectangle.height = paned->handle_size;
+  paned->groove_rectangle.y = child1_allocation.y + child1_allocation.height;
+  paned->groove_rectangle.x = border_width;
+  paned->groove_rectangle.width = allocation->width - 2 * border_width;
   
-  child2_allocation.y = paned->groove_rectangle.y + paned->gutter_size / 2 + 1;
-  child2_allocation.height = MAX (1, allocation->height 
-    - child2_allocation.y - border_width);
+  child2_allocation.y = child1_allocation.y + child1_allocation.height + paned->handle_size;
+  child2_allocation.height = allocation->height - 2*border_width - paned->handle_size - paned->child1_size;
   
+
   /* Now allocate the childen, making sure, when resizing not to
    * overlap the windows */
   if (GTK_WIDGET_MAPPED(widget) &&
@@ -235,18 +240,8 @@
 	  gtk_widget_intersect (paned->child2, area, &child_area))
         gtk_widget_draw (paned->child2, &child_area);
 
-      gdk_draw_line (widget->window,
-		     widget->style->dark_gc[widget->state],
-		     0,
-		     border_width + paned->child1_size + paned->gutter_size / 2 - 1,
-		     widget->allocation.width - 1,
-		     border_width + paned->child1_size + paned->gutter_size / 2 - 1);
-      gdk_draw_line (widget->window,
-		     widget->style->light_gc[widget->state],
-		     0,
-		     border_width + paned->child1_size + paned->gutter_size / 2,
-		     widget->allocation.width - 1,
-		     border_width + paned->child1_size + paned->gutter_size / 2);
+/* I wait for gtk_draw_oval so it could look like NextStep */  
+
     }
 }
 
@@ -272,12 +267,12 @@
     }
 
   ypos = paned->child1_size
-    + GTK_CONTAINER (paned)->border_width + paned->gutter_size / 2;
+    + GTK_CONTAINER (paned)->border_width + paned->handle_size / 2;
 
   gdk_draw_line (widget->window, paned->xor_gc,
-		 0,
+		 GTK_CONTAINER (paned)->border_width,
 		 ypos,
-		 widget->allocation.width - 1,
+		 widget->allocation.width - GTK_CONTAINER (paned)->border_width,
 		 ypos);
 }
 
@@ -290,23 +285,25 @@
   g_return_val_if_fail (GTK_IS_PANED (widget),FALSE);
 
   paned = GTK_PANED (widget);
-
   if (!paned->in_drag &&
-      (event->window == paned->handle) && (event->button == 1))
+      (event->window == widget->window) 
+        && POINT_IN_RECTANGLE(paned->groove_rectangle, event->x, event->y)
+	&& (event->button == 1))
     {
       paned->in_drag = TRUE;
       /* We need a server grab here, not gtk_grab_add(), since
        * we don't want to pass events on to the widget's children */
-      gdk_pointer_grab (paned->handle, FALSE,
+      gdk_pointer_grab (widget->window, FALSE,
 			GDK_POINTER_MOTION_HINT_MASK 
 			| GDK_BUTTON1_MOTION_MASK 
 			| GDK_BUTTON_RELEASE_MASK,
 			NULL, NULL, event->time);
-      paned->child1_size += event->y - paned->handle_size / 2;
+      paned->child1_size = event->y - GTK_CONTAINER (paned)->border_width - paned->handle_size / 2;
       paned->child1_size = CLAMP (paned->child1_size, 0,
-                                  widget->allocation.height - paned->gutter_size
+                                  widget->allocation.height - paned->handle_size
                                   - 2 * GTK_CONTAINER (paned)->border_width);
       gtk_vpaned_xor_line (paned);
+      return TRUE;
     }
 
   return FALSE;
@@ -329,9 +326,10 @@
       paned->position_set = TRUE;
       gdk_pointer_ungrab (event->time);
       gtk_widget_queue_resize (GTK_WIDGET (paned));
+      return TRUE;
     }
 
-  return TRUE;
+  return FALSE;
 }
 
 static gint
@@ -353,11 +351,11 @@
   if (paned->in_drag)
     {
       gtk_vpaned_xor_line (paned);
-      paned->child1_size = y - GTK_CONTAINER (paned)->border_width -
-	paned->gutter_size/2;
+      paned->child1_size = y - GTK_CONTAINER (paned)->border_width - paned->handle_size/2;
       paned->child1_size = CLAMP (paned->child1_size, 0,
-                                  widget->allocation.height - paned->gutter_size
-                                  - 2 * GTK_CONTAINER (paned)->border_width);
+                                  widget->allocation.height 
+                                  - paned->handle_size
+                                  - 2*GTK_CONTAINER (paned)->border_width);
       gtk_vpaned_xor_line (paned);
     }
 


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