ROOT  6.05/03
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gdkim-win32.c
Go to the documentation of this file.
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 "gdkwin32.h"
39 
40 /*
41  *--------------------------------------------------------------
42  * gdk_set_locale
43  *
44  * Arguments:
45  *
46  * Results:
47  *
48  * Side effects:
49  *
50  *--------------------------------------------------------------
51  */
52 
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 gdk_im_begin(GdkIC * ic, GdkWindow * window)
62 {
63 }
64 
65 void gdk_im_end(void)
66 {
67 }
68 
70 {
72 }
73 
75 {
77 }
78 
80 {
81  return FALSE;
82 }
83 
85 {
86  return NULL;
87 }
88 
90 {
91 }
92 
94 {
96 }
97 
98 void gdk_ic_set_values(GdkIC * ic, ...)
99 {
100 }
101 
102 void gdk_ic_get_values(GdkIC * ic, ...)
103 {
104 }
105 
108 {
109  return 0;
110 }
111 
114 {
115  return 0;
116 }
117 
119 {
120  return 0;
121 }
122 
123 /*
124  * gdk_wcstombs
125  *
126  * Returns a multi-byte string converted from the specified array
127  * of wide characters. The string is newly allocated. The array of
128  * wide characters must be null-terminated. If the conversion is
129  * failed, it returns NULL.
130  *
131  * On Win32, we always use UTF-8.
132  */
134 {
135  gint len;
136  const GdkWChar *wcp;
137  guchar *mbstr, *bp;
138 
139  wcp = src;
140  len = 0;
141  while (*wcp) {
142  const GdkWChar c = *wcp++;
143 
144  if (c < 0x80)
145  len += 1;
146  else if (c < 0x800)
147  len += 2;
148  else if (c < 0x10000)
149  len += 3;
150  else if (c < 0x200000)
151  len += 4;
152  else if (c < 0x4000000)
153  len += 5;
154  else
155  len += 6;
156  }
157 
158  mbstr = g_malloc(len + 1);
159 
160  wcp = src;
161  bp = mbstr;
162  while (*wcp) {
163  int first;
164  GdkWChar c = *wcp++;
165 
166  if (c < 0x80) {
167  first = 0;
168  len = 1;
169  } else if (c < 0x800) {
170  first = 0xc0;
171  len = 2;
172  } else if (c < 0x10000) {
173  first = 0xe0;
174  len = 3;
175  } else if (c < 0x200000) {
176  first = 0xf0;
177  len = 4;
178  } else if (c < 0x4000000) {
179  first = 0xf8;
180  len = 5;
181  } else {
182  first = 0xfc;
183  len = 6;
184  }
185 
186  /* Woo-hoo! */
187  switch (len) {
188  case 6:
189  bp[5] = (c & 0x3f) | 0x80;
190  c >>= 6; /* Fall through */
191  case 5:
192  bp[4] = (c & 0x3f) | 0x80;
193  c >>= 6; /* Fall through */
194  case 4:
195  bp[3] = (c & 0x3f) | 0x80;
196  c >>= 6; /* Fall through */
197  case 3:
198  bp[2] = (c & 0x3f) | 0x80;
199  c >>= 6; /* Fall through */
200  case 2:
201  bp[1] = (c & 0x3f) | 0x80;
202  c >>= 6; /* Fall through */
203  case 1:
204  bp[0] = c | first;
205  }
206 
207  bp += len;
208  }
209  *bp = 0;
210  return mbstr;
211 }
212 
213 
214 /*
215  * gdk_mbstowcs
216  *
217  * Converts the specified string into GDK wide characters, and,
218  * returns the number of wide characters written. The string 'src'
219  * must be null-terminated. If the conversion is failed, it returns
220  * -1.
221  *
222  * On Win32, the string is assumed to be in UTF-8. Also note that
223  * GdkWChar is 32 bits, while wchar_t, and the wide characters the
224  * Windows API uses, are 16 bits!
225  */
226 
227 /* First a helper function for not zero-terminated strings */
228 gint
230  const gchar * src, gint src_len, gint dest_max)
231 {
232  guchar *cp, *end;
233  gint n;
234 
235  cp = (guchar *) src;
236  end = cp + src_len;
237  n = 0;
238  while (cp != end && dest != dest + dest_max) {
239  gint i, mask = 0, len;
240  guchar c = *cp;
241 
242  if (c < 0x80) {
243  len = 1;
244  mask = 0x7f;
245  } else if ((c & 0xe0) == 0xc0) {
246  len = 2;
247  mask = 0x1f;
248  } else if ((c & 0xf0) == 0xe0) {
249  len = 3;
250  mask = 0x0f;
251  } else if ((c & 0xf8) == 0xf0) {
252  len = 4;
253  mask = 0x07;
254  } else if ((c & 0xfc) == 0xf8) {
255  len = 5;
256  mask = 0x03;
257  } else if ((c & 0xfc) == 0xfc) {
258  len = 6;
259  mask = 0x01;
260  } else
261  return -1;
262 
263  if (cp + len > end)
264  return -1;
265 
266  *dest = (cp[0] & mask);
267  for (i = 1; i < len; i++) {
268  if ((cp[i] & 0xc0) != 0x80)
269  return -1;
270  *dest <<= 6;
271  *dest |= (cp[i] & 0x3f);
272  }
273  if (*dest == -1)
274  return -1;
275 
276  cp += len;
277  dest++;
278  n++;
279  }
280  if (cp != end)
281  return -1;
282 
283  return n;
284 }
285 
286 gint gdk_mbstowcs(GdkWChar * dest, const gchar * src, gint dest_max)
287 {
288  return gdk_nmbstowcs(dest, src, strlen(src), dest_max);
289 }
290 
291 
292 /* A version that converts to wchar_t wide chars */
293 
294 gint
296  const gchar * src, gint src_len, gint dest_max)
297 {
298 #if 1
299  return mbstowcs(dest, src, src_len);
300 #else
301  wchar_t *wcp;
302  guchar *cp, *end;
303  gint n;
304 
305  wcp = dest;
306  cp = (guchar *) src;
307  end = cp + src_len;
308  n = 0;
309  while (cp != end && wcp != dest + dest_max) {
310  gint i, mask = 0, len;
311  guchar c = *cp;
312 
313  if (c < 0x80) {
314  len = 1;
315  mask = 0x7f;
316  } else if ((c & 0xe0) == 0xc0) {
317  len = 2;
318  mask = 0x1f;
319  } else if ((c & 0xf0) == 0xe0) {
320  len = 3;
321  mask = 0x0f;
322  } else /* Other lengths are not possible with 16-bit wchar_t! */
323  return -1;
324 
325  if (cp + len > end)
326  return -1;
327 
328  *wcp = (cp[0] & mask);
329  for (i = 1; i < len; i++) {
330  if ((cp[i] & 0xc0) != 0x80)
331  return -1;
332  *wcp <<= 6;
333  *wcp |= (cp[i] & 0x3f);
334  }
335  if (*wcp == 0xFFFF)
336  return -1;
337 
338  cp += len;
339  wcp++;
340  n++;
341  }
342  if (cp != end)
343  return -1;
344 
345  return n;
346 #endif
347 }
void gdk_ic_destroy(GdkIC *ic)
Definition: gdkim-win32.c:89
unsigned char guchar
Definition: g_types.h:48
gint gdk_nmbstowcs(GdkWChar *dest, const gchar *src, gint src_len, gint dest_max)
Definition: gdkim-win32.c:229
gpointer g_malloc(gulong n_bytes)
Definition: gmem.c:130
void gdk_ic_get_values(GdkIC *ic,...)
Definition: gdkim-win32.c:102
GdkIC * gdk_ic_new(GdkICAttr *attr, GdkICAttributesType mask)
Definition: gdkim-win32.c:84
GdkIMStyle gdk_im_decide_style(GdkIMStyle supported_style)
Definition: gdkim-win32.c:69
GdkICAttributesType gdk_ic_get_attr(GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
Definition: gdkim-win32.c:113
gint gdk_im_ready(void)
Definition: gdkim-win32.c:79
G_BEGIN_DECLS typedef char gchar
Definition: g_types.h:41
gint gdk_mbstowcs(GdkWChar *dest, const gchar *src, gint dest_max)
Definition: gdkim-win32.c:286
GdkIMStyle gdk_im_set_best_style(GdkIMStyle style)
Definition: gdkim-win32.c:74
GdkICAttributesType gdk_ic_set_attr(GdkIC *ic, GdkICAttr *attr, GdkICAttributesType mask)
Definition: gdkim-win32.c:107
struct _GdkIC GdkIC
Definition: gdkim.h:15
gchar * g_win32_getlocale(void)
g_win32_getlocale:
Definition: gwin32.c:356
void gdk_ic_set_values(GdkIC *ic,...)
Definition: gdkim-win32.c:98
int gint
Definition: g_types.h:44
#define FALSE
Definition: gmacros.h:126
GdkIMStyle gdk_ic_get_style(GdkIC *ic)
Definition: gdkim-win32.c:93
GdkIMStyle
Definition: gdkim.h:18
gchar * gdk_set_locale(void)
Definition: gdkim-win32.c:53
guint32 GdkWChar
Definition: gdktypes.h:76
gchar * gdk_wcstombs(const GdkWChar *src)
Definition: gdkim-win32.c:133
const char * cp
Definition: iconv_open1.h:32
TCanvas * style()
Definition: style.C:1
unsigned int len
Definition: cp1255.h:87
void gdk_im_end(void)
Definition: gdkim-win32.c:65
static void g_warning(const gchar *format,...)
Definition: gmessages.h:155
void gdk_im_begin(GdkIC *ic, GdkWindow *window)
Definition: gdkim-win32.c:61
char * bp
Definition: iconv_open1.h:35
GdkICAttributesType
Definition: gdkim.h:33
#define dest(otri, vertexptr)
Definition: triangle.c:1040
#define NULL
Definition: Rtypes.h:82
GdkEventMask gdk_ic_get_events(GdkIC *ic)
Definition: gdkim-win32.c:118
gint gdk_nmbstowchar_ts(wchar_t *dest, const gchar *src, gint src_len, gint dest_max)
Definition: gdkim-win32.c:295
const Int_t n
Definition: legend1.C:16
GdkEventMask
Definition: gdkevents.h:113