]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkim-win32.c
35ea6b5683b0f418f5ab237a7410632b4efbce65
[~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 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 #endif
30
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include "gdkim.h"
35 #include "gdkpixmap.h"
36 #include "gdkprivate.h"
37 #include "gdki18n.h"
38 #include "gdkx.h"
39
40 /* If this variable is FALSE, it indicates that we should
41  * avoid trying to use multibyte conversion functions and
42  * assume everything is 1-byte per character
43  */
44 static gboolean gdk_use_mb;
45
46 /*
47  *--------------------------------------------------------------
48  * gdk_set_locale
49  *
50  * Arguments:
51  *
52  * Results:
53  *
54  * Side effects:
55  *
56  *--------------------------------------------------------------
57  */
58
59 gchar*
60 gdk_set_locale (void)
61 {
62   wchar_t result;
63   gchar *current_locale;
64
65   gdk_use_mb = FALSE;
66
67   if (!setlocale (LC_ALL,""))
68     g_warning ("locale not supported by C library");
69   
70   current_locale = setlocale (LC_ALL, NULL);
71
72   if (MB_CUR_MAX > 1)
73     gdk_use_mb = TRUE;
74
75   GDK_NOTE (XIM, g_message ("%s multi-byte string functions.", 
76                             gdk_use_mb ? "Using" : "Not using"));
77   
78   return current_locale;
79 }
80
81 void 
82 gdk_im_begin (GdkIC *ic, GdkWindow* window)
83 {
84 }
85
86 void 
87 gdk_im_end (void)
88 {
89 }
90
91 GdkIMStyle
92 gdk_im_decide_style (GdkIMStyle supported_style)
93 {
94   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
95 }
96
97 GdkIMStyle
98 gdk_im_set_best_style (GdkIMStyle style)
99 {
100   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
101 }
102
103 gint 
104 gdk_im_ready (void)
105 {
106   return FALSE;
107 }
108
109 GdkIC * 
110 gdk_ic_new (GdkICAttr *attr, GdkICAttributesType mask)
111 {
112   return NULL;
113 }
114
115 void 
116 gdk_ic_destroy (GdkIC *ic)
117 {
118 }
119
120 GdkIMStyle
121 gdk_ic_get_style (GdkIC *ic)
122 {
123   return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
124 }
125
126 void 
127 gdk_ic_set_values (GdkIC *ic, ...)
128 {
129 }
130
131 void 
132 gdk_ic_get_values (GdkIC *ic, ...)
133 {
134 }
135
136 GdkICAttributesType 
137 gdk_ic_set_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
138 {
139   return 0;
140 }
141
142 GdkICAttributesType 
143 gdk_ic_get_attr (GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
144 {
145   return 0;
146 }
147
148 GdkEventMask 
149 gdk_ic_get_events (GdkIC *ic)
150 {
151   return 0;
152 }
153
154 /*
155  * gdk_wcstombs 
156  *
157  * Returns a multi-byte string converted from the specified array
158  * of wide characters. The string is newly allocated. The array of
159  * wide characters must be null-terminated. If the conversion is
160  * failed, it returns NULL.
161  */
162 gchar *
163 gdk_wcstombs (const GdkWChar *src)
164 {
165   gchar *mbstr;
166
167   if (gdk_use_mb)
168     {
169       gint i, wcsl, mbsl;
170       wchar_t *src_alt;
171
172       for (wcsl = 0; src[wcsl]; wcsl++)
173         ;
174       src_alt = g_new (wchar_t, wcsl+1);
175       for (i = wcsl; i >= 0; i--)
176         src_alt[i] = src[i];
177       mbsl = WideCharToMultiByte (CP_OEMCP, 0, src_alt, wcsl,
178                                   NULL, 0, NULL, NULL);
179       mbstr = g_new (guchar, mbsl + 1);
180       if (!WideCharToMultiByte (CP_OEMCP, 0, src_alt, wcsl,
181                                 mbstr, mbsl, NULL, NULL))
182         {
183           g_warning ("gdk_wcstombs: WideCharToMultiByte failed");
184           g_free (mbstr);
185           g_free (src_alt);
186           return NULL;
187         }
188       mbstr[mbsl] = '\0';
189       g_free (src_alt);
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_OEMCP, 0, src, -1, NULL, 0);
225       wcstr = g_new (wchar_t, wcsl);
226       if (!MultiByteToWideChar (CP_OEMCP, 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 && wcstr[i]; i++)
235         dest[i] = wcstr[i];
236       g_free (wcstr);
237
238       return i;
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 }