comparison src/gtkimhtml.c @ 11840:047f85200139

[gaim-migrate @ 14131] SF Patch #1338002 from sadrul "When an image in a non-editable GtkIMHtml is just enough wide/long to cause the imhtml to have a scrollbar, the size-allocate callback for the imhtml falls into an infinite loop. Bleeter hit this bug with the profile of a specific yahoo-id. So did I. This patch prevents such lockups." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Wed, 26 Oct 2005 08:35:12 +0000
parents 2cf6d4cf2cb0
children a0956e22fdde
comparison
equal deleted inserted replaced
11839:216a05e0a6f1 11840:047f85200139
379 } 379 }
380 g_free (t); 380 g_free (t);
381 } 381 }
382 } 382 }
383 383
384 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) 384 static void gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data)
385 { 385 {
386 GdkRectangle rect; 386 GdkRectangle rect;
387 int xminus; 387 int xminus;
388 388
389 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); 389 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect);
401 iter = iter->next; 401 iter = iter->next;
402 } 402 }
403 } 403 }
404 404
405 widget->old_rect = rect; 405 widget->old_rect = rect;
406 return FALSE; 406 return;
407 } 407 }
408 408
409 static gint 409 static gint
410 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) 410 gtk_imhtml_tip_paint (GtkIMHtml *imhtml)
411 { 411 {
3150 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) 3150 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height)
3151 { 3151 {
3152 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; 3152 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
3153 3153
3154 if(image->width > width || image->height > height){ 3154 if(image->width > width || image->height > height){
3155 double ratio_w, ratio_h, ratio;
3156 int new_h, new_w;
3155 GdkPixbuf *new_image = NULL; 3157 GdkPixbuf *new_image = NULL;
3156 float factor; 3158
3157 int new_width = image->width, new_height = image->height; 3159 ratio_w = ((double)width - 2) / image->width;
3158 3160 ratio_h = ((double)height - 2) / image->height;
3159 if(image->width > (width - 2)){ 3161
3160 factor = (float)(width)/image->width; 3162 ratio = (ratio_w < ratio_h) ? ratio_w : ratio_h;
3161 new_width = width; 3163
3162 new_height = image->height * factor; 3164 new_w = (int)(image->width * ratio);
3163 } 3165 new_h = (int)(image->height * ratio);
3164 if(new_height >= (height - 2)){ 3166
3165 factor = (float)(height)/new_height; 3167 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_w, new_h, GDK_INTERP_BILINEAR);
3166 new_height = height;
3167 new_width = new_width * factor;
3168 }
3169
3170 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR);
3171 gtk_image_set_from_pixbuf(image->image, new_image); 3168 gtk_image_set_from_pixbuf(image->image, new_image);
3172 g_object_unref(G_OBJECT(new_image)); 3169 g_object_unref(G_OBJECT(new_image));
3173 } 3170 }
3174 } 3171 }
3175 3172