gdkim-win32.c

Go to the documentation of this file.
00001 /* GDK - The GIMP Drawing Kit
00002  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
00022  * file for a list of people on the GTK+ Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
00025  */
00026 
00027 #if HAVE_CONFIG_H
00028 #  include <config.h>
00029 #endif
00030 
00031 #include <stdlib.h>
00032 #include <string.h>
00033 
00034 #include "gdkim.h"
00035 #include "gdkpixmap.h"
00036 #include "gdkprivate.h"
00037 #include "gdki18n.h"
00038 #include "gdkwin32.h"
00039 
00040 /*
00041  *--------------------------------------------------------------
00042  * gdk_set_locale
00043  *
00044  * Arguments:
00045  *
00046  * Results:
00047  *
00048  * Side effects:
00049  *
00050  *--------------------------------------------------------------
00051  */
00052 
00053 gchar *gdk_set_locale(void)
00054 {
00055    if (!setlocale(LC_ALL, ""))
00056       g_warning("locale not supported by C library");
00057 
00058    return g_win32_getlocale();
00059 }
00060 
00061 void gdk_im_begin(GdkIC * ic, GdkWindow * window)
00062 {
00063 }
00064 
00065 void gdk_im_end(void)
00066 {
00067 }
00068 
00069 GdkIMStyle gdk_im_decide_style(GdkIMStyle supported_style)
00070 {
00071    return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
00072 }
00073 
00074 GdkIMStyle gdk_im_set_best_style(GdkIMStyle style)
00075 {
00076    return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
00077 }
00078 
00079 gint gdk_im_ready(void)
00080 {
00081    return FALSE;
00082 }
00083 
00084 GdkIC *gdk_ic_new(GdkICAttr * attr, GdkICAttributesType mask)
00085 {
00086    return NULL;
00087 }
00088 
00089 void gdk_ic_destroy(GdkIC * ic)
00090 {
00091 }
00092 
00093 GdkIMStyle gdk_ic_get_style(GdkIC * ic)
00094 {
00095    return GDK_IM_PREEDIT_NONE | GDK_IM_STATUS_NONE;
00096 }
00097 
00098 void gdk_ic_set_values(GdkIC * ic, ...)
00099 {
00100 }
00101 
00102 void gdk_ic_get_values(GdkIC * ic, ...)
00103 {
00104 }
00105 
00106 GdkICAttributesType
00107 gdk_ic_set_attr(GdkIC * ic, GdkICAttr * attr, GdkICAttributesType mask)
00108 {
00109    return 0;
00110 }
00111 
00112 GdkICAttributesType
00113 gdk_ic_get_attr(GdkIC * ic, GdkICAttr * attr, GdkICAttributesType mask)
00114 {
00115    return 0;
00116 }
00117 
00118 GdkEventMask gdk_ic_get_events(GdkIC * ic)
00119 {
00120    return 0;
00121 }
00122 
00123 /*
00124  * gdk_wcstombs 
00125  *
00126  * Returns a multi-byte string converted from the specified array
00127  * of wide characters. The string is newly allocated. The array of
00128  * wide characters must be null-terminated. If the conversion is
00129  * failed, it returns NULL.
00130  *
00131  * On Win32, we always use UTF-8.
00132  */
00133 gchar *gdk_wcstombs(const GdkWChar * src)
00134 {
00135    gint len;
00136    const GdkWChar *wcp;
00137    guchar *mbstr, *bp;
00138 
00139    wcp = src;
00140    len = 0;
00141    while (*wcp) {
00142       const GdkWChar c = *wcp++;
00143 
00144       if (c < 0x80)
00145          len += 1;
00146       else if (c < 0x800)
00147          len += 2;
00148       else if (c < 0x10000)
00149          len += 3;
00150       else if (c < 0x200000)
00151          len += 4;
00152       else if (c < 0x4000000)
00153          len += 5;
00154       else
00155          len += 6;
00156    }
00157 
00158    mbstr = g_malloc(len + 1);
00159 
00160    wcp = src;
00161    bp = mbstr;
00162    while (*wcp) {
00163       int first;
00164       int i;
00165       GdkWChar c = *wcp++;
00166 
00167       if (c < 0x80) {
00168          first = 0;
00169          len = 1;
00170       } else if (c < 0x800) {
00171          first = 0xc0;
00172          len = 2;
00173       } else if (c < 0x10000) {
00174          first = 0xe0;
00175          len = 3;
00176       } else if (c < 0x200000) {
00177          first = 0xf0;
00178          len = 4;
00179       } else if (c < 0x4000000) {
00180          first = 0xf8;
00181          len = 5;
00182       } else {
00183          first = 0xfc;
00184          len = 6;
00185       }
00186 
00187       /* Woo-hoo! */
00188       switch (len) {
00189       case 6:
00190          bp[5] = (c & 0x3f) | 0x80;
00191          c >>= 6;               /* Fall through */
00192       case 5:
00193          bp[4] = (c & 0x3f) | 0x80;
00194          c >>= 6;               /* Fall through */
00195       case 4:
00196          bp[3] = (c & 0x3f) | 0x80;
00197          c >>= 6;               /* Fall through */
00198       case 3:
00199          bp[2] = (c & 0x3f) | 0x80;
00200          c >>= 6;               /* Fall through */
00201       case 2:
00202          bp[1] = (c & 0x3f) | 0x80;
00203          c >>= 6;               /* Fall through */
00204       case 1:
00205          bp[0] = c | first;
00206       }
00207 
00208       bp += len;
00209    }
00210    *bp = 0;
00211    return mbstr;
00212 }
00213 
00214 
00215 /*
00216  * gdk_mbstowcs
00217  *
00218  * Converts the specified string into GDK wide characters, and,
00219  * returns the number of wide characters written. The string 'src'
00220  * must be null-terminated. If the conversion is failed, it returns
00221  * -1.
00222  *
00223  * On Win32, the string is assumed to be in UTF-8.  Also note that
00224  * GdkWChar is 32 bits, while wchar_t, and the wide characters the
00225  * Windows API uses, are 16 bits!
00226  */
00227 
00228 /* First a helper function for not zero-terminated strings */
00229 gint
00230 gdk_nmbstowcs(GdkWChar * dest,
00231               const gchar * src, gint src_len, gint dest_max)
00232 {
00233    guchar *cp, *end;
00234    gint n;
00235 
00236    cp = (guchar *) src;
00237    end = cp + src_len;
00238    n = 0;
00239    while (cp != end && dest != dest + dest_max) {
00240       gint i, mask = 0, len;
00241       guchar c = *cp;
00242 
00243       if (c < 0x80) {
00244          len = 1;
00245          mask = 0x7f;
00246       } else if ((c & 0xe0) == 0xc0) {
00247          len = 2;
00248          mask = 0x1f;
00249       } else if ((c & 0xf0) == 0xe0) {
00250          len = 3;
00251          mask = 0x0f;
00252       } else if ((c & 0xf8) == 0xf0) {
00253          len = 4;
00254          mask = 0x07;
00255       } else if ((c & 0xfc) == 0xf8) {
00256          len = 5;
00257          mask = 0x03;
00258       } else if ((c & 0xfc) == 0xfc) {
00259          len = 6;
00260          mask = 0x01;
00261       } else
00262          return -1;
00263 
00264       if (cp + len > end)
00265          return -1;
00266 
00267       *dest = (cp[0] & mask);
00268       for (i = 1; i < len; i++) {
00269          if ((cp[i] & 0xc0) != 0x80)
00270             return -1;
00271          *dest <<= 6;
00272          *dest |= (cp[i] & 0x3f);
00273       }
00274       if (*dest == -1)
00275          return -1;
00276 
00277       cp += len;
00278       dest++;
00279       n++;
00280    }
00281    if (cp != end)
00282       return -1;
00283 
00284    return n;
00285 }
00286 
00287 gint gdk_mbstowcs(GdkWChar * dest, const gchar * src, gint dest_max)
00288 {
00289    return gdk_nmbstowcs(dest, src, strlen(src), dest_max);
00290 }
00291 
00292 
00293 /* A version that converts to wchar_t wide chars */
00294 
00295 gint
00296 gdk_nmbstowchar_ts(wchar_t * dest,
00297                    const gchar * src, gint src_len, gint dest_max)
00298 {
00299 #if 1
00300    return mbstowcs(dest, src, src_len);
00301 #else
00302    wchar_t *wcp;
00303    guchar *cp, *end;
00304    gint n;
00305 
00306    wcp = dest;
00307    cp = (guchar *) src;
00308    end = cp + src_len;
00309    n = 0;
00310    while (cp != end && wcp != dest + dest_max) {
00311       gint i, mask = 0, len;
00312       guchar c = *cp;
00313 
00314       if (c < 0x80) {
00315          len = 1;
00316          mask = 0x7f;
00317       } else if ((c & 0xe0) == 0xc0) {
00318          len = 2;
00319          mask = 0x1f;
00320       } else if ((c & 0xf0) == 0xe0) {
00321          len = 3;
00322          mask = 0x0f;
00323       } else                    /* Other lengths are not possible with 16-bit wchar_t! */
00324          return -1;
00325 
00326       if (cp + len > end)
00327          return -1;
00328 
00329       *wcp = (cp[0] & mask);
00330       for (i = 1; i < len; i++) {
00331          if ((cp[i] & 0xc0) != 0x80)
00332             return -1;
00333          *wcp <<= 6;
00334          *wcp |= (cp[i] & 0x3f);
00335       }
00336       if (*wcp == 0xFFFF)
00337          return -1;
00338 
00339       cp += len;
00340       wcp++;
00341       n++;
00342    }
00343    if (cp != end)
00344       return -1;
00345 
00346    return n;
00347 #endif
00348 }

Generated on Tue Jul 5 14:14:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1