Back to index

im-sdk  12.3.91
ctfilter.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 
00045 #include "codetable.h"
00046 #include "unit_input.h"
00047 #include "SunIM.h"
00048 #include "logf.h"
00049 #include "keymap.h"
00050 
00051 #define LOOKUP_CHOICE_NUM   7
00052 
00053 #define IME_Status  ime_buffer->return_status
00054 #define Input_Buf  ime_buffer->inputkey_buf
00055 #define Input_Len  ime_buffer->inputkey_len
00056 #define Preedit_Buf  ime_buffer->preedit_buf
00057 #define Preedit_Len  ime_buffer->preedit_len
00058 #define Preedit_CaretPos ime_buffer->preedit_caretpos
00059 #define Commit_Buf  ime_buffer->commit_buf
00060 #define Commit_Len  ime_buffer->commit_len
00061 #define Status_Buf  ime_buffer->status_buf
00062 #define Status_Len  ime_buffer->status_len
00063 #define Lookup_Buf  ime_buffer->lookup_buf
00064 #define Lookup_Num  ime_buffer->lookup_num
00065 #define Lookup_Pos  ime_buffer->cur_lookup_pos
00066 #define Candidates_Buf  ime_buffer->candidates_buf
00067 #define Additions_Buf  ime_buffer->additions_buf
00068 #define DeadKey_Flag  ime_buffer->hotkey_flag
00069 
00070 int Is_UsedCodes_Key(hztbl, key)
00071      CodeTableStruct *hztbl;
00072      int key;
00073 {
00074   if ( index(hztbl->UsedCodes, key) )
00075     return(1);
00076   else
00077     return(0);
00078 }
00079 
00080 int get_select_num(hztbl, key)
00081      CodeTableStruct *hztbl;
00082      int key;
00083 {
00084   int ret = -1;
00085   switch(hztbl->nSelectKeyMode)
00086     {
00087     case NUMBER_MODE:
00088       if (key >= '0' && key <= '9')
00089        ret = (key - '0' + 9) % 10;
00090       break;
00091 
00092     case LOWER_MODE:
00093       if (key >= 'a' && key <= 'a' + 10)
00094        ret = key - 'a';
00095       break;
00096 
00097     case UPPER_MODE:
00098       if (key >= 'A' && key <= 'A' + 10)
00099        ret = key - 'A';
00100       break;
00101     }
00102   return(ret);
00103 }
00104 
00105 int Is_Select_Key(hztbl, key)
00106      CodeTableStruct *hztbl;
00107      int key;
00108 {
00109   int ret = get_select_num(hztbl, key);
00110   if (ret == -1)
00111     return(0);
00112   else
00113     return(1);
00114 }
00115 
00116 int Is_Commit_Key(hztbl, key)
00117      CodeTableStruct *hztbl;
00118      int key;
00119 {
00120   if (key == SPACE_KEY || key == RETURN_KEY)
00121     return(1);
00122   else
00123     return(0);
00124 }
00125 
00126 int Is_BackSpace_Key(hztbl, key)
00127      CodeTableStruct *hztbl;
00128      int key;
00129 {
00130   unsigned char *keylist = hztbl->functionkey[BACKSPACE_KEY_ID].keylist;
00131 
00132   if (key == BACKSPACE_KEY || key == DELETE_KEY)
00133     return(1);
00134 
00135   if ( keylist[0] )
00136     {
00137       if ( index(keylist, key) )
00138        return(1);
00139     }
00140 
00141   return(0);
00142 }
00143 
00144 int Is_ClearAll_Key(hztbl, key)
00145      CodeTableStruct *hztbl;
00146      int key;
00147 {
00148   unsigned char *keylist = hztbl->functionkey[CLEARALL_KEY_ID].keylist;
00149 
00150   if (key == ESC_KEY)
00151     return(1);
00152 
00153   if ( keylist[0] )
00154     {
00155       if ( index(keylist, key) )
00156        return(1);
00157     }
00158   return(0);
00159 }
00160 
00161 int Is_NextPage_Key(hztbl, key)
00162      CodeTableStruct *hztbl;
00163      int key;
00164 {
00165   unsigned char *keylist = hztbl->functionkey[PAGEDOWN_KEY_ID].keylist;
00166 
00167   if (key == PAGEDOWN_KEY)
00168     return(1);
00169 
00170   if ( keylist[0] )
00171     {
00172       if ( index(keylist, key) )
00173        return(1);
00174     }
00175   return(0);
00176 }
00177 
00178 int Is_PrevPage_Key(hztbl, key)
00179      CodeTableStruct *hztbl;
00180      int key;
00181 {
00182   unsigned char *keylist = hztbl->functionkey[PAGEUP_KEY_ID].keylist;
00183 
00184   if (key == PAGEUP_KEY)
00185     return(1);
00186  
00187   if ( keylist[0] )
00188     {
00189       if ( index(keylist, key) )
00190        return(1);
00191     }
00192   return(0);
00193 }
00194 
00195 int get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, pos, max_lookup_num)
00196      CodeTableStruct *hztbl;
00197      IMEBufferRec *ime_buffer;
00198      int nHelpInfoMode;
00199      int pos;
00200      int max_lookup_num;
00201 {
00202   int i, lookup_num;
00203 
00204   log_f("get_lookup_result : Input_Len[%d]\n",Input_Len);
00205   lookup_num = codetable_search(hztbl, Input_Buf, Input_Len, Candidates_Buf, Additions_Buf, pos, max_lookup_num); 
00206   if (lookup_num > 0)
00207     {
00208       for (i=0; i<lookup_num; i++)
00209        {
00210          log_f("%d: %s %s\n", i, Candidates_Buf[i], Additions_Buf[i]);
00211          if (nHelpInfoMode)
00212            sprintf((char *)Lookup_Buf[i], "%s %s", Candidates_Buf[i], Additions_Buf[i]);
00213          else
00214            strcpy(Lookup_Buf[i], Candidates_Buf[i]);
00215        }
00216     }
00217   return(lookup_num);
00218 }
00219 
00220 int commit_candidate(ime_buffer, id)
00221      IMEBufferRec *ime_buffer;
00222      int id;
00223 {
00224   if (id >= Lookup_Num)
00225     return(-1);
00226  
00227   strcpy((char *)Commit_Buf, (char *)Candidates_Buf[id]);
00228   Commit_Len = strlen((char *)Commit_Buf);
00229   log_f("Inside commit_candidate, Commit_Buf <%s>\n",Commit_Buf);
00230   IME_Status = IME_COMMIT;
00231   Input_Len = 0;
00232   Input_Buf[Input_Len] = 0;
00233   Preedit_Len = 0;
00234   Lookup_Num = 0;
00235   Preedit_CaretPos = 0;
00236   IME_Status |= IME_PREEDIT_AREA | IME_LOOKUP_AREA;
00237   if (DeadKey_Flag == IME_HOTKEY_START)
00238     DeadKey_Flag = IME_HOTKEY_END;
00239   return(0);
00240 }
00241 
00242 int commit_candidate2(ime_buffer, key)
00243      IMEBufferRec *ime_buffer;
00244      int key;
00245 {
00246   Commit_Len = 0;
00247   Commit_Buf[Commit_Len] = key;
00248   Commit_Len++;
00249   Commit_Buf[Commit_Len] = '\0';
00250   Commit_Len = strlen((char *)Commit_Buf);
00251   IME_Status = IME_COMMIT;
00252   Input_Len = 0;
00253   Input_Buf[Input_Len] = 0;
00254   Preedit_Len = 0;
00255   Lookup_Num = 0;
00256   Preedit_CaretPos = 0;
00257   IME_Status |= IME_PREEDIT_AREA | IME_LOOKUP_AREA;
00258   if (DeadKey_Flag == IME_HOTKEY_START)
00259     DeadKey_Flag = IME_HOTKEY_END;
00260   return(0);
00261 }
00262 
00263 
00264 void warning_bell()
00265 {
00266 }
00267 
00268 /* return value:  IME_NOT_USED_KEY:  if IME not use this key, return this key to systerm directly */
00269 /*                IME_USED_KEY:      if IME has used this key */
00270 int codetable_filter(hztbl, key_event, ime_buffer)
00271      CodeTableStruct *hztbl;
00272      IMEKey key_event;
00273      IMEBufferRec *ime_buffer;
00274 {
00275   int     i, hznum;
00276   int     keycode, modifier, pos;
00277   int nLookup_Pos_Save = 0;
00278   int  bNeedCheckMore = 0;
00279   int is_dead_key = 0;
00280   int prev_Input_Len;
00281   static int static_prev_Input_Buf[MAX_INPUT_KEY_NUM];
00282   int *prev_Input_Buf = static_prev_Input_Buf;
00283  
00284   int  Max_Lookup_Num = LOOKUP_CHOICE_NUM;
00285   int  nKeyByKeyMode = hztbl->nKeyByKeyMode;
00286   int  nHelpInfoMode = hztbl->nHelpInfoMode;
00287   int  nAutoSelectMode = hztbl->nAutoSelectMode;
00288   int  nKeyPromptMode = hztbl->nKeyPromptMode;
00289  
00290   ime_buffer->encode = hztbl->Encode;
00291 
00292   IME_Status = 0;
00293 
00294   if((key_event->keyCode >= 65) && (key_event->keyCode <= 90)){
00295     if (key_event->keyCode == key_event->keyChar && key_event->modifier == 0)
00296       /* CAPS_LOCK is pressed */
00297         modifier = 1;
00298       else
00299         modifier = key_event->modifier;
00300   }else{
00301     modifier = 0;
00302     /* for dead key support */
00303     if ((key_event->keyCode >= 128) && (key_event->keyCode <= 143))
00304       is_dead_key = 1;
00305   }
00306 
00307   keycode = map_keyevent_to_imekey(hztbl, key_event);
00308   log_f("ctfilter: map_keyevent_to_imekey: return keycode:0x%x\n", keycode);
00309  
00310   if (keycode == IME_NOT_USED_KEY)
00311     return(IME_NOT_USED_KEY);
00312   else if (keycode == 0xb1){ /* PlusMinus */
00313     key_event->keyCode = keycode = IM_VK_MINUS;
00314   } else if ((keycode == 0xd1) || (keycode == 0xf1)) {
00315      is_dead_key = 1;
00316      modifier = key_event->modifier;
00317   /*
00318   } else if (keycode == 0x7e) {
00319      is_dead_key = 1;
00320      key_event->keyCode = keycode = IM_VK_DEAD_TILDE ;
00321   */
00322   } else if ((keycode == IM_VK_4) || (keycode == IM_VK_5)) {
00323      if (key_event->modifier & IM_ALT_GRAPH_MASK)
00324        modifier = key_event->modifier;
00325   } else if ((keycode >= IM_VK_DEAD_GRAVE) && (keycode <= IM_VK_DEAD_SEMIVOICED_SOUND)) {
00326      is_dead_key = 1;
00327      key_event->keyCode = keycode;
00328   }
00329  
00330   switch(hztbl->nSelectKeyMode) {
00331   case NUMBER_MODE:
00332     ime_buffer->lookup_label_type = NUMERIC_LABEL;
00333     break;
00334   case LOWER_MODE:
00335     ime_buffer->lookup_label_type = LOWER_LABEL;
00336     break;
00337   case UPPER_MODE:
00338     ime_buffer->lookup_label_type = UPPER_LABEL;
00339     break;
00340   default:
00341     ime_buffer->lookup_label_type = NUMERIC_LABEL;
00342   }
00343 
00344   if((Is_UsedCodes_Key(hztbl, keycode)) || (Is_Wildchar_Key(hztbl, keycode)) || (keycode == IM_VK_COMPOSE) || (is_dead_key)) { 
00345     prev_Input_Buf = Input_Buf;
00346     prev_Input_Len = Input_Len;
00347 
00348     if (Input_Len >= hztbl->MaxCodes) {
00349       warning_bell();
00350       return (IME_USED_KEY);
00351     }
00352 
00353     /* if not key by key, and is selectkey, and Lookup Mode */
00354     /* directly select */
00355 
00356     if(!nKeyByKeyMode && (Is_Select_Key(hztbl, key_event->keyChar)) && (Lookup_Num>0)) { 
00357 
00358       /* select from candidata */
00359       /* here should see whether there is enough candidates */
00360 
00361       int select_num;
00362       select_num = get_select_num(hztbl, keycode);
00363       if ((select_num >= 0) && (select_num < Lookup_Num)) {
00364         commit_candidate(ime_buffer, select_num);
00365       }else warning_bell();
00366 
00367       return(IME_USED_KEY);
00368     }
00369   
00370     Input_Buf[Input_Len] = key_event->keyCode;
00371     /*
00372     Input_Buf[Input_Len] = keycode;
00373     */
00374     Input_Len ++;
00375     Input_Buf[Input_Len] = modifier ;
00376     Input_Len ++;
00377     Input_Buf[Input_Len] = 0;
00378     log_f("ctfilter: Input_Len[%d]\n", Input_Len);
00379     for(i=0;i<Input_Len;i++) 
00380       log_f("Input_Buf [%d]\n",Input_Buf[i]);
00381 
00382     if ((key_event->keyCode == 84) && (key_event->modifier == 3) && (Input_Len == 2)){
00383       return(IME_USED_KEY);
00384     }
00385 
00386     Lookup_Num = 0;
00387     bNeedCheckMore = 0;
00388     /* if need display key by key */
00389     if (nKeyByKeyMode) {
00390       nLookup_Pos_Save = Lookup_Pos;
00391       Lookup_Pos = 0;
00392       Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num); 
00393       log_f("Lookup_Num [%d]\n",Lookup_Num);
00394       log_f("Preedit_Len [%d]\n",Preedit_Len);
00395       if (Lookup_Num == 1 && nAutoSelectMode) {
00396         commit_candidate(ime_buffer, 0);
00397         return(IME_USED_KEY);
00398       }
00399 
00400       if (Lookup_Num == 0) {
00401         /* if key is also a seleck key */
00402         if (Is_Select_Key(hztbl, key_event->keyChar))
00403           bNeedCheckMore = 1;
00404         else {
00405           Input_Buf = prev_Input_Buf;
00406           Input_Len = prev_Input_Len;
00407           if (Input_Len == 0) {
00408             commit_candidate2(ime_buffer, key_event->keyChar);
00409             return(IME_NOT_USED_KEY);
00410           }
00411           nLookup_Pos_Save = Lookup_Pos;
00412           Lookup_Pos = 0;
00413           Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num);
00414           commit_candidate(ime_buffer, 0);
00415           Input_Len = 0;
00416           Input_Buf[Input_Len] = key_event->keyCode;
00417           // Input_Buf[Input_Len] = keycode;
00418           Input_Len ++;
00419           Input_Buf[Input_Len] = modifier;
00420           Input_Len ++;
00421           Input_Buf[Input_Len] = '\0';
00422           Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num);
00423           if (Lookup_Num == 0) {
00424             Commit_Len = 0;
00425             Commit_Buf[Commit_Len] = '\0';
00426             Input_Len = 0;
00427             Input_Buf[Input_Len] = 0;
00428             Preedit_Len = 0;
00429             Preedit_Buf[Preedit_Len] = '\0';
00430             return(IME_USED_KEY);
00431           }
00432           Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num);
00433           if (bNeedCheckMore == 0) {
00434            size_t copy_length = strlen (Candidates_Buf[0]);
00435            copy_length = (copy_length > MAX_PREEDIT_CHAR_NUM ?
00436                          MAX_PREEDIT_CHAR_NUM : copy_length);
00437            strncpy (Preedit_Buf, Candidates_Buf[0], copy_length);
00438            Preedit_Buf[copy_length] = 0;
00439            Preedit_Len = strlen(Preedit_Buf);
00440             Preedit_CaretPos = Preedit_Len;
00441             return(IME_USED_KEY);
00442           }
00443         }
00444       }
00445       log_f("prev_Input_Len [%d], Input_Len [%d]\n",prev_Input_Len, Input_Len);
00446       if (prev_Input_Len != Input_Len) {
00447         /*
00448              It seems that the code below which caused a memory leak by
00449                Preedit_Buf = strdup(Candidates_Buf[0]);
00450         is not actually used.
00451 
00452         Anyway, we should avoid strdup here, as Preedit_Buf
00453         (ime_buffer->preedit_buf) is allocated in different place
00454         (ime_buffer_malloc). Let's do string copy.
00455         */
00456              size_t copy_length = strlen (Candidates_Buf[0]);
00457              copy_length = (copy_length > MAX_PREEDIT_CHAR_NUM ?
00458                            MAX_PREEDIT_CHAR_NUM : copy_length);
00459              strncpy (Preedit_Buf, Candidates_Buf[0], copy_length);
00460              Preedit_Buf[copy_length] = 0;
00461              Preedit_Len = strlen(Preedit_Buf);
00462              log_f("Preedit_Buf: [%s]\n",Preedit_Buf);
00463              log_f("strlen of Preedit_Buf: [%d]\n",strlen(Preedit_Buf));
00464       }
00465     } else {
00466       Preedit_Buf[Preedit_Len] = key_event->keyChar;
00467       Preedit_Len = strlen(Preedit_Buf);
00468       Preedit_Buf[Preedit_Len] = '\0';
00469       log_f("Preedit_Buf: [%s]\n",Preedit_Buf);
00470       log_f("strlen of Preedit_Buf: [%d]\n",strlen(Preedit_Buf));
00471     }
00472     Preedit_CaretPos = Preedit_Len;
00473     IME_Status = IME_PREEDIT_AREA;
00474 
00475     if (bNeedCheckMore == 0) {
00476       IME_Status |= IME_LOOKUP_AREA;
00477       return(IME_USED_KEY);
00478     }
00479   }
00480   
00481   if (bNeedCheckMore == 1) {
00482     /* restore the original status that before into this function */
00483     IME_Status = 0;
00484     Input_Len-=2;
00485     if (Input_Len) {
00486       Input_Buf[Input_Len] = 0;
00487       Lookup_Pos = nLookup_Pos_Save;
00488       Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos,Max_Lookup_Num);
00489     }
00490     commit_candidate2(ime_buffer, key_event->keyChar);
00491     return(IME_NOT_USED_KEY);
00492   }
00493 
00494   if (Is_Select_Key(hztbl, keycode)) { /* select from candidata */
00495     /* here should see whether there is enough candidates */
00496     int select_num;
00497 
00498     /*  if no inputted key, directly return this key */
00499     if ((Input_Len==0) || (Lookup_Num==0)) return(IME_NOT_USED_KEY);
00500     log_f("Select Key, keycode:%c, Lookup_Num:%d\n", keycode, Lookup_Num);
00501     select_num = get_select_num(hztbl, keycode);
00502     log_f("select_num :%d\n",select_num);
00503     if (Lookup_Num>0 && (select_num >= 0) && (select_num < Lookup_Num)) {
00504       commit_candidate(ime_buffer, select_num);
00505     } else warning_bell();
00506 
00507     return(IME_USED_KEY);
00508   }
00509 
00510   if (Is_ClearAll_Key(hztbl, key_event->keyChar)) { 
00511     /* Esc , clear preedit, lookup choice pointer, and so on */
00512     log_f("ESC_KEY\n");
00513     /*  if no inputted key, directly return this key */
00514     if (Input_Len==0) return(IME_NOT_USED_KEY);
00515   
00516     Input_Len = 0;
00517     Preedit_Len = 0;
00518     Lookup_Num = 0;
00519     Preedit_CaretPos = 0;
00520     IME_Status = IME_PREEDIT_AREA | IME_LOOKUP_AREA;
00521     return (IME_USED_KEY);
00522   }
00523 
00524   if (Is_BackSpace_Key(hztbl, keycode)) { /* Back Space & Delete */
00525     log_f("BACKSPACE_KEY\n");
00526     /*  if no inputted key, directly return this key */
00527     if ((Input_Len==0) || (Preedit_Len==0) || (Lookup_Num==0)) return(IME_NOT_USED_KEY);
00528   
00529     /* Delete characters in pre-edit region */
00530     Input_Len -= 2;
00531     if (nKeyPromptMode) {
00532       Preedit_Len = 0;
00533       Preedit_Buf[Preedit_Len] = '\0';
00534     }else{
00535       Preedit_Len = 0;
00536       Preedit_Buf[Preedit_Len] = '\0';
00537     }
00538 
00539     Input_Buf[Input_Len] = 0;
00540     Preedit_CaretPos = Preedit_Len;
00541     IME_Status = IME_PREEDIT_AREA;
00542 
00543     Lookup_Num = 0;
00544   
00545     /* if still left some keys, and need display key by key, then search. */
00546     /* else undisplay the candidate window */
00547     if ((Input_Len > 0) && nKeyByKeyMode) {
00548       Lookup_Pos = 0;
00549       Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num); 
00550     }
00551 
00552     IME_Status |= IME_LOOKUP_AREA;
00553     return(IME_USED_KEY);
00554   }
00555 
00556   if (Is_NextPage_Key(hztbl, keycode)) { /* select from candidata */
00557     /*  if no inputted key, directly return this key */
00558     if (Input_Len==0) return(IME_NOT_USED_KEY);
00559 
00560     /* if any preedit key and not in Lookup status */
00561     log_f("NextPage:  Lookup_Num:%d\n", Lookup_Num);
00562     if (Lookup_Num==0) return(IME_USED_KEY);
00563 
00564     pos = Lookup_Pos + Max_Lookup_Num;
00565     log_f("NextPage: pos:%d\n", pos);
00566     hznum = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, pos, Max_Lookup_Num); 
00567     if (hznum > 0) {
00568       Lookup_Num = hznum;
00569       Lookup_Pos = pos;
00570       IME_Status = IME_LOOKUP_AREA;
00571     }else warning_bell();
00572     
00573     return(IME_USED_KEY);
00574 
00575   }
00576 
00577   if (Is_PrevPage_Key(hztbl, keycode)) { /* select from candidata */
00578 
00579     /*  if no inputted key, directly return this key */
00580     if (Input_Len==0) return(IME_NOT_USED_KEY);
00581     log_f("PrevPage:  Lookup_Num:%d\n", Lookup_Num);
00582     /* if any preedit key and not in Lookup status */
00583     if (Lookup_Num==0) return(IME_USED_KEY);
00584   
00585     /* if in beginning pos */
00586     if (Lookup_Pos<=0) {
00587       warning_bell();
00588       return(IME_USED_KEY);
00589     }
00590 
00591     pos = Lookup_Pos - Max_Lookup_Num;
00592     hznum = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, pos, Max_Lookup_Num); 
00593     log_f("hznum :%d\n", hznum);
00594     if (hznum > 0) {
00595       Lookup_Num = hznum;
00596       Lookup_Pos = pos;
00597       IME_Status = IME_LOOKUP_AREA;
00598     }else warning_bell();
00599 
00600     return(IME_USED_KEY);
00601   }
00602 
00603   if (Is_Commit_Key(hztbl, keycode)) { /* space or return key */
00604     log_f("Space or Return key, Commit Key ===\n");
00605     /* if no input keys and no candidates */
00606     if (Input_Len==0 && Lookup_Num==0)
00607       return(IME_NOT_USED_KEY);
00608 
00609     /* if any candidates, then commit the first candidate */
00610     if (Lookup_Num > 0) {
00611       log_f("Commit Key , Commit the first candidate===\n");
00612       commit_candidate(ime_buffer, 0);
00613       return(IME_USED_KEY);
00614     }
00615 
00616     /* if any keys and key is Space key and mode is not keybykey */
00617     /* then search and display the candidates */
00618     if (key_event->keyChar == SPACE_KEY && !nKeyByKeyMode) {
00619       Lookup_Pos = 0;
00620       Lookup_Num = get_lookup_result(hztbl, ime_buffer, nHelpInfoMode, Lookup_Pos, Max_Lookup_Num); 
00621       log_f("Lookup_Num:%d\n", Lookup_Num);
00622       if (Lookup_Num == 1 && nAutoSelectMode) {
00623         commit_candidate(ime_buffer, 0);
00624         return(IME_USED_KEY);
00625       }
00626 
00627       if (Lookup_Num == 0)
00628         warning_bell();
00629 
00630       IME_Status = IME_LOOKUP_AREA;
00631       return(IME_USED_KEY);
00632     }
00633 
00634     return(IME_USED_KEY);
00635   }
00636 
00637   /* for unnormal keys */
00638   log_f(" unnormal keycode:%d\n", keycode);
00639   if (Input_Len==0) return(IME_NOT_USED_KEY);
00640   else return(IME_USED_KEY);
00641 }
00642