comparison pidgin/plugins/timestamp.c @ 29361: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 ea62e934c80b
children
comparison
equal deleted inserted replaced
29359:757a386a5c93 29361:eb024bcff0c9
47 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml)); 47 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml));
48 GtkTextIter iter; 48 GtkTextIter iter;
49 const char *mdate; 49 const char *mdate;
50 int y, height; 50 int y, height;
51 GdkRectangle rect; 51 GdkRectangle rect;
52 gboolean scrolled = FALSE;
53 GtkTextTag *tag;
52 54
53 /* display timestamp */ 55 /* display timestamp */
54 mdate = purple_utf8_strftime(then == 0 ? "%H:%M" : "\n%H:%M", 56 mdate = purple_utf8_strftime(then == 0 ? "%H:%M" : "\n%H:%M",
55 localtime(&now)); 57 localtime(&now));
56 gtk_text_buffer_get_end_iter(buffer, &iter); 58 gtk_text_buffer_get_end_iter(buffer, &iter);
57 59
58 if (gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), "TIMESTAMP") == NULL) 60 /* is the view already scrolled? */
59 gtk_text_buffer_create_tag(buffer, "TIMESTAMP", 61 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
62 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height);
63 if (((y + height) - (rect.y + rect.height)) > height)
64 scrolled = TRUE;
65
66 if ((tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), "TIMESTAMP")) == NULL)
67 tag = gtk_text_buffer_create_tag(buffer, "TIMESTAMP",
60 "foreground", "#888888", "justification", GTK_JUSTIFY_CENTER, 68 "foreground", "#888888", "justification", GTK_JUSTIFY_CENTER,
61 "weight", PANGO_WEIGHT_BOLD, NULL); 69 "weight", PANGO_WEIGHT_BOLD, NULL);
62 70
63 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, mdate, 71 gtk_text_buffer_insert_with_tags(buffer, &iter, mdate,
64 strlen(mdate), "TIMESTAMP", NULL); 72 strlen(mdate), tag, NULL);
65 73
66 /* scroll view if necessary */ 74 /* scroll view if necessary */
67 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); 75 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
68 gtk_text_view_get_line_yrange( 76 gtk_text_view_get_line_yrange(
69 GTK_TEXT_VIEW(imhtml), &iter, &y, &height); 77 GTK_TEXT_VIEW(imhtml), &iter, &y, &height);
70 if (((y + height) - (rect.y + rect.height)) > height && 78 if (!scrolled && ((y + height) - (rect.y + rect.height)) > height &&
71 gtk_text_buffer_get_char_count(buffer)) { 79 gtk_text_buffer_get_char_count(buffer)) {
72 gboolean smooth = purple_prefs_get_bool( 80 gboolean smooth = purple_prefs_get_bool(
73 PIDGIN_PREFS_ROOT "/conversations/use_smooth_scrolling"); 81 PIDGIN_PREFS_ROOT "/conversations/use_smooth_scrolling");
74 gtk_imhtml_scroll_to_end(GTK_IMHTML(imhtml), smooth); 82 gtk_imhtml_scroll_to_end(GTK_IMHTML(imhtml), smooth);
75 } 83 }