Back to index

im-sdk  12.3.91
NewPYLE.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 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 "NewPY.h"
00043 #include "PYIM.h"
00044 #include <assert.h>
00045 
00046 SesGuiElement* pSge[512];
00047 SesGuiElement* pCurSge;
00048 
00049 ImToXSunChar*  IM_trans(JINT nSesID, JINT nXKey, JINT nAsciiKey, JINT nSpecKey);
00050 ImToXSunChar*  ConvImToXSun(ImToXSun* pIeh);
00051 ImToXSun*      ImTrans(JINT nSesID, JINT* pKsThis, JINT nSpecKeyState);
00052 VOID    JwordInfo(JWORD* pwJwordArray, JINT nMaxLen);
00053 VOID    Jword2Uchar(JWORD* pwJword, UCHAR* szUch, JINT nMaxLen);
00054 JINT    JwordValidLen(JWORD* pwJwordArray, JINT nMaxLen);
00055 VOID    ProcFreq(SesGuiElement* pSge);
00056 VOID    ProcUdCizu(SesGuiElement* pSge);
00057 VOID    IM_close(JINT nSesID);
00058 
00059 VOID    InitSge(SesGuiElement* pSgeStruct);
00060 VOID    IehReturn(ImToXSun* pieh, JINT nCaseFlag);
00061 JINT    IsQuitKeysym(JINT *pks);
00062 JINT    IsQpSpSwitchKeysym(JINT *pks);
00063 JINT    IsWantedKeysym(JINT *pks);
00064 JINT    IsPyKeysym(JINT *pks);
00065 JINT    IsPageKeysym(JINT *pks);
00066 JINT    IsSelectKeysym(JINT *pks);
00067 JWORD   GetQuanjiaoSymbol(JINT *pks, JINT IsChnPunc, JINT IsChnAscii);
00068 
00069 VOID    ProcAllKeysym(JINT* pKsThis, SesGuiElement* pSge);
00070 VOID    DrawImToXSun(ImToXSun* pIeh, SesGuiElement* pSge);
00071 VOID    GetIehFromSge(ImToXSun* pIeh, SesGuiElement* pSge);
00072 VOID    GetLookupChoiceFromCandi(ImToXSun* pIeh, JWORD* pwCandi);
00073 
00074 /* CikuOper.c */
00075 JINT    GetCikuData(CHAR* szSysCikuName);
00076 JINT    WriteCikuData(CHAR* szSysCikuName, JINT nTimeStamp);
00077 VOID    FreePckAll();
00078 VOID    InitStructSc(SysCandi* psc);
00079 VOID    AdjustFreq(JWORD* pwHz2244, JINT nLenThis);
00080 
00081 /* UdCikuOper.c */
00082 VOID   InitStructUc(UdcCandi* puc);
00083 JINT    ReadUdcData(CHAR* szUdcName);
00084 JINT    WriteUdcData(CHAR* szUdcName, JINT nTimeStamp);
00085 JINT    AddUdc(JWORD* pwHz2244, JINT nLen);
00086 JINT    DelUdc(JWORD* pwHz2244, JINT nLen);
00087 JINT    PureUdc(VOID);
00088 VOID    FreeUdcData();
00089 
00090 VOID    ProcSymbIMKey(SesGuiElement* pSge, JINT nSymbType, JINT *pNextKeysym, ImToXSun *pIeh);
00091 
00092 extern  BYTE      *pCkAll;      /* Defined in file "CikuOper.c" */
00093 extern  UdcMemAll  udcAll;      /* Defined in file "UdCikuOper.c" */
00094 
00095 #define PUNCTUATION_STATUS    1
00096 #define SOFTKEYBOARD_LAYOUT   2
00097 #define GBKSWITCH_STATUS      3
00098 
00099 #define SKB_QUANPIN           0
00100 #define SKB_SPZRM             1
00101 #define SKB_SPCSTAR           2
00102 #define SKB_SPABC             3
00103 
00104 #define  SKB_SYMBSCIENT     0
00105 #define  SKB_SERIESONE      1
00106 #define  SKB_SERIESTWO      2
00107 #define  SKB_SERIESTHREE    3
00108 #define  SKB_SERIESFOUR     4
00109 #define  SKB_GREECE         5
00110 #define  SKB_RUSSIAN        6
00111 #define  SKB_PYSYM          7
00112 #define  SKB_JAPPIN         8
00113 #define  SKB_JAPPIAN        9
00114 #define  SKB_TABSYMB        10
00115 #define  SKB_GBKEXTSYM1     11
00116 #define  SKB_GBKEXTSYM2     12
00117 #define  SKB_QP_MODE        13
00118 #define  SKB_SP_MODE        14
00119 #define  SKB_FULLWID_ENG    15
00120 
00121 #define  PUNCT_CHINESE      0
00122 #define  PUNCT_ENGLISH      1
00123 
00124 CHAR *    pszUserName = NULL;
00125 CHAR *   pszEnginePath = NULL;
00126 
00127 ImToXSunChar* IM_setAuxValue(JINT nSesID, JINT nWhichBmp, JINT nBmpValue)
00128 {
00129        ImToXSunChar*   pImxsun;
00130        
00131        if (pSge[nSesID] == NULL)
00132        {
00133               IM_trans (nSesID, (JINT)IMXK_Escape, (JINT)IMXK_Escape, 0);
00134        }
00135        
00136        if ((nWhichBmp == PUNCTUATION_STATUS) && (nBmpValue >= 0) && (nBmpValue <= 1)) {
00137               if (pSge[nSesID]->nPunctMode == nBmpValue) return NULL;
00138               pSge[nSesID]->nPunctMode  = nBmpValue;
00139        }
00140        else if ((nWhichBmp == GBKSWITCH_STATUS) && (nBmpValue >= 0) && (nBmpValue <= 1)) {
00141               if (pSge[nSesID]->nGBKMode == nBmpValue) return NULL;
00142               pSge[nSesID]->nGBKMode =  nBmpValue;
00143 
00144               if(pSge[nSesID]->nKeyLayMode >= SKB_QP_MODE) InitSge(pSge[nSesID]);
00145 
00146        }
00147        else if ((nWhichBmp == SOFTKEYBOARD_LAYOUT) && (nBmpValue >= 0) && (nBmpValue <= 15))
00148        {
00149               if (pSge[nSesID]->nKeyLayMode == nBmpValue) return NULL;
00150 
00151               if ((nBmpValue == SKB_QP_MODE) || (nBmpValue == SKB_SP_MODE) || (nBmpValue == SKB_FULLWID_ENG))
00152               {
00153                   if(nBmpValue == SKB_SP_MODE) {
00154                      pSge[nSesID]->nPinyinType = 0; 
00155                   }         
00156                   else {
00157                      pSge[nSesID]->nPinyinType = KEYLAYMODE_NEWPY;
00158                   }
00159                   InitSge(pSge[nSesID]);
00160               }
00161               pSge[nSesID]->nKeyLayMode = nBmpValue;
00162        }
00163        else printf("Invalid nWhichBmp[%d] or nBmpValue[%d]\n", nWhichBmp, nBmpValue);
00164        
00165        pImxsun = IM_trans (nSesID, (JINT)IMXK_Clear, (JINT)IMXK_Clear, 0);
00166        return (pImxsun);
00167 }
00168 
00169 
00170 VOID IM_close (JINT nSesID)
00171 {
00172        IM_trans (nSesID, (JINT)IMXK_QUIT_PYIM, (JINT)IMXK_QUIT_PYIM, 0);
00173 }
00174 
00175 VOID IM_init (JINT nSesID)
00176 {
00177        IM_trans (nSesID, (JINT)IMXK_Escape, (JINT)IMXK_Escape, 0);
00178 }
00179 
00180 VOID IM_setValue(int arg, void * value)
00181 {
00182     if (arg == USER_NAME) {
00183        pszUserName = (CHAR*) strdup(value);
00184 #ifdef DEBUG
00185        printf("pszUserName = %s\n",pszUserName);
00186 #endif
00187     } else if(arg == ENGINE_PATH) {
00188        pszEnginePath = (CHAR*) strdup(value);
00189 #ifdef DEBUG
00190        printf("pszEnginePath = %s\n",pszEnginePath);
00191 #endif
00192     }
00193 }
00194 
00195 ImToXSunChar* IM_trans(JINT nSesID, JINT nXKey, JINT nAsciiKey, JINT nSpecKeyState)
00196 {
00197        JINT    i;
00198        JINT    ksThis[5];
00199        JINT    nSpecKey;
00200        
00201        for(i = 0; i < 5; i++)
00202               ksThis[i] = 0x00000000;
00203        if ((nAsciiKey >= 0x20) && (nAsciiKey <= 0x7E))
00204               ksThis[0] = nAsciiKey;
00205        else
00206               ksThis[0] = nXKey;
00207        
00208        /* PATCH for ^p and ^n: Scott Ma: 98-04-28 */
00209        nSpecKey = nSpecKeyState;
00210        if ((nAsciiKey == 0x000e) && (nSpecKeyState == 4))
00211        {
00212               ksThis[0] = (JINT)IMXK_MOUSENEXT;
00213               nSpecKey  = 0;
00214        }
00215        if ((nAsciiKey == 0x0010) && (nSpecKeyState == 4))
00216        {
00217               ksThis[0] = (JINT)IMXK_MOUSEPREV;
00218               nSpecKey  = 0;
00219        }
00220        
00221        bShiftIsPressed  = (JSHORT)((nSpecKey & SPEC_KEY_SHIFT)    / SPEC_KEY_SHIFT);
00222        bCapsIsPressed   = (JSHORT)((nSpecKey & SPEC_KEY_CAPSLOCK) / SPEC_KEY_CAPSLOCK); /* ??? Not Certain. MXL */
00223        bCapsIsPressed   = (JSHORT)0;
00224        bCtrlIsPressed   = (JSHORT)((nSpecKey & SPEC_KEY_CONTROL)  / SPEC_KEY_CONTROL);
00225        bAltIsPressed    = (JSHORT)((nSpecKey & SPEC_KEY_ALT)      / SPEC_KEY_ALT);
00226        bAltGrIsPressed  = (JSHORT)((nSpecKey & SPEC_KEY_ALTGRAPH) / SPEC_KEY_ALTGRAPH);
00227        bCompIsPressed   = (JSHORT)((nSpecKey & SPEC_KEY_COMPOSE)  / SPEC_KEY_COMPOSE);  /* ??? Not Certain. MXL */
00228        bCompIsPressed   = (JSHORT)0;
00229        bMetaIsPressed   = (JSHORT)((nSpecKey & SPEC_KEY_DIAMOND)  / SPEC_KEY_DIAMOND);
00230 
00231        return ( ConvImToXSun( ImTrans(nSesID, ksThis, nSpecKey) ) );
00232 }
00233 
00234 
00235 ImToXSun* ImTrans(JINT nSesID, JINT* pKsThis, JINT nSpecKeyState)
00236 {
00237        JINT    i, nLen, nTmpRes, nTmp1, nTmp2;
00238        static  ImToXSun ieh;
00239        static  JINT     nActiveSesNum = 0;
00240        static  JINT     pnSesIDArray[512];
00241        CHAR    pszHome[128];
00242        CHAR    szPath[128];
00243        
00244        JWORD   wPuncAscii;      /* For Chinese Punctation and Alpha Char */
00245        JINT    FlagChnPunc, FlagChnAscii;
00246 
00247        /* 
00248        ** 在正式版本中, 应该先读szSysCikuBak & szUdcCikuBak, 
00249        ** 如果失败, 再读szSysCiku & szUdcCiku!!      MXL 97-12-14
00250        */
00251        if (pCkAll == NULL)
00252        {
00253               memset(szPath, '\0', 128);
00254 
00255               strcpy(szPath, pszEnginePath);
00256               nTmpRes = GetCikuData(szPath);
00257 
00258               if(nTmpRes == FALSE) {
00259                      memset(szPath, '\0', 128);
00260                      strcpy(szPath, pszEnginePath);
00261 #ifndef WIN32
00262                      strcat(szPath, szSysCiku_Gbk);
00263 #else
00264                      strcat(szPath, szSysCiku_Gbk_WIN32);
00265 #endif
00266                      nTmpRes = GetCikuData(szPath);
00267               }
00268               if (nTmpRes == FALSE)
00269               {
00270                      fprintf (stderr, "IME Error: Failed to Open System Ciku < PyCiku.dat >\n");
00271                      return NULL;
00272               }
00273 
00274               /* Read in UdCiku.dat Data */
00275               memset (szPath, '\0', 128);
00276 
00277               strcpy(szPath, pszEnginePath);
00278               nTmpRes = ReadUdcData(szPath);
00279 
00280               if(nTmpRes == FALSE) {
00281                      memset(szPath, '\0', 128);
00282                      strcpy(szPath, pszEnginePath);
00283 #ifndef WIN32
00284                      strcat(szPath, szUdcCiku_Gbk);
00285 #else
00286                      strcat(szPath, szUdcCiku_Gbk_WIN32);
00287 #endif
00288                      nTmpRes = ReadUdcData(szPath);
00289               }
00290               if (nTmpRes == FALSE) {
00291                      fprintf (stderr, "IME Error: Failed to Open User Defined Ciku < UdCiku.dat >\n");
00292                      return NULL;
00293               }
00294        }
00295 
00296        if (nActiveSesNum == 0)
00297        {
00298               for (i = 0; i < MAX_SES_NUM; i++)
00299                      pnSesIDArray[i] = 0x0000;
00300        }
00301        
00302        if (pnSesIDArray[nSesID] == 0x0000)       /* New Session */
00303               nActiveSesNum++;
00304        
00305        if (nActiveSesNum > MAX_SES_NUM)   /* Return: Too many sessions */
00306        {
00307               nActiveSesNum--;
00308               IehReturn(&ieh, TOO_MANY_SESSION);
00309               return (&ieh);
00310        }
00311 
00312        if (pnSesIDArray[nSesID] == 0x0000)       /* New Session */
00313        {
00314               pnSesIDArray[nSesID] = (0xF000 + nSesID);
00315               pSge[nSesID] = (SesGuiElement*) malloc(sizeof(SesGuiElement));
00316               if (pSge[nSesID] == NULL)
00317               {
00318                      IehReturn(&ieh, FAILED_ALLOC_MEM);    /* Failed to Alloc Memory */
00319                      pnSesIDArray[nSesID] = 0x0000;
00320                      nActiveSesNum--;
00321                      return (&ieh);
00322               }
00323               pSge[nSesID]->scSysCandi.pwMhCandi  = NULL;
00324               pSge[nSesID]->scSysCandi.pwDhCandi  = NULL;
00325               pSge[nSesID]->scSysCandi.pwShCandi  = NULL;
00326               pSge[nSesID]->scSysCandi.pwGbkCandi = NULL;
00327               pSge[nSesID]->ucUdcCandi.pwUdc28Candi = NULL;
00328               InitSge(pSge[nSesID]);
00329        }
00330        pCurSge = pSge[nSesID];
00331        
00332        if (IsQuitKeysym(pKsThis))
00333        {
00334               /* Free Space Occupied by struct SysCandi */
00335               free (pSge[nSesID]->scSysCandi.pwMhCandi);
00336               free (pSge[nSesID]->scSysCandi.pwDhCandi);
00337               free (pSge[nSesID]->scSysCandi.pwShCandi);
00338               free (pSge[nSesID]->scSysCandi.pwGbkCandi);
00339               free (pSge[nSesID]->ucUdcCandi.pwUdc28Candi);
00340 
00341               pSge[nSesID]->scSysCandi.pwMhCandi  = NULL;
00342               pSge[nSesID]->scSysCandi.pwDhCandi  = NULL;
00343               pSge[nSesID]->scSysCandi.pwShCandi  = NULL;
00344               pSge[nSesID]->scSysCandi.pwGbkCandi = NULL;
00345               pSge[nSesID]->ucUdcCandi.pwUdc28Candi = NULL;
00346               
00347               free (pSge[nSesID]);
00348               pSge[nSesID] = NULL;
00349               pnSesIDArray[nSesID] = 0x0000;
00350               nActiveSesNum--;
00351               IehReturn(&ieh, QUIT_THIS_IM);     /* Application Quit or Switch to other IM */
00352               
00353               /*
00354               **  If nActiveSesNum == 0, means No any Application is still using this IM, SO,
00355               **  Must Write these Adjuested Ciku Data back to File!!!!
00356               */
00357               if(nActiveSesNum == 0)
00358               {
00359 /* Do not rewrite Ciku */
00360 /*
00361                      strcpy(pszHome,"/home/");
00362                      strcat(pszHome, pszUserName);
00363                      nLen    = strlen(pszHome);
00364                      
00365                      memset (szPath, '\0', 128);
00366                      strcat (szPath, pszHome);
00367                      if (szPath[nLen - 1] == '/')
00368                             szPath[nLen - 1] = '\0';
00369                      strcat (szPath, szSysCikuBak);
00370               
00371                      WriteCikuData(szPath, 0);
00372 */
00373 
00374                      FreePckAll();
00375                      pCkAll = NULL;
00376 /*
00377                      memset (szPath, '\0', 128);
00378                      strcat (szPath, pszHome);
00379                      if (szPath[nLen - 1] == '/')
00380                             szPath[nLen - 1] = '\0';
00381                      strcat (szPath, szUdcCikuBak);
00382                      
00383                      WriteUdcData (szPath, 0);
00384 */
00385                      FreeUdcData();
00386               }
00387               return (&ieh);
00388        }
00389        
00390        else if (IsQpSpSwitchKeysym(pKsThis))
00391        {
00392               nQpSpFlag[nSesID] = 1 - nQpSpFlag[nSesID];
00393 /*
00394               nGlobalSpMode = 4 - nGlobalSpMode;
00395 */
00396               IehReturn(&ieh, SWITCH_BEWTEEN_QPSP);     /* Application Quit or Switch to other IM */
00397               
00398               /* Initialize pSge[nSesID] */
00399               InitSge(pSge[nSesID]);
00400               return (&ieh);
00401        }
00402        
00403        else if (IsWantedKeysym(pKsThis))
00404        {
00405               if ((pCurSge->nKeyLayMode >= 0) && (pCurSge->nKeyLayMode <= 12))
00406               {
00407                      ProcSymbIMKey(pCurSge, pCurSge->nKeyLayMode, pKsThis, &ieh);
00408 #ifdef _DRAW_IM_WIN_H
00409                      DrawImToXSun(&ieh, pCurSge);
00410                      if (ieh.nType == IMXSUN_TYPE_COMMITSYMBOL)
00411                             JwordInfo(ieh.pwCommit, 256);
00412 #endif
00413                      return (&ieh);
00414               }
00415               
00416               /*
00417               **  Determine if this keySym is really valid for current pSge enviroment (GUI Logic).
00418               **  If NO, return!!
00419               **  Some KeySyms that is not useful during PYIM's Input GUI Logic,
00420               **       although that is defined in IsWantedkeysym().
00421               **       IMXSUN_TYPE_BOUNCEKEY 0x0002 was defined in file CmSo.h
00422               */
00423               
00424               /* NULL in preedit line, enter symbol now */
00425               if ( (JwordValidLen(pCurSge->pwMixPeStr, UONE) == 0)  && 
00426                      ((pCurSge->nKeyLayMode == SKB_QP_MODE) || 
00427                       (pCurSge->nKeyLayMode == SKB_SP_MODE) || 
00428                       (pCurSge->nKeyLayMode == SKB_FULLWID_ENG)) &&
00429                      (((pKsThis[0] >= 0x20) && (pKsThis[0] <= 0x7E)) || (pKsThis[0] == IMXK_Clear)) )
00430               {
00431                      if (pKsThis[0] == IMXK_Clear)                    
00432                      {
00433                             nTmp1 = pCurSge->nPunctMode;
00434                             nTmp2 = pCurSge->nKeyLayMode;
00435                             InitSge(pCurSge);
00436                             pCurSge->nPunctMode  = nTmp1;
00437                             pCurSge->nKeyLayMode = nTmp2;
00438                             
00439                             pCurSge->nPrevKeyLayMode = pCurSge->nKeyLayMode;
00440 
00441                             memset(&ieh, 0x00, sizeof(ImToXSun));
00442                             ieh.nType = IMXSUN_TYPE_NORMAL;
00443 #ifdef _DRAW_IM_WIN_H
00444                             DrawImToXSun(&ieh, pCurSge);
00445 #endif
00446                             return (&ieh);
00447                      }
00448                             
00449                      pCurSge->nPrevKeyLayMode = pCurSge->nKeyLayMode;
00450                      if (pCurSge->nPunctMode == PUNCT_CHINESE)
00451                             FlagChnPunc = TRUE;
00452                      else 
00453                             FlagChnPunc = FALSE;
00454                             
00455                      if (pCurSge->nKeyLayMode == SKB_FULLWID_ENG)
00456                             FlagChnAscii = TRUE;
00457                      else
00458                             FlagChnAscii = FALSE;
00459 
00460                      wPuncAscii = GetQuanjiaoSymbol(pKsThis, FlagChnPunc, FlagChnAscii);
00461                      if (wPuncAscii != 0x0000)
00462                      {
00463                             ieh.nType = IMXSUN_TYPE_COMMIT;
00464                             memset(ieh.pwCommit, 0x00, sizeof(JWORD) * UONE);
00465                             ieh.pwCommit[0] = wPuncAscii;
00466 #ifdef _DRAW_IM_WIN_H
00467                             JwordInfo(ieh.pwCommit, 256);
00468 #endif
00469                             return (&ieh);
00470                      }
00471               }
00472               
00473 #ifndef _DRAW_IM_WIN_H
00474               if(   bCapsIsPressed  || bCtrlIsPressed || bAltIsPressed  ||
00475                     bAltGrIsPressed || bCompIsPressed || bMetaIsPressed || 
00476                   ( (JwordValidLen(pCurSge->pwMixPeStr, UONE) == 0) && 
00477                     ( (IsPageKeysym(pKsThis)) || (IsSelectKeysym(pKsThis)) || (!IsPyKeysym(pKsThis)) )
00478                   )
00479                 )
00480               {
00481                      ieh.nType = IMXSUN_TYPE_BOUNCEKEY;
00482                      return (&ieh);
00483               }
00484 #endif
00485               
00486               pCurSge->nErrorCode = 0;                /* Clear All Error Message before a KeySym */
00487               ieh.nType   = IMXSUN_TYPE_NORMAL;
00488               for(i = 0; i < UONE; i++)
00489                      pCurSge->pwCommit[i] = ieh.pwCommit[i] = 0x0000;
00490               
00491               ProcAllKeysym(pKsThis, pCurSge);
00492               
00493               /*
00494               **  Determine if there is any other English chars in the end of pwMixPeStr[256].
00495               **  If there is no char lefted, indicates all is committed, pass it to IMToXSun,
00496               **  and InitSge(pCurSge) again. 
00497               **
00498               **  If pwMixPeStr[nLen - 1] is ['], How to deal it???
00499               **
00500               **  To create User defined Cizu HERE!!! Only after a committment.   97.11.08 MXL
00501               */
00502               nLen = JwordValidLen(pCurSge->pwMixPeStr, 256);
00503               if (pCurSge->pwMixPeStr[nLen - 1] >= 0x8140)      /* First Char defined in GBK */
00504               {
00505                      for (i = 0; i < UONE; i++)
00506                             pCurSge->pwCommit[i] = ieh.pwCommit[i] = 0x0000;
00507                      for (i = 0; i < nLen; i++)
00508                      {
00509                             /*
00510                             ** The following line was commented ONLY Because For SUN's HTT!!
00511                             pCurSge->pwCommit[i] = pCurSge->pwMixPeStr[i];
00512                             */
00513                             ieh.pwCommit[i] = pCurSge->pwMixPeStr[i];
00514                      }
00515                      ieh.nType = IMXSUN_TYPE_COMMIT;
00516                      ProcFreq(pCurSge);
00517                      ProcUdCizu(pCurSge);
00518                      
00519                      nTmp1 = pCurSge->nPunctMode;
00520                      InitSge(pCurSge);
00521                      pCurSge->nPunctMode = nTmp1;
00522                      GetIehFromSge(&ieh, pCurSge);
00523                      
00524 #ifdef _DRAW_IM_WIN_H
00525                      DrawImToXSun(&ieh, pCurSge);
00526                      JwordInfo(ieh.pwCommit, 256);
00527                      
00528                      /* Write Ciku File After each Committment */
00529                      strcpy(pszHome,"/home/");
00530                      strcat(pszHome, pszUserName);
00531                      nLen    = strlen(pszHome);
00532                      
00533                      memset (szPath, '\0', 128);
00534                      strcat (szPath, pszHome);
00535                      if (szPath[nLen - 1] == '/')
00536                             szPath[nLen - 1] = '\0';
00537                      strcat (szPath, szSysCikuBak);
00538               
00539                      WriteCikuData(szPath, 0);
00540 
00541                      memset (szPath, '\0', 128);
00542                      strcat (szPath, pszHome);
00543                      if (szPath[nLen - 1] == '/')
00544                             szPath[nLen - 1] = '\0';
00545                      strcat (szPath, szUdcCikuBak);
00546                      
00547                      WriteUdcData (szPath, 0);
00548 #endif
00549               }
00550               else
00551               {
00552                      GetIehFromSge(&ieh, pCurSge);
00553                      
00554 #ifdef _DRAW_IM_WIN_H
00555                      DrawImToXSun(&ieh, pCurSge);
00556 #endif
00557               }
00558               return (&ieh);
00559        }
00560        
00561        /*
00562        **  Bounce Other KeySym which is not in the range of above wanted key.
00563        */
00564        else
00565        {
00566               ieh.nType = IMXSUN_TYPE_BOUNCEKEY;  /* In CmSo.h:  IMXSUN_TYPE_BOUNCEKEY 0x0002 */
00567               return (&ieh);
00568        }
00569 }
00570 
00571 
00572 /*
00573 **  Process Specific case.  *** This Function is to be rearranged Later.
00574 */
00575 VOID IehReturn (ImToXSun* pIeh, JINT nCaseFlag)
00576 {
00577        JINT   i, j;
00578        
00579        pIeh->nType      = IMXSUN_TYPE_ERROR;
00580        pIeh->nErrorCode = nCaseFlag;
00581 
00582        if (nCaseFlag == SWITCH_BEWTEEN_QPSP)
00583               pIeh->nCaretPos = 0;
00584        else
00585               pIeh->nCaretPos = -1;
00586 
00587        for (i = 0; i < 128; i++)
00588               pIeh->pwPreedit[i] = 0x0000;
00589        for (i = 0; i < 8; i++)
00590               for (j = 0; j < 24; j++)
00591                      pIeh->pwLookupChoice[i][j] = 0x0000;
00592        pIeh->nChoiceNum  = 0;
00593 }
00594 
00595 
00596 /*
00597 **  Initialize / Reset / Clear SesGuiElement Structure.
00598 */
00599 VOID InitSge(SesGuiElement* pSgeStruct)
00600 {
00601        JINT    i;
00602        
00603        pSgeStruct->nSpRawCaretPos    = 0;
00604 
00605        for (i = 0; i < 40; i++)
00606               pSgeStruct->pwSpRawPyStr[i]  = 0x0000;
00607        for (i = 0; i < UONE; i++)
00608               pSgeStruct->pwSpMixPeStr[i]  = 0x0000;
00609        for (i = 0; i < UTWO; i++)
00610               pSgeStruct->pwSpSlctRawPy[i] = 0x0000;
00611        
00612        for (i = 0; i < UONE; i++)
00613        {
00614               pSgeStruct->pwRawPyStr[i]    = 0x0000;
00615               pSgeStruct->pwMixPeStr[i]    = 0x0000;
00616               pSgeStruct->nPrsPyYjCode[i]  = 0;
00617               pSgeStruct->pwCommit[i]      = 0x0000;
00618        }
00619        
00620        for (i = 0; i < UTWO; i++)
00621        {
00622               pSgeStruct->pwPrsPyStr[i]    = 0x0000;
00623               pSgeStruct->pwPrsMixStr[i]   = 0x0000;
00624               pSgeStruct->pwSlctHz[i]      = 0x0000;
00625               pSgeStruct->pwSlctRawPy[i]   = 0x0000;
00626        }
00627        
00628        for (i = 0; i < UHLF; i++)
00629        {
00630               pSgeStruct->pwViewPe[i]      = 0x0000;
00631               pSgeStruct->pwViewCandi[i]   = 0x0000;
00632        }
00633        
00634 /*
00635        pSgeStruct->nPinyinType       = -1;
00636 */
00637        pSgeStruct->nPrevKeyLayMode   = pSgeStruct->nKeyLayMode;
00638 /*
00639        pSgeStruct->nPunctMode        = 0;   
00640 */
00641        
00642        pSgeStruct->nRawCaretPos      = 0;
00643        pSgeStruct->nViewCaretPos     = 0;
00644        pSgeStruct->nViewPage         = 0;
00645        pSgeStruct->nViewPeStart      = 0;
00646        pSgeStruct->nViewPeEnd        = 0;
00647        pSgeStruct->nViewCandiStart   = 0;
00648        pSgeStruct->nViewCandiEnd     = 0;
00649        pSgeStruct->nSlctSteps        = 0;
00650 
00651        for (i = 0; i < 16; i++)
00652               pSgeStruct->pwStatus[i]   = 0x0000;
00653        pSgeStruct->nErrorCode        = 0;
00654 
00655        pSgeStruct->nIconFlag = F_HALFWIDTH | F_SETUP;
00656        
00657        InitStructSc(&(pSgeStruct->scSysCandi));
00658        InitStructUc(&(pSgeStruct->ucUdcCandi));
00659 
00660        /* The following 3 items were added to Fix Bug 4165549: Scott Ma, 12/8, 1998 */
00661        pSgeStruct->nPrevMatchMode       = -1;
00662        for (i = 0; i < 9; i++)
00663        {
00664               pSgeStruct->pnCurChoiceYjNew[i] = 1;
00665               pSgeStruct->pnCurChoiceYjOld[i] = 0;
00666        }
00667 }
00668 
00669 
00670 /*
00671 **  Get these Common Part of struct Ieh from struct Sge.
00672 **  Notes that these different part is not filled in this function.
00673 **  Include:   i)   nType          ii)    szCommittString
00674 **             iii) szBounceKey    iv)    Error Code
00675 */
00676 VOID GetIehFromSge(ImToXSun* pIeh, SesGuiElement* pSge)
00677 {
00678        JINT   i, j;
00679        
00680        for (i = 0; i < 128; i++)
00681               pIeh->pwPreedit[i] = pSge->pwViewPe[i];
00682               
00683        pIeh->nCaretPos  = pSge->nViewCaretPos;
00684        
00685        pIeh->nChoiceNum = pSge->nViewCandiEnd - pSge->nViewCandiStart;
00686        for (i = 0; i < 8; i++)
00687               for (j = 0; j < 24; j++)
00688                      pIeh->pwLookupChoice[i][j] = 0x0000;
00689        
00690        GetLookupChoiceFromCandi(pIeh, pSge->pwViewCandi);
00691        
00692        for (i = 0; i < 16; i++)
00693               pIeh->pwStatus[i] = pSge->pwStatus[i];
00694        
00695        /* Because nErrorCode was cleared before each new KeySym Process */
00696        if (pSge->nErrorCode != 0)
00697        {
00698               pIeh->nType = IMXSUN_TYPE_ERROR;
00699               pIeh->nErrorCode = pSge->nErrorCode;
00700        }
00701 }
00702 
00703 
00704 VOID GetLookupChoiceFromCandi(ImToXSun* pIeh, JWORD* pwCandi)
00705 {
00706        JINT    i, j, k, nLen;
00707        JINT    nbStartCandi;
00708        
00709        nLen = JwordValidLen(pwCandi, 128);
00710        
00711        i = j = k = nbStartCandi = 0;
00712        for (i = 0; i < nLen; i++)
00713        {
00714               if (pwCandi[i] >= 0x8140)   /* First Hanzi in GBK */
00715               {
00716                      nbStartCandi = 1;
00717                      pIeh->pwLookupChoice[j][k++] = pwCandi[i];
00718                      while(pwCandi[++i] >= 0x8140)
00719                             pIeh->pwLookupChoice[j][k++] = pwCandi[i];
00720                      j++;
00721                      k = 0;
00722                      nbStartCandi = 0;
00723               }
00724        }
00725        pIeh->nChoiceNum = j;
00726 }
00727 
00728 
00729 /*
00730 **  Convert from Struct ImToXSun to Struct ImToXSunChar
00731 */
00732 ImToXSunChar* ConvImToXSun(ImToXSun* pIeh)
00733 {
00734        JINT   i, j, nHz;
00735        JINT   nNumDollar;   /* Number of Numsign and Dollar before Caret */
00736        static ImToXSunChar  iehc;
00737        
00738        for (i = 0; i < 256; i++)
00739               iehc.szPreedit[i]   = '\0';
00740               
00741        for (i = 0; i < 10; i++)
00742               for (j = 0; j < 48; j++)
00743                      iehc.szLookupChoice[i][j] = '\0';
00744                      
00745        for (i = 0; i < 512; i++)
00746               iehc.szCommit[i]    = '\0';
00747               
00748        for (i = 0; i < 32; i++)
00749               iehc.szStatus[i]    = '\0';
00750               
00751        /* One Hanzi is  2 Bytes */
00752        nHz = 0;
00753        for (i = 0; (pIeh->pwPreedit[i] >= 0x8140); i++)
00754               nHz++;
00755               
00756        iehc.nType        = pIeh->nType;
00757        iehc.nErrorCode   = pIeh->nErrorCode;
00758        iehc.nChoiceNum   = pIeh->nChoiceNum;
00759        iehc.nLabelType   = LABELTYPE_1234567;
00760        
00761        nNumDollar = 0;
00762        j = 0;
00763        for (i = 0; pIeh->pwPreedit[i] != 0x0000; i++)
00764        {
00765               if ((pIeh->pwPreedit[i] != (JWORD)'#') && (pIeh->pwPreedit[i] != (JWORD)'$'))
00766               {
00767                      pIeh->pwPreedit[j++] = pIeh->pwPreedit[i];
00768               }
00769               else  /* '#' and '$' before pIeh->nCaretPos should be counted!! */
00770               {
00771                      if (i < pIeh->nCaretPos)
00772                             nNumDollar ++;
00773               }
00774        }
00775        for (; j < 128; j++)
00776               pIeh->pwPreedit[j++] = 0x0000;
00777        
00778        iehc.nCaretPos    = pIeh->nCaretPos + nHz - nNumDollar;
00779        
00780        Jword2Uchar(pIeh->pwPreedit, iehc.szPreedit, 128);
00781        Jword2Uchar(pIeh->pwCommit,  iehc.szCommit,  256);
00782        Jword2Uchar(pIeh->pwStatus,  iehc.szStatus,   16);
00783        
00784        for(i = 0; i < 8; i++)
00785               Jword2Uchar(pIeh->pwLookupChoice[i], iehc.szLookupChoice[i],  24);
00786        
00787        return (&iehc);
00788 }
00789