summaryrefslogtreecommitdiff
path: root/gdk/win32/gdkim-win32.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2004-07-07 00:10:03 +0000
committerTor Lillqvist <tml@src.gnome.org>2004-07-07 00:10:03 +0000
commitd8b2f46c18a85929f6a860b5161cf3d12d589614 (patch)
treedc4d750ba15d2dbc38344f12fe36364f01bb1f33 /gdk/win32/gdkim-win32.c
parentd1c69ab84eb2880b83e712bb5d5fd0a3ae3f10ec (diff)
downloadgtk+-d8b2f46c18a85929f6a860b5161cf3d12d589614.tar.gz
gdk/win32/gdkdrawable-win32.c (gdk_win32_draw_text)
2004-07-07 Tor Lillqvist <tml@iki.fi> * gdk/win32/gdkdrawable-win32.c (gdk_win32_draw_text) * gdk/win32/gdkfont-win32.c (gdk_text_extents) * gdk/win32/gdkproperty-win32.c (find_common_locale, gdk_property_change) * gdk/win32/gdkselection-win32.c (gdk_selection_convert): Use g_utf8_to_utf16() instead of the removed _gdk_utf8_to_ucs2() (see below). * gdk/win32/gdkglobals-win32.c * gdk/win32/gdkmain-win32.c (_gdk_windowing_init) * gdk/win3/gdkprivate-win32.h: Add a variable for the TARGETS atom. Initialize it. Declare it. Drop the variable for the COMPOUND_TEXT atom. * gdk/win32/gdkim-win32.c (gdk_wcstombs): Don't return UTF-8. This function is supposed to return the string in the locale's charset and encoding. Use g_convert(). (gdk_mbstowcs): Similarily, don't take an UTF-8 string, but a string in the locale's charset. Use g_convert(). (_gdk_ucs2_to_utf8, _gdk_utf8_to_wcs, _gdk_utf8_to_ucs2): Delete. The UCS-2 functions didn't handle surrogates anyway. Use GLib's UTF-16 functions instead. Windows uses UTF-16. * gdk/win32/gdkprivate-win32.h: Remove declarations of the deleted functions mentioned above. * gdk/win32/gdkproperty-win32.c (gdk_property_change): Use CF_TEXT also if the string is of type STRING, i.e. ISO-8859-1, and the current codepage is 1252, and contains no C1 chars. Accept also UTF8_STRING. * gdk/win32/gdkselection-win32.c (_gdk_selection_property_store): Mark as static. When storing STRING data, convert to Latin-1. (#140537) (gdk_selection_owner_set_for_display): Now that STRING is always ISO-8859-1, use UTF8_STRING when sending the selection request to ourselves. (gdk_selection_convert): Handle also UTF8_STRING. (#140537, John Ehresman) (gdk_text_property_to_text_list_for_display): Make work more like X11 version. Do obey the encoding parameter. (gdk_string_to_compound_text_for_display, gdk_utf8_to_compound_text_for_display): Don't even pretend supporting COMPOUND_TEXT. (gdk_utf8_to_string_target): Convert to ISO-8859-1, like on X11. (sanitize_utf8): Zero-terminate string.
Diffstat (limited to 'gdk/win32/gdkim-win32.c')
-rw-r--r--gdk/win32/gdkim-win32.c322
1 files changed, 18 insertions, 304 deletions
diff --git a/gdk/win32/gdkim-win32.c b/gdk/win32/gdkim-win32.c
index b31b1b5dd3..aeb29bf7dd 100644
--- a/gdk/win32/gdkim-win32.c
+++ b/gdk/win32/gdkim-win32.c
@@ -1,6 +1,6 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- * Copyright (C) 1998-2002 Tor Lillqvist
+ * Copyright (C) 1998-2004 Tor Lillqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -58,321 +58,35 @@ gdk_set_locale (void)
return g_win32_getlocale ();
}
-/*
- * gdk_wcstombs
- *
- * Returns a multi-byte string converted from the specified array
- * of wide characters. The string is newly allocated. The array of
- * wide characters must be null-terminated. If the conversion is
- * failed, it returns NULL.
- *
- * On Win32, we always use UTF-8.
- */
gchar *
gdk_wcstombs (const GdkWChar *src)
{
- gint len;
- const GdkWChar *wcp;
- guchar *mbstr, *bp;
-
- wcp = src;
- len = 0;
- while (*wcp)
- {
- const GdkWChar c = *wcp++;
-
- if (c < 0x80)
- len += 1;
- else if (c < 0x800)
- len += 2;
- else if (c < 0x10000)
- len += 3;
- else if (c < 0x200000)
- len += 4;
- else if (c < 0x4000000)
- len += 5;
- else
- len += 6;
- }
-
- mbstr = g_malloc (len + 1);
-
- wcp = src;
- bp = mbstr;
- while (*wcp)
- {
- int first;
- GdkWChar c = *wcp++;
-
- if (c < 0x80)
- {
- first = 0;
- len = 1;
- }
- else if (c < 0x800)
- {
- first = 0xc0;
- len = 2;
- }
- else if (c < 0x10000)
- {
- first = 0xe0;
- len = 3;
- }
- else if (c < 0x200000)
- {
- first = 0xf0;
- len = 4;
- }
- else if (c < 0x4000000)
- {
- first = 0xf8;
- len = 5;
- }
- else
- {
- first = 0xfc;
- len = 6;
- }
-
- /* Woo-hoo! */
- switch (len)
- {
- case 6: bp[5] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
- case 5: bp[4] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
- case 4: bp[3] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
- case 3: bp[2] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
- case 2: bp[1] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
- case 1: bp[0] = c | first;
- }
-
- bp += len;
- }
- *bp = 0;
- return mbstr;
-}
-
-/* A vesion that converts from wchar_t strings to UTF-8 */
-
-gchar *
-_gdk_ucs2_to_utf8 (const wchar_t *src,
- gint src_len)
-{
- gint len;
- const wchar_t *wcp;
- guchar *mbstr, *bp;
-
- wcp = src;
- len = 0;
- while (wcp < src + src_len)
- {
- const wchar_t c = *wcp++;
-
- if (c < 0x80)
- len += 1;
- else if (c < 0x800)
- len += 2;
- else
- len += 3;
- }
-
- mbstr = g_malloc (len + 1);
-
- wcp = src;
- bp = mbstr;
- while (wcp < src + src_len)
- {
- int first;
- wchar_t c = *wcp++;
-
- if (c < 0x80)
- {
- first = 0;
- len = 1;
- }
- else if (c < 0x800)
- {
- first = 0xc0;
- len = 2;
- }
- else
- {
- first = 0xe0;
- len = 3;
- }
-
- /* Woo-hoo! */
- switch (len)
- {
- case 3: bp[2] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
- case 2: bp[1] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
- case 1: bp[0] = c | first;
- }
-
- bp += len;
- }
- *bp = 0;
-
- return mbstr;
-}
-
-/* Convert from UTF-8 to GdkWChar */
-
-gint
-_gdk_utf8_to_wcs (GdkWChar *dest,
- const gchar *src,
- gint src_len,
- gint dest_max)
-{
- guchar *cp, *end;
- gint n;
-
- cp = (guchar *) src;
- end = cp + src_len;
- n = 0;
- while (cp != end && dest != dest + dest_max)
- {
- gint i, mask = 0, len;
- guchar c = *cp;
-
- if (c < 0x80)
- {
- len = 1;
- mask = 0x7f;
- }
- else if ((c & 0xe0) == 0xc0)
- {
- len = 2;
- mask = 0x1f;
- }
- else if ((c & 0xf0) == 0xe0)
- {
- len = 3;
- mask = 0x0f;
- }
- else if ((c & 0xf8) == 0xf0)
- {
- len = 4;
- mask = 0x07;
- }
- else if ((c & 0xfc) == 0xf8)
- {
- len = 5;
- mask = 0x03;
- }
- else if ((c & 0xfc) == 0xfc)
- {
- len = 6;
- mask = 0x01;
- }
- else
- return -1;
+ gchar *utf8;
+ gchar *retval;
+ const gchar *charset;
- if (cp + len > end)
- return -1;
-
- *dest = (cp[0] & mask);
- for (i = 1; i < len; i++)
- {
- if ((cp[i] & 0xc0) != 0x80)
- return -1;
- *dest <<= 6;
- *dest |= (cp[i] & 0x3f);
- }
- if (*dest == -1)
- return -1;
-
- cp += len;
- dest++;
- n++;
- }
- if (cp != end)
- return -1;
-
- return n;
+ g_get_charset (&charset);
+ return g_convert (src, -1, charset, "UCS-4LE", NULL, NULL, NULL);
}
-/*
- * gdk_mbstowcs
- *
- * Converts the specified string into GDK wide characters, and,
- * returns the number of wide characters written. The string 'src'
- * must be null-terminated. If the conversion is failed, it returns
- * -1.
- *
- * On Win32, the string is assumed to be in UTF-8. Also note that
- * GdkWChar is 32 bits, while wchar_t, and the wide characters the
- * Windows API uses, are 16 bits!
- */
-
gint
gdk_mbstowcs (GdkWChar *dest,
const gchar *src,
gint dest_max)
{
- return _gdk_utf8_to_wcs (dest, src, strlen (src), dest_max);
-}
-
-
-/* A version that converts to a wchar_t string */
-
-gint
-_gdk_utf8_to_ucs2 (wchar_t *dest,
- const gchar *src,
- gint src_len,
- gint dest_max)
-{
- wchar_t *wcp;
- guchar *cp, *end;
- gint n;
-
- wcp = dest;
- cp = (guchar *) src;
- end = cp + src_len;
- n = 0;
- while (cp != end && wcp != dest + dest_max)
- {
- gint i, mask = 0, len;
- guchar c = *cp;
-
- if (c < 0x80)
- {
- len = 1;
- mask = 0x7f;
- }
- else if ((c & 0xe0) == 0xc0)
- {
- len = 2;
- mask = 0x1f;
- }
- else if ((c & 0xf0) == 0xe0)
- {
- len = 3;
- mask = 0x0f;
- }
- else /* Other lengths are not possible with 16-bit wchar_t! */
- return -1;
-
- if (cp + len > end)
- return -1;
+ gint retval;
+ gsize nwritten;
+ gint n_ucs4;
+ gunichar *ucs4;
+ const gchar *charset;
- *wcp = (cp[0] & mask);
- for (i = 1; i < len; i++)
- {
- if ((cp[i] & 0xc0) != 0x80)
- return -1;
- *wcp <<= 6;
- *wcp |= (cp[i] & 0x3f);
- }
- if (*wcp == 0xFFFF)
- return -1;
+ g_get_charset (&charset);
+ ucs4 = g_convert (src, -1, "UCS-4LE", charset, NULL, &nwritten, NULL);
+ n_ucs4 = nwritten * sizeof (GdkWChar);
- cp += len;
- wcp++;
- n++;
- }
- if (cp != end)
- return -1;
+ retval = MIN (dest_max, n_ucs4);
+ memmove (dest, ucs4, retval * sizeof (GdkWChar));
+ g_free (ucs4);
- return n;
+ return retval;
}