]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkim-win32.c
gdk/gdk.def Provide dummy implementations.
[~andy/gtk] / gdk / win32 / gdkim-win32.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 <stdlib.h>
30 #include <string.h>
31 #include <locale.h>
32
33 #include "gdkim.h"
34 #include "gdkpixmap.h"
35 #include "gdkinternals.h"
36 #include "gdki18n.h"
37 #include "gdkwin32.h"
38
39 /*
40  *--------------------------------------------------------------
41  * gdk_set_locale
42  *
43  * Arguments:
44  *
45  * Results:
46  *
47  * Side effects:
48  *
49  *--------------------------------------------------------------
50  */
51
52 gchar*
53 gdk_set_locale (void)
54 {
55   if (!setlocale (LC_ALL, ""))
56     g_warning ("locale not supported by C library");
57   
58   return g_win32_getlocale ();
59 }
60
61 void 
62 gdk_im_begin (GdkIC *ic, GdkWindow* window)
63 {
64 }
65
66 void 
67 gdk_im_end (void)
68 {
69 }
70
71 GdkIMStyle
72 gdk_im_decide_style (GdkIMStyle supported_style)
73 {
74   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
75 }
76
77 GdkIMStyle
78 gdk_im_set_best_style (GdkIMStyle style)
79 {
80   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
81 }
82
83 gint 
84 gdk_im_ready (void)
85 {
86   return FALSE;
87 }
88
89 GdkIC * 
90 gdk_ic_new (GdkICAttr *attr, GdkICAttributesType mask)
91 {
92   return NULL;
93 }
94
95 void 
96 gdk_ic_destroy (GdkIC *ic)
97 {
98 }
99
100 GdkIMStyle
101 gdk_ic_get_style (GdkIC *ic)
102 {
103   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
104 }
105
106 GdkICAttr*
107 gdk_ic_attr_new (void)
108 {
109   return NULL;
110 }
111
112 void
113 gdk_ic_attr_destroy (GdkICAttr *attr)
114 {
115 }
116
117 void 
118 gdk_ic_set_values (GdkIC *ic, ...)
119 {
120 }
121
122 void 
123 gdk_ic_get_values (GdkIC *ic, ...)
124 {
125 }
126
127 GdkICAttributesType 
128 gdk_ic_set_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
129 {
130   return 0;
131 }
132
133 GdkICAttributesType 
134 gdk_ic_get_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
135 {
136   return 0;
137 }
138
139 GdkEventMask 
140 gdk_ic_get_events (GdkIC *ic)
141 {
142   return 0;
143 }
144
145 /*
146  * gdk_wcstombs 
147  *
148  * Returns a multi-byte string converted from the specified array
149  * of wide characters. The string is newly allocated. The array of
150  * wide characters must be null-terminated. If the conversion is
151  * failed, it returns NULL.
152  *
153  * On Win32, we always use UTF-8.
154  */
155 gchar *
156 gdk_wcstombs (const GdkWChar *src)
157 {
158   gint len;
159   const GdkWChar *wcp;
160   guchar *mbstr, *bp;
161
162   wcp = src;
163   len = 0;
164   while (*wcp)
165     {
166       const GdkWChar c = *wcp++;
167
168       if (c < 0x80)
169         len += 1;
170       else if (c < 0x800)
171         len += 2;
172       else if (c < 0x10000)
173         len += 3;
174       else if (c < 0x200000)
175         len += 4;
176       else if (c < 0x4000000)
177         len += 5;
178       else
179         len += 6;
180     }
181
182   mbstr = g_malloc (len + 1);
183   
184   wcp = src;
185   bp = mbstr;
186   while (*wcp)
187     {
188       int first;
189       int i;
190       GdkWChar c = *wcp++;
191
192       if (c < 0x80)
193         {
194           first = 0;
195           len = 1;
196         }
197       else if (c < 0x800)
198         {
199           first = 0xc0;
200           len = 2;
201         }
202       else if (c < 0x10000)
203         {
204           first = 0xe0;
205           len = 3;
206         }
207       else if (c < 0x200000)
208         {
209           first = 0xf0;
210           len = 4;
211         }
212       else if (c < 0x4000000)
213         {
214           first = 0xf8;
215           len = 5;
216         }
217       else
218         {
219           first = 0xfc;
220           len = 6;
221         }
222       
223       /* Woo-hoo! */
224       switch (len)
225         {
226         case 6: bp[5] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
227         case 5: bp[4] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
228         case 4: bp[3] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
229         case 3: bp[2] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
230         case 2: bp[1] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
231         case 1: bp[0] = c | first;
232         }
233
234       bp += len;
235     }
236   *bp = 0;
237   return mbstr;
238 }
239
240   
241 /*
242  * gdk_mbstowcs
243  *
244  * Converts the specified string into GDK wide characters, and,
245  * returns the number of wide characters written. The string 'src'
246  * must be null-terminated. If the conversion is failed, it returns
247  * -1.
248  *
249  * On Win32, the string is assumed to be in UTF-8.  Also note that
250  * GdkWChar is 32 bits, while wchar_t, and the wide characters the
251  * Windows API uses, are 16 bits!
252  */
253
254 /* First a helper function for not zero-terminated strings */
255 gint
256 gdk_nmbstowcs (GdkWChar    *dest,
257                const gchar *src,
258                gint         src_len,
259                gint         dest_max)
260 {
261   guchar *cp, *end;
262   gint n;
263   
264   cp = (guchar *) src;
265   end = cp + src_len;
266   n = 0;
267   while (cp != end && dest != dest + dest_max)
268     {
269       gint i, mask = 0, len;
270       guchar c = *cp;
271
272       if (c < 0x80)
273         {
274           len = 1;
275           mask = 0x7f;
276         }
277       else if ((c & 0xe0) == 0xc0)
278         {
279           len = 2;
280           mask = 0x1f;
281         }
282       else if ((c & 0xf0) == 0xe0)
283         {
284           len = 3;
285           mask = 0x0f;
286         }
287       else if ((c & 0xf8) == 0xf0)
288         {
289           len = 4;
290           mask = 0x07;
291         }
292       else if ((c & 0xfc) == 0xf8)
293         {
294           len = 5;
295           mask = 0x03;
296         }
297       else if ((c & 0xfc) == 0xfc)
298         {
299           len = 6;
300           mask = 0x01;
301         }
302       else
303         return -1;
304
305       if (cp + len > end)
306         return -1;
307
308       *dest = (cp[0] & mask);
309       for (i = 1; i < len; i++)
310         {
311           if ((cp[i] & 0xc0) != 0x80)
312             return -1;
313           *dest <<= 6;
314           *dest |= (cp[i] & 0x3f);
315         }
316       if (*dest == -1)
317         return -1;
318
319       cp += len;
320       dest++;
321       n++;
322     }
323   if (cp != end)
324     return -1;
325
326   return n;
327 }
328
329 gint
330 gdk_mbstowcs (GdkWChar    *dest,
331               const gchar *src,
332               gint         dest_max)
333 {
334   return gdk_nmbstowcs (dest, src, strlen (src), dest_max);
335 }
336
337
338 /* A version that converts to wchar_t wide chars */
339
340 gint
341 gdk_nmbstowchar_ts (wchar_t     *dest,
342                     const gchar *src,
343                     gint         src_len,
344                     gint         dest_max)
345 {
346   wchar_t *wcp;
347   guchar *cp, *end;
348   gint n;
349   
350   wcp = dest;
351   cp = (guchar *) src;
352   end = cp + src_len;
353   n = 0;
354   while (cp != end && wcp != dest + dest_max)
355     {
356       gint i, mask = 0, len;
357       guchar c = *cp;
358
359       if (c < 0x80)
360         {
361           len = 1;
362           mask = 0x7f;
363         }
364       else if ((c & 0xe0) == 0xc0)
365         {
366           len = 2;
367           mask = 0x1f;
368         }
369       else if ((c & 0xf0) == 0xe0)
370         {
371           len = 3;
372           mask = 0x0f;
373         }
374       else /* Other lengths are not possible with 16-bit wchar_t! */
375         return -1;
376
377       if (cp + len > end)
378         return -1;
379
380       *wcp = (cp[0] & mask);
381       for (i = 1; i < len; i++)
382         {
383           if ((cp[i] & 0xc0) != 0x80)
384             return -1;
385           *wcp <<= 6;
386           *wcp |= (cp[i] & 0x3f);
387         }
388       if (*wcp == 0xFFFF)
389         return -1;
390
391       cp += len;
392       wcp++;
393       n++;
394     }
395   if (cp != end)
396     return -1;
397
398   return n;
399 }