comparison src/gtkimhtml.c @ 8869:ab5a46dd132a

[gaim-migrate @ 9637] Copy/paste fixes for UCS-2 encoded selections committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Tue, 04 May 2004 06:08:47 +0000
parents d7b5fbc451da
children 1ab2a9c17f4a
comparison
equal deleted inserted replaced
8868:db80183f251c 8869:ab5a46dd132a
687 } 687 }
688 688
689 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data) 689 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data)
690 { 690 {
691 char *text; 691 char *text;
692 guint16 c;
693 GtkIMHtml *imhtml = data; 692 GtkIMHtml *imhtml = data;
694 GtkTextIter iter; 693 GtkTextIter iter;
695 GtkIMHtmlOptions flags = GTK_IMHTML_NO_NEWLINE; 694 GtkIMHtmlOptions flags = GTK_IMHTML_NO_NEWLINE;
696 gboolean plaintext = FALSE; 695 gboolean plaintext = FALSE;
697 696
759 #endif 758 #endif
760 text = g_malloc(selection_data->length); 759 text = g_malloc(selection_data->length);
761 memcpy(text, selection_data->data, selection_data->length); 760 memcpy(text, selection_data->data, selection_data->length);
762 } 761 }
763 762
764 memcpy (&c, text, 2); 763 if (selection_data->length >= 2 &&
765 if (c == 0xfeff) { 764 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) {
766 /* This is UCS2 */ 765 /* This is UCS-2 */
767 char *utf8 = g_convert(text+2, selection_data->length - 2, "UTF-8", "UCS-2", NULL, NULL, NULL); 766 char *utf8 = g_convert(text, selection_data->length, "UTF-8", "UCS-2", NULL, NULL, NULL);
768 g_free(text); 767 g_free(text);
769 text = utf8; 768 text = utf8;
770 if (!text) { 769 if (!text) {
771 gaim_debug_warning("gtkimhtml", "g_convert failed in paste_received_cb\n"); 770 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in paste_received_cb\n");
772 return; 771 return;
773 } 772 }
774 } 773 }
775 774
776 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { 775 if (!(*text) || !g_utf8_validate(text, -1, NULL)) {