Back to index

im-sdk  12.3.91
keymap.c
Go to the documentation of this file.
00001 /*
00002   Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004   Permission is hereby granted, free of charge, to any person obtaining a
00005   copy of this software and associated documentation files (the
00006   "Software"), to deal in the Software without restriction, including
00007   without limitation the rights to use, copy, modify, merge, publish,
00008   distribute, sublicense, and/or sell copies of the Software, and to
00009   permit persons to whom the Software is furnished to do so, subject to
00010   the following conditions: The above copyright notice and this
00011   permission notice shall be included in all copies or substantial
00012   portions of the Software.
00013 
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 THE OPEN GROUP OR SUN MICROSYSTEMS, INC. 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 
00025   Except as contained in this notice, the names of The Open Group and/or
00026   Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027   promote the sale, use or other dealings in this Software without prior
00028   written authorization from The Open Group and/or Sun Microsystems,
00029   Inc., as applicable.
00030 
00031 
00032   X Window System is a trademark of The Open Group
00033 
00034   OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035   logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036   Group. All other trademarks and registered trademarks mentioned herein
00037   are the property of their respective owners. No right, title or
00038   interest in or to any trademark, service mark, logo or trade name of
00039   Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include <stdio.h>
00043 #include <string.h>
00044 #include "SunIM.h"
00045 #include "unit_input.h"
00046 #include "codetable.h"
00047 #include "logf.h"
00048 
00049 /*********************** Key Mapping ***********************/
00050 
00051 /*  get the keys that IME will use */
00052 int map_keyevent_to_imekey(CodeTableStruct *hztbl, IMEKey key_event)
00053 {
00054   int keycode, keystatus, keychar;
00055 
00056   keycode = key_event->keyCode;
00057   keychar = key_event->keyChar;
00058   keystatus = key_event->modifier;
00059   log_f("keycode: 0x%x, keychar:0x%x, keystatus: 0x%x\n", keycode, keychar, keystatus);
00060   log_f("keycode: %d, keychar:%d, keystatus: %d\n", keycode, keychar, keystatus);
00061 
00062   /* normal status */
00063   if (keystatus  == 0) {
00064     /* Function Keys */
00065     if (keychar == 0) {
00066       log_f(" Function Key :%d\n", keycode);
00067       switch (keycode) {
00068       case IM_VK_ESCAPE:
00069        return(ESC_KEY);
00070 
00071       case IM_VK_BACK_SPACE:
00072        return(BACKSPACE_KEY);
00073 
00074       case IM_VK_ENTER:
00075        return(RETURN_KEY);
00076 
00077       case IM_VK_INSERT:
00078        return(INSERT_KEY);
00079 
00080       case IM_VK_DELETE:
00081        return(DELETE_KEY);
00082 
00083       case IM_VK_HOME:
00084        return(HOME_KEY);
00085 
00086       case IM_VK_END:
00087        return(END_KEY);
00088 
00089       case IM_VK_PAGE_UP:
00090        return(PAGEUP_KEY);
00091 
00092       case IM_VK_PAGE_DOWN:
00093        return(PAGEDOWN_KEY);
00094 
00095       case IM_VK_COMPOSE:
00096        return(IM_VK_COMPOSE);
00097 
00098       case IM_VK_DEAD_GRAVE:
00099       case IM_VK_DEAD_ACUTE:
00100       case IM_VK_DEAD_CIRCUMFLEX:
00101       case IM_VK_DEAD_TILDE:
00102       case IM_VK_DEAD_MACRON:
00103       case IM_VK_DEAD_BREVE:
00104       case IM_VK_DEAD_ABOVEDOT:
00105       case IM_VK_DEAD_DIAERESIS:
00106       case IM_VK_DEAD_ABOVERING:
00107       case IM_VK_DEAD_DOUBLEACUTE:
00108       case IM_VK_DEAD_CARON:
00109       case IM_VK_DEAD_CEDILLA:
00110       case IM_VK_DEAD_OGONEK:
00111       case IM_VK_DEAD_IOTA:
00112       case IM_VK_DEAD_VOICED_SOUND:
00113       case IM_VK_DEAD_SEMIVOICED_SOUND:
00114         return(keycode);
00115 
00116       }
00117       return(IME_NOT_USED_KEY);
00118     } else {
00119       /*  normal key  */
00120       log_f(" Normal Key :0x%x, %c\n", keychar, keychar);
00121       switch (keychar) {
00122       case IME_QUOTE:
00123        return IM_VK_DEAD_ACUTE;
00124       case IME_BACK_QUOTE:
00125        return IM_VK_DEAD_GRAVE;
00126       case IME_ASCIICIRCUM:
00127       case IME_GREATER:
00128         return IM_VK_DEAD_CIRCUMFLEX;
00129       case IME_QUOTEDBL:
00130         return IM_VK_DEAD_DIAERESIS;
00131       case IME_ASCIITILDE:
00132         return IM_VK_DEAD_TILDE;
00133       }
00134       return(keycode);
00135     }
00136   }
00137 
00138   /*  Shift status */
00139   if (keystatus == IM_SHIFT_MASK) {
00140     if (keychar == 0) {
00141       if ((keycode >= IM_VK_DEAD_GRAVE) && (keycode <= IM_VK_DEAD_SEMIVOICED_SOUND))
00142         return(keycode);
00143     } else if (keychar != 0) {
00144       /*  normal key  */
00145       log_f(" Ascii Key :0x%x, %c\n", keychar, keychar);
00146       switch (keychar) {
00147         case IME_QUOTE:
00148          return IM_VK_DEAD_ACUTE;
00149         case IME_BACK_QUOTE:
00150          return IM_VK_DEAD_GRAVE;
00151         case IME_ASCIICIRCUM:
00152         case IME_GREATER:
00153           return IM_VK_DEAD_CIRCUMFLEX;
00154         case IME_QUOTEDBL:
00155           return IM_VK_DEAD_DIAERESIS;
00156         case IME_ASCIITILDE:
00157           return IM_VK_DEAD_TILDE;
00158       }
00159       return(keychar);
00160     }else
00161       return(IME_NOT_USED_KEY);
00162   }
00163 
00164   /*  Ctrl status */
00165   if (keystatus == IM_CTRL_MASK) {
00166     if (keychar != 0) {
00167       /*  normal key  */
00168       unsigned char *keylist;
00169       int i, key_id;
00170 
00171       keychar = keycode | 0x80;
00172 
00173       key_id = -1;
00174       for (i = 0; i<MAX_FUNCTIONKEY_NUM; i++) {
00175        keylist = hztbl->functionkey[i].keylist;
00176        if (*keylist) {
00177          if (index(keylist, keychar)) {
00178            key_id = i;
00179            break;
00180          }
00181        }
00182       }
00183                      
00184       if (key_id != -1) {
00185        switch (key_id) {
00186        case PAGEUP_KEY_ID:
00187          return(PAGEUP_KEY);
00188        case PAGEDOWN_KEY_ID:
00189          return(PAGEDOWN_KEY);
00190        case BACKSPACE_KEY_ID:
00191          return(BACKSPACE_KEY);
00192        case CLEARALL_KEY_ID:
00193          return(ESC_KEY);
00194        }
00195       }
00196     }
00197   }
00198 
00199   if (keystatus & IM_ALT_GRAPH_MASK) {
00200     log_f("ALT_GRAPH_KEY is pressed \n");
00201     if (keycode != 0) 
00202       return(keycode);
00203   }
00204 
00205   if (keystatus == (IM_CTRL_MASK|IM_SHIFT_MASK)){
00206     log_f("COMPOSE KEY is pressed \n");
00207     if (keycode != 0) 
00208       return(keycode);
00209   }
00210 
00211   return (IME_NOT_USED_KEY);
00212 }
00213