]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkim-x11.c
Fix string offsets.
[~andy/gtk] / gdk / x11 / gdkim-x11.c
index bd118b0aa0f7c0c4840e82235f9f41e23fb0a96d..0ee7356531530ded634d775fb90d80a68acdde08 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <config.h>
+
 #include <locale.h>
+#include <stdlib.h>
+#include <string.h>
 
+#include "gdkx.h"
 #include "gdk.h"               /* For gdk_flush() */
+#include "gdkx.h"
 #include "gdkpixmap.h"
-#include "gdki18n.h"
 #include "gdkinternals.h"
-#include "gdkprivate-x11.h"
-
-#if HAVE_CONFIG_H
-#  include <config.h>
-#  if STDC_HEADERS
-#    include <string.h>
-#  endif
-#endif
+#include "gdkdisplay-x11.h"
+#include "gdkalias.h"
 
 
 /* If this variable is FALSE, it indicates that we should
@@ -67,7 +66,7 @@ _gdk_x11_initialize_locale (void)
     g_warning ("locale not supported by Xlib");
   
   if (!XSetLocaleModifiers (""))
-    g_warning ("can not set locale modifiers");
+    g_warning ("cannot set locale modifiers");
 
   if ((strcmp (current_locale, "C")) && (strcmp (current_locale, "POSIX")))
     {
@@ -84,7 +83,8 @@ _gdk_x11_initialize_locale (void)
          result == 0x765)
        {
          if ((strlen (current_locale) < 4) ||
-             g_strcasecmp (current_locale + strlen(current_locale) - 4, "utf8"))
+             g_ascii_strcasecmp (current_locale + strlen(current_locale) - 4,
+                                 "utf8"))
            gdk_use_mb = FALSE;
        }
 #endif /* X_LOCALE */
@@ -94,7 +94,7 @@ _gdk_x11_initialize_locale (void)
            g_message ("%s multi-byte string functions.", 
                       gdk_use_mb ? "Using" : "Not using"));
   
-  return current_locale;
+  return;
 }
 
 gchar*
@@ -108,14 +108,29 @@ gdk_set_locale (void)
   return setlocale (LC_ALL, NULL);
 }
 
-/*
- * 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.
- */
+static GdkDisplay *
+find_a_display (void)
+{
+  GdkDisplay *display = gdk_display_get_default ();
+
+  if (!display)
+    display = _gdk_displays->data;
+
+  return display;
+}
+
+/**
+ * gdk_wcstombs:
+ * @src: a wide character string.
+ * 
+ * Converts a wide character string to a multi-byte string.
+ * (The function name comes from an acronym of 'Wide Character String TO
+ * Multi-Byte String').
+ * 
+ * Return value: the multi-byte string corresponding to @src, or %NULL if the
+ * conversion failed. The returned string should be freed with g_free() when no
+ * longer needed.
+ **/
 gchar *
 gdk_wcstombs (const GdkWChar *src)
 {
@@ -123,6 +138,8 @@ gdk_wcstombs (const GdkWChar *src)
 
   if (gdk_use_mb)
     {
+      GdkDisplay *display = find_a_display ();
+      Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
       XTextProperty tpr;
 
       if (sizeof(wchar_t) != sizeof(GdkWChar))
@@ -133,7 +150,7 @@ gdk_wcstombs (const GdkWChar *src)
          src_alt = g_new (wchar_t, i+1);
          for (; i>=0; i--)
            src_alt[i] = src[i];
-         if (XwcTextListToTextProperty (gdk_display, &src_alt, 1, XTextStyle, &tpr)
+         if (XwcTextListToTextProperty (xdisplay, &src_alt, 1, XTextStyle, &tpr)
              != Success)
            {
              g_free (src_alt);
@@ -143,11 +160,15 @@ gdk_wcstombs (const GdkWChar *src)
        }
       else
        {
-         if (XwcTextListToTextProperty (gdk_display, (wchar_t**)&src, 1,
+         wchar_t *tmp;
+         
+         if (XwcTextListToTextProperty (xdisplay, &tmp, 1,
                                         XTextStyle, &tpr) != Success)
            {
              return NULL;
            }
+         
+         src = (GdkWChar *)tmp;
        }
       /*
        * We must copy the string into an area allocated by glib, because
@@ -172,31 +193,39 @@ gdk_wcstombs (const GdkWChar *src)
 
   return mbstr;
 }
+/**
+ * gdk_mbstowcs:
+ * @dest: the space to place the converted wide character string into.
+ * @src: the multi-byte string to convert, which must be nul-terminated.
+ * @dest_max: the maximum number of wide characters to place in @dest.
+ * 
+ * Converts a multi-byte string to a wide character string.
+ * (The function name comes from an acronym of 'Multi-Byte String TO Wide
+ * Character String').
+ * 
+ * Return value: the number of wide characters written into @dest, or -1 if 
+ *   the conversion failed.
+ **/
   
-/*
- * gdk_mbstowcs
- *
- * Converts the specified string into 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.
- */
 gint
 gdk_mbstowcs (GdkWChar *dest, const gchar *src, gint dest_max)
 {
   if (gdk_use_mb)
     {
+      GdkDisplay *display = find_a_display ();
+      Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
       XTextProperty tpr;
       wchar_t **wstrs, *wstr_src;
       gint num_wstrs;
       gint len_cpy;
-      if (XmbTextListToTextProperty (gdk_display, (char **)&src, 1, XTextStyle,
+      if (XmbTextListToTextProperty (xdisplay, (char **)&src, 1, XTextStyle,
                                     &tpr)
          != Success)
        {
          /* NoMem or LocaleNotSupp */
          return -1;
        }
-      if (XwcTextPropertyToTextList (gdk_display, &tpr, &wstrs, &num_wstrs)
+      if (XwcTextPropertyToTextList (xdisplay, &tpr, &wstrs, &num_wstrs)
          != Success)
        {
          /* InvalidChar */
@@ -222,3 +251,6 @@ gdk_mbstowcs (GdkWChar *dest, const gchar *src, gint dest_max)
       return i;
     }
 }
+
+#define __GDK_IM_X11_C__
+#include "gdkaliasdef.c"