# HG changeset patch # User Tim Ringenbach # Date 1113000242 0 # Node ID 08981462ebbb31313bdb44e0237228f46e12d69c # Parent 5335eb2b8b9524671e15447459e8043654d8b7cb [gaim-migrate @ 12441] smooth scrolling I'll assume you can figure out how to adjust how long it takes to scroll, so you can play with it. I expect feedback. committer: Tailor Script diff -r 5335eb2b8b95 -r 08981462ebbb src/gtkimhtml.c --- a/src/gtkimhtml.c Fri Apr 08 20:47:19 2005 +0000 +++ b/src/gtkimhtml.c Fri Apr 08 22:44:02 2005 +0000 @@ -1061,6 +1061,11 @@ GList *scalables; GSList *l; + if (imhtml->scroll_src) + g_source_remove(imhtml->scroll_src); + if (imhtml->scroll_time) + g_timer_destroy(imhtml->scroll_time); + g_hash_table_destroy(imhtml->smiley_data); gtk_smiley_tree_destroy(imhtml->default_smilies); gdk_cursor_unref(imhtml->hand_cursor); @@ -2165,21 +2170,51 @@ } } +#define MAX_SCROLL_TIME 0.5 + +gboolean scroll_cb(gpointer data) +{ + GtkIMHtml *imhtml = data; + GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; + gdouble val = adj->upper - adj->page_size; + gdouble t; + + t = g_timer_elapsed(imhtml->scroll_time, NULL); + + + gaim_debug_info("gtkimhtml", "in scroll_cb\n"); + + if (adj->value >= val || t >= MAX_SCROLL_TIME) { + gaim_debug_info("gtkimhtml", "scroll_cb: out of time\n"); + gtk_adjustment_set_value(adj, val); + } else { + gtk_adjustment_set_value(adj, + adj->value + (((val - adj->value) * t ) / MAX_SCROLL_TIME)); + } + + if (adj->value >= val) { + g_timer_destroy(imhtml->scroll_time); + imhtml->scroll_time = NULL; + return FALSE; + } else + return TRUE; +} + gboolean scroll_idle_cb(gpointer data) { - GtkTextView *imhtml = data; - GtkAdjustment *adj; - - gaim_debug_info("gtkimhtml", "in scroll_idle_cb\n"); - adj = GTK_TEXT_VIEW(imhtml)->vadjustment; - gtk_adjustment_set_value(adj, adj->upper - adj->page_size); - + GtkIMHtml *imhtml = data; + imhtml->scroll_src = g_timeout_add(33, scroll_cb, imhtml); return FALSE; } void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml) { - g_idle_add_full(GTK_TEXT_VIEW_PRIORITY_VALIDATE + 10, scroll_idle_cb, imhtml, NULL); + if (imhtml->scroll_time) + g_timer_destroy(imhtml->scroll_time); + imhtml->scroll_time = g_timer_new(); + if (imhtml->scroll_src) + g_source_remove(imhtml->scroll_src); + imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, imhtml, NULL); } void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, diff -r 5335eb2b8b95 -r 08981462ebbb src/gtkimhtml.h --- a/src/gtkimhtml.h Fri Apr 08 20:47:19 2005 +0000 +++ b/src/gtkimhtml.h Fri Apr 08 22:44:02 2005 +0000 @@ -81,6 +81,8 @@ GHashTable *smiley_data; GtkSmileyTree *default_smilies; char *protocol_name; + guint scroll_src; + GTimer *scroll_time; gboolean show_comments;