subs.c
上传用户:szljw888
上传日期:2010-04-11
资源大小:124k
文件大小:33k
源码类别:

输入法编程

开发平台:

C/C++

  1. /* 大熊猫输入法(Free Chinese Input)  由YJMSIR(yjmsir@163.com)编写
  2.  * 协议: GPL
  3.  * freeinput( A Chinese Input Method) by YJMSIR(yjmsir@163.com)
  4.  * Licence: GPL 
  5.  */
  6. #include "freepy.h"
  7. void GetRelativeTableDirList()
  8. {
  9. WIN32_FIND_DATA ffd;
  10. char szDirFile[1024];
  11. HANDLE hFind;
  12. sprintf(szDirFile,"%s//mb//*",InstallFromDir);
  13. hFind = FindFirstFile(szDirFile,&ffd);
  14. if (hFind != INVALID_HANDLE_VALUE)
  15. {
  16. int i=0;
  17. if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
  18. strcmp(ffd.cFileName,".") && 
  19. strcmp(ffd.cFileName,".."))
  20. {//确定找到一个目录并且不为 . 或 ..
  21. sprintf(RelativeTableDirList[i],"%s",ffd.cFileName);
  22. i++;
  23. }
  24. while(FindNextFile(hFind,&ffd))
  25. {
  26. if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
  27. strcmp(ffd.cFileName,".") && 
  28. strcmp(ffd.cFileName,".."))
  29. {//确定找到一个目录并且不为 . 或 ..
  30. sprintf(RelativeTableDirList[i],"%s",ffd.cFileName);
  31. i++;
  32. }
  33. }
  34. FindClose(hFind);
  35. }
  36. }
  37. BOOL IsFileExist(LPCSTR pszFileName)
  38. {
  39.   WIN32_FIND_DATA FindFileData;
  40.   HANDLE hFind;
  41.   hFind = FindFirstFile(pszFileName, &FindFileData);
  42.   if (hFind == INVALID_HANDLE_VALUE) 
  43.       return FALSE;//not found
  44.   else
  45.   {
  46.       FindClose(hFind);
  47.       return TRUE;//found it
  48.   }
  49. }
  50. void ReadRegRecord()
  51. {
  52. HKEY hKey;
  53. DWORD dwData = sizeof(DWORD),dwData1 = MAX_PATH,dwData2 = MAX_PATH;
  54. if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  55. REGKEYNAME,
  56. 0,
  57. KEY_READ,
  58. &hKey) == ERROR_SUCCESS ){
  59. RegQueryValueEx( hKey,
  60. _T("InstallFromDir"),
  61. NULL,
  62. NULL,
  63. (LPBYTE)InstallFromDir,
  64. &dwData1);
  65. }
  66. RegCloseKey(hKey);
  67. }
  68. BOOL IsIMEOpen(HIMC hIMC)//输入法是否打开
  69. {
  70. BOOL fOpen;
  71. LPINPUTCONTEXT lpIMC;
  72. if (!(lpIMC = ImmLockIMC(hIMC)))
  73. return FALSE;
  74. fOpen = lpIMC->fOpen;
  75. ImmUnlockIMC(hIMC);
  76. return fOpen;
  77. }
  78. BOOL IsCompStr(HIMC hIMC)
  79. {
  80.     LPINPUTCONTEXT lpIMC;
  81.     LPCOMPOSITIONSTRING lpCompStr;
  82.     BOOL fRet = FALSE;
  83.     if (!(lpIMC = ImmLockIMC(hIMC)))
  84.         return FALSE;
  85.     if (ImmGetIMCCSize(lpIMC->hCompStr) < sizeof (COMPOSITIONSTRING))
  86.     {
  87.         ImmUnlockIMC(hIMC);
  88.         return FALSE;
  89.     }
  90.     lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  91.     fRet = (lpCompStr->dwCompStrLen > 0);
  92.     ImmUnlockIMCC(lpIMC->hCompStr);
  93.     ImmUnlockIMC(hIMC);
  94.     return fRet;
  95. }
  96. /**********************************************************************/
  97. /*                                                                    */
  98. /*      InitCompStr()                                                  */
  99. /*                                                                    */
  100. /**********************************************************************/
  101. void InitCompStr(LPCOMPOSITIONSTRING lpCompStr)
  102. {
  103. LPFREEPYCOMP lpFreePYComp;
  104. lpCompStr->dwSize = sizeof(MYCOMPSTR);
  105. lpCompStr->dwCompStrOffset = 
  106.             (DWORD)((LPMYCOMPSTR)lpCompStr)->szCompStr - (DWORD)lpCompStr;
  107. lpCompStr->dwCompStrLen = 0;
  108. *GETLPCOMPSTR(lpCompStr) = _T('');
  109. lpCompStr->dwResultStrOffset = 
  110.           (DWORD)((LPMYCOMPSTR)lpCompStr)->szResultStr - (DWORD)lpCompStr;
  111. lpCompStr->dwResultStrLen = 0;
  112. *GETLPRESULTSTR(lpCompStr) = _T('');
  113. lpCompStr->dwCursorPos = 0;
  114. lpFreePYComp= &(((LPMYCOMPSTR)lpCompStr)->FreePYComp);
  115. lpFreePYComp->szConvCompStr[0] = _T('');
  116. lpFreePYComp->szPaintCompStr[0] = _T('');
  117. lpFreePYComp->szPreResultStr[0] = _T('');
  118. lpFreePYComp->wEditCaret = 0;
  119. lpFreePYComp->wUnConvPos = 0;
  120. lpFreePYComp->wPYArrayLen = 0;
  121. lpFreePYComp->wPYArrayCurPos = 0;
  122. }
  123. void ClearCompStr(LPCOMPOSITIONSTRING lpCompStr)
  124. {
  125. LPFREEPYCOMP lpFreePYComp;
  126. lpCompStr->dwCursorPos = 0;
  127. lpCompStr->dwCompStrLen = 0;
  128. ((LPMYCOMPSTR)lpCompStr)->szCompStr[0] = _T('');
  129. lpCompStr->dwResultStrLen = 0;
  130. ((LPMYCOMPSTR)lpCompStr)->szResultStr[0] = _T('');
  131. lpFreePYComp= &(((LPMYCOMPSTR)lpCompStr)->FreePYComp);
  132. lpFreePYComp->szConvCompStr[0] = _T('');
  133. lpFreePYComp->szPaintCompStr[0] = _T('');
  134. lpFreePYComp->wEditCaret = 0;
  135. lpFreePYComp->wUnConvPos = 0;
  136. lpFreePYComp->wPYArrayLen = 0;
  137. lpFreePYComp->wPYArrayCurPos = 0;
  138. }
  139. BOOL IsCandidate(HIMC hIMC)
  140. {
  141.     LPINPUTCONTEXT lpIMC;
  142.     LPCANDIDATEINFO lpCandInfo;
  143. LPCANDIDATELIST lpCandList;
  144.     BOOL fRet = FALSE;
  145.     if (!(lpIMC = ImmLockIMC(hIMC)))
  146.         return FALSE;
  147.     if (ImmGetIMCCSize(lpIMC->hCandInfo) < sizeof (CANDIDATEINFO)){
  148. ImmUnlockIMC(hIMC);
  149.         return FALSE;
  150. }
  151.     lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  152. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo  + lpCandInfo->dwOffset[0]);
  153.     fRet = (lpCandList->dwCount > 0);
  154.     ImmUnlockIMCC(lpIMC->hCandInfo);
  155. ImmUnlockIMC(hIMC);
  156.     return fRet;
  157. }
  158. void InitCandInfo(LPCANDIDATEINFO lpCandInfo)
  159. {
  160. LPCANDIDATELIST lpCandList;
  161. LPFREEPYCAND lpFreePYCand;
  162. int i;
  163. lpCandInfo->dwSize = sizeof(MYCAND);
  164. lpCandInfo->dwCount = 1;
  165. lpCandInfo->dwOffset[0] = (DWORD)(&(((LPMYCAND)lpCandInfo)->cl)) - (DWORD)lpCandInfo;
  166. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo + lpCandInfo->dwOffset[0]);
  167. for(i=0;i<MAXCANDSTRNUM;i++) {
  168. lpCandList->dwOffset[i] = (DWORD)((LPMYCAND)lpCandInfo)->szCandStr[i] - (DWORD)lpCandList;
  169. }
  170. lpCandList->dwSize = sizeof(MYCAND) - sizeof(CANDIDATEINFO); 
  171. lpCandList->dwCount = 0L;
  172. lpCandList->dwSelection = 0L;
  173. lpCandList->dwPageStart = 0L;
  174. lpCandList->dwPageSize = 0L;
  175. lpFreePYCand= &(((LPMYCAND)lpCandInfo)->FreePYCand);
  176. lpFreePYCand->wPhraseNum = 0;
  177. lpFreePYCand->wHZNum = 0;
  178. lpFreePYCand->wKeyLen = 0;
  179. lpFreePYCand->awKey[0] = 0;
  180. }
  181. void ClearCandidate(LPCANDIDATEINFO lpCandInfo)
  182. {
  183. LPFREEPYCAND lpFreePYCand;
  184.     ((LPMYCAND)lpCandInfo)->cl.dwCount =0L;
  185.     ((LPMYCAND)lpCandInfo)->cl.dwSelection =0L;
  186.     ((LPMYCAND)lpCandInfo)->cl.dwPageStart =0L;
  187.     ((LPMYCAND)lpCandInfo)->cl.dwPageSize =0L;
  188. lpFreePYCand= &(((LPMYCAND)lpCandInfo)->FreePYCand);
  189. lpFreePYCand->wPhraseNum = 0;
  190. lpFreePYCand->wHZNum = 0;
  191. lpFreePYCand->wKeyLen = 0;
  192. lpFreePYCand->awKey[0] = 0;
  193. }
  194. HKL GetMyHKL()
  195. {
  196.     DWORD dwSize;
  197.     DWORD dwi;
  198.     HKL hKL = 0;
  199.     HKL *lphkl;
  200.     dwSize = GetKeyboardLayoutList(0, NULL);
  201.     lphkl = (HKL *)GlobalAlloc(GPTR, dwSize * sizeof(DWORD));
  202.     if (!lphkl)
  203.         return NULL;
  204.     GetKeyboardLayoutList(dwSize, lphkl);
  205.     for (dwi = 0; dwi < dwSize; dwi++)
  206.     {
  207.         char szFile[32];
  208.         HKL hKLTemp = *(lphkl + dwi);
  209.         ImmGetIMEFileName(hKLTemp, szFile, sizeof(szFile));
  210.         if (!_tcsicmp(szFile, FREEPYFILENAME))
  211.         {
  212.              hKL = hKLTemp;
  213.              goto exit;
  214.         }
  215.     }
  216. exit:
  217.     GlobalFree((HANDLE)lphkl);
  218.     return hKL;
  219. }
  220. /*****************************************************************************
  221. *                                                                            *
  222. * UpdateIndicIcon( hIMC )                                                    *
  223. *                                                                            *
  224. *****************************************************************************/
  225. void UpdateIndicIcon(HIMC hIMC)
  226. {
  227.     HWND hwndIndicate;
  228.     BOOL fOpen = FALSE;
  229.     LPINPUTCONTEXT lpIMC;
  230.     if (!hFreePYKL)
  231.     {
  232.        hFreePYKL = GetMyHKL();
  233.        if (!hFreePYKL)
  234.            return;
  235.     }
  236.     hwndIndicate = FindWindow(INDICATOR_CLASS, NULL);
  237.     if (hIMC)
  238.     {
  239.         lpIMC = ImmLockIMC(hIMC);
  240.         if (lpIMC)
  241.         {
  242.             fOpen = lpIMC->fOpen;
  243.             ImmUnlockIMC(hIMC);
  244.         }
  245.     }
  246.     if (IsWindow(hwndIndicate))
  247.     {
  248.         ATOM atomTip;
  249.         atomTip = GlobalAddAtom(ATOMTIP1);
  250.         PostMessage(hwndIndicate, INDICM_SETIMEICON, 
  251.                     fOpen ? 1 : (-1), (LPARAM)hFreePYKL);
  252.         PostMessage(hwndIndicate, INDICM_SETIMETOOLTIPS, 
  253.                     fOpen ? atomTip : (-1), (LPARAM)hFreePYKL);
  254.         PostMessage(hwndIndicate, INDICM_REMOVEDEFAULTMENUITEMS, 
  255.                     // fOpen ? (RDMI_LEFT | RDMI_RIGHT) : 0, (LPARAM)hMyKL);
  256.                     fOpen ? (RDMI_LEFT) : 0, (LPARAM)hFreePYKL);
  257.     }
  258. }
  259. /**********************************************************************/
  260. /*                                                                    */
  261. /* MyIsIMEMessage(message)                                            */
  262. /*                                                                    */
  263. /* Any UI window should not pass the IME messages to DefWindowProc.   */
  264. /*                                                                    */
  265. /**********************************************************************/
  266. BOOL MyIsIMEMessage(UINT message)
  267. {
  268.     switch(message){
  269.             case WM_IME_STARTCOMPOSITION:
  270.             case WM_IME_ENDCOMPOSITION:
  271.             case WM_IME_COMPOSITION:
  272.             case WM_IME_NOTIFY:
  273.             case WM_IME_SETCONTEXT:
  274.             case WM_IME_CONTROL:
  275.             case WM_IME_COMPOSITIONFULL:
  276.             case WM_IME_SELECT:
  277.             case WM_IME_CHAR:
  278.                 return TRUE;
  279.     }
  280.     return FALSE;
  281. }
  282. BOOL MakeResultString( HIMC hIMC,BOOL fFlag)
  283. {
  284.     GENEMSG GnMsg;
  285.     LPCOMPOSITIONSTRING lpCompStr;
  286.     LPINPUTCONTEXT lpIMC;
  287. LPTSTR lpConvStr,lpPreResultStr,WubiCode,lpStr;
  288. LPCANDIDATEINFO lpCandInfo;
  289. LPCANDIDATELIST lpCandList;
  290. char AutoSaveWubiCode[5],AutoSaveWubiChr[3];
  291. WORD ConvStrLength,i;
  292. LPTSTR lpDest;
  293. static TCHAR PreThreeConvStr[3][MAXSTRHZLENGTH*3]={0};
  294. /*
  295.     if (!IsCompStr(hIMC))
  296.         return FALSE;
  297. */
  298. dwCurPhraseAttrib=0;
  299.     lpIMC = ImmLockIMC(hIMC);
  300.     lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  301. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  302. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  303. lpStr = GETLPCOMPSTR(lpCompStr);
  304. if(fFlag) {
  305. GnMsg.msg = WM_IME_NOTIFY;
  306. GnMsg.wParam = IMN_SETCOMPOSITIONWINDOW;
  307. GnMsg.lParam = 0;
  308. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  309. GnMsg.msg = WM_IME_NOTIFY;
  310. GnMsg.wParam = IMN_SETSTATUSWINDOWPOS;
  311. GnMsg.lParam = 0;
  312. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  313. lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
  314. if(PunctPushWordFlag){
  315. ImmUnlockIMCC(lpIMC->hCompStr);
  316. ImmUnlockIMCC(lpIMC->hCandInfo);
  317. ImmUnlockIMC(hIMC);
  318. return TRUE;
  319. }
  320. if(wConversionMode == CONVERSION_MODE_ENGLISH){
  321. _tcscpy(lpConvStr,lpStr);
  322. goto Noaddhistory;//Word_Existed_Hint_next;
  323. }
  324. lpPreResultStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr;
  325. for(i=0;i<=1;i++){
  326. _tcscpy(PreThreeConvStr[2-i],PreThreeConvStr[1-i]);
  327. _tcscat(PreThreeConvStr[2-i],lpConvStr);
  328. }
  329. _tcscpy(PreThreeConvStr[0],lpPreResultStr);
  330. _tcscat(PreThreeConvStr[0],lpConvStr);
  331. _tcscpy(lpPreResultStr,lpConvStr);
  332. if(wConversionMode == CONVERSION_MODE_WUBI) _tcscpy(szPreResultCode,lpStr);
  333. //保存输入历史记录
  334. ConvStrLength=_tcslen(lpConvStr);
  335. InputAccumulateNum+=ConvStrLength;//输出数目的累积
  336. if(ConvStrLength%2 || wConversionMode != CONVERSION_MODE_WUBI) goto Noaddhistory;
  337. //如果是奇数位,可能产生错误,干脆取消
  338. if(_tcslen(WordHistoryStr)>MAXHISTORYNUM-100){
  339. _tcscpy(WordHistoryStr,WordHistoryStr+200);
  340. _tcscpy(HistoryTwoCodes,HistoryTwoCodes+200);
  341. }
  342. //自动保存编码首两位
  343. for(i=0;i<ConvStrLength;i+=2){
  344. AutoSaveWubiChr[0]=lpConvStr[i];
  345. AutoSaveWubiChr[1]=lpConvStr[i+1];
  346. AutoSaveWubiChr[2]='';
  347. //完备了,不会再产生错误了。
  348. if(wConversionSet &CONVERSION_SET_STANDARDSEARCH)
  349. {
  350. if(QueryQuickSearchTablegbk(AutoSaveWubiChr,AutoSaveWubiCode)){
  351. _tcscat(WordHistoryStr,AutoSaveWubiChr);
  352. AutoSaveWubiCode[2]='';
  353. _tcscat(HistoryTwoCodes,AutoSaveWubiCode);
  354. }
  355. }
  356. else
  357. if(WubiCode=FindWuBiCode (AutoSaveWubiChr)){
  358. _tcscat(WordHistoryStr,AutoSaveWubiChr);
  359. _tcscpy(AutoSaveWubiCode,WubiCode);
  360. AutoSaveWubiCode[2]='';
  361. _tcscat(HistoryTwoCodes,AutoSaveWubiCode);
  362. }
  363. }
  364. Noaddhistory:
  365. //
  366. if((wConversionSet & CONVERSION_SET_HISTORYREUSE) &&
  367. (wConversionMode == CONVERSION_MODE_WUBI)){
  368. _tcscpy(YJMMessage,"");
  369. if(lpDest = _tcsstr(WordHistoryStr,PreThreeConvStr[0])){
  370. lpDest+=_tcslen(PreThreeConvStr[0]);
  371. _tcsncpy(YJMMessage,lpDest,20);//10个汉字
  372. }
  373. }
  374. //
  375. if(wConversionSet & CONVERSION_SET_JP) 
  376. gb2jfb(GB2JP,lpConvStr);
  377. else if(wConversionSet & CONVERSION_SET_GBJT2FT) 
  378. gb2jfb(GB2FT,lpConvStr);
  379. else if(wConversionSet & CONVERSION_SET_BIG5) 
  380. gb2jfb(GB2BIG5,lpConvStr);
  381. _tcscpy(GETLPRESULTSTR(lpCompStr),lpConvStr);//?
  382. lpCompStr->dwResultStrLen = _tcslen(lpConvStr);
  383. }
  384. else{//false在此处理
  385. if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR)
  386. wConversionMode =wPreConversionMode;
  387. lpCandList->dwCount = 0;
  388. lpCompStr->dwCompStrLen = 0;
  389. _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
  390. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
  391. //_tcscpy(GETLPCANDSTR(lpCandList,2),_T(""));
  392. //_tcscpy(YJMMessage,"");
  393. ImmUnlockIMCC(lpIMC->hCompStr);
  394. ImmUnlockIMCC(lpIMC->hCandInfo);
  395. GnMsg.msg = WM_IME_COMPOSITION;
  396. GnMsg.wParam = 0;
  397. GnMsg.lParam = GCS_COMPSTR;
  398. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  399. GnMsg.msg = WM_IME_ENDCOMPOSITION;
  400. GnMsg.wParam = 0;
  401. GnMsg.lParam = 0;
  402. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  403.         goto my_makestring_exit;
  404. }
  405. lpCandList->dwCount = 0;
  406.     lpCompStr->dwCompStrLen = 0;
  407. _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
  408. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
  409. //
  410. if((wConversionSet & CONVERSION_SET_HISTORYREUSE) &&
  411. (wConversionMode == CONVERSION_MODE_WUBI)&& _tcslen(YJMMessage)){
  412. _tcscpy(GETLPCANDSTR(lpCandList,2),YJMMessage);
  413. //_tcscpy(GETLPCANDSTR(lpCandList,3),_T("用法:\+数字"));
  414. lpCandList->dwCount=1;
  415. lpCompStr->dwCompStrLen = 0;
  416. }
  417. else if((wConversionSet1 & C_SET1_Word_Existed_Hint) &&
  418.     (wConversionMode == CONVERSION_MODE_WUBI)){
  419. for(i=0;i<=2;i++){
  420. if(_tcslen(PreThreeConvStr[2-i])>ConvStrLength && 
  421. (WubiCode=FindWuBiCode(PreThreeConvStr[2-i]))){
  422. _stprintf(YJMMessage,_T("已有词组:%s %s"),PreThreeConvStr[2-i],WubiCode);
  423. _tcscpy(GETLPCANDSTR(lpCandList,2),YJMMessage);
  424. lpCandList->dwCount=1;
  425. lpCompStr->dwCompStrLen = 0;
  426. goto Word_Existed_Hint_next;
  427. }
  428. }
  429. }
  430. Word_Existed_Hint_next:
  431. ImmUnlockIMCC(lpIMC->hCompStr);
  432. ImmUnlockIMCC(lpIMC->hCandInfo);
  433. GnMsg.msg = WM_IME_COMPOSITION;
  434. GnMsg.wParam = 0;
  435. GnMsg.lParam = GCS_RESULTSTR;
  436. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  437. GnMsg.msg = WM_IME_ENDCOMPOSITION;
  438. GnMsg.wParam = 0;
  439. GnMsg.lParam = 0;
  440. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  441. //
  442. my_makestring_exit:
  443. if(wConversionMode == CONVERSION_MODE_ATTACHLIB){
  444. AttachLibDictCurrentRecord=AttachLibDictHead->next;
  445. }
  446. else if(wConversionMode == CONVERSION_MODE_WUBI){
  447. wubiDictCurrentRecord=wubiDictHead->next;
  448. }
  449. else if(wConversionMode == CONVERSION_MODE_WUBIATTACHLIB){
  450. AttachLibDictCurrentRecord=AttachLibDictHead->next;
  451. wubiDictCurrentRecord=wubiDictHead->next;
  452. }
  453. if(fTempState){
  454. wConversionMode = wPreConversionMode;
  455. UpdateStatusByMessage(hIMC);
  456. fTempState=0;
  457. }
  458.     ImmUnlockIMC(hIMC);
  459.     return TRUE;
  460. }
  461. /**********************************************************************/
  462. /*                                                                    */
  463. /*      GenerateMessage()                                             */
  464. /*                                                                    */
  465. /*      Update the transrate key buffer.                              */
  466. /*                                                                    */
  467. /**********************************************************************/
  468. BOOL GenerateMessage(HIMC hIMC, LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
  469. {
  470.     LPINPUTCONTEXT lpIMC;
  471. if( (lpIMC = ImmLockIMC(hIMC)) == NULL ) return FALSE;
  472.     if (lpdwTransKey){
  473. ImmUnlockIMC(hIMC);
  474.         return GenerateMessageToTransKey(lpdwTransKey,lpGeneMsg);
  475. }
  476.     
  477.     if (IsWindow(lpIMC->hWnd)){
  478.         LPDWORD lpdw;
  479.         if (!(lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf,
  480. sizeof(DWORD) * (lpIMC->dwNumMsgBuf +1) * 3)))
  481.             return FALSE;
  482.         if (!(lpdw = (LPDWORD)ImmLockIMCC(lpIMC->hMsgBuf)))
  483.             return FALSE;
  484.         lpdw += (lpIMC->dwNumMsgBuf) * 3;
  485.         *((LPGENEMSG)lpdw) = *lpGeneMsg;
  486.         ImmUnlockIMCC(lpIMC->hMsgBuf);
  487.         lpIMC->dwNumMsgBuf++;
  488.         ImmGenerateMessage(hIMC);
  489.     }
  490. ImmUnlockIMC(hIMC);
  491.     return TRUE;
  492. }
  493. /**********************************************************************/
  494. /*      GenerateMessageToTransKey()                                   */
  495. /*                                                                    */
  496. /*      Update the transrate key buffer.                              */
  497. /**********************************************************************/
  498. BOOL GenerateMessageToTransKey(LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
  499. {
  500. LPDWORD lpdwTemp;
  501.     uNumTransKey++;
  502.     if (uNumTransKey >= (UINT)*lpdwTransKey)
  503.     {
  504.         fOverTransKey = TRUE;
  505.         return FALSE;
  506.     }
  507. lpdwTemp = (LPDWORD)lpdwTransKey + 1 + (uNumTransKey - 1)*3;
  508. *(lpdwTemp++) = lpGeneMsg->msg;
  509. *(lpdwTemp++) = lpGeneMsg->wParam;
  510. *(lpdwTemp++) = lpGeneMsg->lParam;
  511.     return TRUE;
  512. }
  513. /**********************************************************************/
  514. /*                                                                    */
  515. /* DrawUIBorder()                                                     */
  516. /*                                                                    */
  517. /* When draging the child window, this function draws the border.     */
  518. /*                                                                    */
  519. /**********************************************************************/
  520. void DrawUIBorder( LPRECT lprc )
  521. {
  522.     HDC hDC;
  523.     int sbx, sby;
  524.     hDC = CreateDC( "DISPLAY", NULL, NULL, NULL );
  525.     SelectObject( hDC, GetStockObject( GRAY_BRUSH ) );
  526.     sbx = GetSystemMetrics( SM_CXBORDER );
  527.     sby = GetSystemMetrics( SM_CYBORDER );
  528.     PatBlt( hDC, lprc->left, 
  529. lprc->top, 
  530. lprc->right - lprc->left-sbx, 
  531. sby, PATINVERT );
  532.     PatBlt( hDC, lprc->right - sbx, 
  533. lprc->top, 
  534. sbx, 
  535. lprc->bottom - lprc->top-sby, PATINVERT );
  536.     PatBlt( hDC, lprc->right, 
  537. lprc->bottom-sby, 
  538. -(lprc->right - lprc->left-sbx), 
  539. sby, PATINVERT );
  540.     PatBlt( hDC, lprc->left, 
  541. lprc->bottom, 
  542. sbx, 
  543. -(lprc->bottom - lprc->top-sby), PATINVERT );
  544.     DeleteDC( hDC );
  545. }
  546. void DragUI( HWND hWnd, HWND hWnd1,UINT message, WPARAM wParam, LPARAM lParam,BOOL fIsCompWnd)
  547. {
  548.     POINT     pt;
  549.     static    POINT ptdif,ptdif1;
  550.     static    RECT drc,drc1;
  551.     static    SIZE sz,sz1;
  552.     DWORD     dwT;
  553.     switch (message)
  554.     {
  555. case WM_SETCURSOR:
  556. if ( HIWORD(lParam) == WM_LBUTTONDOWN
  557. || HIWORD(lParam) == WM_RBUTTONDOWN ) 
  558. {
  559. GetCursorPos( &pt );
  560. SetCapture(hWnd);
  561. GetWindowRect(hWnd,&drc);
  562. ptdif.x = pt.x - drc.left;
  563. ptdif.y = pt.y - drc.top;
  564. sz.cx = drc.right - drc.left;
  565. sz.cy = drc.bottom - drc.top;
  566. if (IsWindow(hWnd1)) {
  567. GetWindowRect(hWnd1,&drc1);
  568. ptdif1.x = pt.x - drc1.left;
  569. ptdif1.y = pt.y - drc1.top;
  570. sz1.cx = drc1.right - drc1.left;
  571. sz1.cy = drc1.bottom - drc1.top;
  572. }
  573. SetWindowLong(hWnd,FIGWL_MOUSE,FIM_CAPUTURED);
  574. }
  575. break;
  576. case WM_MOUSEMOVE:
  577. dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
  578. if (dwT & FIM_MOVED)
  579. {
  580. DrawUIBorder(&drc);
  581. if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
  582. GetCursorPos( &pt );
  583. drc.left   = pt.x - ptdif.x;
  584. drc.top    = pt.y - ptdif.y;
  585. drc.right  = drc.left + sz.cx;
  586. drc.bottom = drc.top + sz.cy;
  587. if (IsWindow(hWnd1)) {
  588. drc1.left   = pt.x - ptdif1.x;
  589. drc1.top    = pt.y - ptdif1.y;
  590. drc1.right  = drc1.left + sz1.cx;
  591. drc1.bottom = drc1.top + sz1.cy;
  592. }
  593. DrawUIBorder(&drc);
  594. if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
  595. }
  596. else if (dwT & FIM_CAPUTURED)
  597. {
  598. DrawUIBorder(&drc);
  599. if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
  600. SetWindowLong(hWnd,FIGWL_MOUSE,dwT | FIM_MOVED);
  601. }
  602. break;
  603. case WM_LBUTTONUP:
  604. case WM_RBUTTONUP:
  605. dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
  606. if (dwT & FIM_CAPUTURED)
  607. {
  608. ReleaseCapture();
  609. if (dwT & FIM_MOVED)
  610. {
  611. DrawUIBorder(&drc);
  612. if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
  613. GetCursorPos( &pt );
  614. MoveWindow(hWnd,pt.x - ptdif.x,
  615. pt.y - ptdif.y,
  616. sz.cx,
  617. sz.cy,TRUE);
  618. if(fIsCompWnd) {
  619. HWND hUIWnd;
  620. LPARAM mylParam;
  621. *((LPWORD)(&mylParam)) = (WORD)(pt.x - ptdif.x);
  622. *((LPWORD)(&mylParam)+1) = (WORD)(pt.y - ptdif.y);
  623. hUIWnd = (HWND)GetWindowLong(hWnd,FIGWL_SVRWND);
  624. if (IsWindow(hUIWnd))
  625. SendMessage(hUIWnd,WM_UI_COMPMOVE,0,mylParam);
  626. }
  627. if (IsWindow(hWnd1)) {
  628. MoveWindow(hWnd1,pt.x - ptdif1.x,
  629. pt.y - ptdif1.y,
  630. sz1.cx,
  631. sz1.cy,TRUE);
  632. }
  633. }
  634. }
  635. break;
  636.     }
  637. }
  638. void SelectCandFromCandlist( HIMC hIMC, WORD wParam)
  639. {
  640. if( wParam >= _T('0') && wParam <= _T('9') ){
  641. DWORD dwIdx;
  642. LPTSTR lpConvStr,lpStr;
  643.     LPINPUTCONTEXT lpIMC;
  644. LPCANDIDATEINFO lpCandInfo;
  645. LPCANDIDATELIST lpCandList;
  646. LPCOMPOSITIONSTRING lpCompStr;
  647. UINT lpConvStrLen;
  648. lpIMC = ImmLockIMC(hIMC);
  649. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  650. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  651. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  652. lpStr = GETLPCOMPSTR(lpCompStr);
  653.     if( wParam == (WORD)_T('0')) dwIdx=9;
  654. else dwIdx = wParam - _T('1');
  655. if(dwIdx < lpCandList->dwPageSize ) {
  656. dwIdx += lpCandList->dwPageStart;
  657. //DebugLog(2,(DebugLogFile,"dwIdx: %dn",dwIdx));
  658. if( dwIdx < (lpCandList->dwCount + 2) && lpCandList->dwCount){
  659. lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
  660. _tcscpy(lpConvStr,GETLPCANDSTR(lpCandList,dwIdx));
  661. lpConvStrLen=_tcslen(lpConvStr);
  662. //DebugLog(2,(DebugLogFile,"lpConvStr: %sn",lpConvStr));
  663. //实现五笔的自动提示词的自动加入
  664. if(wConversionMode == CONVERSION_MODE_WUBI && HaveAutoCandList && 
  665. (dwIdx==CodeHintTextBegin+1)&&!_tcscmp(AutoWuBiCode1,AutoWuBiCode)){//lpCandList->dwCount+1
  666. if(wConversionSet1 & C_SET1_ERBIMAKEWORD) AutoGetWordErbiCode(AutoWuBiWord,1);
  667. else AutoGetWordWubiCode(AutoWuBiWord,1);
  668. _tcscpy(AutoWuBiCode1,_T(""));
  669. // SaveWubiUserDict();
  670. }
  671. //词频调整,加入if( wConversionSet & CONVERSION_SET_SORT)
  672. if((wConversionMode == CONVERSION_MODE_WUBI) && 
  673. (wConversionSet & CONVERSION_SET_SORT) &&
  674. (lpConvStrLen>2||wConversionSet1 & C_SET1_SingleHZAdjFre)) {
  675. //AdjustOrderByIndex (dwIdx-2);
  676. if(dwIdx>CodeHintTextBegin+1 && HaveAutoCandList)
  677. AdjustOrderByIndexToNo1(dwIdx-3,lpConvStr);
  678. else 
  679. AdjustOrderByIndexToNo1(dwIdx-2,lpConvStr);
  680. }
  681. //DebugLog(2,(DebugLogFile,"dwIdx: %d lpCandList->dwCount:%dn ",dwIdx,lpCandList->dwCount));
  682. MakeResultString(hIMC,TRUE);
  683. lpCandList->dwPageStart=2;
  684. }
  685. else if(PunctPushWordFlag){
  686. lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
  687. _tcscpy(lpConvStr,lpStr);
  688. lpConvStrLen=_tcslen(lpConvStr);
  689. }
  690. else MakeResultString(hIMC,FALSE);
  691. }
  692. //myexit:
  693. ImmUnlockIMCC(lpIMC->hCompStr);
  694. ImmUnlockIMCC(lpIMC->hCandInfo);
  695. ImmUnlockIMC(hIMC);
  696. }
  697. return;
  698. }
  699. void DeleteCharBackward(HIMC hIMC,WORD wParam)
  700. {
  701. if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR){
  702. MakeResultString(hIMC,FALSE);
  703. }
  704. else if( wConversionMode == CONVERSION_MODE_I   || 
  705.  wConversionMode == CONVERSION_MODE_U   || 
  706.  wConversionMode == CONVERSION_MODE_V ) {
  707. //时间,自定义模式
  708.     LPINPUTCONTEXT lpIMC;
  709. LPCANDIDATEINFO lpCandInfo;
  710. LPCANDIDATELIST lpCandList;
  711. LPCOMPOSITIONSTRING lpCompStr;
  712. GENEMSG GnMsg;
  713. LPTSTR lpStr;
  714. lpIMC = ImmLockIMC(hIMC);
  715. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  716. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  717. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  718. if( !lpCandList->dwCount ) MakeResultString(hIMC,FALSE);
  719. else{
  720. lpCandList->dwCount = 0;
  721. lpStr = GETLPCOMPSTR(lpCompStr);
  722. lpStr = CharPrev(lpStr,lpStr + _tcslen(lpStr));
  723. *lpStr= _T('');
  724. lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  725. lpStr = CharPrev(lpStr,lpStr + _tcslen(lpStr));
  726. *lpStr= _T('');
  727. GnMsg.msg = WM_IME_COMPOSITION;
  728. GnMsg.wParam = 0;
  729. GnMsg.lParam = GCS_COMPSTR;
  730. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  731. }
  732. ImmUnlockIMCC(lpIMC->hCompStr);
  733. ImmUnlockIMCC(lpIMC->hCandInfo);
  734. ImmUnlockIMC(hIMC);
  735. }
  736. else if( wConversionMode == CONVERSION_MODE_WUBIATTACHLIB) {
  737. //五笔附库模式//退格成功。
  738.     LPINPUTCONTEXT lpIMC;
  739. LPCOMPOSITIONSTRING lpCompStr;
  740. LPTSTR lpStr;
  741. WORD StrLen;
  742. lpIMC = ImmLockIMC(hIMC);
  743. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  744. lpStr = GETLPCOMPSTR(lpCompStr);
  745. StrLen=_tcslen(lpStr);
  746. lpStr = CharPrev(lpStr,lpStr + StrLen);
  747. *lpStr= _T('');
  748. if(StrLen<=1){
  749. ImmUnlockIMCC(lpIMC->hCompStr);
  750. ImmUnlockIMC(hIMC);
  751. MakeResultString(hIMC,FALSE);
  752. return;
  753. }
  754. lpStr = GETLPCOMPSTR(lpCompStr);
  755. StrLen=_tcslen(lpStr);
  756. wParam=*(lpStr+StrLen-1);
  757. *(lpStr+StrLen-1)=_T('');
  758. wubiDictCurrentRecord=wubiDictHead->next;//应对快速搜索
  759. AttachLibDictCurrentRecord=AttachLibDictHead->next;//应对快速搜索
  760. CodeForward=0;
  761. ImmUnlockIMCC(lpIMC->hCompStr);
  762. ImmUnlockIMC(hIMC);
  763. CharHandleWuBiAttachLib(hIMC,wParam,0) ;
  764. }
  765. else if( wConversionMode == CONVERSION_MODE_WUBI) {
  766. //五笔模式//退格成功。
  767.     LPINPUTCONTEXT lpIMC;
  768. LPCOMPOSITIONSTRING lpCompStr;
  769. LPTSTR lpStr;
  770. WORD StrLen;
  771. TCHAR cFirstChr;
  772. lpIMC = ImmLockIMC(hIMC);
  773. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  774. lpStr = GETLPCOMPSTR(lpCompStr);
  775. StrLen=_tcslen(lpStr);
  776. lpStr = CharPrev(lpStr,lpStr + StrLen);
  777. *lpStr= _T('');
  778. /*if(StrLen==0){
  779. ImmUnlockIMCC(lpIMC->hCompStr);
  780. ImmUnlockIMC(hIMC);
  781. return;
  782. }
  783. else*/ 
  784. if(StrLen<=1){
  785. ImmUnlockIMCC(lpIMC->hCompStr);
  786. ImmUnlockIMC(hIMC);
  787. MakeResultString(hIMC,FALSE);
  788. return;
  789. }
  790. lpStr = GETLPCOMPSTR(lpCompStr);
  791. StrLen=_tcslen(lpStr);
  792. wParam=*(lpStr+StrLen-1);
  793. *(lpStr+StrLen-1)=_T('');
  794. if(cFirstChr=*lpStr){
  795. SetwubiFirstLeadChr(cFirstChr);
  796. wubiDictCurrentRecord=wubiFirstLeadChr[cFirstChr-_T('!')];
  797. }
  798. else 
  799. wubiDictCurrentRecord=wubiDictHead->next;//应对快速搜索
  800. CodeForward=0;
  801. ImmUnlockIMCC(lpIMC->hCompStr);
  802. ImmUnlockIMC(hIMC);
  803. CharHandleWuBi(hIMC,wParam,0);
  804. }
  805. else if( wConversionMode == CONVERSION_MODE_ATTACHLIB||
  806.  wConversionMode == CONVERSION_MODE_TEMPATTACHLIB) {
  807. //附加词库模式//退格成功。
  808.     LPINPUTCONTEXT lpIMC;
  809. LPCOMPOSITIONSTRING lpCompStr;
  810. LPTSTR lpStr;
  811. WORD StrLen;
  812. lpIMC = ImmLockIMC(hIMC);
  813. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  814. lpStr = GETLPCOMPSTR(lpCompStr);
  815. StrLen=_tcslen(lpStr);
  816. lpStr = CharPrev(lpStr,lpStr + StrLen);
  817. *lpStr= _T('');
  818. if(StrLen<=1){
  819. ImmUnlockIMCC(lpIMC->hCompStr);
  820. ImmUnlockIMC(hIMC);
  821. MakeResultString(hIMC,FALSE);
  822. return;
  823. }
  824. lpStr = GETLPCOMPSTR(lpCompStr);
  825. StrLen=_tcslen(lpStr);
  826. wParam=*(lpStr+StrLen-1);
  827. *(lpStr+StrLen-1)=_T('');
  828. AttachLibDictCurrentRecord=AttachLibDictHead->next;//应对快速搜索
  829. CodeForward=0;
  830. ImmUnlockIMCC(lpIMC->hCompStr);
  831. ImmUnlockIMC(hIMC);
  832. CharHandleAttachLib(hIMC,wParam,0) ;
  833. }
  834. else AddChar(hIMC,wParam,EDIT_BACK);
  835. return;
  836. }
  837. void DeleteCharForward(HIMC hIMC,WORD wParam)
  838. {
  839. WORD WordHistoryStrLen=_tcslen(WordHistoryStr);
  840. if(wConversionMode == CONVERSION_MODE_WUBI) 
  841. *(WordHistoryStr+WordHistoryStrLen-2)=_T('');
  842. AddChar(hIMC,wParam,EDIT_DELETE);
  843. return;
  844. }
  845. void SpaceSelect(HIMC hIMC,WORD wParam)
  846. {
  847. WORD wCode;
  848. wCode = (WORD)_T('1');
  849. //DebugLog(2,(DebugLogFile,"wParam: %d  ",wParam));
  850. if(wConversionMode == CONVERSION_MODE_PHRASETOCHAR)
  851. CharHandlePhToCh( hIMC,wCode,0);
  852. else if( wConversionMode == CONVERSION_MODE_I   || 
  853. wConversionMode == CONVERSION_MODE_U   ||
  854. wConversionMode == CONVERSION_MODE_V   ||
  855. wConversionMode == CONVERSION_MODE_ATTACHLIB   ||
  856. wConversionMode == CONVERSION_MODE_TEMPATTACHLIB   ||
  857. wConversionMode == CONVERSION_MODE_WUBI ||
  858. wConversionMode == CONVERSION_MODE_WUBIATTACHLIB ) {
  859. SelectCandFromCandlist( hIMC, wCode);
  860. }
  861. else
  862. SelectCand(hIMC,wCode);
  863. return;
  864. }
  865. void SelectForwardFromCand(HIMC hIMC,LPCANDIDATELIST lpCandList)
  866. {
  867. HDC hDC;
  868. HFONT oldFont;
  869. TCHAR szTotal[200],szTemp[100];
  870. SIZE sz;
  871. WORD wPos;
  872. GENEMSG GnMsg;
  873. //
  874. /*if(wConversionMode == CONVERSION_MODE_WUBI&&
  875. lpCandList->dwPageStart<lpCandList->dwCount-8){
  876. lpCandList->dwPageStart+=10;
  877. }*/
  878. //DebugLog(2,(DebugLogFile,"1 start: %d  pagesize: %dn",lpCandList->dwPageStart,lpCandList->dwCount-8));
  879. //
  880. if(wConversionSet & CONVERSION_SET_SHAPE) {
  881. wPos = (WORD) lpCandList->dwSelection;
  882. if(wPos < lpCandList->dwCount) {
  883. hDC = GetDC(NULL);
  884. oldFont = SelectObject(hDC, hUIFont);
  885. lpCandList->dwPageStart = wPos + 2;
  886. _tcscpy(szTotal,"<>");
  887. lpCandList->dwPageSize = 0;
  888. while(wPos < lpCandList->dwCount && lpCandList->dwPageSize < CAND_PAGESIZE) {
  889. _stprintf(szTemp,"%d%s ",1,GETLPCANDSTR(lpCandList,wPos+2));
  890. _tcscat(szTotal,szTemp);
  891. GetTextExtentPoint(hDC,szTotal,_tcslen(szTotal),&sz);
  892. if(sz.cx > sizeCand[1].cx*2) {//yjm
  893. break;
  894. }
  895. (lpCandList->dwPageSize)++;
  896. wPos++;
  897. //DebugLog(2,(DebugLogFile,"4 wPos: %d  lpCandList->dwPageSize: %dn",wPos,lpCandList->dwPageSize));
  898. }
  899. SelectObject(hDC, oldFont);
  900. ReleaseDC(NULL,hDC);
  901. lpCandList->dwSelection = wPos;
  902. if(lpCandList->dwPageStart > 2)
  903. _tcscpy(GETLPCANDSTR(lpCandList,0),_T("<"));
  904. else
  905. _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
  906. if(wPos < lpCandList->dwCount)
  907. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(">"));
  908. else
  909. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
  910. GnMsg.msg = WM_IME_COMPOSITION;
  911. GnMsg.wParam = 0;
  912. GnMsg.lParam = GCS_COMPSTR;
  913. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  914. }
  915. else MessageBeep(0xFFFFFFFF );
  916. }
  917. else{
  918. if( lpCandList->dwPageStart + lpCandList->dwPageSize -2 < 
  919. lpCandList->dwCount) {
  920. lpCandList->dwPageStart += lpCandList->dwPageSize;
  921. lpCandList->dwPageSize = CAND_PAGESIZE;
  922. GnMsg.msg = WM_IME_COMPOSITION;
  923. GnMsg.wParam = 0;
  924. GnMsg.lParam = GCS_COMPSTR;
  925. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  926. }
  927. else MessageBeep(0xFFFFFFFF );
  928. }
  929. }
  930. void SelectBackwardFromCand(HIMC hIMC,LPCANDIDATELIST lpCandList)
  931. {
  932. HDC hDC;
  933. HFONT oldFont;
  934. TCHAR szTotal[200],szTemp[100];
  935. SIZE sz;
  936. WORD wCount;
  937. GENEMSG GnMsg;
  938. //
  939. //DebugLog(2,(DebugLogFile,"1 start: %d  pagesize: %dn",lpCandList->dwPageStart,lpCandList->dwCount-8));
  940. //
  941. if(lpCandList->dwPageStart > 2) {
  942. if(wConversionSet & CONVERSION_SET_SHAPE) {
  943. hDC = GetDC(NULL);
  944. oldFont = SelectObject(hDC, hUIFont);
  945. lpCandList->dwSelection = (WORD)lpCandList->dwPageStart - 2;
  946. wCount = (WORD)lpCandList->dwPageStart - 2;
  947. _tcscpy(szTotal,"<>");
  948. lpCandList->dwPageSize = 0;
  949. while(wCount > 0 && lpCandList->dwPageSize < CAND_PAGESIZE) {
  950. _stprintf(szTemp,"%d%s ",1,GETLPCANDSTR(lpCandList,wCount+2));
  951. _tcscat(szTotal,szTemp);
  952. GetTextExtentPoint(hDC,szTotal,_tcslen(szTotal),&sz);
  953. if(sz.cx > sizeCand[1].cx*2) {//yjm
  954. break;
  955. }
  956. (lpCandList->dwPageSize)++;
  957. wCount--;
  958. }
  959. SelectObject(hDC, oldFont);
  960. ReleaseDC(NULL,hDC);
  961. lpCandList->dwPageStart -= (lpCandList->dwSelection - wCount);
  962. if(lpCandList->dwPageStart > 2)
  963. _tcscpy(GETLPCANDSTR(lpCandList,0),_T("<"));
  964. else
  965. _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
  966. if(lpCandList->dwSelection < lpCandList->dwCount)
  967. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(">"));
  968. else
  969. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
  970. }
  971. else {
  972. if( (int)(lpCandList->dwPageStart) - (int)(lpCandList->dwPageSize)  >= 1){ 
  973. lpCandList->dwPageStart -= lpCandList->dwPageSize;
  974. }
  975. }
  976. GnMsg.msg = WM_IME_COMPOSITION;
  977. GnMsg.wParam = 0;
  978. GnMsg.lParam = GCS_COMPSTR;
  979. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  980. }
  981. else MessageBeep(0xFFFFFFFF );
  982. }
  983. void SetPaintColor(HDC hDC, WORD wMode)
  984. {
  985. if(wMode == CONVERSION_MODE_PHRASETOCHAR) {
  986. SetTextColor(hDC,RGB(0,0,128));
  987. }
  988. else if(wMode == CONVERSION_MODE_U||wMode == CONVERSION_MODE_WUBI) {
  989. SetTextColor(hDC,RGB(128,0,0));
  990. }
  991. else if(wMode == CONVERSION_MODE_I) {
  992. SetTextColor(hDC,RGB(0,128,128));
  993. }
  994. else if(wMode == CONVERSION_MODE_V) {
  995. SetTextColor(hDC,RGB(128,0,128));
  996. }
  997. else{
  998. SetTextColor(hDC,RGB(0,0,0));
  999. }
  1000. }