pidgin/gtkimhtml.c

changeset 18178
d461ccafa1fb
parent 17695
5e7fcc2f23cc
parent 18151
97fd60f47229
child 18185
d4f1719d812b
equal deleted inserted replaced
17755:ed70e92f7c28 18178:d461ccafa1fb
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>
134 BUTTONS_UPDATE, 139 BUTTONS_UPDATE,
135 TOGGLE_FORMAT, 140 TOGGLE_FORMAT,
136 CLEAR_FORMAT, 141 CLEAR_FORMAT,
137 UPDATE_FORMAT, 142 UPDATE_FORMAT,
138 MESSAGE_SEND, 143 MESSAGE_SEND,
144 UNDO,
145 REDO,
139 LAST_SIGNAL 146 LAST_SIGNAL
140 }; 147 };
141 static guint signals [LAST_SIGNAL] = { 0 }; 148 static guint signals [LAST_SIGNAL] = { 0 };
142 149
143 static char *html_clipboard = NULL; 150 static char *html_clipboard = NULL;
1146 1153
1147 return TRUE; 1154 return TRUE;
1148 } 1155 }
1149 1156
1150 return FALSE; 1157 return FALSE;
1158 }
1159
1160 static void
1161 gtk_imhtml_undo(GtkIMHtml *imhtml) {
1162 g_return_if_fail(GTK_IS_IMHTML(imhtml));
1163 g_return_if_fail(imhtml->editable);
1164
1165 gtk_source_undo_manager_undo(imhtml->undo_manager);
1166 }
1167
1168 static void
1169 gtk_imhtml_redo(GtkIMHtml *imhtml) {
1170 g_return_if_fail(GTK_IS_IMHTML(imhtml));
1171 g_return_if_fail(imhtml->editable);
1172
1173 gtk_source_undo_manager_redo(imhtml->undo_manager);
1174
1151 } 1175 }
1152 1176
1153 static gboolean imhtml_message_send(GtkIMHtml *imhtml) 1177 static gboolean imhtml_message_send(GtkIMHtml *imhtml)
1154 { 1178 {
1155 return FALSE; 1179 return FALSE;
1226 g_list_free(imhtml->scalables); 1250 g_list_free(imhtml->scalables);
1227 g_slist_free(imhtml->im_images); 1251 g_slist_free(imhtml->im_images);
1228 g_queue_free(imhtml->animations); 1252 g_queue_free(imhtml->animations);
1229 g_free(imhtml->protocol_name); 1253 g_free(imhtml->protocol_name);
1230 g_free(imhtml->search_string); 1254 g_free(imhtml->search_string);
1255 g_object_unref(imhtml->undo_manager);
1231 G_OBJECT_CLASS(parent_class)->finalize (object); 1256 G_OBJECT_CLASS(parent_class)->finalize (object);
1232 if (clipboard_selection) 1257 if (clipboard_selection)
1233 gtk_clipboard_set_with_owner(clipboard_selection, 1258 gtk_clipboard_set_with_owner(clipboard_selection,
1234 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), 1259 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
1235 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, 1260 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
1295 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, 1320 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1296 G_STRUCT_OFFSET(GtkIMHtmlClass, message_send), 1321 G_STRUCT_OFFSET(GtkIMHtmlClass, message_send),
1297 NULL, 1322 NULL,
1298 0, g_cclosure_marshal_VOID__VOID, 1323 0, g_cclosure_marshal_VOID__VOID,
1299 G_TYPE_NONE, 0); 1324 G_TYPE_NONE, 0);
1325 signals [UNDO] = g_signal_new ("undo",
1326 G_TYPE_FROM_CLASS (klass),
1327 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1328 G_STRUCT_OFFSET (GtkIMHtmlClass, undo),
1329 NULL,
1330 NULL,
1331 gtksourceview_marshal_VOID__VOID,
1332 G_TYPE_NONE,
1333 0);
1334 signals [REDO] = g_signal_new ("redo",
1335 G_TYPE_FROM_CLASS (klass),
1336 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1337 G_STRUCT_OFFSET (GtkIMHtmlClass, redo),
1338 NULL,
1339 NULL,
1340 gtksourceview_marshal_VOID__VOID,
1341 G_TYPE_NONE,
1342 0);
1343
1344
1300 1345
1301 klass->toggle_format = imhtml_toggle_format; 1346 klass->toggle_format = imhtml_toggle_format;
1302 klass->message_send = imhtml_message_send; 1347 klass->message_send = imhtml_message_send;
1303 klass->clear_format = imhtml_clear_formatting; 1348 klass->clear_format = imhtml_clear_formatting;
1349 klass->undo = gtk_imhtml_undo;
1350 klass->redo = gtk_imhtml_redo;
1304 1351
1305 gobject_class->finalize = gtk_imhtml_finalize; 1352 gobject_class->finalize = gtk_imhtml_finalize;
1306 widget_class->drag_motion = gtk_text_view_drag_motion; 1353 widget_class->drag_motion = gtk_text_view_drag_motion;
1307 widget_class->expose_event = gtk_imhtml_expose_event; 1354 widget_class->expose_event = gtk_imhtml_expose_event;
1308 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color", 1355 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color",
1323 gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK); 1370 gtk_binding_entry_add_signal (binding_set, GDK_minus, GDK_CONTROL_MASK, "format_function_toggle", 1, G_TYPE_INT, GTK_IMHTML_SHRINK);
1324 binding_set = gtk_binding_set_by_class(klass); 1371 binding_set = gtk_binding_set_by_class(klass);
1325 gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0); 1372 gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0);
1326 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0); 1373 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0);
1327 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "message_send", 0); 1374 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "message_send", 0);
1375 gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK, "undo", 0);
1376 gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "redo", 0);
1377 gtk_binding_entry_add_signal (binding_set, GDK_F14, 0, "undo", 0);
1378
1328 } 1379 }
1329 1380
1330 static void gtk_imhtml_init (GtkIMHtml *imhtml) 1381 static void gtk_imhtml_init (GtkIMHtml *imhtml)
1331 { 1382 {
1332 GtkTextIter iter; 1383 GtkTextIter iter;
1333 imhtml->text_buffer = gtk_text_buffer_new(NULL); 1384 imhtml->text_buffer = gtk_text_buffer_new(NULL);
1385 imhtml->undo_manager = gtk_source_undo_manager_new(imhtml->text_buffer);
1334 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); 1386 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter);
1335 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); 1387 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer);
1336 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); 1388 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR);
1337 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); 1389 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5);
1338 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2); 1390 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2);
3111 3163
3112 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ 3164 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */
3113 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id) 3165 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id)
3114 { 3166 {
3115 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); 3167 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage));
3116 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img));
3117 3168
3118 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; 3169 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
3119 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; 3170 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to;
3120 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; 3171 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free;
3121 3172
3122 im_image->pixbuf = img; 3173 im_image->pixbuf = img;
3123 im_image->image = image; 3174 im_image->image = GTK_IMAGE(gtk_image_new_from_pixbuf(im_image->pixbuf));
3124 im_image->width = gdk_pixbuf_get_width(img); 3175 im_image->width = gdk_pixbuf_get_width(img);
3125 im_image->height = gdk_pixbuf_get_height(img); 3176 im_image->height = gdk_pixbuf_get_height(img);
3126 im_image->mark = NULL; 3177 im_image->mark = NULL;
3127 im_image->filename = g_strdup(filename); 3178 im_image->filename = g_strdup(filename);
3128 im_image->id = id; 3179 im_image->id = id;
3129 im_image->filesel = NULL; 3180 im_image->filesel = NULL;
3130 3181
3131 g_object_ref(img); 3182 g_object_ref(img);
3183 return GTK_IMHTML_SCALABLE(im_image);
3184 }
3185
3186 static gboolean
3187 animate_image_cb(gpointer data)
3188 {
3189 GtkIMHtmlImage *im_image;
3190 int width, height;
3191 int delay;
3192
3193 im_image = data;
3194
3195 /* Update the pointer to this GdkPixbuf frame of the animation */
3196 g_object_unref(G_OBJECT(im_image->pixbuf));
3197 gdk_pixbuf_animation_iter_advance(GTK_IMHTML_ANIMATION(im_image)->iter, NULL);
3198 im_image->pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(GTK_IMHTML_ANIMATION(im_image)->iter);
3199 g_object_ref(G_OBJECT(im_image->pixbuf));
3200
3201 /* Update the displayed GtkImage */
3202 width = gdk_pixbuf_get_width(gtk_image_get_pixbuf(im_image->image));
3203 height = gdk_pixbuf_get_height(gtk_image_get_pixbuf(im_image->image));
3204 if (width > 0 && height > 0)
3205 {
3206 /* Need to scale the new frame to the same size as the old frame */
3207 GdkPixbuf *tmp;
3208 tmp = gdk_pixbuf_scale_simple(im_image->pixbuf, width, height, GDK_INTERP_BILINEAR);
3209 gtk_image_set_from_pixbuf(im_image->image, tmp);
3210 g_object_unref(G_OBJECT(tmp));
3211 } else {
3212 /* Display at full-size */
3213 gtk_image_set_from_pixbuf(im_image->image, im_image->pixbuf);
3214 }
3215
3216 delay = MIN(gdk_pixbuf_animation_iter_get_delay_time(GTK_IMHTML_ANIMATION(im_image)->iter), 100);
3217 GTK_IMHTML_ANIMATION(im_image)->timer = g_timeout_add(delay, animate_image_cb, im_image);
3218
3219 return FALSE;
3220 }
3221
3222 GtkIMHtmlScalable *gtk_imhtml_animation_new(GdkPixbufAnimation *anim, const gchar *filename, int id)
3223 {
3224 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlAnimation));
3225
3226 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
3227 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to;
3228 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_animation_free;
3229
3230 GTK_IMHTML_ANIMATION(im_image)->anim = anim;
3231 if (gdk_pixbuf_animation_is_static_image(anim)) {
3232 GTK_IMHTML_ANIMATION(im_image)->iter = NULL;
3233 im_image->pixbuf = gdk_pixbuf_animation_get_static_image(anim);
3234 GTK_IMHTML_ANIMATION(im_image)->timer = 0;
3235 } else {
3236 int delay;
3237 GTK_IMHTML_ANIMATION(im_image)->iter = gdk_pixbuf_animation_get_iter(anim, NULL);
3238 im_image->pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(GTK_IMHTML_ANIMATION(im_image)->iter);
3239 delay = MIN(gdk_pixbuf_animation_iter_get_delay_time(GTK_IMHTML_ANIMATION(im_image)->iter), 100);
3240 GTK_IMHTML_ANIMATION(im_image)->timer = g_timeout_add(delay, animate_image_cb, im_image);
3241 }
3242 im_image->image = GTK_IMAGE(gtk_image_new_from_pixbuf(im_image->pixbuf));
3243 im_image->width = gdk_pixbuf_animation_get_width(anim);
3244 im_image->height = gdk_pixbuf_animation_get_height(anim);
3245 im_image->mark = NULL;
3246 im_image->filename = g_strdup(filename);
3247 im_image->id = id;
3248 im_image->filesel = NULL;
3249
3250 g_object_ref(anim);
3251 g_object_ref(im_image->pixbuf);
3252
3132 return GTK_IMHTML_SCALABLE(im_image); 3253 return GTK_IMHTML_SCALABLE(im_image);
3133 } 3254 }
3134 3255
3135 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) 3256 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height)
3136 { 3257 {
3404 } 3525 }
3405 3526
3406 static gboolean gtk_imhtml_smiley_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlSmiley *smiley) 3527 static gboolean gtk_imhtml_smiley_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlSmiley *smiley)
3407 { 3528 {
3408 GdkPixbufAnimation *anim = NULL; 3529 GdkPixbufAnimation *anim = NULL;
3409 GdkPixbuf *pix = NULL;
3410 GtkIMHtmlScalable *image = NULL; 3530 GtkIMHtmlScalable *image = NULL;
3411 gboolean ret; 3531 gboolean ret;
3412 3532
3413 if (event->type != GDK_BUTTON_RELEASE || ((GdkEventButton*)event)->button != 3) 3533 if (event->type != GDK_BUTTON_RELEASE || ((GdkEventButton*)event)->button != 3)
3414 return FALSE; 3534 return FALSE;
3415 3535
3416 anim = gtk_smiley_get_image(smiley); 3536 anim = gtk_smiley_get_image(smiley);
3417 if (!anim) 3537 if (!anim)
3418 return FALSE; 3538 return FALSE;
3419 3539
3420 pix = gdk_pixbuf_animation_get_static_image(anim); 3540 image = gtk_imhtml_animation_new(anim, smiley->smile, 0);
3421 image = gtk_imhtml_image_new(pix, smiley->smile, 0);
3422 ret = gtk_imhtml_image_clicked(w, event, (GtkIMHtmlImage*)image); 3541 ret = gtk_imhtml_image_clicked(w, event, (GtkIMHtmlImage*)image);
3423 g_object_set_data_full(G_OBJECT(w), "image-data", image, (GDestroyNotify)gtk_imhtml_image_free); 3542 g_object_set_data_full(G_OBJECT(w), "image-data", image, (GDestroyNotify)gtk_imhtml_image_free);
3424 g_object_unref(G_OBJECT(pix));
3425 return ret; 3543 return ret;
3426 } 3544 }
3427 3545
3428 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) 3546 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale)
3429 { 3547 {
3432 g_object_unref(image->pixbuf); 3550 g_object_unref(image->pixbuf);
3433 g_free(image->filename); 3551 g_free(image->filename);
3434 if (image->filesel) 3552 if (image->filesel)
3435 gtk_widget_destroy(image->filesel); 3553 gtk_widget_destroy(image->filesel);
3436 g_free(scale); 3554 g_free(scale);
3555 }
3556
3557 void gtk_imhtml_animation_free(GtkIMHtmlScalable *scale)
3558 {
3559 GtkIMHtmlAnimation *animation = (GtkIMHtmlAnimation *)scale;
3560
3561 if (animation->timer > 0)
3562 g_source_remove(animation->timer);
3563 if (animation->iter != NULL)
3564 g_object_unref(animation->iter);
3565 g_object_unref(animation->anim);
3566
3567 gtk_imhtml_image_free(scale);
3437 } 3568 }
3438 3569
3439 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) 3570 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter)
3440 { 3571 {
3441 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; 3572 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
4514 g_free(unescaped); 4645 g_free(unescaped);
4515 } 4646 }
4516 4647
4517 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter) 4648 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter)
4518 { 4649 {
4519 GdkPixbuf *pixbuf = NULL; 4650 GdkPixbufAnimation *anim = NULL;
4520 const char *filename = NULL; 4651 const char *filename = NULL;
4521 gpointer image; 4652 gpointer image;
4522 GdkRectangle rect; 4653 GdkRectangle rect;
4523 GtkIMHtmlScalable *scalable = NULL; 4654 GtkIMHtmlScalable *scalable = NULL;
4524 struct scalable_data *sd; 4655 struct scalable_data *sd;
4541 4672
4542 if (data && len) { 4673 if (data && len) {
4543 GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); 4674 GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
4544 gdk_pixbuf_loader_write(loader, data, len, NULL); 4675 gdk_pixbuf_loader_write(loader, data, len, NULL);
4545 gdk_pixbuf_loader_close(loader, NULL); 4676 gdk_pixbuf_loader_close(loader, NULL);
4546 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); 4677 anim = gdk_pixbuf_loader_get_animation(loader);
4547 if (pixbuf) 4678 if (anim)
4548 g_object_ref(G_OBJECT(pixbuf)); 4679 g_object_ref(G_OBJECT(anim));
4549 g_object_unref(G_OBJECT(loader)); 4680 g_object_unref(G_OBJECT(loader));
4550 } 4681 }
4551 4682
4552 } 4683 }
4553 4684
4554 if (pixbuf) { 4685 if (anim) {
4555 struct im_image_data *t = g_new(struct im_image_data, 1); 4686 struct im_image_data *t = g_new(struct im_image_data, 1);
4556 filename = imhtml->funcs->image_get_filename(image); 4687 filename = imhtml->funcs->image_get_filename(image);
4557 imhtml->funcs->image_ref(id); 4688 imhtml->funcs->image_ref(id);
4558 t->id = id; 4689 t->id = id;
4559 t->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); 4690 t->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
4560 imhtml->im_images = g_slist_prepend(imhtml->im_images, t); 4691 imhtml->im_images = g_slist_prepend(imhtml->im_images, t);
4692 scalable = gtk_imhtml_animation_new(anim, filename, id);
4693 g_object_unref(G_OBJECT(anim));
4561 } else { 4694 } else {
4695 GdkPixbuf *pixbuf;
4562 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, 4696 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE,
4563 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image"); 4697 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image");
4698 scalable = gtk_imhtml_image_new(pixbuf, filename, id);
4699 g_object_unref(G_OBJECT(pixbuf));
4564 } 4700 }
4565 4701
4566 sd = g_new(struct scalable_data, 1); 4702 sd = g_new(struct scalable_data, 1);
4567 sd->scalable = scalable = gtk_imhtml_image_new(pixbuf, filename, id); 4703 sd->scalable = scalable;
4568 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); 4704 sd->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE);
4569 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); 4705 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
4570 scalable->add_to(scalable, imhtml, iter); 4706 scalable->add_to(scalable, imhtml, iter);
4571 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + 4707 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) +
4572 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); 4708 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml));
4573 scalable->scale(scalable, rect.width - minus, rect.height); 4709 scalable->scale(scalable, rect.width - minus, rect.height);
4574 imhtml->scalables = g_list_append(imhtml->scalables, sd); 4710 imhtml->scalables = g_list_append(imhtml->scalables, sd);
4575
4576 g_object_unref(G_OBJECT(pixbuf));
4577 } 4711 }
4578 4712
4579 static const gchar *tag_to_html_start(GtkTextTag *tag) 4713 static const gchar *tag_to_html_start(GtkTextTag *tag)
4580 { 4714 {
4581 const gchar *name; 4715 const gchar *name;
4897 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f) 5031 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f)
4898 { 5032 {
4899 g_return_if_fail(imhtml != NULL); 5033 g_return_if_fail(imhtml != NULL);
4900 imhtml->funcs = f; 5034 imhtml->funcs = f;
4901 } 5035 }
5036
5037 void gtk_imhtml_setup_entry(GtkIMHtml *imhtml, PurpleConnectionFlags flags)
5038 {
5039 if (flags & PURPLE_CONNECTION_HTML) {
5040 char color[8];
5041 GdkColor fg_color, bg_color;
5042
5043 gtk_imhtml_set_format_functions(imhtml, GTK_IMHTML_ALL);
5044 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold") != imhtml->edit.bold)
5045 gtk_imhtml_toggle_bold(imhtml);
5046
5047 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic") != imhtml->edit.italic)
5048 gtk_imhtml_toggle_italic(imhtml);
5049
5050 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline") != imhtml->edit.underline)
5051 gtk_imhtml_toggle_underline(imhtml);
5052
5053 gtk_imhtml_toggle_fontface(imhtml,
5054 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/font_face"));
5055
5056 if (!(flags & PURPLE_CONNECTION_NO_FONTSIZE))
5057 {
5058 int size = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/font_size");
5059
5060 /* 3 is the default. */
5061 if (size != 3)
5062 gtk_imhtml_font_set_size(imhtml, size);
5063 }
5064
5065 if(strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"), "") != 0)
5066 {
5067 gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/fgcolor"),
5068 &fg_color);
5069 g_snprintf(color, sizeof(color), "#%02x%02x%02x",
5070 fg_color.red / 256,
5071 fg_color.green / 256,
5072 fg_color.blue / 256);
5073 } else
5074 strcpy(color, "");
5075
5076 gtk_imhtml_toggle_forecolor(imhtml, color);
5077
5078 if(!(flags & PURPLE_CONNECTION_NO_BGCOLOR) &&
5079 strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"), "") != 0)
5080 {
5081 gdk_color_parse(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/bgcolor"),
5082 &bg_color);
5083 g_snprintf(color, sizeof(color), "#%02x%02x%02x",
5084 bg_color.red / 256,
5085 bg_color.green / 256,
5086 bg_color.blue / 256);
5087 } else
5088 strcpy(color, "");
5089
5090 gtk_imhtml_toggle_background(imhtml, color);
5091
5092 if (flags & PURPLE_CONNECTION_FORMATTING_WBFO)
5093 gtk_imhtml_set_whole_buffer_formatting_only(imhtml, TRUE);
5094 else
5095 gtk_imhtml_set_whole_buffer_formatting_only(imhtml, FALSE);
5096 } else {
5097 imhtml_clear_formatting(imhtml);
5098 gtk_imhtml_set_format_functions(imhtml, 0);
5099 }
5100 }
5101
5102

mercurial