comparison pidgin/gtkimhtml.c @ 27741:6befd211e707

propagate from branch 'im.pidgin.pidgin' (head e07a38238ee8acc8258a095a26e721d95125cb05) to branch 'im.pidgin.pidgin.yaz' (head 6a0bd510aa27104e63a52cca66874f672dc37dfa)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 28 Nov 2007 08:44:35 +0000
parents 98604b4bfa3b c9946b9965c9
children e13759a83714
comparison
equal deleted inserted replaced
27740:ae8a9f2866bd 27741:6befd211e707
29 #include <config.h> 29 #include <config.h>
30 #endif 30 #endif
31 31
32 #include "internal.h" 32 #include "internal.h"
33 #include "pidgin.h" 33 #include "pidgin.h"
34 #include "pidginstock.h"
34 35
35 #include "debug.h" 36 #include "debug.h"
36 #include "util.h" 37 #include "util.h"
37 #include "gtkimhtml.h" 38 #include "gtkimhtml.h"
38 #include "gtksourceiter.h" 39 #include "gtksourceiter.h"
817 } 818 }
818 819
819 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data) 820 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data)
820 { 821 {
821 GtkWidget *menuitem; 822 GtkWidget *menuitem;
823 GtkWidget *mi, *img;
822 824
823 menuitem = gtk_menu_item_new_with_mnemonic(_("Paste as Plain _Text")); 825 menuitem = gtk_menu_item_new_with_mnemonic(_("Paste as Plain _Text"));
824 gtk_widget_show(menuitem); 826 gtk_widget_show(menuitem);
825 /* 827 /*
826 * TODO: gtk_clipboard_wait_is_text_available() iterates the glib 828 * TODO: gtk_clipboard_wait_is_text_available() iterates the glib
842 gtk_widget_set_sensitive(menuitem, imhtml->editable); 844 gtk_widget_set_sensitive(menuitem, imhtml->editable);
843 /* put it after Delete */ 845 /* put it after Delete */
844 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 5); 846 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 5);
845 847
846 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(clear_formatting_cb), imhtml); 848 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(clear_formatting_cb), imhtml);
849
850 mi = gtk_menu_item_new();
851 gtk_widget_show(mi);
852 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), mi);
853
854 img = gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_SMILEY, GTK_ICON_SIZE_MENU);
855 mi = gtk_image_menu_item_new_with_label(_("_Smile!"));
856 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
857 gtk_widget_show(mi);
858 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), mi);
859
860 img = gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_INSERT, GTK_ICON_SIZE_MENU);
861 mi = gtk_image_menu_item_new_with_label(_("_Insert"));
862 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
863 gtk_widget_show(mi);
864 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), mi);
865
866 img = gtk_image_new_from_stock(GTK_STOCK_BOLD, GTK_ICON_SIZE_MENU);
867 mi = gtk_image_menu_item_new_with_label(_("_Font"));
868 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
869 gtk_widget_show(mi);
870 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), mi);
847 } 871 }
848 872
849 static char * 873 static char *
850 ucs2_order(gboolean swap) 874 ucs2_order(gboolean swap)
851 { 875 {
1101 return; 1125 return;
1102 } 1126 }
1103 1127
1104 imhtml_paste_insert(imhtml, text, FALSE); 1128 imhtml_paste_insert(imhtml, text, FALSE);
1105 g_free(text); 1129 g_free(text);
1130 }
1131
1132
1133 static void smart_backspace_cb(GtkIMHtml *imhtml, gpointer blah)
1134 {
1135 GtkTextIter iter;
1136 GtkTextChildAnchor* anchor;
1137 char * text;
1138 gint offset;
1139
1140 if (!imhtml->editable)
1141 return;
1142
1143 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer));
1144
1145 /* Get the character before the insertion point */
1146 offset = gtk_text_iter_get_offset(&iter);
1147 if (offset <= 0)
1148 return;
1149
1150 gtk_text_iter_backward_char(&iter);
1151 anchor = gtk_text_iter_get_child_anchor(&iter);
1152
1153 if (!anchor)
1154 return; /* No smiley here */
1155
1156 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext");
1157 if (!text)
1158 return;
1159
1160 /* ok, then we need to insert the image buffer text before the anchor */
1161 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1);
1106 } 1162 }
1107 1163
1108 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) 1164 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah)
1109 { 1165 {
1110 #ifdef _WIN32 1166 #ifdef _WIN32
4058 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ 4114 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */
4059 imhtml->editable = editable; 4115 imhtml->editable = editable;
4060 imhtml->format_functions = GTK_IMHTML_ALL; 4116 imhtml->format_functions = GTK_IMHTML_ALL;
4061 4117
4062 if (editable) 4118 if (editable)
4119 {
4063 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", 4120 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set",
4064 G_CALLBACK(mark_set_cb), imhtml); 4121 G_CALLBACK(mark_set_cb), imhtml);
4122 g_signal_connect(G_OBJECT(imhtml), "backspace", G_CALLBACK(smart_backspace_cb), NULL);
4123 }
4065 } 4124 }
4066 4125
4067 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo) 4126 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo)
4068 { 4127 {
4069 g_return_if_fail(imhtml != NULL); 4128 g_return_if_fail(imhtml != NULL);
4226 g_return_if_fail(imhtml != NULL); 4285 g_return_if_fail(imhtml != NULL);
4227 4286
4228 object = g_object_ref(G_OBJECT(imhtml)); 4287 object = g_object_ref(G_OBJECT(imhtml));
4229 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button); 4288 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, button);
4230 g_object_unref(object); 4289 g_object_unref(object);
4290 }
4291
4292 static void populate_popup_cb(GtkTextView *textview, GtkMenu *menu, gpointer nul)
4293 {
4294 GtkWidget *mi, *img;
4295
4296 mi = gtk_menu_item_new();
4297 gtk_widget_show(mi);
4298 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), mi);
4299
4300 img = gtk_image_new_from_stock(GTK_STOCK_BOLD, GTK_ICON_SIZE_MENU);
4301 mi = gtk_image_menu_item_new_with_label(_("_Font"));
4302 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
4303 gtk_widget_show(mi);
4304 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), mi);
4305
4306 img = gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_INSERT, GTK_ICON_SIZE_MENU);
4307 mi = gtk_image_menu_item_new_with_label(_("_Insert"));
4308 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
4309 gtk_widget_show(mi);
4310 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), mi);
4311
4312 img = gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_SMILEY, GTK_ICON_SIZE_MENU);
4313 mi = gtk_image_menu_item_new_with_label(_("_Smile!"));
4314 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
4315 gtk_widget_show(mi);
4316 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), mi);
4231 } 4317 }
4232 4318
4233 static void imhtml_toggle_bold(GtkIMHtml *imhtml) 4319 static void imhtml_toggle_bold(GtkIMHtml *imhtml)
4234 { 4320 {
4235 GtkTextIter start, end; 4321 GtkTextIter start, end;