diff pidgin/gtkimhtml.c @ 27905:45ce87f9a07f

propagate from branch 'im.pidgin.pidgin' (head 7821a3549d7d99473e999dc067afc4218addcc1e) to branch 'im.pidgin.pidgin.yaz' (head a23f8b0bf428af45a81e2d1baa0305cca0ad2a59)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Fri, 31 Oct 2008 08:37:42 +0000
parents 8282911d5e17 15d6ae92aeb4
children 6ecfc6b9667c
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c	Fri Oct 31 04:03:44 2008 +0000
+++ b/pidgin/gtkimhtml.c	Fri Oct 31 08:37:42 2008 +0000
@@ -95,6 +95,10 @@
                            gint              y,
                            guint             time);
 
+/* yaz. If you want to use shortcut keys that may conflict with
+   inputmethods, change this to 1. */
+#define ENABLE_SHORTCUT 0
+
 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml);
 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml);
 static void delete_cb(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter *end, GtkIMHtml *imhtml);
@@ -485,10 +489,11 @@
 static gint
 gtk_imhtml_tip (gpointer data)
 {
-	GtkIMHtml *imhtml = data;
+	GtkIMHtml *imhtml = (GtkIMHtml *)data;
 	PangoFontMetrics *font_metrics;
 	PangoLayout *layout;
 	PangoFont *font;
+	PangoLanguage *lang;
 
 	gint gap, x, y, h, w, scr_w, baseline_skip;
 
@@ -534,7 +539,9 @@
 		return FALSE;
 	}
 
-	font_metrics = pango_font_get_metrics(font, NULL);
+	lang = pango_context_get_language (pango_layout_get_context(layout));
+	font_metrics = pango_font_get_metrics(font, lang); //it's ok.
+//	font_metrics = pango_font_get_metrics(font, NULL); //crash!
 
 	pango_layout_get_pixel_size(layout, &scr_w, NULL);
 	gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) +
@@ -647,14 +654,12 @@
 		tip = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_tiptext");
 		hand = FALSE;
 	}
-
 	if (tip && *tip) {
 		if (!GTK_IMHTML(imhtml)->editable && hand)
 			gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor);
 		GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT,
 							       gtk_imhtml_tip, imhtml);
 	}
-
 	GTK_IMHTML(imhtml)->tip = tip;
 	g_slist_free(tags);
 	return FALSE;
@@ -1010,18 +1015,25 @@
 	if (info == TARGET_HTML) {
 		char *selection;
 #ifndef _WIN32
-		gsize len;
 		if (primary) {
 			text = gtk_imhtml_get_markup_range(imhtml, &start, &end);
 		} else
 			text = html_clipboard;
 
-		/* Mozilla asks that we start our text/html with the Unicode byte order mark */
-		selection = g_convert(text, -1, "UTF-16", "UTF-8", NULL, &len, NULL);
-		gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len);
-#else
+		selection = NULL;
+		if (primary) {
+			text = gtk_imhtml_get_markup_range(imhtml, &start, &end);
+		} else {
+			text = html_clipboard;
+		}
+		/* xxx should remove following line --yaz */
+		purple_debug_info("imhtml clipboard", "html_clipboard: %s len = %d\n", text, strlen(text));
+		gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE),
+				       8, (const guchar *)text, strlen(text)+1); // include trailing '\0' --yaz
+#else /*_WIN32 */
 		selection = clipboard_html_to_win32(html_clipboard);
-		gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), 8, (const guchar *)selection, strlen(selection));
+		gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE),
+				       8, (const guchar *)selection, strlen(selection));
 #endif
 		g_free(selection);
 	} else {
@@ -1172,7 +1184,8 @@
 	if (selection_data->length >= 2 &&
 		(*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) {
 		/* This is UTF-16 */
-		char *utf8 = utf16_to_utf8_with_bom_check(text, selection_data->length);
+//		char *utf8 = utf16_to_utf8_with_bom_check(text, selection_data->length);
+		char *utf8 = g_convert(text, selection_data->length, "UTF-8", "UTF-16", NULL, NULL, NULL);
 		g_free(text);
 		text = utf8;
 		if (!text) {
@@ -1925,7 +1938,8 @@
 			 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html
 			 */
 			if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) {
-				utf8 = utf16_to_utf8_with_bom_check(text, sd->length);
+//				utf8 = utf16_to_utf8_with_bom_check(text, sd->length);
+				utf8 = g_convert(text, sd->length, "UTF-8", "UTF-16", NULL, NULL, NULL);
 
 				if (!utf8) {
 					purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in drag_rcv_cb\n");
@@ -3314,6 +3328,7 @@
 			break;
 		}
 	}
+	ws[wpos] = '\0'; // chop ws at wpos. due to bug of gtk_text_buffer_insert() --yaz
 	gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos);
 	ws[0] = '\0'; wpos = 0;
 
@@ -3328,7 +3343,7 @@
 		ws[wpos++]  = 0xE2;
 		ws[wpos++]  = 0x80;
 		ws[wpos++]  = 0x8F;
-    
+
 		if (!rtl_direction)
 		{
 			/* insert LRM character to set direction */