|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 /* "$Id: $" 00002 * 00003 * Author: Jean-Marc Lienher ( http://oksid.ch ) 00004 * Copyright 2000-2003 by O'ksi'D. 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00019 * USA. 00020 * 00021 * Please report all bugs and problems on the following page: 00022 * 00023 * http://www.fltk.org/str.php 00024 */ 00025 00026 /* 00027 * UTF-8 X test program 00028 * 00029 ***************** 00030 * To test it do : 00031 ***************** 00032 00033 kinput2 -canna 00034 XMODIFIERS="@im=kinput2"; export XMODIFIERS 00035 LANG=ja_JP; export LANG 00036 ./test 00037 00038 to open a conversion window press "Shift space" 00039 type some keys. 00040 press space. 00041 select glyph with arrows keys. 00042 press return. 00043 press return. 00044 press "Shift space" to close the window 00045 00046 LANG=ar_AE; export LANG 00047 LANG=he_IL; export LANG 00048 export LANG=ja_JP; export XMODIFIERS="@im=kinput2" 00049 export LANG=ja_JP; export XMODIFIERS="@im=nicolatter" 00050 export LANG=ja_JP; export XMODIFIERS="@im=jmode" 00051 export LANG=ja_JP; export XMODIFIERS="@im=htt" 00052 export LANG=ko_KR; export XMODIFIERS="@im=ami" 00053 export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_TW" 00054 export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_CN" 00055 export LANG=fr_FR.UTF-8; export XMODIFIERS="@im=interxim" 00056 00057 export LD_PRELOAD="/usr/src/x11/xc/exports/lib/libX11.so /usr/src/x11/xc/exports/lib/libxlcDef.so.2 /usr/src/x11/xc/exports/lib/libxlibi18n.so.2 /usr/src/x11/xc/exports/lib/libxlocale.so.2 /usr/src/x11/xc/exports/lib/libxomGeneric.so.2 /usr/src/x11/xc/exports/lib/libximcp.so.2" 00058 00059 */ 00060 00061 #include <stdlib.h> 00062 #include <string.h> 00063 #include <stdio.h> 00064 #include <wchar.h> 00065 #include <X11/Xlocale.h> 00066 #include <X11/X.h> 00067 #include <X11/Xlib.h> 00068 #include <X11/Xutil.h> 00069 #include <X11/Intrinsic.h> 00070 #include <X11/Xmd.h> 00071 00072 char *jp_txt = "é UTF-8 e\xCC\x82=\xC3\xAA" 00073 " \357\274\270\357\274\254\357\274\246\357\274" 00074 "\244\345\220\215\343\201\247\346\214\207 \345\256\232" 00075 "\343\201\231\343\202\213"; 00076 00077 char *rtl_txt = "->e\xCC\x82=\xC3\xAA"; 00078 00079 XIM xim_im = NULL; 00080 XIC xim_ic = NULL; 00081 static XIMStyles* xim_styles = NULL; 00082 XFontSet fontset; 00083 GC gc; 00084 int x = 2; 00085 int y = 40; 00086 00087 int main(int argc, char**argv) { 00088 char **missing_charset_list; 00089 int missing_charset_count; 00090 XGCValues xgcv; 00091 unsigned long mask; 00092 Display* dpy; 00093 int scr; 00094 Window w, root; 00095 XSetWindowAttributes set_attr; 00096 int i; 00097 XIMStyle *style; 00098 static char buf[128]; 00099 KeySym keysym = 0; 00100 Status status; 00101 XWMHints wm_hints; 00102 XClassHint class_hints; 00103 XIMStyle input_style = 0; 00104 char **font_name_list; 00105 char *def_string; 00106 XFontStruct **font_struct_list; 00107 char **font_encoding_list; 00108 int nb_font; 00109 int len = 0; 00110 int no_xim = 0; 00111 char **missing_charset_list_return; 00112 int missing_charset_count_return; 00113 char *def_string_return; 00114 00115 if (!setlocale(LC_ALL, "")) 00116 puts("locale not supported by C library, locale unchanged"); 00117 00118 if (!XSetLocaleModifiers("")) 00119 puts("X locale modifiers not supported, using default"); 00120 00121 dpy = XOpenDisplay(0); 00122 scr = DefaultScreen(dpy); 00123 root = RootWindow(dpy, scr); 00124 set_attr.event_mask = KeyPressMask|FocusChangeMask; 00125 set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy)); 00126 set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy)); 00127 w = XCreateWindow(dpy, root, 10,10,200,100,0, 00128 DefaultDepth(dpy, DefaultScreen(dpy)), 00129 InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)), 00130 CWEventMask | CWBackPixel | CWBorderPixel, &set_attr); 00131 00132 class_hints.res_name = "test"; 00133 class_hints.res_class = "Test"; 00134 wm_hints.input = True; 00135 wm_hints.flags = InputHint; 00136 00137 XmbSetWMProperties(dpy, w, "test", "test", NULL, 0, 00138 NULL, &wm_hints, &class_hints); 00139 00140 XMapWindow(dpy, w); 00141 xim_im = XOpenIM(dpy, NULL, "test", "Test"); 00142 XGetIMValues(xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL); 00143 for (i = 0, style = xim_styles->supported_styles; 00144 i < xim_styles->count_styles; i++, style++) { 00145 if (*style == (XIMStatusNone|XIMPreeditNone)) { 00146 printf("this is not a XIM server !!!\n"); 00147 no_xim = 1; 00148 } 00149 printf("input style : 0x%X\n", *style); 00150 } 00151 XFree(xim_styles); 00152 00153 xim_ic = XCreateIC(xim_im, 00154 XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), 00155 XNClientWindow, w, 00156 XNFocusWindow, w, 00157 NULL); 00158 XSetICFocus(xim_ic); 00159 00160 /*************************************************************** 00161 * I don't recommend to use a font base name list similar 00162 * to the following one in a real application ;-) 00163 ***************************************************************/ 00164 fontset = XCreateFontSet(dpy, 00165 "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */ 00166 "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1," 00167 "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6," 00168 "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8," 00169 "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific," 00170 "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2," 00171 "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1," 00172 "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0," 00173 "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0," 00174 "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0," 00175 "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0," 00176 "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500]," 00177 "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", 00178 &missing_charset_list_return, 00179 &missing_charset_count_return, 00180 &def_string_return); 00181 mask = (GCForeground | GCBackground); 00182 xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy)); 00183 xgcv.background = WhitePixel(dpy, DefaultScreen(dpy)); 00184 00185 gc = XCreateGC(dpy, w, mask, &xgcv); 00186 00187 /***************************************************************/ 00188 while (1) { 00189 int filtered; 00190 static XEvent xevent; 00191 static XVaNestedList list1 = 0; 00192 int r; 00193 00194 XNextEvent(dpy, &xevent); 00195 if (xevent.type == KeyPress) { 00196 XKeyEvent *e = (XKeyEvent*) &xevent; 00197 printf ("0x%X %d\n", e->state, e->keycode); 00198 } 00199 filtered = XFilterEvent(&xevent, w); 00200 if (xevent.type == FocusOut) XUnsetICFocus(xim_ic); 00201 if (xevent.type == FocusIn) XSetICFocus(xim_ic); 00202 00203 if (xevent.type == KeyPress && !filtered) { 00204 len = Xutf8LookupString(xim_ic, &xevent.xkey, buf, 127, &keysym, &status); 00205 Xutf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len); 00206 Xutf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt)); 00207 Xutf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt)); 00208 buf[len] = 0; 00209 printf("'%s' %d\n", buf, keysym); 00210 buf[0] = 0; 00211 XCloseIM(xim_im); 00212 } 00213 if (filtered) { 00214 printf("Dead key\n"); 00215 } 00216 } 00217 XFreeFontSet(dpy, fontset); 00218 return 0; 00219 } 00220 00221 /* 00222 * End of "$Id$". 00223 */