#50200: patch



Hi,

Here's a patch for #50200 (gtkspinbutton hardcodes ARROW_SIZE), diffed
more recently. ChangeLog:


Fri Oct  5 18:32:30 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

        Fixes bug #50200


The actual patch has been appended.

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/10/05 16:27:16
@@ -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.75
diff -u -r1.75 gtkspinbutton.c
--- gtkspinbutton.c	2001/10/03 21:50:57	1.75
+++ gtkspinbutton.c	2001/10/05 16:27:18
@@ -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
@@ -102,6 +101,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);
@@ -201,6 +202,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->activate = gtk_spin_button_activate;

@@ -413,6 +415,8 @@
 static void
 gtk_spin_button_init (GtkSpinButton *spin_button)
 {
+  PangoFontMask mask;
+
   spin_button->adjustment = NULL;
   spin_button->panel = NULL;
   spin_button->timer = 0;
@@ -431,6 +435,15 @@
   spin_button->snap_to_ticks = FALSE;
   gtk_spin_button_set_adjustment (spin_button,
 	  (GtkAdjustment*) gtk_adjustment_new (0, 0, 0, 0, 0, 0));
+
+  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;
+
+
 }

 static void
@@ -481,7 +494,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);
@@ -499,11 +513,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),
@@ -608,27 +623,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);

@@ -636,11 +656,12 @@

   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;
@@ -681,7 +702,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
 	 {
@@ -761,7 +782,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
@@ -780,7 +802,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);
 	}
     }
@@ -860,6 +883,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)
@@ -1009,7 +1055,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.85
diff -u -r1.85 gtkstyle.c
--- gtkstyle.c	2001/10/03 19:48:54	1.85
+++ gtkstyle.c	2001/10/05 16:27:22
@@ -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]