Back to index

im-sdk  12.3.91
IIIMGdkEventKey.c
Go to the documentation of this file.
00001 /*
00002   IIIMGdkEventKey.c
00003   Copyright (C) 2003 Free Standards Group
00004 
00005   Permission is hereby granted, free of charge, to any person obtaining a
00006   copy of this software and associated documentation files (the
00007   "Software"), to deal in the Software without restriction, including
00008   without limitation the rights to use, copy, modify, merge, publish,
00009   distribute, sublicense, and/or sell copies of the Software, and to
00010   permit persons to whom the Software is furnished to do so, subject to
00011   the following conditions: The above copyright notice and this
00012   permission notice shall be included in all copies or substantial
00013   portions of the Software.
00014 
00015   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018   IN NO EVENT SHALL OPENI18N WG OR FREE STANDARDS GROUP. BE LIABLE
00019   FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020   CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021   THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022   ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024   Except as contained in this notice, the names of OpenI18N WG and/or
00025   Free Standards Group shall not be used in advertising or otherwise to
00026   promote the sale, use or other dealings in this Software without prior
00027   written authorization from OpenI18N WG and/or Free Standards Group
00028   as applicable.
00029 
00030   Author: MIYASHITA, Hisashi <himi@OpenI18N.org>
00031 
00032 */
00033 #include <gdk/gdkkeysyms.h>
00034 #include "IIIMGdkEventKey.h"
00035 
00036 #ifdef linux
00037 #define       USE_KANA_TABLE       1      /* for japanese kana support */
00038 #endif /* linux */
00039 
00040 #if    USE_KANA_TABLE
00041 #include <stdlib.h>
00042 #include <X11/Xlib.h>
00043 #include <X11/Xatom.h>
00044 #include <gdk/gdkx.h>
00045 #endif /* USE_KANA_TABLE */
00046 
00047 #if defined(sun)
00048 #include <X11/Sunkeysym.h>
00049 #endif /* sun */
00050 
00051 #if    USE_KANA_TABLE
00052 static Atom kanawin_atom = 0;
00053 static Atom kanaflag_atom = 0;
00054 #endif /* USE_KANA_TABLE */
00055 
00056 #if    USE_KANA_TABLE
00057 typedef struct KEYMAP_ENTRY2 {
00058   IIIMP_int32 iiimf_keycode;
00059   guint gdk_keysym;
00060   guint gdk_alt_keysym;
00061   IIIMP_int32 iiimf_keychar;
00062   guint hardware_keycode;
00063 } KeymapEntry2;
00064 #endif /* USE_KANA_TABLE */
00065 
00066 #if    USE_KANA_TABLE
00067 static KeymapEntry2 kana_normal_keymapTable[] = {
00068   { IIIMF_KEYCODE_1, GDK_kana_NU, GDK_1, 0xff87, 0 },
00069   { IIIMF_KEYCODE_2, GDK_kana_FU, GDK_2, 0xff8c, 0 },
00070   { IIIMF_KEYCODE_3, GDK_kana_A, GDK_3, 0xff71, 0 },
00071   { IIIMF_KEYCODE_4, GDK_kana_U, GDK_4, 0xff73, 0 },
00072   { IIIMF_KEYCODE_5, GDK_kana_E, GDK_5, 0xff74, 0 },
00073   { IIIMF_KEYCODE_6, GDK_kana_O, GDK_6, 0xff75, 0 },
00074   { IIIMF_KEYCODE_7, GDK_kana_YA, GDK_7, 0xff94, 0 },
00075   { IIIMF_KEYCODE_8, GDK_kana_YU, GDK_8, 0xff95, 0 },
00076   { IIIMF_KEYCODE_9, GDK_kana_YO, GDK_9, 0xff96, 0 },
00077   { IIIMF_KEYCODE_0, GDK_kana_WA, GDK_0, 0xff9c, 0 },
00078   { '-',                     GDK_kana_HO, GDK_minus, 0xff8e, 0 },
00079   { '~',                     GDK_kana_HE, GDK_asciicircum, 0xff8d, 0 },
00080   { IIIMF_KEYCODE_Q, GDK_kana_TA, GDK_q, 0xff80, 0 },
00081   { IIIMF_KEYCODE_W, GDK_kana_TE, GDK_w, 0xff83, 0 },
00082   { IIIMF_KEYCODE_E, GDK_kana_I, GDK_e, 0xff72, 0 },
00083   { IIIMF_KEYCODE_R, GDK_kana_SU, GDK_r, 0xff7d, 0 },
00084   { IIIMF_KEYCODE_T, GDK_kana_KA, GDK_t, 0xff76, 0 },
00085   { IIIMF_KEYCODE_Y, GDK_kana_N, GDK_y, 0xff9d, 0 },
00086   { IIIMF_KEYCODE_U, GDK_kana_NA, GDK_u, 0xff85, 0 },
00087   { IIIMF_KEYCODE_I, GDK_kana_NI, GDK_i, 0xff86, 0 },
00088   { IIIMF_KEYCODE_O, GDK_kana_RA, GDK_o, 0xff97, 0 },
00089   { IIIMF_KEYCODE_P, GDK_kana_SE, GDK_p, 0xff7e, 0 },
00090   { IIIMF_KEYCODE_AT, GDK_voicedsound, GDK_at, 0xff9e, 0 },
00091   { IIIMF_KEYCODE_OPEN_BRACKET, GDK_semivoicedsound, GDK_bracketleft, 0xff9f, 0 },
00092   { IIIMF_KEYCODE_A, GDK_kana_CHI, GDK_a, 0xff81, 0 },
00093   { IIIMF_KEYCODE_S, GDK_kana_TO, GDK_s, 0xff84, 0 },
00094   { IIIMF_KEYCODE_D, GDK_kana_SHI, GDK_d, 0xff7c, 0 },
00095   { IIIMF_KEYCODE_F, GDK_kana_HA, GDK_f, 0xff8a, 0 },
00096   { IIIMF_KEYCODE_G, GDK_kana_KI, GDK_g, 0xff77, 0 },
00097   { IIIMF_KEYCODE_H, GDK_kana_KU, GDK_h, 0xff78, 0 },
00098   { IIIMF_KEYCODE_J, GDK_kana_MA, GDK_j, 0xff8f, 0 },
00099   { IIIMF_KEYCODE_K, GDK_kana_NO, GDK_k, 0xff89, 0 },
00100   { IIIMF_KEYCODE_L, GDK_kana_RI, GDK_l, 0xff98, 0 },
00101   { IIIMF_KEYCODE_SEMICOLON, GDK_kana_RE, GDK_semicolon, 0xff9a, 0 },
00102   { ':',                               GDK_kana_KE, GDK_colon, 0xff79, 0 },
00103   { IIIMF_KEYCODE_CLOSE_BRACKET, GDK_kana_MU, GDK_bracketright, 0xff91, 0 },
00104   { IIIMF_KEYCODE_Z, GDK_kana_TSU, GDK_z, 0xff82, 0 },
00105   { IIIMF_KEYCODE_X, GDK_kana_SA, GDK_x, 0xff7b, 0 },
00106   { IIIMF_KEYCODE_C, GDK_kana_SO, GDK_c, 0xff7f, 0 },
00107   { IIIMF_KEYCODE_V, GDK_kana_HI, GDK_v, 0xff8b, 0 },
00108   { IIIMF_KEYCODE_B, GDK_kana_KO, GDK_b, 0xff7a, 0 },
00109   { IIIMF_KEYCODE_N, GDK_kana_MI, GDK_n, 0xff90, 0 },
00110   { IIIMF_KEYCODE_M, GDK_kana_MO, GDK_m, 0xff93, 0 },
00111   { IIIMF_KEYCODE_COMMA, GDK_kana_NE, GDK_comma, 0xff88, 0 },
00112   { IIIMF_KEYCODE_PERIOD, GDK_kana_RU, GDK_period, 0xff99, 0},
00113   { IIIMF_KEYCODE_SLASH, GDK_kana_ME, GDK_slash, 0xff92, 0 },
00114   /* hack to japanese keyboard */
00115   /* backslash is duplicate for RO and prolongedsound */
00116   { IIIMF_KEYCODE_BACK_SLASH, GDK_kana_RO, GDK_underscore, 0xff9b, 0 },
00117   { IIIMF_KEYCODE_BACK_SLASH, GDK_prolongedsound, GDK_bar, 0xff70, 0 },
00118   { 0, 0, 0 }
00119 };
00120 #endif /* USE_KANA_TABLE */
00121 
00122 #if    USE_KANA_TABLE
00123 static KeymapEntry2 kana_shift_keymapTable[] = {
00124   { IIIMF_KEYCODE_3, GDK_kana_a, GDK_numbersign, 0xff67, 0 },
00125   { IIIMF_KEYCODE_4, GDK_kana_u, GDK_dollar, 0xff69, 0 },
00126   { IIIMF_KEYCODE_5, GDK_kana_e, GDK_percent, 0xff6a, 0 },
00127   { IIIMF_KEYCODE_6, GDK_kana_o, GDK_ampersand, 0xff6b, 0 },
00128   { IIIMF_KEYCODE_7, GDK_kana_ya, GDK_apostrophe, 0xff6c, 0 },
00129   { IIIMF_KEYCODE_8, GDK_kana_yu, GDK_parenleft, 0xff6d, 0 },
00130   { IIIMF_KEYCODE_9, GDK_kana_yo, GDK_parenright, 0xff6e, 0 },
00131   { IIIMF_KEYCODE_0, GDK_kana_WO, GDK_asciitilde, 0xff66, 0 },
00132   { IIIMF_KEYCODE_E, GDK_kana_i, GDK_E, 0xff68, 0 },
00133   { IIIMF_KEYCODE_OPEN_BRACKET, GDK_kana_openingbracket, GDK_braceleft, 0xff62, 0 },
00134   { IIIMF_KEYCODE_CLOSE_BRACKET, GDK_kana_closingbracket, GDK_braceright, 0xff63, 0 },
00135   { IIIMF_KEYCODE_Z, GDK_kana_tsu, GDK_Z, 0xff6f, 0 },
00136   /* GDK_less does not return correct keycode on VineLinux 1.1 */
00137   { IIIMF_KEYCODE_COMMA, GDK_kana_comma, GDK_comma, 0xff64, 0 },
00138   { IIIMF_KEYCODE_PERIOD, GDK_kana_fullstop, GDK_greater, 0xff61, 0 },
00139   { IIIMF_KEYCODE_SLASH, GDK_kana_conjunctive, GDK_question, 0xff65, 0 },
00140   { 0, 0, 0 }
00141 };
00142 #endif /* USE_KANA_TABLE */
00143 
00144 #if    USE_KANA_TABLE
00145 static void
00146 set_keymap_table(GdkDisplay *display)
00147 {
00148   GdkKeymap *keymap;
00149   gint i;
00150   gboolean result;
00151   GdkKeymapKey *keys;
00152   gint n_keys;
00153 
00154 #if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 2
00155   keymap = gdk_keymap_get_for_display (gdk_drawable_get_display (e->window));
00156 #else
00157   keymap = gdk_keymap_get_default ();
00158 #endif
00159 
00160   /* Get Keycodes for Kana keys */
00161   for (i = 0; kana_normal_keymapTable[i].iiimf_keycode != 0; i++)
00162     {
00163       result = gdk_keymap_get_entries_for_keyval
00164          (keymap, kana_normal_keymapTable[i].gdk_keysym, &keys, &n_keys);
00165       if ((result) && (n_keys))
00166         {
00167           kana_normal_keymapTable[i].hardware_keycode = keys->keycode;
00168           g_free (keys);
00169         }
00170       else
00171         {
00172           result = gdk_keymap_get_entries_for_keyval
00173              (keymap, kana_normal_keymapTable[i].gdk_alt_keysym, &keys, &n_keys);
00174           if ((result != FALSE) && (n_keys >= 1))
00175             {
00176               kana_normal_keymapTable[i].hardware_keycode = keys->keycode;
00177               g_free (keys);
00178             }
00179         }
00180     }
00181   for (i = 0; kana_shift_keymapTable[i].iiimf_keycode != 0; i++)
00182     {
00183       result = gdk_keymap_get_entries_for_keyval
00184          (keymap, kana_shift_keymapTable[i].gdk_keysym, &keys, &n_keys);
00185       if ((result) && (n_keys))
00186         {
00187           kana_shift_keymapTable[i].hardware_keycode = keys->keycode;
00188           g_free (keys);
00189         }
00190       else
00191         {
00192           result = gdk_keymap_get_entries_for_keyval
00193              (keymap, kana_shift_keymapTable[i].gdk_alt_keysym, &keys, &n_keys);
00194           if ((result != FALSE) && (n_keys >= 1))
00195             {
00196               kana_shift_keymapTable[i].hardware_keycode = keys->keycode;
00197               g_free (keys);
00198             }
00199         }
00200     }
00201 }
00202 #endif /* USE_KANA_TABLE */
00203 
00204 #if    USE_KANA_TABLE
00205 static int
00206 ignore_error(Display *displayp, XErrorEvent *eventp)
00207 {
00208   return 0;
00209 }
00210 #endif /* USE_KANA_TABLE */
00211 
00212 #if    USE_KANA_TABLE
00213 static gint
00214 get_kana_flag (GdkEventKey *e)
00215 {
00216   static int KanaMode = -1;
00217   int (*oldhandler)(Display *, XErrorEvent *) = NULL;
00218   Window kana_w;
00219   GdkDisplay *gdkdisplay;
00220   Display *xdisplay;
00221   Atom ret_type;
00222   gint ret_format;
00223   unsigned long nitems, bytes_left;
00224   unsigned long *tmp = 0;
00225 
00226   if (KanaMode == -2)
00227     return 0;
00228 
00229   if (!e->window)
00230     return -2;
00231 
00232   gdkdisplay = gdk_drawable_get_display (e->window);
00233   xdisplay = GDK_DISPLAY_XDISPLAY (gdkdisplay);
00234 
00235   if (KanaMode == -1)
00236     {
00237       if (!getenv("HTT_GENERATES_KANAKEY"))
00238         {
00239           KanaMode = -2;
00240           return 0;
00241         }
00242 
00243       KanaMode = 0;
00244       set_keymap_table(gdkdisplay);
00245     }
00246 
00247   if (!kanawin_atom)
00248     {
00249       kanawin_atom = XInternAtom(xdisplay, "HTT_KANA_WIN", False);
00250       kanaflag_atom = XInternAtom(xdisplay, "HTT_KANA_FLAG", False);
00251     }
00252 
00253   XSync(xdisplay, False);
00254   oldhandler = XSetErrorHandler(ignore_error);
00255  
00256   kana_w = XGetSelectionOwner(xdisplay, kanawin_atom);
00257 
00258   if (kana_w == None)
00259     {
00260       XSync(xdisplay, False);
00261       XSetErrorHandler(oldhandler);
00262       return 0;
00263     }
00264 
00265   XGetWindowProperty(xdisplay, kana_w,
00266                      kanaflag_atom, 0, 4, False, XA_WINDOW,
00267                      &ret_type, &ret_format,
00268                      &nitems, &bytes_left, (unsigned char **) &tmp);
00269 
00270   XSync(xdisplay, False);
00271   XSetErrorHandler(oldhandler);
00272 
00273   if ((tmp != NULL) && (ret_type == XA_WINDOW) && ((*tmp == 0) || (*tmp == 1)))
00274     KanaMode = *tmp;
00275   if (tmp)
00276     free((char*)tmp);
00277 
00278   return KanaMode;
00279 }
00280 #endif /* USE_KANA_TABLE */
00281 
00282 #if    USE_KANA_TABLE
00283 static void
00284 toggle_kana_flag (GdkEventKey *e)
00285 {
00286   int (*oldhandler)(Display *, XErrorEvent *) = NULL;
00287   int kanamode;
00288   Window kana_w;
00289   GdkDisplay *gdkdisplay;
00290   Display *xdisplay;
00291 
00292   kanamode = get_kana_flag (e);
00293   if (kanamode < 0)
00294     return;
00295 
00296   if (kanamode == 0)
00297     kanamode = 1;
00298   else
00299     kanamode = 0;
00300 
00301   gdkdisplay = gdk_drawable_get_display (e->window);
00302   xdisplay = GDK_DISPLAY_XDISPLAY (gdkdisplay);
00303 
00304   XSync(xdisplay, False);
00305   oldhandler = XSetErrorHandler(ignore_error);
00306 
00307   kana_w = XGetSelectionOwner(xdisplay, kanawin_atom);
00308 
00309   if (kana_w != None)
00310     {
00311       XChangeProperty(xdisplay, kana_w, kanaflag_atom, XA_WINDOW, 32,
00312                       PropModeReplace,
00313                       (unsigned char*) &kanamode,
00314                       sizeof(kanamode));
00315     }
00316 
00317   XSync(xdisplay, False);
00318   XSetErrorHandler(oldhandler);
00319 }
00320 #endif /* USE_KANA_TABLE */
00321 
00322 int
00323 g2icode (guint kv)
00324 {
00325   switch (kv)
00326     {
00327     case GDK_VoidSymbol:
00328       return 0;
00329     case GDK_BackSpace:
00330       return IIIMF_KEYCODE_BACK_SPACE;
00331     case GDK_Tab:
00332       return IIIMF_KEYCODE_TAB;
00333     case GDK_Linefeed:
00334       return IIIMF_KEYCODE_ENTER;
00335     case GDK_Clear:
00336       return -IIIMF_KEYCODE_CLEAR;
00337     case GDK_Return:
00338       return IIIMF_KEYCODE_ENTER;
00339     case GDK_Pause:
00340       return IIIMF_KEYCODE_PAUSE;
00341     case GDK_Scroll_Lock:
00342       return -IIIMF_KEYCODE_SCROLL_LOCK;
00343     case GDK_Sys_Req:
00344       return 0;
00345     case GDK_Escape:
00346       return IIIMF_KEYCODE_ESCAPE;
00347     case GDK_Delete:
00348       return IIIMF_KEYCODE_DELETE;
00349     case GDK_Multi_key:
00350       return IIIMF_KEYCODE_COMPOSE;
00351     case GDK_Codeinput:
00352       return -IIIMF_KEYCODE_CODE_INPUT;
00353     case GDK_SingleCandidate:
00354     case GDK_MultipleCandidate:
00355       return 0;
00356     case GDK_PreviousCandidate:
00357       return -IIIMF_KEYCODE_PREVIOUS_CANDIDATE;
00358     case GDK_Kanji:
00359 #ifdef linux
00360       return -IIIMF_KEYCODE_KANJI;
00361 #else
00362       return -IIIMF_KEYCODE_CONVERT;
00363 #endif
00364     case GDK_Muhenkan:
00365     case GDK_Execute:
00366       return -IIIMF_KEYCODE_NONCONVERT;
00367     case GDK_Henkan_Mode:
00368       /* case GDK_Henkan: */
00369 #ifdef linux
00370       return -IIIMF_KEYCODE_CONVERT;
00371 #else
00372       return -IIIMF_KEYCODE_KANJI;
00373 #endif
00374     case GDK_Romaji:
00375       return -IIIMF_KEYCODE_ROMAN_CHARACTERS;
00376     case GDK_Hiragana:
00377       return -IIIMF_KEYCODE_HIRAGANA;
00378     case GDK_Katakana:
00379       return -IIIMF_KEYCODE_KATAKANA;
00380     case GDK_Hiragana_Katakana:
00381       return 0;
00382     case GDK_Zenkaku:
00383       return -IIIMF_KEYCODE_FULL_WIDTH;
00384     case GDK_Hankaku:
00385       return -IIIMF_KEYCODE_HALF_WIDTH;
00386     case GDK_Kana_Lock:
00387       return -IIIMF_KEYCODE_KANA_LOCK;
00388     case GDK_Home:
00389       return -IIIMF_KEYCODE_HOME;
00390     case GDK_Left:
00391       return -IIIMF_KEYCODE_LEFT;
00392     case GDK_Up:
00393       return -IIIMF_KEYCODE_UP;
00394     case GDK_Right:
00395       return -IIIMF_KEYCODE_RIGHT;
00396     case GDK_Down:
00397       return -IIIMF_KEYCODE_DOWN;
00398     case GDK_Page_Up:
00399       return -IIIMF_KEYCODE_PAGE_UP;
00400     case GDK_Page_Down:
00401       return -IIIMF_KEYCODE_PAGE_DOWN;
00402     case GDK_End:
00403       return -IIIMF_KEYCODE_END;
00404     case GDK_Print:
00405       return -IIIMF_KEYCODE_PRINTSCREEN;
00406     case GDK_Insert:
00407       return IIIMF_KEYCODE_INSERT;
00408     case GDK_Undo:
00409       return -IIIMF_KEYCODE_UNDO;
00410     case GDK_Find:
00411       return -IIIMF_KEYCODE_FIND;
00412     case GDK_Cancel:
00413       return -IIIMF_KEYCODE_CANCEL;
00414     case GDK_Help:
00415       return -IIIMF_KEYCODE_HELP;
00416     case GDK_Mode_switch:
00417       /* case GDK_script_switch: */
00418       return -IIIMF_KEYCODE_MODECHANGE;
00419     case GDK_Num_Lock:
00420       return -IIIMF_KEYCODE_NUM_LOCK;
00421     case GDK_KP_Space:
00422       return IIIMF_KEYCODE_SPACE;
00423     case GDK_KP_Tab:
00424       return IIIMF_KEYCODE_TAB;
00425     case GDK_KP_Enter:
00426       return IIIMF_KEYCODE_ENTER;
00427     case GDK_KP_F1:
00428       return -IIIMF_KEYCODE_F1;
00429     case GDK_KP_F2:
00430       return -IIIMF_KEYCODE_F2;
00431     case GDK_KP_F3:
00432       return -IIIMF_KEYCODE_F3;
00433     case GDK_KP_F4:
00434       return -IIIMF_KEYCODE_F4;
00435     case GDK_KP_Home:
00436       return -IIIMF_KEYCODE_HOME;
00437     case GDK_KP_Left:
00438       return -IIIMF_KEYCODE_LEFT;
00439     case GDK_KP_Up:
00440       return -IIIMF_KEYCODE_UP;
00441     case GDK_KP_Right:
00442       return -IIIMF_KEYCODE_RIGHT;
00443     case GDK_KP_Down:
00444       return -IIIMF_KEYCODE_DOWN;
00445     case GDK_KP_Page_Up:
00446       return -IIIMF_KEYCODE_PAGE_UP;
00447     case GDK_KP_Page_Down:
00448       return -IIIMF_KEYCODE_PAGE_DOWN;
00449     case GDK_KP_End:
00450       return -IIIMF_KEYCODE_END;
00451     case GDK_KP_Insert:
00452       return IIIMF_KEYCODE_INSERT;
00453     case GDK_KP_Delete:
00454       return IIIMF_KEYCODE_DELETE;
00455     case GDK_KP_Equal:
00456       return IIIMF_KEYCODE_EQUALS;
00457     case GDK_KP_Multiply:
00458       return IIIMF_KEYCODE_MULTIPLY;
00459     case GDK_KP_Add:
00460       return IIIMF_KEYCODE_ADD;
00461     case GDK_KP_Separator:
00462       return IIIMF_KEYCODE_SEPARATOR;
00463     case GDK_KP_Subtract:
00464       return IIIMF_KEYCODE_SUBTRACT;
00465     case GDK_KP_Decimal:
00466       return IIIMF_KEYCODE_DECIMAL;
00467     case GDK_KP_Divide:
00468       return IIIMF_KEYCODE_DIVIDE;
00469     case GDK_KP_0:
00470       return IIIMF_KEYCODE_NUMPAD0;
00471     case GDK_KP_1:
00472       return IIIMF_KEYCODE_NUMPAD1;
00473     case GDK_KP_2:
00474       return IIIMF_KEYCODE_NUMPAD2;
00475     case GDK_KP_3:
00476       return IIIMF_KEYCODE_NUMPAD3;
00477     case GDK_KP_4:
00478       return IIIMF_KEYCODE_NUMPAD4;
00479     case GDK_KP_5:
00480       return IIIMF_KEYCODE_NUMPAD5;
00481     case GDK_KP_6:
00482       return IIIMF_KEYCODE_NUMPAD6;
00483     case GDK_KP_7:
00484       return IIIMF_KEYCODE_NUMPAD7;
00485     case GDK_KP_8:
00486       return IIIMF_KEYCODE_NUMPAD8;
00487     case GDK_KP_9:
00488       return IIIMF_KEYCODE_NUMPAD9;
00489     case GDK_F1:
00490       return -IIIMF_KEYCODE_F1;
00491     case GDK_F2:
00492       return -IIIMF_KEYCODE_F2;
00493     case GDK_F3:
00494       return -IIIMF_KEYCODE_F3;
00495     case GDK_F4:
00496       return -IIIMF_KEYCODE_F4;
00497     case GDK_F5:
00498       return -IIIMF_KEYCODE_F5;
00499     case GDK_F6:
00500       return -IIIMF_KEYCODE_F6;
00501     case GDK_F7:
00502       return -IIIMF_KEYCODE_F7;
00503     case GDK_F8:
00504       return -IIIMF_KEYCODE_F8;
00505     case GDK_F9:
00506       return -IIIMF_KEYCODE_F9;
00507     case GDK_F10:
00508       return -IIIMF_KEYCODE_F10;
00509 #if defined(SunXK_F36)
00510     case SunXK_F36:
00511 #endif /* SunXK_F36 */
00512     case GDK_F11:
00513       /*case GDK_L1: */
00514       return -IIIMF_KEYCODE_F11;
00515 #if defined(SunXK_F37)
00516     case SunXK_F37:
00517 #endif /* SunXK_F37 */
00518     case GDK_F12:
00519       /* case GDK_L2: */
00520       return -IIIMF_KEYCODE_F12;
00521     case GDK_F13:
00522       /* case GDK_L3: */
00523       return -IIIMF_KEYCODE_F13;
00524     case GDK_F14:
00525       /* case GDK_L4: */
00526       return -IIIMF_KEYCODE_F14;
00527     case GDK_F15:
00528       /* case GDK_L5: */
00529       return -IIIMF_KEYCODE_F15;
00530     case GDK_F16:
00531       /* case GDK_L6: */
00532       return -IIIMF_KEYCODE_F16;
00533     case GDK_F17:
00534       /* case GDK_L7: */
00535       return -IIIMF_KEYCODE_F17;
00536     case GDK_F18:
00537       /* case GDK_L8: */
00538       return -IIIMF_KEYCODE_F18;
00539     case GDK_F19:
00540       /* case GDK_L9: */
00541       return -IIIMF_KEYCODE_F19;
00542     case GDK_F20:
00543       /* case GDK_L10: */
00544       return -IIIMF_KEYCODE_F20;
00545     case GDK_F21:
00546       /* case GDK_R1: */
00547       return -IIIMF_KEYCODE_F21;
00548     case GDK_F22:
00549       /* case GDK_R2: */
00550       return -IIIMF_KEYCODE_F22;
00551     case GDK_F23:
00552       /* case GDK_R3: */
00553       return -IIIMF_KEYCODE_F23;
00554     case GDK_F24:
00555       /* case GDK_R4: */
00556       return -IIIMF_KEYCODE_F24;
00557     case GDK_Shift_L:
00558     case GDK_Shift_R:
00559       return -IIIMF_KEYCODE_SHIFT;
00560     case GDK_Control_L:
00561     case GDK_Control_R:
00562       return -IIIMF_KEYCODE_CONTROL;
00563     case GDK_Caps_Lock:
00564       return -IIIMF_KEYCODE_CAPS_LOCK;
00565     case GDK_Meta_L:
00566     case GDK_Meta_R:
00567       return -IIIMF_KEYCODE_META;
00568     case GDK_Alt_L:
00569     case GDK_Alt_R:
00570       return -IIIMF_KEYCODE_ALT;
00571     case GDK_dead_grave:
00572       return IIIMF_KEYCODE_DEAD_GRAVE;
00573     case GDK_dead_acute:
00574       return IIIMF_KEYCODE_DEAD_ACUTE;
00575     case GDK_dead_circumflex:
00576       return IIIMF_KEYCODE_DEAD_CIRCUMFLEX;
00577     case GDK_dead_tilde:
00578       return IIIMF_KEYCODE_DEAD_TILDE;
00579     case GDK_dead_macron:
00580       return IIIMF_KEYCODE_DEAD_MACRON;
00581     case GDK_dead_breve:
00582       return IIIMF_KEYCODE_DEAD_BREVE;
00583     case GDK_dead_abovedot:
00584       return IIIMF_KEYCODE_DEAD_ABOVEDOT;
00585     case GDK_dead_diaeresis:
00586       return IIIMF_KEYCODE_DEAD_DIAERESIS;
00587     case GDK_dead_abovering:
00588       return IIIMF_KEYCODE_DEAD_ABOVERING;
00589     case GDK_dead_doubleacute:
00590       return IIIMF_KEYCODE_DEAD_DOUBLEACUTE;
00591     case GDK_dead_caron:
00592       return IIIMF_KEYCODE_DEAD_CARON;
00593     case GDK_dead_cedilla:
00594       return IIIMF_KEYCODE_DEAD_CEDILLA;
00595     case GDK_dead_ogonek:
00596       return IIIMF_KEYCODE_DEAD_OGONEK;
00597     case GDK_dead_iota:
00598       return IIIMF_KEYCODE_DEAD_IOTA;
00599     case GDK_dead_voiced_sound:
00600       return IIIMF_KEYCODE_DEAD_VOICED_SOUND;
00601     case GDK_dead_semivoiced_sound:
00602       return IIIMF_KEYCODE_DEAD_SEMIVOICED_SOUND;
00603 
00604     case GDK_space:
00605       return IIIMF_KEYCODE_SPACE;
00606     case GDK_exclam:
00607       return IIIMF_KEYCODE_EXCLAMATION_MARK;
00608     case GDK_quotedbl:
00609       return IIIMF_KEYCODE_QUOTEDBL;
00610     case GDK_numbersign:
00611       return IIIMF_KEYCODE_NUMBER_SIGN;
00612     case GDK_dollar:
00613       return IIIMF_KEYCODE_DOLLAR;
00614     case GDK_ampersand:
00615       return IIIMF_KEYCODE_AMPERSAND;
00616     case GDK_apostrophe:
00617       /* case GDK_quoteright: */
00618       return IIIMF_KEYCODE_QUOTE;
00619     case GDK_parenleft:
00620       return IIIMF_KEYCODE_LEFT_PARENTHESIS;
00621     case GDK_parenright:
00622       return IIIMF_KEYCODE_RIGHT_PARENTHESIS;
00623     case GDK_asterisk:
00624       return IIIMF_KEYCODE_ASTERISK;
00625     case GDK_plus:
00626       return IIIMF_KEYCODE_PLUS;
00627     case GDK_comma:
00628       return IIIMF_KEYCODE_COMMA;
00629     case GDK_minus:
00630       return IIIMF_KEYCODE_MINUS;
00631     case GDK_period:
00632       return IIIMF_KEYCODE_PERIOD;
00633     case GDK_slash:
00634       return IIIMF_KEYCODE_SLASH;
00635     case GDK_0:
00636       return IIIMF_KEYCODE_0;
00637     case GDK_1:
00638       return IIIMF_KEYCODE_1;
00639     case GDK_2:
00640       return IIIMF_KEYCODE_2;
00641     case GDK_3:
00642       return IIIMF_KEYCODE_3;
00643     case GDK_4:
00644       return IIIMF_KEYCODE_4;
00645     case GDK_5:
00646       return IIIMF_KEYCODE_5;
00647     case GDK_6:
00648       return IIIMF_KEYCODE_6;
00649     case GDK_7:
00650       return IIIMF_KEYCODE_7;
00651     case GDK_8:
00652       return IIIMF_KEYCODE_8;
00653     case GDK_9:
00654       return IIIMF_KEYCODE_9;
00655     case GDK_colon:
00656       return IIIMF_KEYCODE_COLON;
00657     case GDK_semicolon:
00658       return IIIMF_KEYCODE_SEMICOLON;
00659     case GDK_less:
00660       return IIIMF_KEYCODE_LESS;
00661     case GDK_equal:
00662       return IIIMF_KEYCODE_EQUALS;
00663     case GDK_greater:
00664       return IIIMF_KEYCODE_GREATER;
00665     case GDK_at:
00666       return IIIMF_KEYCODE_AT;
00667     case GDK_A:
00668       return IIIMF_KEYCODE_A;
00669     case GDK_B:
00670       return IIIMF_KEYCODE_B;
00671     case GDK_C:
00672       return IIIMF_KEYCODE_C;
00673     case GDK_D:
00674       return IIIMF_KEYCODE_D;
00675     case GDK_E:
00676       return IIIMF_KEYCODE_E;
00677     case GDK_F:
00678       return IIIMF_KEYCODE_F;
00679     case GDK_G:
00680       return IIIMF_KEYCODE_G;
00681     case GDK_H:
00682       return IIIMF_KEYCODE_H;
00683     case GDK_I:
00684       return IIIMF_KEYCODE_I;
00685     case GDK_J:
00686       return IIIMF_KEYCODE_J;
00687     case GDK_K:
00688       return IIIMF_KEYCODE_K;
00689     case GDK_L:
00690       return IIIMF_KEYCODE_L;
00691     case GDK_M:
00692       return IIIMF_KEYCODE_M;
00693     case GDK_N:
00694       return IIIMF_KEYCODE_N;
00695     case GDK_O:
00696       return IIIMF_KEYCODE_O;
00697     case GDK_P:
00698       return IIIMF_KEYCODE_P;
00699     case GDK_Q:
00700       return IIIMF_KEYCODE_Q;
00701     case GDK_R:
00702       return IIIMF_KEYCODE_R;
00703     case GDK_S:
00704       return IIIMF_KEYCODE_S;
00705     case GDK_T:
00706       return IIIMF_KEYCODE_T;
00707     case GDK_U:
00708       return IIIMF_KEYCODE_U;
00709     case GDK_V:
00710       return IIIMF_KEYCODE_V;
00711     case GDK_W:
00712       return IIIMF_KEYCODE_W;
00713     case GDK_X:
00714       return IIIMF_KEYCODE_X;
00715     case GDK_Y:
00716       return IIIMF_KEYCODE_Y;
00717     case GDK_Z:
00718       return IIIMF_KEYCODE_Z;
00719 
00720     case GDK_bracketleft:
00721       return IIIMF_KEYCODE_OPEN_BRACKET;
00722     case GDK_backslash:
00723       return IIIMF_KEYCODE_BACK_SLASH;
00724     case GDK_bracketright:
00725       return IIIMF_KEYCODE_CLOSE_BRACKET;
00726     case GDK_asciicircum:
00727       return IIIMF_KEYCODE_CIRCUMFLEX;
00728     case GDK_underscore:
00729       return IIIMF_KEYCODE_UNDERSCORE;
00730     case GDK_grave:
00731       /* case GDK_quoteleft: */
00732       return IIIMF_KEYCODE_BACK_QUOTE;
00733 
00734     case GDK_a:
00735       return IIIMF_KEYCODE_A;
00736     case GDK_b:
00737       return IIIMF_KEYCODE_B;
00738     case GDK_c:
00739       return IIIMF_KEYCODE_C;
00740     case GDK_d:
00741       return IIIMF_KEYCODE_D;
00742     case GDK_e:
00743       return IIIMF_KEYCODE_E;
00744     case GDK_f:
00745       return IIIMF_KEYCODE_F;
00746     case GDK_g:
00747       return IIIMF_KEYCODE_G;
00748     case GDK_h:
00749       return IIIMF_KEYCODE_H;
00750     case GDK_i:
00751       return IIIMF_KEYCODE_I;
00752     case GDK_j:
00753       return IIIMF_KEYCODE_J;
00754     case GDK_k:
00755       return IIIMF_KEYCODE_K;
00756     case GDK_l:
00757       return IIIMF_KEYCODE_L;
00758     case GDK_m:
00759       return IIIMF_KEYCODE_M;
00760     case GDK_n:
00761       return IIIMF_KEYCODE_N;
00762     case GDK_o:
00763       return IIIMF_KEYCODE_O;
00764     case GDK_p:
00765       return IIIMF_KEYCODE_P;
00766     case GDK_q:
00767       return IIIMF_KEYCODE_Q;
00768     case GDK_r:
00769       return IIIMF_KEYCODE_R;
00770     case GDK_s:
00771       return IIIMF_KEYCODE_S;
00772     case GDK_t:
00773       return IIIMF_KEYCODE_T;
00774     case GDK_u:
00775       return IIIMF_KEYCODE_U;
00776     case GDK_v:
00777       return IIIMF_KEYCODE_V;
00778     case GDK_w:
00779       return IIIMF_KEYCODE_W;
00780     case GDK_x:
00781       return IIIMF_KEYCODE_X;
00782     case GDK_y:
00783       return IIIMF_KEYCODE_Y;
00784     case GDK_z:
00785       return IIIMF_KEYCODE_Z;
00786     case GDK_braceleft:
00787       return IIIMF_KEYCODE_BRACELEFT;
00788     case GDK_braceright:
00789       return IIIMF_KEYCODE_BRACERIGHT;
00790 
00791     case GDK_exclamdown:
00792       return IIIMF_KEYCODE_INVERTED_EXCLAMATION_MARK;
00793 
00794     case GDK_EuroSign:
00795       return IIIMF_KEYCODE_EURO_SIGN;
00796 
00797     case GDK_Zenkaku_Hankaku:
00798       return IIIMF_KEYCODE_KANJI;
00799 
00800     default:
00801       return 0;
00802     }
00803 
00804   return 0;
00805 }
00806 
00807 static int
00808 modifier (guint st)
00809 {
00810   int mod = 0;
00811 
00812   if (st & GDK_SHIFT_MASK)
00813     mod |= IIIMF_SHIFT_MODIFIER;
00814   if (st & GDK_CONTROL_MASK)
00815     mod |= IIIMF_CONTROL_MODIFIER;
00816   if (st & GDK_MOD1_MASK)
00817     mod |= IIIMF_ALT_MODIFIER;
00818   if (st & GDK_MOD3_MASK)
00819     mod |= IIIMF_ALT_GRAPH_MODIFIER;
00820 
00821   return mod;
00822 }
00823 
00824 IIIMF_status
00825 convert_GdkEventKey_to_IIIMCF_keyevent (GdkEventKey * e,
00826                                    IIIMCF_keyevent * pkev)
00827 {
00828   int c;
00829   guint keyval;
00830   int key_release;
00831 
00832   key_release = ((e->type == GDK_KEY_PRESS) ? 0 : 0x80000000);
00833 
00834 #if    USE_KANA_TABLE
00835   gint kanaflag;
00836   gint i;
00837 
00838   kanaflag = get_kana_flag(e);
00839   if (kanaflag >= 0)
00840     {
00841       if (e->keyval == GDK_Hiragana_Katakana)
00842         toggle_kana_flag(e);
00843     }
00844 
00845   if (kanaflag == 1)
00846     {
00847       if (e->state & GDK_SHIFT_MASK)
00848         {
00849           /* check kana_shift_keymapTable first is ShiftMask */
00850           for (i = 0; kana_shift_keymapTable[i].iiimf_keycode != 0; i++)
00851             {
00852               if (kana_shift_keymapTable[i].hardware_keycode == e->hardware_keycode)
00853                 {
00854                   pkev->keycode = kana_shift_keymapTable[i].iiimf_keycode;
00855                   pkev->keychar = kana_shift_keymapTable[i].iiimf_keychar;
00856                   if (pkev->keycode)
00857                     {
00858                       pkev->modifier = (modifier (e->state) | key_release);
00859                       pkev->time_stamp = e->time;
00860                       return IIIMF_STATUS_SUCCESS;
00861                     }
00862                   break;
00863                 }
00864             }
00865         }
00866 
00867       for (i = 0; kana_normal_keymapTable[i].iiimf_keycode != 0; i++)
00868         {
00869           if (kana_normal_keymapTable[i].hardware_keycode == e->hardware_keycode)
00870             {
00871               pkev->keycode = kana_normal_keymapTable[i].iiimf_keycode;
00872               pkev->keychar = kana_normal_keymapTable[i].iiimf_keychar;
00873               if (pkev->keycode)
00874                 {
00875                   pkev->modifier = (modifier (e->state) | key_release);
00876                   pkev->time_stamp = e->time;
00877                   return IIIMF_STATUS_SUCCESS;
00878                 }
00879               break;
00880             }
00881         }
00882 
00883       for (i = 0; kana_shift_keymapTable[i].iiimf_keycode != 0; i++)
00884         {
00885           if (kana_shift_keymapTable[i].hardware_keycode == e->hardware_keycode)
00886             {
00887               pkev->keycode = kana_shift_keymapTable[i].iiimf_keycode;
00888               pkev->keychar = kana_shift_keymapTable[i].iiimf_keychar;
00889               if (pkev->keycode)
00890                 {
00891                   pkev->modifier = (modifier (e->state) | key_release);
00892                   pkev->time_stamp = e->time;
00893                   return IIIMF_STATUS_SUCCESS;
00894                 }
00895               break;
00896             }
00897         }
00898     }
00899   else
00900     {
00901       for (i = 0; kana_normal_keymapTable[i].iiimf_keycode != 0; i++)
00902         {
00903           if (kana_normal_keymapTable[i].gdk_keysym == e->keyval)
00904             {
00905               pkev->keycode = kana_normal_keymapTable[i].iiimf_keycode;
00906               pkev->keychar = kana_normal_keymapTable[i].iiimf_keychar;
00907               if (pkev->keycode)
00908                 {
00909                   pkev->modifier = (modifier (e->state) | key_release);
00910                   pkev->time_stamp = e->time;
00911                   return IIIMF_STATUS_SUCCESS;
00912                 }
00913               break;
00914             }
00915         }
00916 
00917       for (i = 0; kana_shift_keymapTable[i].iiimf_keycode != 0; i++)
00918         {
00919           if (kana_shift_keymapTable[i].gdk_keysym == e->keyval)
00920             {
00921               pkev->keycode = kana_normal_keymapTable[i].iiimf_keycode;
00922               pkev->keychar = kana_normal_keymapTable[i].iiimf_keychar;
00923               if (pkev->keycode)
00924                 {
00925                   pkev->modifier = (modifier (e->state) | key_release);
00926                   pkev->time_stamp = e->time;
00927                   return IIIMF_STATUS_SUCCESS;
00928                 }
00929               break;
00930             }
00931         }
00932     }
00933 #endif /* USE_KANA_TABLE */
00934 
00935   /* first, try to get keycode from KeySym */
00936   c = g2icode (e->keyval);
00937   if (c == 0)
00938     {
00939       GdkKeymap *keymap;
00940 #if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 2
00941       keymap =
00942        gdk_keymap_get_for_display (gdk_drawable_get_display (e->window));
00943 #else
00944       keymap = gdk_keymap_get_default ();
00945 #endif
00946       /* 
00947        * Cannot get IIIMF keycode from keysym.
00948        * So, we genarate base keysym by ignoring mod mask from hardware keycode.
00949        */
00950       if (!gdk_keymap_translate_keyboard_state (keymap, e->hardware_keycode,
00951                                           0, 0, &keyval, NULL, NULL,
00952                                           NULL))
00953        return IIIMF_STATUS_FAIL;
00954 
00955 
00956       /* retry */
00957       c = g2icode (keyval);
00958 
00959       if (c == 0)
00960        return IIIMF_STATUS_FAIL;
00961     }
00962   if (c < 0)
00963     {
00964       pkev->keychar = 0;
00965       pkev->keycode = -c;
00966     }
00967   else
00968     {
00969       pkev->keychar = gdk_keyval_to_unicode (e->keyval);
00970       pkev->keycode = c;
00971     }
00972   pkev->modifier = (modifier (e->state) | key_release);
00973 
00974   pkev->time_stamp = e->time;
00975 
00976   return IIIMF_STATUS_SUCCESS;
00977 }
00978 
00979 static guint
00980 i2gmodifier (int st)
00981 {
00982   int mod = 0;
00983   if (st & IIIMF_SHIFT_MODIFIER)
00984     mod |= GDK_SHIFT_MASK;
00985   if (st & IIIMF_CONTROL_MODIFIER)
00986     mod |= GDK_CONTROL_MASK;
00987   if (st & IIIMF_ALT_MODIFIER)
00988     mod |= GDK_MOD1_MASK;
00989 
00990   return mod;
00991 }
00992 
00993 static guint
00994 i2gcode (int kv, int kc)
00995 {
00996   switch (kv)
00997     {
00998 
00999       /* case IIIMF_KEYCODE_UNDEFINED */
01000     case IIIMF_KEYCODE_CANCEL:
01001       return GDK_Cancel;
01002     case IIIMF_KEYCODE_BACK_SPACE:
01003       return GDK_BackSpace;
01004     case IIIMF_KEYCODE_TAB:
01005       return GDK_Tab;
01006     case IIIMF_KEYCODE_ENTER:
01007       return GDK_Return;
01008     case IIIMF_KEYCODE_CLEAR:
01009       return GDK_Clear;
01010     case IIIMF_KEYCODE_SHIFT:
01011       return GDK_Shift_L;   /* ... */
01012     case IIIMF_KEYCODE_CONTROL:
01013       return GDK_Control_L; /* ... */
01014     case IIIMF_KEYCODE_ALT:
01015       return GDK_Alt_L;
01016     case IIIMF_KEYCODE_PAUSE:
01017       return GDK_Pause;
01018     case IIIMF_KEYCODE_CAPS_LOCK:
01019       return GDK_Caps_Lock;
01020       /*
01021          case IIIMF_KEYCODE_KANA
01022          case IIIMF_KEYCODE_FINAL
01023        */
01024     case IIIMF_KEYCODE_KANJI:
01025 #ifdef linux
01026       return GDK_Kanji;
01027 #else
01028       return GDK_Henkan_Mode;
01029 #endif
01030 
01031     case IIIMF_KEYCODE_ESCAPE:
01032       return GDK_Escape;
01033     case IIIMF_KEYCODE_CONVERT:
01034 #ifdef linux
01035       return GDK_Henkan_Mode;
01036 #else
01037       return GDK_Kanji;
01038 #endif
01039     case IIIMF_KEYCODE_NONCONVERT:
01040 #ifdef linux
01041       return GDK_Muhenkan;
01042 #else
01043       return GDK_Execute;
01044 #endif
01045       /* case IIIMF_KEYCODE_ACCEPT */
01046     case IIIMF_KEYCODE_MODECHANGE:
01047       return GDK_Mode_switch;
01048     case IIIMF_KEYCODE_SPACE:
01049       return GDK_space;
01050     case IIIMF_KEYCODE_PAGE_UP:
01051       return GDK_Page_Up;
01052     case IIIMF_KEYCODE_PAGE_DOWN:
01053       return GDK_Page_Down;
01054     case IIIMF_KEYCODE_END:
01055       return GDK_End;
01056     case IIIMF_KEYCODE_HOME:
01057       return GDK_Home;
01058     case IIIMF_KEYCODE_LEFT:
01059       return GDK_Left;
01060     case IIIMF_KEYCODE_UP:
01061       return GDK_Up;
01062     case IIIMF_KEYCODE_RIGHT:
01063       return GDK_Right;
01064     case IIIMF_KEYCODE_DOWN:
01065       return GDK_Down;
01066     case IIIMF_KEYCODE_COMMA:
01067       return GDK_comma;
01068     case IIIMF_KEYCODE_MINUS:
01069       return GDK_minus;
01070     case IIIMF_KEYCODE_PERIOD:
01071       return GDK_period;
01072     case IIIMF_KEYCODE_SLASH:
01073       return GDK_slash;
01074     case IIIMF_KEYCODE_0:
01075       return GDK_0;
01076     case IIIMF_KEYCODE_1:
01077       return GDK_1;
01078     case IIIMF_KEYCODE_2:
01079       return GDK_2;
01080     case IIIMF_KEYCODE_3:
01081       return GDK_3;
01082     case IIIMF_KEYCODE_4:
01083       return GDK_4;
01084     case IIIMF_KEYCODE_5:
01085       return GDK_5;
01086     case IIIMF_KEYCODE_6:
01087       return GDK_6;
01088     case IIIMF_KEYCODE_7:
01089       return GDK_7;
01090     case IIIMF_KEYCODE_8:
01091       return GDK_8;
01092     case IIIMF_KEYCODE_9:
01093       return GDK_9;
01094     case IIIMF_KEYCODE_SEMICOLON:
01095       return GDK_semicolon;
01096     case IIIMF_KEYCODE_EQUALS:
01097       return GDK_equal;
01098     case IIIMF_KEYCODE_A:
01099       return GDK_a;
01100     case IIIMF_KEYCODE_B:
01101       return GDK_b;
01102     case IIIMF_KEYCODE_C:
01103       return GDK_c;
01104     case IIIMF_KEYCODE_D:
01105       return GDK_d;
01106     case IIIMF_KEYCODE_E:
01107       return GDK_e;
01108     case IIIMF_KEYCODE_F:
01109       return GDK_f;
01110     case IIIMF_KEYCODE_G:
01111       return GDK_g;
01112     case IIIMF_KEYCODE_H:
01113       return GDK_h;
01114     case IIIMF_KEYCODE_I:
01115       return GDK_i;
01116     case IIIMF_KEYCODE_J:
01117       return GDK_j;
01118     case IIIMF_KEYCODE_K:
01119       return GDK_k;
01120     case IIIMF_KEYCODE_L:
01121       return GDK_l;
01122     case IIIMF_KEYCODE_M:
01123       return GDK_m;
01124     case IIIMF_KEYCODE_N:
01125       return GDK_n;
01126     case IIIMF_KEYCODE_O:
01127       return GDK_o;
01128     case IIIMF_KEYCODE_P:
01129       return GDK_p;
01130     case IIIMF_KEYCODE_Q:
01131       return GDK_q;
01132     case IIIMF_KEYCODE_R:
01133       return GDK_r;
01134     case IIIMF_KEYCODE_S:
01135       return GDK_s;
01136     case IIIMF_KEYCODE_T:
01137       return GDK_t;
01138     case IIIMF_KEYCODE_U:
01139       return GDK_u;
01140     case IIIMF_KEYCODE_V:
01141       return GDK_v;
01142     case IIIMF_KEYCODE_W:
01143       return GDK_w;
01144     case IIIMF_KEYCODE_X:
01145       return GDK_x;
01146     case IIIMF_KEYCODE_Y:
01147       return GDK_y;
01148     case IIIMF_KEYCODE_Z:
01149       return GDK_z;
01150     case IIIMF_KEYCODE_OPEN_BRACKET:
01151       return GDK_bracketleft;
01152     case IIIMF_KEYCODE_BACK_SLASH:
01153       return GDK_backslash;
01154     case IIIMF_KEYCODE_CLOSE_BRACKET:
01155       return GDK_bracketright;
01156     case IIIMF_KEYCODE_NUMPAD0:
01157       return GDK_KP_0;
01158     case IIIMF_KEYCODE_NUMPAD1:
01159       return GDK_KP_1;
01160     case IIIMF_KEYCODE_NUMPAD2:
01161       return GDK_KP_2;
01162     case IIIMF_KEYCODE_NUMPAD3:
01163       return GDK_KP_3;
01164     case IIIMF_KEYCODE_NUMPAD4:
01165       return GDK_KP_4;
01166     case IIIMF_KEYCODE_NUMPAD5:
01167       return GDK_KP_5;
01168     case IIIMF_KEYCODE_NUMPAD6:
01169       return GDK_KP_6;
01170     case IIIMF_KEYCODE_NUMPAD7:
01171       return GDK_KP_7;
01172     case IIIMF_KEYCODE_NUMPAD8:
01173       return GDK_KP_8;
01174     case IIIMF_KEYCODE_NUMPAD9:
01175       return GDK_KP_9;
01176     case IIIMF_KEYCODE_MULTIPLY:
01177       return GDK_KP_Multiply;
01178     case IIIMF_KEYCODE_ADD:
01179       return GDK_KP_Add;
01180     case IIIMF_KEYCODE_SEPARATOR:
01181       return GDK_KP_Separator;
01182     case IIIMF_KEYCODE_SUBTRACT:
01183       return GDK_KP_Subtract;
01184     case IIIMF_KEYCODE_DECIMAL:
01185       return GDK_KP_Decimal;
01186     case IIIMF_KEYCODE_DIVIDE:
01187       return GDK_KP_Divide;
01188     case IIIMF_KEYCODE_F1:
01189       return GDK_F1;
01190     case IIIMF_KEYCODE_F2:
01191       return GDK_F2;
01192     case IIIMF_KEYCODE_F3:
01193       return GDK_F3;
01194     case IIIMF_KEYCODE_F4:
01195       return GDK_F4;
01196     case IIIMF_KEYCODE_F5:
01197       return GDK_F5;
01198     case IIIMF_KEYCODE_F6:
01199       return GDK_F6;
01200     case IIIMF_KEYCODE_F7:
01201       return GDK_F7;
01202     case IIIMF_KEYCODE_F8:
01203       return GDK_F8;
01204     case IIIMF_KEYCODE_F9:
01205       return GDK_F9;
01206     case IIIMF_KEYCODE_F10:
01207       return GDK_F10;
01208     case IIIMF_KEYCODE_F11:
01209 #if defined(SunXK_F36)
01210       return SunXK_F36;
01211 #else /* !SunXK_F36 */
01212       return GDK_F11;
01213 #endif /* !SunXK_F36 */
01214     case IIIMF_KEYCODE_F12:
01215 #if defined(SunXK_F37)
01216       return SunXK_F37;
01217 #else /* !SunXK_F37 */
01218       return GDK_F12;
01219 #endif /* !SunXK_F37 */
01220     case IIIMF_KEYCODE_DELETE:
01221       return GDK_Delete;
01222     case IIIMF_KEYCODE_DEAD_GRAVE:
01223       return GDK_dead_grave;
01224     case IIIMF_KEYCODE_DEAD_ACUTE:
01225       return GDK_dead_acute;
01226     case IIIMF_KEYCODE_DEAD_CIRCUMFLEX:
01227       return GDK_dead_circumflex;
01228     case IIIMF_KEYCODE_DEAD_TILDE:
01229       return GDK_dead_tilde;
01230     case IIIMF_KEYCODE_DEAD_MACRON:
01231       return GDK_dead_macron;
01232     case IIIMF_KEYCODE_DEAD_BREVE:
01233       return GDK_dead_breve;
01234     case IIIMF_KEYCODE_DEAD_ABOVEDOT:
01235       return GDK_dead_abovedot;
01236     case IIIMF_KEYCODE_DEAD_DIAERESIS:
01237       return GDK_dead_diaeresis;
01238     case IIIMF_KEYCODE_DEAD_ABOVERING:
01239       return GDK_dead_abovering;
01240     case IIIMF_KEYCODE_DEAD_DOUBLEACUTE:
01241       return GDK_dead_doubleacute;
01242     case IIIMF_KEYCODE_DEAD_CARON:
01243       return GDK_dead_caron;
01244     case IIIMF_KEYCODE_DEAD_CEDILLA:
01245       return GDK_dead_cedilla;
01246     case IIIMF_KEYCODE_DEAD_OGONEK:
01247       return GDK_dead_ogonek;
01248     case IIIMF_KEYCODE_DEAD_IOTA:
01249       return GDK_dead_iota;
01250     case IIIMF_KEYCODE_DEAD_VOICED_SOUND:
01251       return GDK_dead_voiced_sound;
01252     case IIIMF_KEYCODE_DEAD_SEMIVOICED_SOUND:
01253       return GDK_dead_semivoiced_sound;
01254     case IIIMF_KEYCODE_NUM_LOCK:
01255       return GDK_Num_Lock;
01256     case IIIMF_KEYCODE_SCROLL_LOCK:
01257       return GDK_Scroll_Lock;
01258     case IIIMF_KEYCODE_AMPERSAND:
01259       return GDK_ampersand;
01260     case IIIMF_KEYCODE_ASTERISK:
01261       return GDK_asterisk;
01262     case IIIMF_KEYCODE_QUOTEDBL:
01263       return GDK_quotedbl;
01264     case IIIMF_KEYCODE_LESS:
01265       return GDK_less;
01266     case IIIMF_KEYCODE_PRINTSCREEN:
01267       return GDK_Print;
01268     case IIIMF_KEYCODE_INSERT:
01269       return GDK_Insert;
01270     case IIIMF_KEYCODE_HELP:
01271       return GDK_Help;
01272     case IIIMF_KEYCODE_META:
01273       return GDK_Meta_L;
01274     case IIIMF_KEYCODE_GREATER:
01275       return GDK_greater;
01276     case IIIMF_KEYCODE_BRACELEFT:
01277       return GDK_braceleft;
01278     case IIIMF_KEYCODE_BRACERIGHT:
01279       return GDK_braceright;
01280     case IIIMF_KEYCODE_BACK_QUOTE:
01281       return GDK_grave;
01282     case IIIMF_KEYCODE_QUOTE:
01283       return GDK_apostrophe;
01284     case IIIMF_KEYCODE_KP_UP:
01285       return GDK_KP_Up;
01286     case IIIMF_KEYCODE_KP_DOWN:
01287       return GDK_KP_Down;
01288     case IIIMF_KEYCODE_KP_LEFT:
01289       return GDK_KP_Left;
01290     case IIIMF_KEYCODE_KP_RIGHT:
01291       return GDK_KP_Right;
01292       /* case IIIMF_KEYCODE_ALPHANUMERIC */
01293     case IIIMF_KEYCODE_KATAKANA:
01294       return GDK_Katakana;
01295     case IIIMF_KEYCODE_HIRAGANA:
01296       return GDK_Hiragana;
01297     case IIIMF_KEYCODE_FULL_WIDTH:
01298       return GDK_Zenkaku;
01299     case IIIMF_KEYCODE_HALF_WIDTH:
01300       return GDK_Hankaku;
01301     case IIIMF_KEYCODE_ROMAN_CHARACTERS:
01302       return GDK_Romaji;
01303       /* case IIIMF_KEYCODE_ALL_CANDIDATES */
01304     case IIIMF_KEYCODE_PREVIOUS_CANDIDATE:
01305       return GDK_PreviousCandidate;
01306     case IIIMF_KEYCODE_CODE_INPUT:
01307       return GDK_Codeinput;
01308     case IIIMF_KEYCODE_JAPANESE_KATAKANA:
01309       return GDK_Katakana;
01310     case IIIMF_KEYCODE_JAPANESE_HIRAGANA:
01311       return GDK_Hiragana;
01312 /*     case IIIMF_KEYCODE_JAPANESE_ROMAN */
01313     case IIIMF_KEYCODE_KANA_LOCK:
01314       return GDK_Kana_Lock;
01315       /* case IIIMF_KEYCODE_INPUT_METHOD_ON_OFF */
01316     case IIIMF_KEYCODE_AT:
01317       return GDK_at;
01318     case IIIMF_KEYCODE_COLON:
01319       return GDK_colon;
01320     case IIIMF_KEYCODE_CIRCUMFLEX:
01321       return GDK_asciicircum;
01322     case IIIMF_KEYCODE_DOLLAR:
01323       return GDK_dollar;
01324     case IIIMF_KEYCODE_EURO_SIGN:
01325       return GDK_EuroSign;
01326     case IIIMF_KEYCODE_EXCLAMATION_MARK:
01327       return GDK_exclam;
01328     case IIIMF_KEYCODE_INVERTED_EXCLAMATION_MARK:
01329       return GDK_exclamdown;
01330     case IIIMF_KEYCODE_LEFT_PARENTHESIS:
01331       return GDK_parenleft;
01332     case IIIMF_KEYCODE_NUMBER_SIGN:
01333       return GDK_numbersign;
01334     case IIIMF_KEYCODE_PLUS:
01335       return GDK_plus;
01336     case IIIMF_KEYCODE_RIGHT_PARENTHESIS:
01337       return GDK_parenright;
01338     case IIIMF_KEYCODE_UNDERSCORE:
01339       return GDK_underscore;
01340     case IIIMF_KEYCODE_F13:
01341       return GDK_F13;
01342     case IIIMF_KEYCODE_F14:
01343       return GDK_F14;
01344     case IIIMF_KEYCODE_F15:
01345       return GDK_F15;
01346     case IIIMF_KEYCODE_F16:
01347       return GDK_F16;
01348     case IIIMF_KEYCODE_F17:
01349       return GDK_F17;
01350     case IIIMF_KEYCODE_F18:
01351       return GDK_F18;
01352     case IIIMF_KEYCODE_F19:
01353       return GDK_F19;
01354     case IIIMF_KEYCODE_F20:
01355       return GDK_F20;
01356     case IIIMF_KEYCODE_F21:
01357       return GDK_F21;
01358     case IIIMF_KEYCODE_F22:
01359       return GDK_F22;
01360     case IIIMF_KEYCODE_F23:
01361       return GDK_F23;
01362     case IIIMF_KEYCODE_F24:
01363       return GDK_F24;
01364       /*
01365          case IIIMF_KEYCODE_COMPOSE:
01366          case IIIMF_KEYCODE_ALT_GRAPH
01367          case IIIMF_KEYCODE_STOP
01368          case IIIMF_KEYCODE_AGAIN
01369          case IIIMF_KEYCODE_PROPS
01370        */
01371     case IIIMF_KEYCODE_UNDO:
01372       return GDK_Undo;
01373       /*
01374          case IIIMF_KEYCODE_COPY
01375          case IIIMF_KEYCODE_PASTE
01376        */
01377     case IIIMF_KEYCODE_FIND:
01378       return GDK_Find;
01379       /* case IIIMF_KEYCODE_CUT */
01380 
01381     default:
01382       return (guint) (kv & 0x7fffffff);
01383     }
01384   return 0;
01385 }
01386 
01387 IIIMF_status
01388 convert_IIIMCF_keyevent_to_GdkEventKey (IIIMCF_keyevent * pkev,
01389                                    GdkEventKey * e)
01390 {
01391   guint c;
01392   GdkKeymap *keymap;
01393   GdkKeymapKey *keys;
01394   gint n_keys;
01395 
01396 #if    USE_KANA_TABLE
01397   gint i;
01398 
01399   for (i = 0; kana_normal_keymapTable[i].iiimf_keycode != 0; i++)
01400     {
01401       if (kana_normal_keymapTable[i].iiimf_keychar == pkev->keychar)
01402         {
01403           e->keyval = kana_normal_keymapTable[i].gdk_keysym;
01404           goto FINDKEYVAL;
01405 
01406           break;
01407         }
01408     }
01409 
01410   for (i = 0; kana_shift_keymapTable[i].iiimf_keycode != 0; i++)
01411     {
01412       if (kana_shift_keymapTable[i].iiimf_keychar == pkev->keychar)
01413         {
01414           e->keyval = kana_shift_keymapTable[i].gdk_keysym;
01415           goto FINDKEYVAL;
01416 
01417           break;
01418         }
01419     }
01420 #endif /* USE_KANA_TABLE */
01421 
01422   if (pkev->keychar)
01423     {
01424       e->keyval = gdk_unicode_to_keyval (pkev->keychar);
01425     }
01426   else
01427     {
01428       c = i2gcode (pkev->keycode, pkev->keychar);
01429       if (c == 0)
01430        return IIIMF_STATUS_FAIL;
01431       e->keyval = c;
01432     }
01433 
01434 #if    USE_KANA_TABLE
01435 FINDKEYVAL:
01436 #endif /* USE_KANA_TABLE */
01437 
01438 #if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 2
01439   keymap = gdk_keymap_get_for_display (gdk_drawable_get_display (e->window));
01440 #else
01441   keymap = gdk_keymap_get_default ();
01442 #endif
01443 
01444 
01445   e->state = i2gmodifier (pkev->modifier);
01446 
01447   if (!gdk_keymap_get_entries_for_keyval (keymap, e->keyval, &keys, &n_keys))
01448     return IIIMF_STATUS_FAIL;
01449 
01450   if (n_keys)
01451     {
01452       e->hardware_keycode = keys[0].keycode;
01453       g_free (keys);
01454     }
01455 
01456   e->time = pkev->time_stamp;
01457 
01458   return IIIMF_STATUS_SUCCESS;
01459 }
01460 
01461 /* Local Variables: */
01462 /* c-file-style: "gnu" */
01463 /* End: */