Back to index

im-sdk  12.3.91
newpinyin_filter.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include "newpinyin_im.h"
00003 #include "PYIM.h"
00004 
00005 #define LOOKUP_CHOICE_NUM   6
00006 
00007 #define IME_Status          ime_buffer->return_status
00008 #define Input_Buf           ime_buffer->input_buf
00009 #define Input_Len           ime_buffer->input_len
00010 #define Preedit_Buf         ime_buffer->preedit_buf
00011 #define Preedit_Len         ime_buffer->preedit_len
00012 #define Preedit_CaretPos    ime_buffer->preedit_caretpos
00013 #define Commit_Buf          ime_buffer->commit_buf
00014 #define Commit_Len          ime_buffer->commit_len
00015 #define Status_Buf          ime_buffer->status_buf
00016 #define Status_Len          ime_buffer->status_len
00017 #define Lookups_Num         ime_buffer->num_candidates
00018 #define Lookup_Pos          ime_buffer->cur_lookup_pos
00019 #define Candidates          ime_buffer->candidates
00020 #define Comments            ime_buffer->comments
00021 #define Lookups                    ime_buffer->lookups
00022 
00023 int convert_to_imebuffer(ImToXSun* pIeh, ImeBufferRec *ime_buffer);
00024 
00025 int newpy_open(JINT nSesID)
00026 {
00027        ImToXSun *pIeh;
00028 
00029        pIeh = (ImToXSun *)NewPY_open(nSesID);
00030        if (pIeh == NULL)
00031               return (-1);
00032 
00033        return(0);
00034 }
00035 
00036 int newpy_close(JINT nSesID)
00037 {
00038        NewPY_close(nSesID);
00039        return(0);
00040 }
00041 
00042 int newpy_filter(int keycode, int keychar, int keystatus, ImeBufferRec *ime_buffer)
00043 {
00044        ImToXSun *pIeh;
00045        JINT ret;
00046 
00047        JINT nSesID = ime_buffer->session_id;
00048        pIeh = (ImToXSun *)NewPY_trans (nSesID, (JINT)keycode, (JINT)keychar, (JINT)keystatus);
00049 
00050        if (pIeh == NULL)
00051               return(IME_UNUSED_KEY);
00052               
00053        ret = convert_to_imebuffer(pIeh, ime_buffer);
00054        return (ret);
00055 }
00056 
00057 /*
00058 **  Convert from Struct ImToXSun to Struct ImToXSunChar
00059 */
00060 int convert_to_imebuffer(ImToXSun* pIeh, ImeBufferRec *ime_buffer)
00061 {
00062        JINT   i, j, nHz;
00063        JINT   nNumDollar;   /* Number of Numsign and Dollar before Caret */
00064        static ImToXSunChar  iehc;
00065        
00066        IME_Status = 0;
00067 
00068        DEBUG_printf("nType:%d\n", pIeh->nType);
00069        DEBUG_printf("IMXSUN_TYPE_BOUNCEKEY:%d\n", IMXSUN_TYPE_BOUNCEKEY);
00070        if (pIeh->nType == IMXSUN_TYPE_BOUNCEKEY)
00071               return(IME_UNUSED_KEY);
00072 
00073 /*
00074        ime_buffer->lookup_label_type = NUMERIC_LABEL;
00075 */
00076        Lookups_Num = pIeh->nChoiceNum;
00077        IME_Status |= IME_LOOKUP_AREA;
00078 
00079        /* One Hanzi is  2 Bytes */
00080        nHz = 0;
00081        for (i = 0; (pIeh->pwPreedit[i] >= 0x8140); i++)
00082               nHz++;
00083        
00084 /*
00085        iehc.nType        = pIeh->nType;
00086        iehc.nErrorCode   = pIeh->nErrorCode;
00087        iehc.nChoiceNum   = pIeh->nChoiceNum;
00088        iehc.nLabelType   = LABELTYPE_1234567;
00089 */
00090        
00091        nNumDollar = 0;
00092        j = 0;
00093        for (i = 0; pIeh->pwPreedit[i] != 0x0000; i++)
00094        {
00095               if ((pIeh->pwPreedit[i] != (JWORD)'#') && (pIeh->pwPreedit[i] != (JWORD)'$'))
00096               {
00097                      pIeh->pwPreedit[j++] = pIeh->pwPreedit[i];
00098               }
00099               else  /* '#' and '$' before pIeh->nCaretPos should be counted!! */
00100               {
00101                      if (i < pIeh->nCaretPos)
00102                             nNumDollar ++;
00103               }
00104        }
00105        for (; j < 128; j++)
00106               pIeh->pwPreedit[j++] = 0x0000;
00107        
00108 /*
00109        iehc.nCaretPos    = pIeh->nCaretPos + nHz - nNumDollar;
00110 */
00111        
00112        Jword2Uchar(pIeh->pwPreedit, iehc.szPreedit, 128);
00113        Jword2Uchar(pIeh->pwCommit,  iehc.szCommit,  256);
00114        Jword2Uchar(pIeh->pwStatus,  iehc.szStatus,   16);
00115 
00116 /*
00117        Preedit_CaretPos = pIeh->nCaretPos + nHz - nNumDollar;
00118 
00119        DEBUG_printf("pIeh->nCaretPos:%d, nHz:%d, nNumDollar:%d\n", pIeh->nCaretPos, nHz, nNumDollar);
00120        DEBUG_printf("Preedit_CaretPos:%d\n", Preedit_CaretPos);
00121 */
00122        Preedit_CaretPos = pIeh->nCaretPos;
00123 
00124        strncpy((char *)Preedit_Buf, (char *)(iehc.szPreedit), MAX_PREEDIT_CHAR_NUM);
00125        strncpy((char *)Commit_Buf,  (char *)(iehc.szCommit),  MAX_COMMIT_CHAR_NUM);
00126        
00127        Preedit_Len = strlen((char *)Preedit_Buf);
00128        IME_Status |= IME_PREEDIT_AREA;
00129 
00130        Commit_Len  = strlen((char *)Commit_Buf);
00131        IME_Status |= IME_COMMIT;
00132 
00133 /*
00134        DEBUG_printf("Lookups_Num:%d\n", Lookups_Num);
00135        DEBUG_printf("Preedit:%s\n", Preedit_Buf);
00136        DEBUG_printf("Commit:%s\n",  Commit_Buf);
00137        DEBUG_printf("Preedit:%s\n", iehc.szPreedit);
00138        DEBUG_printf("Commit:%s\n", iehc.szCommit);
00139        DEBUG_printf("Status:%s\n", iehc.szStatus);
00140 */
00141 
00142        DEBUG_printf("Newpy return: commit_len: %d\n", strlen((char *)iehc.szCommit));
00143        DEBUG_printf("Commit:%s\n", (char *)iehc.szCommit);
00144        DEBUG_printf("Commit:%s\n",  Commit_Buf);
00145        for(i = 0; i < 8; i++) {
00146               Jword2Uchar(pIeh->pwLookupChoice[i], iehc.szLookupChoice[i],  24);
00147               strncpy((char *)Lookups[i], (char *)(iehc.szLookupChoice[i]), 24);
00148               DEBUG_printf("Lookups[%d]:%s\n", i, Lookups[i]);
00149 
00150        }
00151        
00152        return(IME_OK);
00153 }
00154