#50200: patch



Hi all,

Appended patch fixes bug #50200 (gtkspinbutton hardcodes ARROW_SIZE).
After applying this patch, the size of the spinbutton arrows will scale up
with the font size. See the example image:

http://home.planet.nl/~kristian/zooi/spin_new.jpg

ChangeLog:

Sun Sep 23 00:59:14 2001  Kristian Rietveld  <kristian planet nl>

        * gtk/gtkspinbutton.h: add arrow_size field

        * gtk/gtkspinbutton.c: remove ARROW_SIZE constant, use
        arrow_size field instead. Arrow size is set to current font size
        and updated on the style_set signal.

        * gtk/gtkstyle.c (gtk_default_draw_arrow): actual size of arrow
        was hardcoded, now it's variable, so it scales up nicely with
        the font size

Ok to commit?

regards,


	Kris


Index: gtkspinbutton.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkspinbutton.h,v
retrieving revision 1.27
diff -u -r1.27 gtkspinbutton.h
--- gtkspinbutton.h	2001/06/24 15:34:47	1.27
+++ gtkspinbutton.h	2001/09/22 22:56:01
@@ -97,6 +97,8 @@
   guint numeric : 1;
   guint wrap : 1;
   guint snap_to_ticks : 1;
+
+  gint arrow_size;
 };

 struct _GtkSpinButtonClass
Index: gtkspinbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkspinbutton.c,v
retrieving revision 1.74
diff -u -r1.74 gtkspinbutton.c
--- gtkspinbutton.c	2001/09/19 00:58:09	1.74
+++ gtkspinbutton.c	2001/09/22 22:56:03
@@ -40,7 +40,6 @@
 #include "gtkintl.h"

 #define MIN_SPIN_BUTTON_WIDTH              30
-#define ARROW_SIZE                         11
 #define SPIN_BUTTON_INITIAL_TIMER_DELAY    200
 #define SPIN_BUTTON_TIMER_DELAY            20
 #define MAX_TIMER_CALLS                    5
@@ -101,6 +100,8 @@
 					    GdkEventCrossing   *event);
 static gint gtk_spin_button_focus_out      (GtkWidget          *widget,
 					    GdkEventFocus      *event);
+static void gtk_spin_button_style_set      (GtkWidget          *widget,
+					    GtkStyle           *previous_style);
 static void gtk_spin_button_draw_arrow     (GtkSpinButton      *spin_button,
 					    guint               arrow);
 static gint gtk_spin_button_timer          (GtkSpinButton      *spin_button);
@@ -190,6 +191,7 @@
   widget_class->enter_notify_event = gtk_spin_button_enter_notify;
   widget_class->leave_notify_event = gtk_spin_button_leave_notify;
   widget_class->focus_out_event = gtk_spin_button_focus_out;
+  widget_class->style_set = gtk_spin_button_style_set;

   entry_class->insert_text = gtk_spin_button_insert_text;
   entry_class->activate = gtk_spin_button_activate;
@@ -397,6 +399,8 @@
 static void
 gtk_spin_button_init (GtkSpinButton *spin_button)
 {
+  PangoFontMask mask;
+
   spin_button->adjustment = NULL;
   spin_button->panel = NULL;
   spin_button->timer = 0;
@@ -413,6 +417,14 @@
   spin_button->numeric = FALSE;
   spin_button->wrap = FALSE;
   spin_button->snap_to_ticks = FALSE;
+
+  mask = pango_font_description_get_set_fields (GTK_WIDGET (spin_button)->style->font_desc);
+  if (mask & PANGO_FONT_MASK_SIZE)
+    spin_button->arrow_size = PANGO_PIXELS (pango_font_description_get_size (GTK_WIDGET (spin_button)->style->font_desc));
+  else
+    /* old default value */
+    spin_button->arrow_size = 11;
+
   gtk_spin_button_set_adjustment (spin_button,
 	  (GtkAdjustment*) gtk_adjustment_new (0, 0, 0, 0, 0, 0));
 }
@@ -465,7 +477,8 @@
   spin_button = GTK_SPIN_BUTTON (widget);

   real_width = widget->allocation.width;
-  widget->allocation.width -= ARROW_SIZE + 2 * widget->style->xthickness;
+  widget->allocation.width -= spin_button->arrow_size +
+    2 * widget->style->xthickness;
   gtk_widget_set_events (widget, gtk_widget_get_events (widget) |
 			 GDK_KEY_RELEASE_MASK);
   GTK_WIDGET_CLASS (parent_class)->realize (widget);
@@ -483,11 +496,12 @@

   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

-  attributes.x = (widget->allocation.x + widget->allocation.width - ARROW_SIZE -
+  attributes.x = (widget->allocation.x +
+		  widget->allocation.width - spin_button->arrow_size -
 		  2 * widget->style->xthickness);
   attributes.y = widget->allocation.y + (widget->allocation.height -
 					 widget->requisition.height) / 2;
-  attributes.width = ARROW_SIZE + 2 * widget->style->xthickness;
+  attributes.width = spin_button->arrow_size + 2 * widget->style->xthickness;
   attributes.height = widget->requisition.height;

   spin_button->panel = gdk_window_new (gtk_widget_get_parent_window (widget),
@@ -592,27 +606,32 @@
       w = MIN (string_len, 10) * digit_width;
       width = MAX (width, w);

-      requisition->width = width + ARROW_SIZE + 2 * widget->style->xthickness;
+      requisition->width = width + spin_button->arrow_size +
+	2 * widget->style->xthickness;
     }
   else
-    requisition->width += ARROW_SIZE + 2 * widget->style->xthickness;
+    requisition->width += spin_button->arrow_size +
+      2 * widget->style->xthickness;
 }

 static void
 gtk_spin_button_size_allocate (GtkWidget     *widget,
 			       GtkAllocation *allocation)
 {
+  GtkSpinButton *spin;
   GtkAllocation child_allocation;

   g_return_if_fail (GTK_IS_SPIN_BUTTON (widget));
   g_return_if_fail (allocation != NULL);

+  spin = GTK_SPIN_BUTTON (widget);
+
   child_allocation = *allocation;
-  if (child_allocation.width > ARROW_SIZE + 2 * widget->style->xthickness)
-    child_allocation.width -= ARROW_SIZE + 2 * widget->style->xthickness;
+  if (child_allocation.width > spin->arrow_size + 2 * widget->style->xthickness)
+    child_allocation.width -= spin->arrow_size + 2 * widget->style->xthickness;

   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
-    child_allocation.x += ARROW_SIZE + 2 * widget->style->xthickness;
+    child_allocation.x += spin->arrow_size + 2 * widget->style->xthickness;

   GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, &child_allocation);

@@ -620,11 +639,11 @@

   if (GTK_WIDGET_REALIZED (widget))
     {
-      child_allocation.width = ARROW_SIZE + 2 * widget->style->xthickness;
+      child_allocation.width = spin->arrow_size + 2 * widget->style->xthickness;
       child_allocation.height = widget->requisition.height;

       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
-	child_allocation.x = (allocation->x + allocation->width - ARROW_SIZE -
+	child_allocation.x = (allocation->x + allocation->width - spin->arrow_size -
 			      2 * widget->style->xthickness);
       else
 	child_allocation.x = allocation->x;
@@ -665,7 +684,7 @@
 		       GTK_STATE_NORMAL, shadow_type,
 		       &event->area, widget, "spinbutton",
 		       0, 0,
-		       ARROW_SIZE + 2 * widget->style->xthickness,
+		       spin->arrow_size + 2 * widget->style->xthickness,
 		       widget->requisition.height);
       else
 	 {
@@ -695,7 +714,7 @@
   gint y;

   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
-
+
   widget = GTK_WIDGET (spin_button);
   spin_shadow_type = spin_button_get_shadow_type (spin_button);

@@ -745,7 +764,8 @@
 			   state_type, shadow_type,
 			   NULL, widget, "spinbutton",
 			   arrow, TRUE,
-			   x, y, ARROW_SIZE, widget->requisition.height / 2
+			   x, y, spin_button->arrow_size,
+			   widget->requisition.height / 2
 			   - widget->style->ythickness);
 	}
       else
@@ -764,7 +784,8 @@
 			   state_type, shadow_type,
 			   NULL, widget, "spinbutton",
 			   arrow, TRUE,
-			   x, y, ARROW_SIZE, widget->requisition.height / 2
+			   x, y, spin_button->arrow_size,
+			   widget->requisition.height / 2
 			   - widget->style->ythickness);
 	}
     }
@@ -844,6 +865,29 @@
   return GTK_WIDGET_CLASS (parent_class)->focus_out_event (widget, event);
 }

+static void
+gtk_spin_button_style_set (GtkWidget *widget,
+			   GtkStyle  *previous_style)
+{
+  PangoFontMask mask;
+  GtkSpinButton *spin;
+
+  g_return_if_fail (GTK_IS_SPIN_BUTTON (widget));
+
+  spin = GTK_SPIN_BUTTON (widget);
+
+  /* font may have changed: update arrow size */
+  mask = pango_font_description_get_set_fields (widget->style->font_desc);
+  if (mask & PANGO_FONT_MASK_SIZE)
+    spin->arrow_size = PANGO_PIXELS (pango_font_description_get_size (widget->style->font_desc));
+  else
+    /* old default value */
+    spin->arrow_size = 11;
+
+  gtk_widget_queue_draw (widget);
+  gtk_widget_queue_resize (widget);
+}
+
 static gint
 gtk_spin_button_scroll (GtkWidget      *widget,
 			GdkEventScroll *event)
@@ -993,7 +1037,7 @@
 	{
 	  if (event->y >= 0 && event->x >= 0 &&
 	      event->y <= widget->requisition.height &&
-	      event->x <= ARROW_SIZE + 2 * widget->style->xthickness)
+	      event->x <= spin->arrow_size + 2 * widget->style->xthickness)
 	    {
 	      if (spin->click_child == GTK_ARROW_UP &&
 		  event->y <= widget->requisition.height / 2)
Index: gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.80
diff -u -r1.80 gtkstyle.c
--- gtkstyle.c	2001/09/18 20:06:46	1.80
+++ gtkstyle.c	2001/09/22 22:56:07
@@ -2558,15 +2558,20 @@

   if (detail && strcmp (detail, "spinbutton") == 0)
     {
-      x += (width - 7) / 2;
+      int hpad, vpad;
+
+      hpad = width / 4;
+
+      if (hpad < 4)
+	hpad = 4;
+
+      vpad = 2 * hpad - 1;

-      if (arrow_type == GTK_ARROW_UP)
-	y += (height - 4) / 2;
-      else
-	y += (1 + height - 4) / 2;
+      x += hpad / 2;
+      y += vpad / 2;

       draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
-		   x, y, 7, 4);
+		   x, y, width - hpad, height - vpad);
     }
   else if (detail && strcmp (detail, "vscrollbar") == 0)
     {
@@ -2575,10 +2580,9 @@

       x += (width - 7) / 2;
       y += (height - 5) / 2;
-
+
       draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
 		   x, y, 7, 5);
-
     }
   else if (detail && strcmp (detail, "hscrollbar") == 0)
     {





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