Mercurial > pidgin.yaz
comparison pidgin/gtkimhtml.c @ 27836:d1dfbedd9e64
- due to bug of gtk_text_buffer_insert(), chop the text at designated position.
- cleanups
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 10 May 2008 10:03:23 +0000 |
parents | 8b269348e97b |
children | 22f8b5512ef4 |
comparison
equal
deleted
inserted
replaced
27835:f9fd7ddf6996 | 27836:d1dfbedd9e64 |
---|---|
584 anchor = gtk_text_iter_get_child_anchor(&iter); | 584 anchor = gtk_text_iter_get_child_anchor(&iter); |
585 if (anchor) { | 585 if (anchor) { |
586 tip = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_tiptext"); | 586 tip = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_tiptext"); |
587 hand = FALSE; | 587 hand = FALSE; |
588 } | 588 } |
589 //yaz here bomb explodes | |
590 #if 1 | |
591 if (tip && *tip) { | 589 if (tip && *tip) { |
592 if (!GTK_IMHTML(imhtml)->editable && hand) | 590 if (!GTK_IMHTML(imhtml)->editable && hand) |
593 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); | 591 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); |
594 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | 592 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, |
595 gtk_imhtml_tip, imhtml); | 593 gtk_imhtml_tip, imhtml); |
596 } | 594 } |
597 #endif | |
598 GTK_IMHTML(imhtml)->tip = tip; | 595 GTK_IMHTML(imhtml)->tip = tip; |
599 g_slist_free(tags); | 596 g_slist_free(tags); |
600 return FALSE; | 597 return FALSE; |
601 } | 598 } |
602 | 599 |
960 if (primary) { | 957 if (primary) { |
961 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); | 958 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); |
962 } else | 959 } else |
963 text = html_clipboard; | 960 text = html_clipboard; |
964 | 961 |
965 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | 962 selection = NULL; |
966 str = g_string_append(str, text); | 963 if (primary) { |
967 str = g_string_append_c(str, 0x00); | 964 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); |
968 selection = g_convert(str->str, str->len, "UTF-16", "UTF-8", NULL, &len, NULL); | 965 } else { |
966 text = html_clipboard; | |
967 } | |
968 /* xxx should remove following line --yaz */ | |
969 purple_debug_info("imhtml clipboard", "html_clipboard: %s len = %d\n", text, strlen(text)); | |
969 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), | 970 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), |
970 16, (const guchar *)selection, len); | 971 8, (const guchar *)text, strlen(text)); |
971 g_string_free(str, TRUE); | |
972 #else /*_WIN32 */ | 972 #else /*_WIN32 */ |
973 selection = clipboard_html_to_win32(html_clipboard); | 973 selection = clipboard_html_to_win32(html_clipboard); |
974 gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), | 974 gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), |
975 8, (const guchar *)selection, strlen(selection)); | 975 8, (const guchar *)selection, strlen(selection)); |
976 #endif | 976 #endif |
1121 } | 1121 } |
1122 | 1122 |
1123 if (selection_data->length >= 2 && | 1123 if (selection_data->length >= 2 && |
1124 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { | 1124 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { |
1125 /* This is UTF-16 */ | 1125 /* This is UTF-16 */ |
1126 char *utf8 = utf16_to_utf8_with_bom_check(text, selection_data->length); | 1126 // char *utf8 = utf16_to_utf8_with_bom_check(text, selection_data->length); |
1127 char *utf8 = g_convert(text, selection_data->length, "UTF-8", "UTF-16", NULL, NULL, NULL); | |
1127 g_free(text); | 1128 g_free(text); |
1128 text = utf8; | 1129 text = utf8; |
1129 if (!text) { | 1130 if (!text) { |
1130 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in paste_received_cb\n"); | 1131 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in paste_received_cb\n"); |
1131 return; | 1132 return; |
1843 * | 1844 * |
1844 * See also the comment on text/html here: | 1845 * See also the comment on text/html here: |
1845 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html | 1846 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html |
1846 */ | 1847 */ |
1847 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) { | 1848 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) { |
1848 utf8 = utf16_to_utf8_with_bom_check(text, sd->length); | 1849 // utf8 = utf16_to_utf8_with_bom_check(text, sd->length); |
1850 utf8 = g_convert(text, sd->length, "UTF-8", "UTF-16", NULL, NULL, NULL); | |
1849 | 1851 |
1850 if (!utf8) { | 1852 if (!utf8) { |
1851 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in drag_rcv_cb\n"); | 1853 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in drag_rcv_cb\n"); |
1852 return; | 1854 return; |
1853 } | 1855 } |
3144 pos++; | 3146 pos++; |
3145 } else { | 3147 } else { |
3146 break; | 3148 break; |
3147 } | 3149 } |
3148 } | 3150 } |
3151 ws[wpos] = '\0'; // chop ws at wpos. due to bug of gtk_text_buffer_insert() --yaz | |
3149 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | 3152 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
3150 ws[0] = '\0'; wpos = 0; | 3153 ws[0] = '\0'; wpos = 0; |
3151 | 3154 |
3152 /* NEW_BIT(NEW_TEXT_BIT); */ | 3155 /* NEW_BIT(NEW_TEXT_BIT); */ |
3153 | 3156 |
3158 gtk_text_iter_set_line(&line_iter, align_line); | 3161 gtk_text_iter_set_line(&line_iter, align_line); |
3159 /* insert RLM character to set alignment */ | 3162 /* insert RLM character to set alignment */ |
3160 ws[wpos++] = 0xE2; | 3163 ws[wpos++] = 0xE2; |
3161 ws[wpos++] = 0x80; | 3164 ws[wpos++] = 0x80; |
3162 ws[wpos++] = 0x8F; | 3165 ws[wpos++] = 0x8F; |
3163 | 3166 |
3164 if (!rtl_direction) | 3167 if (!rtl_direction) |
3165 { | 3168 { |
3166 /* insert LRM character to set direction */ | 3169 /* insert LRM character to set direction */ |
3167 /* (alignment=right and direction=LTR) */ | 3170 /* (alignment=right and direction=LTR) */ |
3168 ws[wpos++] = 0xE2; | 3171 ws[wpos++] = 0xE2; |