Mercurial > pidgin
comparison src/gtkimhtml.c @ 10798:08981462ebbb
[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 <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Fri, 08 Apr 2005 22:44:02 +0000 |
parents | 5335eb2b8b95 |
children | 6f67d4088da0 |
comparison
equal
deleted
inserted
replaced
10797:5335eb2b8b95 | 10798:08981462ebbb |
---|---|
1058 gtk_imhtml_finalize (GObject *object) | 1058 gtk_imhtml_finalize (GObject *object) |
1059 { | 1059 { |
1060 GtkIMHtml *imhtml = GTK_IMHTML(object); | 1060 GtkIMHtml *imhtml = GTK_IMHTML(object); |
1061 GList *scalables; | 1061 GList *scalables; |
1062 GSList *l; | 1062 GSList *l; |
1063 | |
1064 if (imhtml->scroll_src) | |
1065 g_source_remove(imhtml->scroll_src); | |
1066 if (imhtml->scroll_time) | |
1067 g_timer_destroy(imhtml->scroll_time); | |
1063 | 1068 |
1064 g_hash_table_destroy(imhtml->smiley_data); | 1069 g_hash_table_destroy(imhtml->smiley_data); |
1065 gtk_smiley_tree_destroy(imhtml->default_smilies); | 1070 gtk_smiley_tree_destroy(imhtml->default_smilies); |
1066 gdk_cursor_unref(imhtml->hand_cursor); | 1071 gdk_cursor_unref(imhtml->hand_cursor); |
1067 gdk_cursor_unref(imhtml->arrow_cursor); | 1072 gdk_cursor_unref(imhtml->arrow_cursor); |
2163 if (!(options & GTK_IMHTML_NO_SCROLL)) { | 2168 if (!(options & GTK_IMHTML_NO_SCROLL)) { |
2164 gtk_imhtml_scroll_to_end(imhtml); | 2169 gtk_imhtml_scroll_to_end(imhtml); |
2165 } | 2170 } |
2166 } | 2171 } |
2167 | 2172 |
2173 #define MAX_SCROLL_TIME 0.5 | |
2174 | |
2175 gboolean scroll_cb(gpointer data) | |
2176 { | |
2177 GtkIMHtml *imhtml = data; | |
2178 GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
2179 gdouble val = adj->upper - adj->page_size; | |
2180 gdouble t; | |
2181 | |
2182 t = g_timer_elapsed(imhtml->scroll_time, NULL); | |
2183 | |
2184 | |
2185 gaim_debug_info("gtkimhtml", "in scroll_cb\n"); | |
2186 | |
2187 if (adj->value >= val || t >= MAX_SCROLL_TIME) { | |
2188 gaim_debug_info("gtkimhtml", "scroll_cb: out of time\n"); | |
2189 gtk_adjustment_set_value(adj, val); | |
2190 } else { | |
2191 gtk_adjustment_set_value(adj, | |
2192 adj->value + (((val - adj->value) * t ) / MAX_SCROLL_TIME)); | |
2193 } | |
2194 | |
2195 if (adj->value >= val) { | |
2196 g_timer_destroy(imhtml->scroll_time); | |
2197 imhtml->scroll_time = NULL; | |
2198 return FALSE; | |
2199 } else | |
2200 return TRUE; | |
2201 } | |
2202 | |
2168 gboolean scroll_idle_cb(gpointer data) | 2203 gboolean scroll_idle_cb(gpointer data) |
2169 { | 2204 { |
2170 GtkTextView *imhtml = data; | 2205 GtkIMHtml *imhtml = data; |
2171 GtkAdjustment *adj; | 2206 imhtml->scroll_src = g_timeout_add(33, scroll_cb, imhtml); |
2172 | |
2173 gaim_debug_info("gtkimhtml", "in scroll_idle_cb\n"); | |
2174 adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
2175 gtk_adjustment_set_value(adj, adj->upper - adj->page_size); | |
2176 | |
2177 return FALSE; | 2207 return FALSE; |
2178 } | 2208 } |
2179 | 2209 |
2180 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml) | 2210 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml) |
2181 { | 2211 { |
2182 g_idle_add_full(GTK_TEXT_VIEW_PRIORITY_VALIDATE + 10, scroll_idle_cb, imhtml, NULL); | 2212 if (imhtml->scroll_time) |
2213 g_timer_destroy(imhtml->scroll_time); | |
2214 imhtml->scroll_time = g_timer_new(); | |
2215 if (imhtml->scroll_src) | |
2216 g_source_remove(imhtml->scroll_src); | |
2217 imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, imhtml, NULL); | |
2183 } | 2218 } |
2184 | 2219 |
2185 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, | 2220 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, |
2186 const gchar *text, | 2221 const gchar *text, |
2187 GtkIMHtmlOptions options, | 2222 GtkIMHtmlOptions options, |