Mercurial > pidgin
comparison src/gtkimhtml.c @ 11006:5d3b0a920d83
[gaim-migrate @ 12866]
sf patch #1206146, from Ted Percival
"Fix smooth scrolling assertions"
(Start Gaim with the debug window enabled if you don't believe me)
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 14 Jun 2005 00:45:48 +0000 |
parents | 2d30f151146d |
children | 86725cfe0550 |
comparison
equal
deleted
inserted
replaced
11005:bb7fd9359f9e | 11006:5d3b0a920d83 |
---|---|
2239 if (!(options & GTK_IMHTML_NO_SCROLL)) { | 2239 if (!(options & GTK_IMHTML_NO_SCROLL)) { |
2240 gtk_imhtml_scroll_to_end(imhtml); | 2240 gtk_imhtml_scroll_to_end(imhtml); |
2241 } | 2241 } |
2242 } | 2242 } |
2243 | 2243 |
2244 #define MAX_SCROLL_TIME 0.4 | 2244 #define MAX_SCROLL_TIME 0.4 /* seconds */ |
2245 | 2245 #define SCROLL_DELAY 33 /* milliseconds */ |
2246 | |
2247 /* | |
2248 * Smoothly scroll a GtkIMHtml. | |
2249 * | |
2250 * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom. | |
2251 */ | |
2246 static gboolean scroll_cb(gpointer data) | 2252 static gboolean scroll_cb(gpointer data) |
2247 { | 2253 { |
2248 GtkIMHtml *imhtml = data; | 2254 GtkIMHtml *imhtml = data; |
2249 GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | 2255 GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; |
2250 gdouble val = adj->upper - adj->page_size; | 2256 gdouble max_val = adj->upper - adj->page_size; |
2251 gdouble t; | 2257 |
2252 | 2258 g_return_val_if_fail(imhtml->scroll_time != NULL, FALSE); |
2253 t = g_timer_elapsed(imhtml->scroll_time, NULL); | 2259 |
2254 | 2260 if (g_timer_elapsed(imhtml->scroll_time, NULL) > MAX_SCROLL_TIME) { |
2255 if (adj->value >= val || t >= MAX_SCROLL_TIME) { | 2261 /* time's up. jump to the end and kill the timer */ |
2256 gaim_debug_info("gtkimhtml", "scroll_cb: out of time\n"); | 2262 gtk_adjustment_set_value(adj, max_val); |
2257 gtk_adjustment_set_value(adj, val); | |
2258 } else { | |
2259 gtk_adjustment_set_value(adj, | |
2260 adj->value + (((val - adj->value) * t ) / MAX_SCROLL_TIME)); | |
2261 } | |
2262 | |
2263 if (adj->value >= val) { | |
2264 g_timer_destroy(imhtml->scroll_time); | 2263 g_timer_destroy(imhtml->scroll_time); |
2265 imhtml->scroll_time = NULL; | 2264 imhtml->scroll_time = NULL; |
2266 return FALSE; | 2265 return FALSE; |
2267 } else | 2266 } |
2268 return TRUE; | 2267 |
2268 /* scroll by 1/3rd the remaining distance */ | |
2269 gtk_adjustment_set_value(adj, gtk_adjustment_get_value(adj) + ((max_val - gtk_adjustment_get_value(adj)) / 3)); | |
2270 return TRUE; | |
2269 } | 2271 } |
2270 | 2272 |
2271 static gboolean scroll_idle_cb(gpointer data) | 2273 static gboolean scroll_idle_cb(gpointer data) |
2272 { | 2274 { |
2273 GtkIMHtml *imhtml = data; | 2275 GtkIMHtml *imhtml = data; |
2274 imhtml->scroll_src = g_timeout_add(33, scroll_cb, imhtml); | 2276 imhtml->scroll_src = g_timeout_add(SCROLL_DELAY, scroll_cb, imhtml); |
2275 return FALSE; | 2277 return FALSE; |
2276 } | 2278 } |
2277 | 2279 |
2278 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml) | 2280 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml) |
2279 { | 2281 { |