pidgin: b426234b: Change the height-calculation of the ent...

sadrul at pidgin.im sadrul at pidgin.im
Fri Apr 4 02:05:45 EDT 2008


-----------------------------------------------------------------
Revision: b426234bbef68ed60bc6f15fc35ea1690d5a8ed1
Ancestor: ffa049c1806563e26f6a42e7480f11035b4321f4
Author: sadrul at pidgin.im
Date: 2008-04-04T06:09:21
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b426234bbef68ed60bc6f15fc35ea1690d5a8ed1

Modified files:
        pidgin/gtkconv.c

ChangeLog: 

Change the height-calculation of the entry widget a little bit. This should make it better when text with smileys is pasted. If this is even more buggy than it currently is, let me know\! Fixes #5426.

-------------- next part --------------
============================================================
--- pidgin/gtkconv.c	cc7999937fb84fa678ed6b0dc51b0ec0ef762185
+++ pidgin/gtkconv.c	55e9ec08b98b4408d72b56f6fb462910444293a3
@@ -4363,34 +4363,36 @@ static gboolean resize_imhtml_cb(PidginC
 {
 	GtkTextBuffer *buffer;
 	GtkTextIter iter;
-	int wrapped_lines;
 	int lines;
 	GdkRectangle oneline;
 	int height, diff;
 	int pad_top, pad_inside, pad_bottom;
 	int max_height = gtkconv->tab_cont->allocation.height / 2;
 
+	pad_top = gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(gtkconv->entry));
+	pad_bottom = gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(gtkconv->entry));
+	pad_inside = gtk_text_view_get_pixels_inside_wrap(GTK_TEXT_VIEW(gtkconv->entry));
+
 	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
-
-	wrapped_lines = 1;
 	gtk_text_buffer_get_start_iter(buffer, &iter);
 	gtk_text_view_get_iter_location(GTK_TEXT_VIEW(gtkconv->entry), &iter, &oneline);
-	while (gtk_text_view_forward_display_line(GTK_TEXT_VIEW(gtkconv->entry), &iter))
-		wrapped_lines++;
 
 	lines = gtk_text_buffer_get_line_count(buffer);
 
-	/* Show at least two lines */
-	wrapped_lines = MAX(wrapped_lines, 2);
+	height = 0;
+	do {
+		int lineheight = 0;
+		gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(gtkconv->entry), &iter, NULL, &lineheight);
+		height += lineheight;
+		lines--;
+	} while (gtk_text_iter_forward_line(&iter));
+	height += lines * (oneline.height + pad_top + pad_bottom);
 
-	pad_top = gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(gtkconv->entry));
-	pad_bottom = gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(gtkconv->entry));
-	pad_inside = gtk_text_view_get_pixels_inside_wrap(GTK_TEXT_VIEW(gtkconv->entry));
+	/* Make sure there's enough room for at least two lines. Allocate enough space to
+	 * prevent scrolling when the second line is a continuation of the first line, or
+	 * is the beginning of a new paragraph. */
+	height = MAX(height, 2 * (oneline.height + MAX(pad_inside, pad_top + pad_bottom)));
 
-	height = (oneline.height + pad_top + pad_bottom) * lines;
-	if (wrapped_lines > lines)
-		height += (oneline.height + pad_inside) * (wrapped_lines - lines);
-
 	height = MIN(height, max_height);
 
 	diff = height - gtkconv->entry->allocation.height;


More information about the Commits mailing list