]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkim-x11.c
Don't use gtk_set_locale
[~andy/gtk] / gdk / x11 / gdkim-x11.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include "config.h"
28
29 #include "gdkmain.h"
30 #include "gdkinternals.h"
31 #include "gdkdisplay-x11.h"
32 #include "gdkprivate-x11.h"
33
34 #include <locale.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38
39 /* If this variable is FALSE, it indicates that we should
40  * avoid trying to use multibyte conversion functions and
41  * assume everything is 1-byte per character
42  */
43 static gboolean gdk_use_mb;
44
45 void
46 _gdk_x11_initialize_locale (void)
47 {
48   wchar_t result;
49   gchar *current_locale;
50   static char *last_locale = NULL;
51
52   gdk_use_mb = FALSE;
53
54   current_locale = setlocale (LC_ALL, NULL);
55
56   if (last_locale && strcmp (last_locale, current_locale) == 0)
57     return;
58
59   g_free (last_locale);
60   last_locale = g_strdup (current_locale);
61
62   if (XSupportsLocale ())
63     XSetLocaleModifiers ("");
64
65   if ((strcmp (current_locale, "C")) && (strcmp (current_locale, "POSIX")))
66     {
67       gdk_use_mb = TRUE;
68
69 #ifndef X_LOCALE
70       /* Detect ancient GNU libc, where mb == UTF8. Not useful unless it's
71        * really a UTF8 locale. The below still probably will
72        * screw up on Greek, Cyrillic, etc, encoded as UTF8.
73        */
74       
75       if ((MB_CUR_MAX == 2) &&
76           (mbstowcs (&result, "\xdd\xa5", 1) > 0) &&
77           result == 0x765)
78         {
79           if ((strlen (current_locale) < 4) ||
80               g_ascii_strcasecmp (current_locale + strlen(current_locale) - 4,
81                                   "utf8"))
82             gdk_use_mb = FALSE;
83         }
84 #endif /* X_LOCALE */
85     }
86
87   GDK_NOTE (XIM,
88             g_message ("%s multi-byte string functions.", 
89                        gdk_use_mb ? "Using" : "Not using"));
90   
91   return;
92 }
93
94 gchar*
95 gdk_set_locale (void)
96 {
97   if (!setlocale (LC_ALL,""))
98     g_warning ("locale not supported by C library");
99
100   _gdk_x11_initialize_locale ();
101   
102   return setlocale (LC_ALL, NULL);
103 }