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 "SunIM.h"
00044 #include "unit_input.h"
00045 #include "codetable.h"
00046 
00047 /*********************** Key Mapping ***********************/
00048 
00049 /*  get the keys that IME will use */
00050 int map_keyevent_to_imekey(CodeTableStruct *hztbl, IMEKey key_event)
00051 {
00052   int keycode, keystatus, keychar;
00053 
00054   keycode = key_event->keyCode;
00055   keychar = key_event->keyChar;
00056   keystatus = key_event->modifier;
00057 
00058   log_f("keycode: 0x%x, keychar:0x%x, keystatus: 0x%x\n", keycode, keychar, keystatus);
00059   /* normal status */
00060   if (keystatus  == 0) {
00061     /* Function Keys */
00062     if (keychar == 0) {
00063       log_f(" Function Key :%d\n", keycode);
00064       switch (keycode) {
00065       case IM_VK_ESCAPE:
00066        return(ESC_KEY);
00067 
00068       case IM_VK_BACK_SPACE:
00069        return(BACKSPACE_KEY);
00070 
00071       case IM_VK_ENTER:
00072        return(RETURN_KEY);
00073 
00074       case IM_VK_INSERT:
00075        return(INSERT_KEY);
00076 
00077       case IM_VK_DELETE:
00078        return(DELETE_KEY);
00079 
00080       case IM_VK_HOME:
00081        return(HOME_KEY);
00082 
00083       case IM_VK_END:
00084        return(END_KEY);
00085 
00086       case IM_VK_PAGE_UP:
00087        return(PAGEUP_KEY);
00088 
00089       case IM_VK_PAGE_DOWN:
00090        return(PAGEDOWN_KEY);
00091 
00092       }
00093       return(IME_NOT_USED_KEY);
00094     } else {
00095       /*  normal key  */
00096       log_f(" Normal Key :0x%x, %c\n", keychar, keychar);
00097       return(keychar);
00098     }
00099   }
00100 
00101   /*  Shift status */
00102   if (keystatus == IM_SHIFT_MASK) {
00103     if (keychar != 0) {
00104       /*  normal key  */
00105       log_f(" Ascii Key :0x%x, %c\n", keychar, keychar);
00106       return(keychar);
00107     }
00108   }
00109 
00110   /*  Ctrl status */
00111   if (keystatus == IM_CTRL_MASK) {
00112     if (keychar != 0) {
00113       /*  normal key  */
00114       unsigned char *keylist;
00115       int i, key_id;
00116 
00117       keychar = keycode | 0x80;
00118 
00119       key_id = -1;
00120       for (i = 0; i<MAX_FUNCTIONKEY_NUM; i++) {
00121        keylist = hztbl->functionkey[i].keylist;
00122        if (*keylist) {
00123          if (index(keylist, keychar)) {
00124            key_id = i;
00125            break;
00126          }
00127        }
00128       }
00129                      
00130       if (key_id != -1) {
00131        switch (key_id) {
00132        case PAGEUP_KEY_ID:
00133          return(PAGEUP_KEY);
00134        case PAGEDOWN_KEY_ID:
00135          return(PAGEDOWN_KEY);
00136        case BACKSPACE_KEY_ID:
00137          return(BACKSPACE_KEY);
00138        case CLEARALL_KEY_ID:
00139          return(ESC_KEY);
00140        }
00141       }
00142     }
00143   }
00144 
00145   return (IME_NOT_USED_KEY);
00146 }
00147