[PATCH] GtkProgressBar incorrectly calculates widget height



Here's a little snacky snack for the current stable gtk+ to fix some
broken progress bar behaviour.  Currently, widget height is calculated
using gdk_text_height, which is broken when you change the label text
to a string which contains taller characters from what was initially
used.

The attached patch applies to the gtk-1-2 branch and uses the
font->ascent and font->descent to calculate the correct height.  Note
that the decision was made to keep the font baseline fixed on the
progress bar, rather than always directly vertically centering the
text on the bar.  This behaviour is easy to change at line 720 or so,
but I believe that it is now correct as written.

I'm not on gtk-devel-list, so please CC me on any replies.  I'm happy
to apply the patch if someone gives me the go-ahead, and if I don't
hear from anyone in the next few days, I'll probably take that as
license to go ahead.

Thanks!

(BTW I briefly looked at HEAD but the code there seems substantially
different, and I'm not even sure if it's broken there.)

-- 
Ian Peters      "...it is 5 am and the sun has charred the other
itp gnu org      side of the earth and come back to us and painted
itp ximian com   the smoke over our heads an imperial violet..."
Index: gtkprogressbar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkprogressbar.c,v
retrieving revision 1.16
diff -u -r1.16 gtkprogressbar.c
--- gtkprogressbar.c	1999/02/24 07:35:55	1.16
+++ gtkprogressbar.c	2001/02/09 17:00:52
@@ -373,8 +373,8 @@
 
 	  requisition->height = MAX (MIN_HORIZONTAL_BAR_HEIGHT,
 				     2 * widget->style->klass->ythickness + 3 +
-				     gdk_text_height (widget->style->font, 
-						      buf, strlen (buf)) +
+				     widget->style->font->ascent +
+				     widget->style->font->descent +
 				     2 * TEXT_SPACING);
 	  g_free (buf);
 	}
@@ -399,8 +399,8 @@
 
 	  requisition->height = MAX (MIN_VERTICAL_BAR_HEIGHT,
 				     2 * widget->style->klass->ythickness + 3 +
-				     gdk_text_height (widget->style->font, 
-						      buf, strlen (buf)) +
+				     widget->style->font->ascent +
+				     widget->style->font->descent +
 				     2 * TEXT_SPACING);
 	  g_free (buf);
 	}
@@ -717,8 +717,7 @@
 
 	  y = widget->style->font->ascent + 1 +
 	    (widget->allocation.height - 2 * widget->style->klass->ythickness -
-	     3 - gdk_text_height (widget->style->font, buf, strlen (buf)))
-	    * progress->y_align;
+	     3 - widget->style->font->ascent) * progress->y_align;
 
 	  rect.x = widget->style->klass->xthickness + 1;
 	  rect.y = widget->style->klass->ythickness + 1;


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