Call g_convert(), not g_convert() with fallback, since Emacs is happier if
Wed Feb 25 15:36:50 2004 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkselection-x11.c (gdk_utf8_to_compound_text_for_display): Call g_convert(), not g_convert() with fallback, since Emacs is happier if we reject the COMPOUND_TEXT request and it can then ask for UTF-8. (#114527) * gtk/gtkselection.c (gtk_selection_data_set_text): When TEXT is requested, if COMPOUND_TEXT fails, fall back to STRING.
This commit is contained in:
@ -819,15 +819,19 @@ gdk_utf8_to_compound_text_for_display (GdkDisplay *display,
|
|||||||
|
|
||||||
if (need_conversion)
|
if (need_conversion)
|
||||||
{
|
{
|
||||||
locale_str = g_convert_with_fallback (tmp_str, -1,
|
locale_str = g_convert (tmp_str, -1,
|
||||||
charset, "UTF-8",
|
charset, "UTF-8",
|
||||||
NULL, NULL, NULL, &error);
|
NULL, NULL, &error);
|
||||||
g_free (tmp_str);
|
g_free (tmp_str);
|
||||||
|
|
||||||
if (!locale_str)
|
if (!locale_str)
|
||||||
|
{
|
||||||
|
if (!(error->domain = G_CONVERT_ERROR &&
|
||||||
|
error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
|
||||||
{
|
{
|
||||||
g_warning ("Error converting from UTF-8 to '%s': %s",
|
g_warning ("Error converting from UTF-8 to '%s': %s",
|
||||||
charset, error->message);
|
charset, error->message);
|
||||||
|
}
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
|
||||||
if (encoding)
|
if (encoding)
|
||||||
|
@ -813,6 +813,55 @@ init_atoms (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
selection_set_string (GtkSelectionData *selection_data,
|
||||||
|
const gchar *str,
|
||||||
|
gint len)
|
||||||
|
{
|
||||||
|
gchar *tmp = g_strndup (str, len);
|
||||||
|
gchar *latin1 = gdk_utf8_to_string_target (tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
if (latin1)
|
||||||
|
{
|
||||||
|
gtk_selection_data_set (selection_data,
|
||||||
|
GDK_SELECTION_TYPE_STRING,
|
||||||
|
8, latin1, strlen (latin1));
|
||||||
|
g_free (latin1);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
selection_set_compound_text (GtkSelectionData *selection_data,
|
||||||
|
const gchar *str,
|
||||||
|
gint len)
|
||||||
|
{
|
||||||
|
gchar *tmp;
|
||||||
|
guchar *text;
|
||||||
|
GdkAtom encoding;
|
||||||
|
gint format;
|
||||||
|
gint new_length;
|
||||||
|
gboolean result = FALSE;
|
||||||
|
|
||||||
|
tmp = g_strndup (str, len);
|
||||||
|
if (gdk_utf8_to_compound_text_for_display (selection_data->display, tmp,
|
||||||
|
&encoding, &format, &text, &new_length))
|
||||||
|
{
|
||||||
|
gtk_selection_data_set (selection_data, encoding, format, text, new_length);
|
||||||
|
gdk_free_compound_text (text);
|
||||||
|
|
||||||
|
result = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_selection_data_set_text:
|
* gtk_selection_data_set_text:
|
||||||
* @selection_data: a #GtkSelectionData
|
* @selection_data: a #GtkSelectionData
|
||||||
@ -831,8 +880,6 @@ gtk_selection_data_set_text (GtkSelectionData *selection_data,
|
|||||||
const gchar *str,
|
const gchar *str,
|
||||||
gint len)
|
gint len)
|
||||||
{
|
{
|
||||||
gboolean result = FALSE;
|
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen (str);
|
len = strlen (str);
|
||||||
|
|
||||||
@ -843,48 +890,22 @@ gtk_selection_data_set_text (GtkSelectionData *selection_data,
|
|||||||
gtk_selection_data_set (selection_data,
|
gtk_selection_data_set (selection_data,
|
||||||
utf8_atom,
|
utf8_atom,
|
||||||
8, (guchar *)str, len);
|
8, (guchar *)str, len);
|
||||||
result = TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else if (selection_data->target == GDK_TARGET_STRING)
|
else if (selection_data->target == GDK_TARGET_STRING)
|
||||||
{
|
{
|
||||||
gchar *tmp = g_strndup (str, len);
|
return selection_set_string (selection_data, str, len);
|
||||||
gchar *latin1 = gdk_utf8_to_string_target (tmp);
|
|
||||||
g_free (tmp);
|
|
||||||
|
|
||||||
if (latin1)
|
|
||||||
{
|
|
||||||
gtk_selection_data_set (selection_data,
|
|
||||||
GDK_SELECTION_TYPE_STRING,
|
|
||||||
8, latin1, strlen (latin1));
|
|
||||||
g_free (latin1);
|
|
||||||
|
|
||||||
result = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (selection_data->target == ctext_atom ||
|
else if (selection_data->target == ctext_atom ||
|
||||||
selection_data->target == text_atom)
|
selection_data->target == text_atom)
|
||||||
{
|
{
|
||||||
gchar *tmp;
|
if (selection_set_compound_text (selection_data, str, len))
|
||||||
guchar *text;
|
return TRUE;
|
||||||
GdkAtom encoding;
|
else if (selection_data->target == text_atom)
|
||||||
gint format;
|
return selection_set_string (selection_data, str, len);
|
||||||
gint new_length;
|
|
||||||
|
|
||||||
tmp = g_strndup (str, len);
|
|
||||||
if (gdk_utf8_to_compound_text_for_display (selection_data->display, tmp,
|
|
||||||
&encoding, &format, &text, &new_length))
|
|
||||||
{
|
|
||||||
gtk_selection_data_set (selection_data, encoding, format, text, new_length);
|
|
||||||
gdk_free_compound_text (text);
|
|
||||||
|
|
||||||
result = TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (tmp);
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user