changeset 28971:eb024bcff0c9

timestamp: Do not scroll down if it was scrolled up. Also, avoid an unnecessary lookup in the tag-table. Fixes #10440.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 04 Feb 2010 18:27:58 +0000
parents 757a386a5c93
children 1956b27ed87c
files pidgin/plugins/timestamp.c
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/plugins/timestamp.c	Thu Feb 04 05:46:37 2010 +0000
+++ b/pidgin/plugins/timestamp.c	Thu Feb 04 18:27:58 2010 +0000
@@ -49,25 +49,33 @@
 	const char *mdate;
 	int y, height;
 	GdkRectangle rect;
+	gboolean scrolled = FALSE;
+	GtkTextTag *tag;
 
 	/* display timestamp */
 	mdate = purple_utf8_strftime(then == 0 ? "%H:%M" : "\n%H:%M",
 		localtime(&now));
 	gtk_text_buffer_get_end_iter(buffer, &iter);
 
-	if (gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), "TIMESTAMP") == NULL)
-		gtk_text_buffer_create_tag(buffer, "TIMESTAMP",
+	/* is the view already scrolled? */
+	gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
+	gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height);
+	if (((y + height) - (rect.y + rect.height)) > height)
+		scrolled = TRUE;
+
+	if ((tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), "TIMESTAMP")) == NULL)
+		tag = gtk_text_buffer_create_tag(buffer, "TIMESTAMP",
 			"foreground", "#888888", "justification", GTK_JUSTIFY_CENTER,
 			"weight", PANGO_WEIGHT_BOLD, NULL);
 
-	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, mdate,
-		strlen(mdate), "TIMESTAMP", NULL);
+	gtk_text_buffer_insert_with_tags(buffer, &iter, mdate,
+		strlen(mdate), tag, NULL);
 
 	/* scroll view if necessary */
 	gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
 	gtk_text_view_get_line_yrange(
 		GTK_TEXT_VIEW(imhtml), &iter, &y, &height);
-	if (((y + height) - (rect.y + rect.height)) > height &&
+	if (!scrolled && ((y + height) - (rect.y + rect.height)) > height &&
 	    gtk_text_buffer_get_char_count(buffer)) {
 		gboolean smooth = purple_prefs_get_bool(
 			PIDGIN_PREFS_ROOT "/conversations/use_smooth_scrolling");