comparison pidgin/gtkimhtml.c @ 25512:ff69c2a9ccf2

propagate from branch 'im.pidgin.pidgin' (head 725fc6cb64d550dcc3a71741a974e5255f83a366) to branch 'im.pidgin.pidgin.yaz' (head 51241dcb972c543304c03eb0b9edc39a64ba3c6f)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 17 Jun 2007 05:28:54 +0000
parents fb0b82b40f98 97b735ca9d7a
children 90d558470507
comparison
equal deleted inserted replaced
25511:7a3c3c360624 25512:ff69c2a9ccf2
25 */ 25 */
26 26
27 #ifdef HAVE_CONFIG_H 27 #ifdef HAVE_CONFIG_H
28 #include <config.h> 28 #include <config.h>
29 #endif 29 #endif
30
31 #include "pidgin.h"
32
30 #include "debug.h" 33 #include "debug.h"
31 #include "util.h" 34 #include "util.h"
32 #include "gtkimhtml.h" 35 #include "gtkimhtml.h"
33 #include "gtksourceiter.h" 36 #include "gtksourceiter.h"
37 #include "gtksourceundomanager.h"
38 #include "gtksourceview-marshal.h"
34 #include <gtk/gtk.h> 39 #include <gtk/gtk.h>
35 #include <glib/gerror.h> 40 #include <glib/gerror.h>
36 #include <gdk/gdkkeysyms.h> 41 #include <gdk/gdkkeysyms.h>
37 #include <string.h> 42 #include <string.h>
38 #include <ctype.h> 43 #include <ctype.h>
138 BUTTONS_UPDATE, 143 BUTTONS_UPDATE,
139 TOGGLE_FORMAT, 144 TOGGLE_FORMAT,
140 CLEAR_FORMAT, 145 CLEAR_FORMAT,
141 UPDATE_FORMAT, 146 UPDATE_FORMAT,
142 MESSAGE_SEND, 147 MESSAGE_SEND,
148 UNDO,
149 REDO,
143 LAST_SIGNAL 150 LAST_SIGNAL
144 }; 151 };
145 static guint signals [LAST_SIGNAL] = { 0 }; 152 static guint signals [LAST_SIGNAL] = { 0 };
146 153
147 static char *html_clipboard = NULL; 154 static char *html_clipboard = NULL;
1154 1161
1155 return TRUE; 1162 return TRUE;
1156 } 1163 }
1157 1164
1158 return FALSE; 1165 return FALSE;
1166 }
1167
1168 static void
1169 gtk_imhtml_undo(GtkIMHtml *imhtml) {
1170 g_return_if_fail(GTK_IS_IMHTML(imhtml));
1171 g_return_if_fail(imhtml->editable);
1172
1173 gtk_source_undo_manager_undo(imhtml->undo_manager);
1174 }
1175
1176 static void
1177 gtk_imhtml_redo(GtkIMHtml *imhtml) {
1178 g_return_if_fail(GTK_IS_IMHTML(imhtml));
1179 g_return_if_fail(imhtml->editable);
1180
1181 gtk_source_undo_manager_redo(imhtml->undo_manager);
1182
1159 } 1183 }
1160 1184
1161 static gboolean imhtml_message_send(GtkIMHtml *imhtml) 1185 static gboolean imhtml_message_send(GtkIMHtml *imhtml)
1162 { 1186 {
1163 return FALSE; 1187 return FALSE;
1234 g_list_free(imhtml->scalables); 1258 g_list_free(imhtml->scalables);
1235 g_slist_free(imhtml->im_images); 1259 g_slist_free(imhtml->im_images);
1236 g_queue_free(imhtml->animations); 1260 g_queue_free(imhtml->animations);
1237 g_free(imhtml->protocol_name); 1261 g_free(imhtml->protocol_name);
1238 g_free(imhtml->search_string); 1262 g_free(imhtml->search_string);
1263 g_object_unref(imhtml->undo_manager);
1239 G_OBJECT_CLASS(parent_class)->finalize (object); 1264 G_OBJECT_CLASS(parent_class)->finalize (object);
1240 if (clipboard_selection) 1265 if (clipboard_selection)
1241 gtk_clipboard_set_with_owner(clipboard_selection, 1266 gtk_clipboard_set_with_owner(clipboard_selection,
1242 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), 1267 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
1243 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, 1268 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
1303 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, 1328 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1304 G_STRUCT_OFFSET(GtkIMHtmlClass, message_send), 1329 G_STRUCT_OFFSET(GtkIMHtmlClass, message_send),
1305 NULL, 1330 NULL,
1306 0, g_cclosure_marshal_VOID__VOID, 1331 0, g_cclosure_marshal_VOID__VOID,
1307 G_TYPE_NONE, 0); 1332 G_TYPE_NONE, 0);
1333 signals [UNDO] = g_signal_new ("undo",
1334 G_TYPE_FROM_CLASS (klass),
1335 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1336 G_STRUCT_OFFSET (GtkIMHtmlClass, undo),
1337 NULL,
1338 NULL,
1339 gtksourceview_marshal_VOID__VOID,
1340 G_TYPE_NONE,
1341 0);
1342 signals [REDO] = g_signal_new ("redo",
1343 G_TYPE_FROM_CLASS (klass),
1344 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1345 G_STRUCT_OFFSET (GtkIMHtmlClass, redo),
1346 NULL,
1347 NULL,
1348 gtksourceview_marshal_VOID__VOID,
1349 G_TYPE_NONE,
1350 0);
1351
1352
1308 1353
1309 klass->toggle_format = imhtml_toggle_format; 1354 klass->toggle_format = imhtml_toggle_format;
1310 klass->message_send = imhtml_message_send; 1355 klass->message_send = imhtml_message_send;
1311 klass->clear_format = imhtml_clear_formatting; 1356 klass->clear_format = imhtml_clear_formatting;
1357 klass->undo = gtk_imhtml_undo;
1358 klass->redo = gtk_imhtml_redo;
1312 1359
1313 gobject_class->finalize = gtk_imhtml_finalize; 1360 gobject_class->finalize = gtk_imhtml_finalize;
1314 widget_class->drag_motion = gtk_text_view_drag_motion; 1361 widget_class->drag_motion = gtk_text_view_drag_motion;
1315 widget_class->expose_event = gtk_imhtml_expose_event; 1362 widget_class->expose_event = gtk_imhtml_expose_event;
1316 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color", 1363 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color",
1331 gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK); 1378 gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK);
1332 binding_set = gtk_binding_set_by_class(klass); 1379 binding_set = gtk_binding_set_by_class(klass);
1333 gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0); 1380 gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0);
1334 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0); 1381 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0);
1335 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "message_send", 0); 1382 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "message_send", 0);
1383 gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK, "undo", 0);
1384 gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "redo", 0);
1385 gtk_binding_entry_add_signal (binding_set, GDK_F14, 0, "undo", 0);
1386
1336 } 1387 }
1337 1388
1338 static void gtk_imhtml_init (GtkIMHtml *imhtml) 1389 static void gtk_imhtml_init (GtkIMHtml *imhtml)
1339 { 1390 {
1340 GtkTextIter iter; 1391 GtkTextIter iter;
1341 imhtml->text_buffer = gtk_text_buffer_new(NULL); 1392 imhtml->text_buffer = gtk_text_buffer_new(NULL);
1393 imhtml->undo_manager = gtk_source_undo_manager_new(imhtml->text_buffer);
1342 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); 1394 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter);
1343 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); 1395 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer);
1344 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); 1396 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR);
1345 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); 1397 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5);
1346 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2); 1398 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2);
3119 3171
3120 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ 3172 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */
3121 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id) 3173 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id)
3122 { 3174 {
3123 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); 3175 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage));
3124 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img));
3125 3176
3126 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; 3177 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
3127 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; 3178 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to;
3128 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; 3179 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free;
3129 3180
3130 im_image->pixbuf = img; 3181 im_image->pixbuf = img;
3131 im_image->image = image; 3182 im_image->image = GTK_IMAGE(gtk_image_new_from_pixbuf(im_image->pixbuf));
3132 im_image->width = gdk_pixbuf_get_width(img); 3183 im_image->width = gdk_pixbuf_get_width(img);
3133 im_image->height = gdk_pixbuf_get_height(img); 3184 im_image->height = gdk_pixbuf_get_height(img);
3134 im_image->mark = NULL; 3185 im_image->mark = NULL;
3135 im_image->filename = g_strdup(filename); 3186 im_image->filename = g_strdup(filename);
3136 im_image->id = id; 3187 im_image->id = id;
3137 im_image->filesel = NULL; 3188 im_image->filesel = NULL;
3138 3189
3139 g_object_ref(img); 3190 g_object_ref(img);
3191 return GTK_IMHTML_SCALABLE(im_image);
3192 }
3193
3194 static gboolean
3195 animate_image_cb(gpointer data)
3196 {
3197 GtkIMHtmlImage *im_image;
3198 int width, height;
3199 int delay;
3200
3201 im_image = data;
3202
3203 /* Update the pointer to this GdkPixbuf frame of the animation */
3204 g_object_unref(G_OBJECT(im_image->pixbuf));
3205 gdk_pixbuf_animation_iter_advance(GTK_IMHTML_ANIMATION(im_image)->iter, NULL);
3206 im_image->pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(GTK_IMHTML_ANIMATION(im_image)->iter);
3207 g_object_ref(G_OBJECT(im_image->pixbuf));
3208
3209 /* Update the displayed GtkImage */
3210 width = gdk_pixbuf_get_width(gtk_image_get_pixbuf(im_image->image));
3211 height = gdk_pixbuf_get_height(gtk_image_get_pixbuf(im_image->image));
3212 if (width > 0 && height > 0)
3213 {
3214 /* Need to scale the new frame to the same size as the old frame */
3215 GdkPixbuf *tmp;
3216 tmp = gdk_pixbuf_scale_simple(im_image->pixbuf, width, height, GDK_INTERP_BILINEAR);
3217 gtk_image_set_from_pixbuf(im_image->image, tmp);
3218 g_object_unref(G_OBJECT(tmp));
3219 } else {
3220 /* Display at full-size */
3221 gtk_image_set_from_pixbuf(im_image->image, im_image->pixbuf);
3222 }
3223
3224 delay = MIN(gdk_pixbuf_animation_iter_get_delay_time(GTK_IMHTML_ANIMATION(im_image)->iter), 100);
3225 GTK_IMHTML_ANIMATION(im_image)->timer = g_timeout_add(delay, animate_image_cb, im_image);
3226
3227 return FALSE;
3228 }
3229
3230 GtkIMHtmlScalable *gtk_imhtml_animation_new(GdkPixbufAnimation *anim, const gchar *filename, int id)
3231 {
3232 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlAnimation));
3233
3234 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
3235 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to;
3236 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_animation_free;
3237
3238 GTK_IMHTML_ANIMATION(im_image)->anim = anim;
3239 if (gdk_pixbuf_animation_is_static_image(anim)) {
3240 GTK_IMHTML_ANIMATION(im_image)->iter = NULL;
3241 im_image->pixbuf = gdk_pixbuf_animation_get_static_image(anim);
3242 GTK_IMHTML_ANIMATION(im_image)->timer = 0;
3243 } else {
3244 int delay;
3245 GTK_IMHTML_ANIMATION(im_image)->iter = gdk_pixbuf_animation_get_iter(anim, NULL);
3246 im_image->pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(GTK_IMHTML_ANIMATION(im_image)->iter);
3247 delay = MIN(gdk_pixbuf_animation_iter_get_delay_time(GTK_IMHTML_ANIMATION(im_image)->iter), 100);
3248 GTK_IMHTML_ANIMATION(im_image)->timer = g_timeout_add(delay, animate_image_cb, im_image);
3249 }
3250 im_image->image = GTK_IMAGE(gtk_image_new_from_pixbuf(im_image->pixbuf));
3251 im_image->width = gdk_pixbuf_animation_get_width(anim);
3252 im_image->height = gdk_pixbuf_animation_get_height(anim);
3253 im_image->mark = NULL;
3254 im_image->filename = g_strdup(filename);
3255 im_image->id = id;
3256 im_image->filesel = NULL;
3257
3258 g_object_ref(anim);
3259 g_object_ref(im_image->pixbuf);
3260
3140 return GTK_IMHTML_SCALABLE(im_image); 3261 return GTK_IMHTML_SCALABLE(im_image);
3141 } 3262 }
3142 3263
3143 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) 3264 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height)
3144 { 3265 {
3412 } 3533 }
3413 3534
3414 static gboolean gtk_imhtml_smiley_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlSmiley *smiley) 3535 static gboolean gtk_imhtml_smiley_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlSmiley *smiley)
3415 { 3536 {
3416 GdkPixbufAnimation *anim = NULL; 3537 GdkPixbufAnimation *anim = NULL;
3417 GdkPixbuf *pix = NULL;
3418 GtkIMHtmlScalable *image = NULL; 3538 GtkIMHtmlScalable *image = NULL;
3419 gboolean ret; 3539 gboolean ret;
3420 3540
3421 if (event->type != GDK_BUTTON_RELEASE || ((GdkEventButton*)event)->button != 3) 3541 if (event->type != GDK_BUTTON_RELEASE || ((GdkEventButton*)event)->button != 3)
3422 return FALSE; 3542 return FALSE;
3423 3543
3424 anim = gtk_smiley_get_image(smiley); 3544 anim = gtk_smiley_get_image(smiley);
3425 if (!anim) 3545 if (!anim)
3426 return FALSE; 3546 return FALSE;
3427 3547
3428 pix = gdk_pixbuf_animation_get_static_image(anim); 3548 image = gtk_imhtml_animation_new(anim, smiley->smile, 0);
3429 image = gtk_imhtml_image_new(pix, smiley->smile, 0);
3430 ret = gtk_imhtml_image_clicked(w, event, (GtkIMHtmlImage*)image); 3549 ret = gtk_imhtml_image_clicked(w, event, (GtkIMHtmlImage*)image);
3431 g_object_set_data_full(G_OBJECT(w), "image-data", image, (GDestroyNotify)gtk_imhtml_image_free); 3550 g_object_set_data_full(G_OBJECT(w), "image-data", image, (GDestroyNotify)gtk_imhtml_image_free);
3432 g_object_unref(G_OBJECT(pix));
3433 return ret; 3551 return ret;
3434 } 3552 }
3435 3553
3436 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) 3554 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale)
3437 { 3555 {
3440 g_object_unref(image->pixbuf); 3558 g_object_unref(image->pixbuf);
3441 g_free(image->filename); 3559 g_free(image->filename);
3442 if (image->filesel) 3560 if (image->filesel)
3443 gtk_widget_destroy(image->filesel); 3561 gtk_widget_destroy(image->filesel);
3444 g_free(scale); 3562 g_free(scale);
3563 }
3564
3565 void gtk_imhtml_animation_free(GtkIMHtmlScalable *scale)
3566 {
3567 GtkIMHtmlAnimation *animation = (GtkIMHtmlAnimation *)scale;
3568
3569 if (animation->timer > 0)
3570 g_source_remove(animation->timer);
3571 if (animation->iter != NULL)
3572 g_object_unref(animation->iter);
3573 g_object_unref(animation->anim);
3574
3575 gtk_imhtml_image_free(scale);
3445 } 3576 }
3446 3577
3447 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) 3578 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter)
3448 { 3579 {
3449 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; 3580 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
4522 g_free(unescaped); 4653 g_free(unescaped);
4523 } 4654 }
4524 4655
4525 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter) 4656 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter)
4526 { 4657 {
4527 GdkPixbuf *pixbuf = NULL; 4658 GdkPixbufAnimation *anim = NULL;
4528 const char *filename = NULL; 4659 const char *filename = NULL;
4529 gpointer image; 4660 gpointer image;
4530 GdkRectangle rect; 4661 GdkRectangle rect;
4531 GtkIMHtmlScalable *scalable = NULL; 4662 GtkIMHtmlScalable *scalable = NULL;
4532 struct scalable_data *sd; 4663 struct scalable_data *sd;
4549 4680
4550 if (data && len) { 4681 if (data && len) {
4551 GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); 4682 GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
4552 gdk_pixbuf_loader_write(loader, data, len, NULL); 4683 gdk_pixbuf_loader_write(loader, data, len, NULL);
4553 gdk_pixbuf_loader_close(loader, NULL); 4684 gdk_pixbuf_loader_close(loader, NULL);
4554 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); 4685 anim = gdk_pixbuf_loader_get_animation(loader);
4555 if (pixbuf) 4686 if (anim)
4556 g_object_ref(G_OBJECT(pixbuf)); 4687 g_object_ref(G_OBJECT(anim));
4557 g_object_unref(G_OBJECT(loader)); 4688 g_object_unref(G_OBJECT(loader));
4558 } 4689 }
4559 4690
4560 } 4691 }
4561 4692
4562 if (pixbuf) { 4693 if (anim) {
4563 struct im_image_data *t = g_new(struct im_image_data, 1); 4694 struct im_image_data *t = g_new(struct im_image_data, 1);
4564 filename = imhtml->funcs->image_get_filename(image); 4695 filename = imhtml->funcs->image_get_filename(image);
4565 imhtml->funcs->image_ref(id); 4696 imhtml->funcs->image_ref(id);
4566 t->id = id; 4697 t->id = id;
4567 t->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); 4698 t->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
4568 imhtml->im_images = g_slist_prepend(imhtml->im_images, t); 4699 imhtml->im_images = g_slist_prepend(imhtml->im_images, t);
4700 scalable = gtk_imhtml_animation_new(anim, filename, id);
4701 g_object_unref(G_OBJECT(anim));
4569 } else { 4702 } else {
4703 GdkPixbuf *pixbuf;
4570 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, 4704 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE,
4571 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image"); 4705 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image");
4706 scalable = gtk_imhtml_image_new(pixbuf, filename, id);
4707 g_object_unref(G_OBJECT(pixbuf));
4572 } 4708 }
4573 4709
4574 sd = g_new(struct scalable_data, 1); 4710 sd = g_new(struct scalable_data, 1);
4575 sd->scalable = scalable = gtk_imhtml_image_new(pixbuf, filename, id); 4711 sd->scalable = scalable;
4576 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); 4712 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
4577 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); 4713 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
4578 scalable->add_to(scalable, imhtml, iter); 4714 scalable->add_to(scalable, imhtml, iter);
4579 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + 4715 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) +
4580 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); 4716 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml));
4581 scalable->scale(scalable, rect.width - minus, rect.height); 4717 scalable->scale(scalable, rect.width - minus, rect.height);
4582 imhtml->scalables = g_list_append(imhtml->scalables, sd); 4718 imhtml->scalables = g_list_append(imhtml->scalables, sd);
4583
4584 g_object_unref(G_OBJECT(pixbuf));
4585 } 4719 }
4586 4720
4587 static const gchar *tag_to_html_start(GtkTextTag *tag) 4721 static const gchar *tag_to_html_start(GtkTextTag *tag)
4588 { 4722 {
4589 const gchar *name; 4723 const gchar *name;
4905 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f) 5039 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f)
4906 { 5040 {
4907 g_return_if_fail(imhtml != NULL); 5041 g_return_if_fail(imhtml != NULL);
4908 imhtml->funcs = f; 5042 imhtml->funcs = f;
4909 } 5043 }
5044
5045 void gtk_imhtml_setup_entry(GtkIMHtml *imhtml, PurpleConnectionFlags flags)
5046 {
5047 if (flags & PURPLE_CONNECTION_HTML) {
5048 char color[8];
5049 GdkColor fg_color, bg_color;
5050
5051 gtk_imhtml_set_format_functions(imhtml, GTK_IMHTML_ALL);
5052 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != imhtml->edit.bold)
5053 gtk_imhtml_toggle_bold(imhtml);
5054
5055 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != imhtml->edit.italic)
5056 gtk_imhtml_toggle_italic(imhtml);
5057
5058 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != imhtml->edit.underline)
5059 gtk_imhtml_toggle_underline(imhtml);
5060
5061 gtk_imhtml_toggle_fontface(imhtml,
5062 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/font_face"));
5063
5064 if (!(flags & PURPLE_CONNECTION_NO_FONTSIZE))
5065 {
5066 int size = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/font_size");
5067
5068 /* 3 is the default. */
5069 if (size != 3)
5070 gtk_imhtml_font_set_size(imhtml, size);
5071 }
5072
5073 if(strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"), "") != 0)
5074 {
5075 gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"),
5076 &fg_color);
5077 g_snprintf(color, sizeof(color), "#%02x%02x%02x",
5078 fg_color.red / 256,
5079 fg_color.green / 256,
5080 fg_color.blue / 256);
5081 } else
5082 strcpy(color, "");
5083
5084 gtk_imhtml_toggle_forecolor(imhtml, color);
5085
5086 if(!(flags & PURPLE_CONNECTION_NO_BGCOLOR) &&
5087 strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"), "") != 0)
5088 {
5089 gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"),
5090 &bg_color);
5091 g_snprintf(color, sizeof(color), "#%02x%02x%02x",
5092 bg_color.red / 256,
5093 bg_color.green / 256,
5094 bg_color.blue / 256);
5095 } else
5096 strcpy(color, "");
5097
5098 gtk_imhtml_toggle_background(imhtml, color);
5099
5100 if (flags & PURPLE_CONNECTION_FORMATTING_WBFO)
5101 gtk_imhtml_set_whole_buffer_formatting_only(imhtml, TRUE);
5102 else
5103 gtk_imhtml_set_whole_buffer_formatting_only(imhtml, FALSE);
5104 } else {
5105 imhtml_clear_formatting(imhtml);
5106 gtk_imhtml_set_format_functions(imhtml, 0);
5107 }
5108 }
5109
5110