]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkim.c
e3f6e09c64535cb357f9a1e61085bdaea14c78f9
[~andy/gtk] / gdk / win32 / gdkim.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 Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library 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-1999.  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 #if HAVE_CONFIG_H
28 #  include <config.h>
29 #  if STDC_HEADERS
30 #    include <string.h>
31 #  endif
32 #endif
33
34 #include "gdk.h"
35 #include "gdkprivate.h"
36 #include "gdki18n.h"
37 #include "gdkx.h"
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 /*
46  *--------------------------------------------------------------
47  * gdk_set_locale
48  *
49  * Arguments:
50  *
51  * Results:
52  *
53  * Side effects:
54  *
55  *--------------------------------------------------------------
56  */
57
58 gchar*
59 gdk_set_locale (void)
60 {
61   wchar_t result;
62   gchar *current_locale;
63
64   gdk_use_mb = FALSE;
65
66   if (!setlocale (LC_ALL,""))
67     g_warning ("locale not supported by C library");
68   
69   current_locale = setlocale (LC_ALL, NULL);
70
71   if (MB_CUR_MAX > 1)
72     gdk_use_mb = TRUE;
73
74   GDK_NOTE (XIM, g_message ("%s multi-byte string functions.", 
75                             gdk_use_mb ? "Using" : "Not using"));
76   
77   return current_locale;
78 }
79
80 void 
81 gdk_im_begin (GdkIC *ic, GdkWindow* window)
82 {
83 }
84
85 void 
86 gdk_im_end (void)
87 {
88 }
89
90 GdkIMStyle
91 gdk_im_decide_style (GdkIMStyle supported_style)
92 {
93   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
94 }
95
96 GdkIMStyle
97 gdk_im_set_best_style (GdkIMStyle style)
98 {
99   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
100 }
101
102 gint 
103 gdk_im_ready (void)
104 {
105   return FALSE;
106 }
107
108 GdkIC * 
109 gdk_ic_new (GdkICAttr *attr, GdkICAttributesType mask)
110 {
111   return NULL;
112 }
113
114 void 
115 gdk_ic_destroy (GdkIC *ic)
116 {
117 }
118
119 GdkIMStyle
120 gdk_ic_get_style (GdkIC *ic)
121 {
122   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
123 }
124
125 void 
126 gdk_ic_set_values (GdkIC *ic, ...)
127 {
128 }
129
130 void 
131 gdk_ic_get_values (GdkIC *ic, ...)
132 {
133 }
134
135 GdkICAttributesType 
136 gdk_ic_set_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
137 {
138   return 0;
139 }
140
141 GdkICAttributesType 
142 gdk_ic_get_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
143 {
144   return 0;
145 }
146
147 GdkEventMask 
148 gdk_ic_get_events (GdkIC *ic)
149 {
150   return 0;
151 }
152
153 /*
154  * gdk_wcstombs 
155  *
156  * Returns a multi-byte string converted from the specified array
157  * of wide characters. The string is newly allocated. The array of
158  * wide characters must be null-terminated. If the conversion is
159  * failed, it returns NULL.
160  */
161 gchar *
162 gdk_wcstombs (const GdkWChar *src)
163 {
164   gchar *mbstr;
165
166   if (gdk_use_mb)
167     {
168       gint i, wcsl, mbsl;
169       wchar_t *src_alt;
170
171       for (wcsl = 0; src[wcsl]; wcsl++)
172         ;
173       src_alt = g_new (wchar_t, wcsl+1);
174       for (i = wcsl; i >= 0; i--)
175         src_alt[i] = src[i];
176       mbsl = WideCharToMultiByte (CP_ACP, 0, src_alt, wcsl,
177                                   NULL, 0, NULL, NULL);
178       mbstr = g_new (guchar, mbsl + 1);
179       if (!WideCharToMultiByte (CP_ACP, 0, src_alt, wcsl,
180                                 mbstr, mbsl, NULL, NULL))
181         {
182           g_warning ("gdk_wcstombs: WideCharToMultiByte failed");
183           g_free (mbstr);
184           g_free (src_alt);
185           return NULL;
186         }
187       mbstr[mbsl] = '\0';
188       g_free (src_alt);
189       return mbstr;
190     }
191   else
192     {
193       gint length = 0;
194       gint i;
195
196       while (src[length] != 0)
197         length++;
198       
199       mbstr = g_new (gchar, length + 1);
200
201       for (i=0; i<length+1; i++)
202         mbstr[i] = src[i];
203     }
204
205   return mbstr;
206 }
207
208   
209 /*
210  * gdk_mbstowcs
211  *
212  * Converts the specified string into wide characters, and, returns the
213  * number of wide characters written. The string 'src' must be
214  * null-terminated. If the conversion is failed, it returns -1.
215  */
216 gint
217 gdk_mbstowcs (GdkWChar *dest, const gchar *src, gint dest_max)
218 {
219   if (gdk_use_mb)
220     {
221       gint i, wcsl;
222       wchar_t *wcstr;
223
224       wcsl = MultiByteToWideChar (CP_ACP, 0, src, -1, NULL, 0);
225       wcstr = g_new (wchar_t, wcsl + 1);
226       if (!MultiByteToWideChar (CP_ACP, 0, src, -1, wcstr, wcsl))
227         {
228           g_warning ("gdk_mbstowcs: MultiByteToWideChar failed");
229           g_free (wcstr);
230           return -1;
231         }
232       if (wcsl > dest_max)
233         wcsl = dest_max;
234       for (i = 0; i < wcsl; i++)
235         dest[i] = wcstr[i];
236
237       return wcsl;
238     }
239   else
240     {
241       gint i;
242
243       for (i=0; i<dest_max && src[i]; i++)
244         dest[i] = src[i];
245
246       return i;
247     }
248 }