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