Mercurial > pidgin.yaz
comparison pidgin/gtkimhtml.c @ 27846:9f91d6e0983c
propagate from branch 'im.pidgin.pidgin' (head 8c6407ae1c2c31473f78557c5805f8efa18e1ed8)
to branch 'im.pidgin.pidgin.yaz' (head f312eb270934d9529df8503635b1d0a62e8de289)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 02 Jun 2008 06:58:38 +0000 |
parents | 86bf0ce0d7ac 0aa090fde749 |
children | 81ebe4fac9ce |
comparison
equal
deleted
inserted
replaced
23266:2b997b690500 | 27846:9f91d6e0983c |
---|---|
92 GdkDragContext *context, | 92 GdkDragContext *context, |
93 gint x, | 93 gint x, |
94 gint y, | 94 gint y, |
95 guint time); | 95 guint time); |
96 | 96 |
97 /* yaz. If you want to use shortcut keys that may conflict with | |
98 inputmethods, change this to 1. */ | |
99 #define ENABLE_SHORTCUT 0 | |
100 | |
97 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); | 101 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
98 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); | 102 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
99 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter *end, GtkIMHtml *imhtml); | 103 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter *end, GtkIMHtml *imhtml); |
100 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data); | 104 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data); |
101 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end); | 105 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end); |
467 } | 471 } |
468 | 472 |
469 static gint | 473 static gint |
470 gtk_imhtml_tip (gpointer data) | 474 gtk_imhtml_tip (gpointer data) |
471 { | 475 { |
472 GtkIMHtml *imhtml = data; | 476 GtkIMHtml *imhtml = (GtkIMHtml *)data; |
473 PangoFontMetrics *font_metrics; | 477 PangoFontMetrics *font_metrics; |
474 PangoLayout *layout; | 478 PangoLayout *layout; |
475 PangoFont *font; | 479 PangoFont *font; |
480 PangoLanguage *lang; | |
476 | 481 |
477 gint gap, x, y, h, w, scr_w, baseline_skip; | 482 gint gap, x, y, h, w, scr_w, baseline_skip; |
478 | 483 |
479 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | 484 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); |
480 | 485 |
516 | 521 |
517 g_object_unref(layout); | 522 g_object_unref(layout); |
518 return FALSE; | 523 return FALSE; |
519 } | 524 } |
520 | 525 |
521 font_metrics = pango_font_get_metrics(font, NULL); | 526 lang = pango_context_get_language (pango_layout_get_context(layout)); |
527 font_metrics = pango_font_get_metrics(font, lang); //it's ok. | |
528 // font_metrics = pango_font_get_metrics(font, NULL); //crash! | |
522 | 529 |
523 pango_layout_get_pixel_size(layout, &scr_w, NULL); | 530 pango_layout_get_pixel_size(layout, &scr_w, NULL); |
524 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + | 531 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + |
525 pango_font_metrics_get_descent(font_metrics))/ 4); | 532 pango_font_metrics_get_descent(font_metrics))/ 4); |
526 | 533 |
632 anchor = gtk_text_iter_get_child_anchor(&iter); | 639 anchor = gtk_text_iter_get_child_anchor(&iter); |
633 if (anchor) { | 640 if (anchor) { |
634 tip = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_tiptext"); | 641 tip = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_tiptext"); |
635 hand = FALSE; | 642 hand = FALSE; |
636 } | 643 } |
637 | |
638 if (tip && *tip) { | 644 if (tip && *tip) { |
639 if (!GTK_IMHTML(imhtml)->editable && hand) | 645 if (!GTK_IMHTML(imhtml)->editable && hand) |
640 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); | 646 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); |
641 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | 647 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, |
642 gtk_imhtml_tip, imhtml); | 648 gtk_imhtml_tip, imhtml); |
643 } | 649 } |
644 | |
645 GTK_IMHTML(imhtml)->tip = tip; | 650 GTK_IMHTML(imhtml)->tip = tip; |
646 g_slist_free(tags); | 651 g_slist_free(tags); |
647 return FALSE; | 652 return FALSE; |
648 } | 653 } |
649 | 654 |
1000 } | 1005 } |
1001 | 1006 |
1002 if (info == TARGET_HTML) { | 1007 if (info == TARGET_HTML) { |
1003 char *selection; | 1008 char *selection; |
1004 #ifndef _WIN32 | 1009 #ifndef _WIN32 |
1005 gsize len; | |
1006 if (primary) { | 1010 if (primary) { |
1007 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); | 1011 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); |
1008 } else | 1012 } else |
1009 text = html_clipboard; | 1013 text = html_clipboard; |
1010 | 1014 |
1011 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | 1015 selection = NULL; |
1012 selection = g_convert(text, -1, "UTF-16", "UTF-8", NULL, &len, NULL); | 1016 if (primary) { |
1013 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len); | 1017 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); |
1014 #else | 1018 } else { |
1019 text = html_clipboard; | |
1020 } | |
1021 /* xxx should remove following line --yaz */ | |
1022 purple_debug_info("imhtml clipboard", "html_clipboard: %s len = %d\n", text, strlen(text)); | |
1023 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), | |
1024 8, (const guchar *)text, strlen(text)+1); // include trailing '\0' --yaz | |
1025 #else /*_WIN32 */ | |
1015 selection = clipboard_html_to_win32(html_clipboard); | 1026 selection = clipboard_html_to_win32(html_clipboard); |
1016 gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), 8, (const guchar *)selection, strlen(selection)); | 1027 gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), |
1028 8, (const guchar *)selection, strlen(selection)); | |
1017 #endif | 1029 #endif |
1018 g_free(selection); | 1030 g_free(selection); |
1019 } else { | 1031 } else { |
1020 if (primary) { | 1032 if (primary) { |
1021 text = gtk_imhtml_get_text(imhtml, &start, &end); | 1033 text = gtk_imhtml_get_text(imhtml, &start, &end); |
1162 } | 1174 } |
1163 | 1175 |
1164 if (selection_data->length >= 2 && | 1176 if (selection_data->length >= 2 && |
1165 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { | 1177 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { |
1166 /* This is UTF-16 */ | 1178 /* This is UTF-16 */ |
1167 char *utf8 = utf16_to_utf8_with_bom_check(text, selection_data->length); | 1179 // char *utf8 = utf16_to_utf8_with_bom_check(text, selection_data->length); |
1180 char *utf8 = g_convert(text, selection_data->length, "UTF-8", "UTF-16", NULL, NULL, NULL); | |
1168 g_free(text); | 1181 g_free(text); |
1169 text = utf8; | 1182 text = utf8; |
1170 if (!text) { | 1183 if (!text) { |
1171 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in paste_received_cb\n"); | 1184 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in paste_received_cb\n"); |
1172 return; | 1185 return; |
1903 * | 1916 * |
1904 * See also the comment on text/html here: | 1917 * See also the comment on text/html here: |
1905 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html | 1918 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html |
1906 */ | 1919 */ |
1907 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) { | 1920 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) { |
1908 utf8 = utf16_to_utf8_with_bom_check(text, sd->length); | 1921 // utf8 = utf16_to_utf8_with_bom_check(text, sd->length); |
1922 utf8 = g_convert(text, sd->length, "UTF-8", "UTF-16", NULL, NULL, NULL); | |
1909 | 1923 |
1910 if (!utf8) { | 1924 if (!utf8) { |
1911 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in drag_rcv_cb\n"); | 1925 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in drag_rcv_cb\n"); |
1912 return; | 1926 return; |
1913 } | 1927 } |
3204 pos++; | 3218 pos++; |
3205 } else { | 3219 } else { |
3206 break; | 3220 break; |
3207 } | 3221 } |
3208 } | 3222 } |
3223 ws[wpos] = '\0'; // chop ws at wpos. due to bug of gtk_text_buffer_insert() --yaz | |
3209 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | 3224 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
3210 ws[0] = '\0'; wpos = 0; | 3225 ws[0] = '\0'; wpos = 0; |
3211 | 3226 |
3212 /* NEW_BIT(NEW_TEXT_BIT); */ | 3227 /* NEW_BIT(NEW_TEXT_BIT); */ |
3213 | 3228 |
3218 gtk_text_iter_set_line(&line_iter, align_line); | 3233 gtk_text_iter_set_line(&line_iter, align_line); |
3219 /* insert RLM character to set alignment */ | 3234 /* insert RLM character to set alignment */ |
3220 ws[wpos++] = 0xE2; | 3235 ws[wpos++] = 0xE2; |
3221 ws[wpos++] = 0x80; | 3236 ws[wpos++] = 0x80; |
3222 ws[wpos++] = 0x8F; | 3237 ws[wpos++] = 0x8F; |
3223 | 3238 |
3224 if (!rtl_direction) | 3239 if (!rtl_direction) |
3225 { | 3240 { |
3226 /* insert LRM character to set direction */ | 3241 /* insert LRM character to set direction */ |
3227 /* (alignment=right and direction=LTR) */ | 3242 /* (alignment=right and direction=LTR) */ |
3228 ws[wpos++] = 0xE2; | 3243 ws[wpos++] = 0xE2; |