| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "config.h" |
| 28 |
|
| 29 |
#include <locale.h> |
| 30 |
#include <stdlib.h> |
| 31 |
#include <string.h> |
| 32 |
|
| 33 |
#include "gdkx.h" |
| 34 |
#include "gdk.h" |
| 35 |
#include "gdkpixmap.h" |
| 36 |
#include "gdkinternals.h" |
| 37 |
#include "gdkdisplay-x11.h" |
| 38 |
#include "gdkalias.h" |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
static gboolean gdk_use_mb; |
| 46 |
|
| 47 |
void |
| 48 |
_gdk_x11_initialize_locale (void) |
| 49 |
{ |
| 50 |
wchar_t result; |
| 51 |
gchar *current_locale; |
| 52 |
static char *last_locale = NULL; |
| 53 |
|
| 54 |
gdk_use_mb = FALSE; |
| 55 |
|
| 56 |
current_locale = setlocale (LC_ALL, NULL); |
| 57 |
|
| 58 |
if (last_locale && strcmp (last_locale, current_locale) == 0) |
| 59 |
return; |
| 60 |
|
| 61 |
g_free (last_locale); |
| 62 |
last_locale = g_strdup (current_locale); |
| 63 |
|
| 64 |
if (XSupportsLocale ()) |
| 65 |
XSetLocaleModifiers (""); |
| 66 |
|
| 67 |
if ((strcmp (current_locale, "C")) && (strcmp (current_locale, "POSIX"))) |
| 68 |
{ |
| 69 |
gdk_use_mb = TRUE; |
| 70 |
|
| 71 |
#ifndef X_LOCALE |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
if ((MB_CUR_MAX == 2) && |
| 78 |
(mbstowcs (&result, "\xdd\xa5", 1) > 0) && |
| 79 |
result == 0x765) |
| 80 |
{ |
| 81 |
if ((strlen (current_locale) < 4) || |
| 82 |
g_ascii_strcasecmp (current_locale + strlen(current_locale) - 4, |
| 83 |
"utf8")) |
| 84 |
gdk_use_mb = FALSE; |
| 85 |
} |
| 86 |
#endif |
| 87 |
} |
| 88 |
|
| 89 |
GDK_NOTE (XIM, |
| 90 |
g_message ("%s multi-byte string functions.", |
| 91 |
gdk_use_mb ? "Using" : "Not using")); |
| 92 |
|
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
gchar* |
| 97 |
gdk_set_locale (void) |
| 98 |
{ |
| 99 |
if (!setlocale (LC_ALL,"")) |
| 100 |
g_warning ("locale not supported by C library"); |
| 101 |
|
| 102 |
_gdk_x11_initialize_locale (); |
| 103 |
|
| 104 |
return setlocale (LC_ALL, NULL); |
| 105 |
} |
| 106 |
|
| 107 |
static GdkDisplay * |
| 108 |
find_a_display (void) |
| 109 |
{ |
| 110 |
GdkDisplay *display = gdk_display_get_default (); |
| 111 |
|
| 112 |
if (!display) |
| 113 |
display = _gdk_displays->data; |
| 114 |
|
| 115 |
return display; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
gchar * |
| 131 |
gdk_wcstombs (const GdkWChar *src) |
| 132 |
{ |
| 133 |
gchar *mbstr; |
| 134 |
|
| 135 |
if (gdk_use_mb) |
| 136 |
{ |
| 137 |
GdkDisplay *display = find_a_display (); |
| 138 |
Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); |
| 139 |
XTextProperty tpr; |
| 140 |
|
| 141 |
if (sizeof(wchar_t) != sizeof(GdkWChar)) |
| 142 |
{ |
| 143 |
gint i; |
| 144 |
wchar_t *src_alt; |
| 145 |
for (i=0; src[i]; i++); |
| 146 |
src_alt = g_new (wchar_t, i+1); |
| 147 |
for (; i>=0; i--) |
| 148 |
src_alt[i] = src[i]; |
| 149 |
if (XwcTextListToTextProperty (xdisplay, &src_alt, 1, XTextStyle, &tpr) |
| 150 |
!= Success) |
| 151 |
{ |
| 152 |
g_free (src_alt); |
| 153 |
return NULL; |
| 154 |
} |
| 155 |
g_free (src_alt); |
| 156 |
} |
| 157 |
else |
| 158 |
{ |
| 159 |
wchar_t *tmp; |
| 160 |
|
| 161 |
if (XwcTextListToTextProperty (xdisplay, &tmp, 1, |
| 162 |
XTextStyle, &tpr) != Success) |
| 163 |
{ |
| 164 |
return NULL; |
| 165 |
} |
| 166 |
|
| 167 |
src = (GdkWChar *)tmp; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
mbstr = g_strdup((gchar *)tpr.value); |
| 174 |
XFree (tpr.value); |
| 175 |
} |
| 176 |
else |
| 177 |
{ |
| 178 |
gint length = 0; |
| 179 |
gint i; |
| 180 |
|
| 181 |
while (src[length] != 0) |
| 182 |
length++; |
| 183 |
|
| 184 |
mbstr = g_new (gchar, length + 1); |
| 185 |
|
| 186 |
for (i=0; i<length+1; i++) |
| 187 |
mbstr[i] = src[i]; |
| 188 |
} |
| 189 |
|
| 190 |
return mbstr; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
gint |
| 207 |
gdk_mbstowcs (GdkWChar *dest, const gchar *src, gint dest_max) |
| 208 |
{ |
| 209 |
if (gdk_use_mb) |
| 210 |
{ |
| 211 |
GdkDisplay *display = find_a_display (); |
| 212 |
Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); |
| 213 |
XTextProperty tpr; |
| 214 |
wchar_t **wstrs, *wstr_src; |
| 215 |
gint num_wstrs; |
| 216 |
gint len_cpy; |
| 217 |
if (XmbTextListToTextProperty (xdisplay, (char **)&src, 1, XTextStyle, |
| 218 |
&tpr) |
| 219 |
!= Success) |
| 220 |
{ |
| 221 |
|
| 222 |
return -1; |
| 223 |
} |
| 224 |
if (XwcTextPropertyToTextList (xdisplay, &tpr, &wstrs, &num_wstrs) |
| 225 |
!= Success) |
| 226 |
{ |
| 227 |
|
| 228 |
XFree(tpr.value); |
| 229 |
return -1; |
| 230 |
} |
| 231 |
XFree(tpr.value); |
| 232 |
if (num_wstrs == 0) |
| 233 |
return 0; |
| 234 |
wstr_src = wstrs[0]; |
| 235 |
for (len_cpy=0; len_cpy<dest_max && wstr_src[len_cpy]; len_cpy++) |
| 236 |
dest[len_cpy] = wstr_src[len_cpy]; |
| 237 |
XwcFreeStringList (wstrs); |
| 238 |
return len_cpy; |
| 239 |
} |
| 240 |
else |
| 241 |
{ |
| 242 |
gint i; |
| 243 |
|
| 244 |
for (i=0; i<dest_max && src[i]; i++) |
| 245 |
dest[i] = src[i]; |
| 246 |
|
| 247 |
return i; |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
#define __GDK_IM_X11_C__ |
| 252 |
#include "gdkaliasdef.c" |