subs.c
上传用户:shdz666
上传日期:2007-01-03
资源大小:566k
文件大小:26k
源码类别:

输入法编程

开发平台:

Visual C++

  1. /*
  2.  * Copyright (C) 1999.4  Li ZhenChun
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License; or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that is will be useful, but
  10.  * WITHOUT ANY WARRANTY; without even the implied warranty of 
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12.  * General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 675 Mass Ave, Cambridge, M A 02139, USA.
  17.  *
  18.  * Author: Li ZhenChun  email: zhchli@163.net or zhchli@126.com
  19.  * 
  20.  */
  21. #include "freepy.h"
  22. BOOL IsCompStr(HIMC hIMC)
  23. {
  24.     LPINPUTCONTEXT lpIMC;
  25.     LPCOMPOSITIONSTRING lpCompStr;
  26.     BOOL fRet = FALSE;
  27.     if (!(lpIMC = ImmLockIMC(hIMC)))
  28.         return FALSE;
  29.     if (ImmGetIMCCSize(lpIMC->hCompStr) < sizeof (COMPOSITIONSTRING))
  30.     {
  31.         ImmUnlockIMC(hIMC);
  32.         return FALSE;
  33.     }
  34.     lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  35.     fRet = (lpCompStr->dwCompStrLen > 0);
  36.     ImmUnlockIMCC(lpIMC->hCompStr);
  37.     ImmUnlockIMC(hIMC);
  38.     return fRet;
  39. }
  40. /**********************************************************************/
  41. /*                                                                    */
  42. /*      InitCompStr()                                                  */
  43. /*                                                                    */
  44. /**********************************************************************/
  45. void InitCompStr(LPCOMPOSITIONSTRING lpCompStr)
  46. {
  47. LPFREEPYCOMP lpFreePYComp;
  48. lpCompStr->dwSize = sizeof(MYCOMPSTR);
  49. lpCompStr->dwCompStrOffset = 
  50.             (DWORD)((LPMYCOMPSTR)lpCompStr)->szCompStr - (DWORD)lpCompStr;
  51. lpCompStr->dwCompStrLen = 0;
  52. *GETLPCOMPSTR(lpCompStr) = _T('');
  53. lpCompStr->dwResultStrOffset = 
  54.           (DWORD)((LPMYCOMPSTR)lpCompStr)->szResultStr - (DWORD)lpCompStr;
  55. lpCompStr->dwResultStrLen = 0;
  56. *GETLPRESULTSTR(lpCompStr) = _T('');
  57. lpCompStr->dwCursorPos = 0;
  58. lpFreePYComp= &(((LPMYCOMPSTR)lpCompStr)->FreePYComp);
  59. lpFreePYComp->szConvCompStr[0] = _T('');
  60. lpFreePYComp->szPaintCompStr[0] = _T('');
  61. lpFreePYComp->szPreResultStr[0] = _T('');
  62. lpFreePYComp->wEditCaret = 0;
  63. lpFreePYComp->wUnConvPos = 0;
  64. lpFreePYComp->wPYArrayLen = 0;
  65. lpFreePYComp->wPYArrayCurPos = 0;
  66. }
  67. void ClearCompStr(LPCOMPOSITIONSTRING lpCompStr)
  68. {
  69. LPFREEPYCOMP lpFreePYComp;
  70. lpCompStr->dwCursorPos = 0;
  71. lpCompStr->dwCompStrLen = 0;
  72. ((LPMYCOMPSTR)lpCompStr)->szCompStr[0] = _T('');
  73. lpCompStr->dwResultStrLen = 0;
  74. ((LPMYCOMPSTR)lpCompStr)->szResultStr[0] = _T('');
  75. lpFreePYComp= &(((LPMYCOMPSTR)lpCompStr)->FreePYComp);
  76. lpFreePYComp->szConvCompStr[0] = _T('');
  77. lpFreePYComp->szPaintCompStr[0] = _T('');
  78. lpFreePYComp->wEditCaret = 0;
  79. lpFreePYComp->wUnConvPos = 0;
  80. lpFreePYComp->wPYArrayLen = 0;
  81. lpFreePYComp->wPYArrayCurPos = 0;
  82. }
  83. BOOL IsCandidate(HIMC hIMC)
  84. {
  85.     LPINPUTCONTEXT lpIMC;
  86.     LPCANDIDATEINFO lpCandInfo;
  87. LPCANDIDATELIST lpCandList;
  88.     BOOL fRet = FALSE;
  89.     if (!(lpIMC = ImmLockIMC(hIMC)))
  90.         return FALSE;
  91.     if (ImmGetIMCCSize(lpIMC->hCandInfo) < sizeof (CANDIDATEINFO)){
  92. ImmUnlockIMC(hIMC);
  93.         return FALSE;
  94. }
  95.     lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  96. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo  + lpCandInfo->dwOffset[0]);
  97.     fRet = (lpCandList->dwCount > 0);
  98.     ImmUnlockIMCC(lpIMC->hCandInfo);
  99. ImmUnlockIMC(hIMC);
  100.     return fRet;
  101. }
  102. void InitCandInfo(LPCANDIDATEINFO lpCandInfo)
  103. {
  104. LPCANDIDATELIST lpCandList;
  105. LPFREEPYCAND lpFreePYCand;
  106. int i;
  107. lpCandInfo->dwSize = sizeof(MYCAND);
  108. lpCandInfo->dwCount = 1;
  109. lpCandInfo->dwOffset[0] = 
  110. (DWORD)(&(((LPMYCAND)lpCandInfo)->cl)) - (DWORD)lpCandInfo;
  111. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo  + lpCandInfo->dwOffset[0]);
  112. for(i=0;i<MAXCANDSTRNUM;i++) {
  113. lpCandList->dwOffset[i] = 
  114.                    (DWORD)((LPMYCAND)lpCandInfo)->szCandStr[i] - (DWORD)lpCandList;
  115. }
  116. lpCandList->dwSize = sizeof(MYCAND) - sizeof(CANDIDATEINFO); 
  117. lpCandList->dwCount = 0L;
  118. lpCandList->dwSelection = 0L;
  119. lpCandList->dwPageStart = 0L;
  120. lpCandList->dwPageSize = 0L;
  121. lpFreePYCand= &(((LPMYCAND)lpCandInfo)->FreePYCand);
  122. lpFreePYCand->wPhraseNum = 0;
  123. lpFreePYCand->wHZNum = 0;
  124. lpFreePYCand->wKeyLen = 0;
  125. lpFreePYCand->abKey[0] = 0;
  126. }
  127. void ClearCandidate(LPCANDIDATEINFO lpCandInfo)
  128. {
  129. LPFREEPYCAND lpFreePYCand;
  130.     ((LPMYCAND)lpCandInfo)->cl.dwCount =0L;
  131.     ((LPMYCAND)lpCandInfo)->cl.dwSelection =0L;
  132.     ((LPMYCAND)lpCandInfo)->cl.dwPageStart =0L;
  133.     ((LPMYCAND)lpCandInfo)->cl.dwPageSize =0L;
  134. lpFreePYCand= &(((LPMYCAND)lpCandInfo)->FreePYCand);
  135. lpFreePYCand->wPhraseNum = 0;
  136. lpFreePYCand->wHZNum = 0;
  137. lpFreePYCand->wKeyLen = 0;
  138. lpFreePYCand->abKey[0] = 0;
  139. }
  140. HKL GetMyHKL()
  141. {
  142.     DWORD dwSize;
  143.     DWORD dwi;
  144.     HKL hKL = 0;
  145.     HKL *lphkl;
  146.     dwSize = GetKeyboardLayoutList(0, NULL);
  147.     lphkl = (HKL *)GlobalAlloc(GPTR, dwSize * sizeof(DWORD));
  148.     if (!lphkl)
  149.         return NULL;
  150.     GetKeyboardLayoutList(dwSize, lphkl);
  151.     for (dwi = 0; dwi < dwSize; dwi++)
  152.     {
  153.         char szFile[32];
  154.         HKL hKLTemp = *(lphkl + dwi);
  155.         ImmGetIMEFileName(hKLTemp, szFile, sizeof(szFile));
  156.         if (!_tcsicmp(szFile, FREEPYFILENAME))
  157.         {
  158.              hKL = hKLTemp;
  159.              goto exit;
  160.         }
  161.     }
  162. exit:
  163.     GlobalFree((HANDLE)lphkl);
  164.     return hKL;
  165. }
  166. /*****************************************************************************
  167. *                                                                            *
  168. * UpdateIndicIcon( hIMC )                                                    *
  169. *                                                                            *
  170. *****************************************************************************/
  171. void UpdateIndicIcon(HIMC hIMC)
  172. {
  173.     HWND hwndIndicate;
  174.     BOOL fOpen = FALSE;
  175.     LPINPUTCONTEXT lpIMC;
  176.     if (!hFreePYKL)
  177.     {
  178.        hFreePYKL = GetMyHKL();
  179.        if (!hFreePYKL)
  180.            return;
  181.     }
  182.     hwndIndicate = FindWindow(INDICATOR_CLASS, NULL);
  183.     if (hIMC)
  184.     {
  185.         lpIMC = ImmLockIMC(hIMC);
  186.         if (lpIMC)
  187.         {
  188.             fOpen = lpIMC->fOpen;
  189.             ImmUnlockIMC(hIMC);
  190.         }
  191.     }
  192.     if (IsWindow(hwndIndicate))
  193.     {
  194.         ATOM atomTip;
  195.         atomTip = GlobalAddAtom(ATOMTIP);
  196.         PostMessage(hwndIndicate, INDICM_SETIMEICON, 
  197.                     fOpen ? 1 : (-1), (LPARAM)hFreePYKL);
  198.         PostMessage(hwndIndicate, INDICM_SETIMETOOLTIPS, 
  199.                     fOpen ? atomTip : (-1), (LPARAM)hFreePYKL);
  200.         PostMessage(hwndIndicate, INDICM_REMOVEDEFAULTMENUITEMS, 
  201.                     // fOpen ? (RDMI_LEFT | RDMI_RIGHT) : 0, (LPARAM)hMyKL);
  202.                     fOpen ? (RDMI_LEFT) : 0, (LPARAM)hFreePYKL);
  203.     }
  204. }
  205. /**********************************************************************/
  206. /*                                                                    */
  207. /* MyIsIMEMessage(message)                                            */
  208. /*                                                                    */
  209. /* Any UI window should not pass the IME messages to DefWindowProc.   */
  210. /*                                                                    */
  211. /**********************************************************************/
  212. BOOL MyIsIMEMessage(UINT message)
  213. {
  214.     switch(message)
  215.     {
  216.             case WM_IME_STARTCOMPOSITION:
  217.             case WM_IME_ENDCOMPOSITION:
  218.             case WM_IME_COMPOSITION:
  219.             case WM_IME_NOTIFY:
  220.             case WM_IME_SETCONTEXT:
  221.             case WM_IME_CONTROL:
  222.             case WM_IME_COMPOSITIONFULL:
  223.             case WM_IME_SELECT:
  224.             case WM_IME_CHAR:
  225.                 return TRUE;
  226.     }
  227.     return FALSE;
  228. }
  229. BOOL MakeResultString( HIMC hIMC,BOOL fFlag)
  230. {
  231.     GENEMSG GnMsg;
  232.     LPCOMPOSITIONSTRING lpCompStr;
  233.     LPINPUTCONTEXT lpIMC;
  234. LPTSTR lpConvStr,lpPreResultStr;
  235. LPCANDIDATEINFO lpCandInfo;
  236. LPCANDIDATELIST lpCandList;
  237. /*
  238.     if (!IsCompStr(hIMC))
  239.         return FALSE;
  240. */
  241. wConversionMode = 0;
  242.     lpIMC = ImmLockIMC(hIMC);
  243.     lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  244. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  245. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  246. if(fFlag) {
  247. lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
  248. lpPreResultStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPreResultStr;
  249. _tcscpy(GETLPRESULTSTR(lpCompStr),lpConvStr);
  250. _tcscpy(lpPreResultStr,lpConvStr);
  251. lpCompStr->dwResultStrLen = _tcslen(lpConvStr);
  252. }
  253. else{
  254. *GETLPRESULTSTR(lpCompStr) = _T('');
  255. lpCompStr->dwResultStrLen = 0;
  256. }
  257. lpCandList->dwCount = 0;
  258.     lpCompStr->dwCompStrLen = 0;
  259. _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
  260. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
  261. ImmUnlockIMCC(lpIMC->hCompStr);
  262. ImmUnlockIMCC(lpIMC->hCandInfo);
  263. GnMsg.msg = WM_IME_COMPOSITION;
  264. GnMsg.wParam = 0;
  265. GnMsg.lParam = GCS_RESULTSTR;
  266. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  267. GnMsg.msg = WM_IME_ENDCOMPOSITION;
  268. GnMsg.wParam = 0;
  269. GnMsg.lParam = 0;
  270. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  271.     ImmUnlockIMC(hIMC);
  272.     return TRUE;
  273. }
  274. /**********************************************************************/
  275. /*                                                                    */
  276. /*      GenerateMessage()                                             */
  277. /*                                                                    */
  278. /*      Update the transrate key buffer.                              */
  279. /*                                                                    */
  280. /**********************************************************************/
  281. BOOL GenerateMessage(HIMC hIMC, LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
  282. {
  283.     LPINPUTCONTEXT lpIMC;
  284. if( (lpIMC = ImmLockIMC(hIMC)) == NULL ) return FALSE;
  285.     if (lpdwTransKey){
  286. ImmUnlockIMC(hIMC);
  287.         return GenerateMessageToTransKey(lpdwTransKey,lpGeneMsg);
  288. }
  289.     
  290.     if (IsWindow(lpIMC->hWnd))
  291.     {
  292.         LPDWORD lpdw;
  293.         if (!(lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf,
  294. sizeof(DWORD) * (lpIMC->dwNumMsgBuf +1) * 3)))
  295.             return FALSE;
  296.         if (!(lpdw = (LPDWORD)ImmLockIMCC(lpIMC->hMsgBuf)))
  297.             return FALSE;
  298.         lpdw += (lpIMC->dwNumMsgBuf) * 3;
  299.         *((LPGENEMSG)lpdw) = *lpGeneMsg;
  300.         ImmUnlockIMCC(lpIMC->hMsgBuf);
  301.         lpIMC->dwNumMsgBuf++;
  302.         ImmGenerateMessage(hIMC);
  303.     }
  304. ImmUnlockIMC(hIMC);
  305.     return TRUE;
  306. }
  307. /**********************************************************************/
  308. /*      GenerateMessageToTransKey()                                   */
  309. /*                                                                    */
  310. /*      Update the transrate key buffer.                              */
  311. /**********************************************************************/
  312. BOOL GenerateMessageToTransKey(LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
  313. {
  314. LPDWORD lpdwTemp;
  315.     uNumTransKey++;
  316.     if (uNumTransKey >= (UINT)*lpdwTransKey)
  317.     {
  318.         fOverTransKey = TRUE;
  319.         return FALSE;
  320.     }
  321. lpdwTemp = (LPDWORD)lpdwTransKey + 1 + (uNumTransKey - 1)*3;
  322. *(lpdwTemp++) = lpGeneMsg->msg;
  323. *(lpdwTemp++) = lpGeneMsg->wParam;
  324. *(lpdwTemp++) = lpGeneMsg->lParam;
  325.     return TRUE;
  326. }
  327. /**********************************************************************/
  328. /*                                                                    */
  329. /* DrawUIBorder()                                                     */
  330. /*                                                                    */
  331. /* When draging the child window, this function draws the border.     */
  332. /*                                                                    */
  333. /**********************************************************************/
  334. void DrawUIBorder( LPRECT lprc )
  335. {
  336.     HDC hDC;
  337.     int sbx, sby;
  338.     hDC = CreateDC( "DISPLAY", NULL, NULL, NULL );
  339.     SelectObject( hDC, GetStockObject( GRAY_BRUSH ) );
  340.     sbx = GetSystemMetrics( SM_CXBORDER );
  341.     sby = GetSystemMetrics( SM_CYBORDER );
  342.     PatBlt( hDC, lprc->left, 
  343. lprc->top, 
  344. lprc->right - lprc->left-sbx, 
  345. sby, PATINVERT );
  346.     PatBlt( hDC, lprc->right - sbx, 
  347. lprc->top, 
  348. sbx, 
  349. lprc->bottom - lprc->top-sby, PATINVERT );
  350.     PatBlt( hDC, lprc->right, 
  351. lprc->bottom-sby, 
  352. -(lprc->right - lprc->left-sbx), 
  353. sby, PATINVERT );
  354.     PatBlt( hDC, lprc->left, 
  355. lprc->bottom, 
  356. sbx, 
  357. -(lprc->bottom - lprc->top-sby), PATINVERT );
  358.     DeleteDC( hDC );
  359. }
  360. void DragUI( HWND hWnd, HWND hWnd1,UINT message, WPARAM wParam, LPARAM lParam,BOOL fIsCompWnd)
  361. {
  362.     POINT     pt;
  363.     static    POINT ptdif,ptdif1;
  364.     static    RECT drc,drc1;
  365.     static    SIZE sz,sz1;
  366.     DWORD     dwT;
  367.     switch (message)
  368.     {
  369. case WM_SETCURSOR:
  370. if ( HIWORD(lParam) == WM_LBUTTONDOWN
  371. || HIWORD(lParam) == WM_RBUTTONDOWN ) 
  372. {
  373. GetCursorPos( &pt );
  374. SetCapture(hWnd);
  375. GetWindowRect(hWnd,&drc);
  376. ptdif.x = pt.x - drc.left;
  377. ptdif.y = pt.y - drc.top;
  378. sz.cx = drc.right - drc.left;
  379. sz.cy = drc.bottom - drc.top;
  380. if (IsWindow(hWnd1)) {
  381. GetWindowRect(hWnd1,&drc1);
  382. ptdif1.x = pt.x - drc1.left;
  383. ptdif1.y = pt.y - drc1.top;
  384. sz1.cx = drc1.right - drc1.left;
  385. sz1.cy = drc1.bottom - drc1.top;
  386. }
  387. SetWindowLong(hWnd,FIGWL_MOUSE,FIM_CAPUTURED);
  388. }
  389. break;
  390. case WM_MOUSEMOVE:
  391. dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
  392. if (dwT & FIM_MOVED)
  393. {
  394. DrawUIBorder(&drc);
  395. if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
  396. GetCursorPos( &pt );
  397. drc.left   = pt.x - ptdif.x;
  398. drc.top    = pt.y - ptdif.y;
  399. drc.right  = drc.left + sz.cx;
  400. drc.bottom = drc.top + sz.cy;
  401. if (IsWindow(hWnd1)) {
  402. drc1.left   = pt.x - ptdif1.x;
  403. drc1.top    = pt.y - ptdif1.y;
  404. drc1.right  = drc1.left + sz1.cx;
  405. drc1.bottom = drc1.top + sz1.cy;
  406. }
  407. DrawUIBorder(&drc);
  408. if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
  409. }
  410. else if (dwT & FIM_CAPUTURED)
  411. {
  412. DrawUIBorder(&drc);
  413. if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
  414. SetWindowLong(hWnd,FIGWL_MOUSE,dwT | FIM_MOVED);
  415. }
  416. break;
  417. case WM_LBUTTONUP:
  418. case WM_RBUTTONUP:
  419. dwT = GetWindowLong(hWnd,FIGWL_MOUSE);
  420. if (dwT & FIM_CAPUTURED)
  421. {
  422. ReleaseCapture();
  423. if (dwT & FIM_MOVED)
  424. {
  425. DrawUIBorder(&drc);
  426. if (IsWindow(hWnd1)) DrawUIBorder(&drc1);
  427. GetCursorPos( &pt );
  428. MoveWindow(hWnd,pt.x - ptdif.x,
  429. pt.y - ptdif.y,
  430. sz.cx,
  431. sz.cy,TRUE);
  432. if(fIsCompWnd) {
  433. HWND hUIWnd;
  434. LPARAM mylParam;
  435. *((LPWORD)(&mylParam)) = (WORD)(pt.x - ptdif.x);
  436. *((LPWORD)(&mylParam)+1) = (WORD)(pt.y - ptdif.y);
  437. hUIWnd = (HWND)GetWindowLong(hWnd,FIGWL_SVRWND);
  438. if (IsWindow(hUIWnd))
  439. SendMessage(hUIWnd,WM_UI_COMPMOVE,0,mylParam);
  440. }
  441. if (IsWindow(hWnd1)) {
  442. MoveWindow(hWnd1,pt.x - ptdif1.x,
  443. pt.y - ptdif1.y,
  444. sz1.cx,
  445. sz1.cy,TRUE);
  446. }
  447. }
  448. }
  449. break;
  450.     }
  451. }
  452. void SelectCandFromCandlist( HIMC hIMC, WORD wParam)
  453. {
  454. if( wParam >= _T('0') && wParam <= _T('9') ){
  455. DWORD dwIdx;
  456. LPTSTR lpConvStr;
  457.     LPINPUTCONTEXT lpIMC;
  458. LPCANDIDATEINFO lpCandInfo;
  459. LPCANDIDATELIST lpCandList;
  460. LPCOMPOSITIONSTRING lpCompStr;
  461. lpIMC = ImmLockIMC(hIMC);
  462. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  463. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  464. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  465.     if( wParam == (WORD)_T('0') ) dwIdx=9;
  466. else dwIdx = wParam - _T('1');
  467. if(dwIdx < lpCandList->dwPageSize ) {
  468. dwIdx += lpCandList->dwPageStart;
  469. if( dwIdx < (lpCandList->dwCount + 2) && lpCandList->dwCount){
  470. lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
  471. _tcscpy(lpConvStr,GETLPCANDSTR(lpCandList,dwIdx));
  472. MakeResultString(hIMC,TRUE);
  473. }
  474. }
  475. ImmUnlockIMCC(lpIMC->hCompStr);
  476. ImmUnlockIMCC(lpIMC->hCandInfo);
  477. ImmUnlockIMC(hIMC);
  478. }
  479. return;
  480. }
  481. void DeleteCharBackward(HIMC hIMC,WORD wParam)
  482. {
  483. if(wConversionMode & CONVERSION_MODE_PHRASETOCHAR){
  484. MakeResultString(hIMC,FALSE);
  485. }
  486. else if( wConversionMode & CONVERSION_MODE_I   || 
  487.  wConversionMode & CONVERSION_MODE_U   ||
  488.  wConversionMode & CONVERSION_MODE_V ) {
  489.     LPINPUTCONTEXT lpIMC;
  490. LPCANDIDATEINFO lpCandInfo;
  491. LPCANDIDATELIST lpCandList;
  492. LPCOMPOSITIONSTRING lpCompStr;
  493. GENEMSG GnMsg;
  494. LPTSTR lpStr;
  495. lpIMC = ImmLockIMC(hIMC);
  496. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  497. lpCandList = (LPCANDIDATELIST)((LPSTR)lpCandInfo  + lpCandInfo->dwOffset[0]);
  498. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  499. if( !lpCandList->dwCount ) MakeResultString(hIMC,FALSE);
  500. else{
  501. lpCandList->dwCount = 0;
  502. lpStr = GETLPCOMPSTR(lpCompStr);
  503. lpStr = CharPrev(lpStr,lpStr + _tcslen(lpStr));
  504. *lpStr= _T('');
  505. lpStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  506. lpStr = CharPrev(lpStr,lpStr + _tcslen(lpStr));
  507. *lpStr= _T('');
  508. GnMsg.msg = WM_IME_COMPOSITION;
  509. GnMsg.wParam = 0;
  510. GnMsg.lParam = GCS_COMPSTR;
  511. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  512. }
  513. ImmUnlockIMCC(lpIMC->hCompStr);
  514. ImmUnlockIMCC(lpIMC->hCandInfo);
  515. ImmUnlockIMC(hIMC);
  516. }
  517. else AddChar(hIMC,wParam,EDIT_BACK);
  518. return;
  519. }
  520. void DeleteCharForward(HIMC hIMC,WORD wParam)
  521. {
  522. AddChar(hIMC,wParam,EDIT_DELETE);
  523. return;
  524. }
  525. void SpaceSelect(HIMC hIMC,WORD wParam)
  526. {
  527. WORD wCode;
  528. wCode = (WORD)_T('1');
  529. if(wConversionMode & CONVERSION_MODE_PHRASETOCHAR)
  530. CharHandlePhToCh( hIMC,wCode,0);
  531. else if( wConversionMode & CONVERSION_MODE_I   || 
  532. wConversionMode & CONVERSION_MODE_U   ||
  533. wConversionMode & CONVERSION_MODE_V ) {
  534. SelectCandFromCandlist( hIMC, wCode);
  535. }
  536. else
  537. SelectCand(hIMC,wCode);
  538. return;
  539. }
  540. void SelectForwardFromCand(HIMC hIMC,LPCANDIDATELIST lpCandList)
  541. {
  542. HDC hDC;
  543. TCHAR szTotal[200],szTemp[100];
  544. SIZE sz;
  545. WORD wPos;
  546. GENEMSG GnMsg;
  547. if(wConversionSet & CONVERSION_SET_SHAPE) {
  548. wPos = (WORD) lpCandList->dwSelection;
  549. if(wPos < lpCandList->dwCount) {
  550. hDC = GetDC(NULL);
  551. lpCandList->dwPageStart = wPos + 2;
  552. _tcscpy(szTotal,"<>");
  553. lpCandList->dwPageSize = 0;
  554. while(wPos < lpCandList->dwCount && lpCandList->dwPageSize < CAND_PAGESIZE) {
  555. _stprintf(szTemp,"%d%s ",1,GETLPCANDSTR(lpCandList,wPos+2));
  556. _tcscat(szTotal,szTemp);
  557. GetTextExtentPoint(hDC,szTotal,_tcslen(szTotal),&sz);
  558. if(sz.cx > sizeCand[1].cx) {
  559. break;
  560. }
  561. (lpCandList->dwPageSize)++;
  562. wPos++;
  563. }
  564. ReleaseDC(NULL,hDC);
  565. lpCandList->dwSelection = wPos;
  566. if(lpCandList->dwPageStart > 2)
  567. _tcscpy(GETLPCANDSTR(lpCandList,0),_T("<"));
  568. else
  569. _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
  570. if(wPos < lpCandList->dwCount)
  571. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(">"));
  572. else
  573. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
  574. GnMsg.msg = WM_IME_COMPOSITION;
  575. GnMsg.wParam = 0;
  576. GnMsg.lParam = GCS_COMPSTR;
  577. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  578. }
  579. else MessageBeep(0xFFFFFFFF );
  580. }
  581. else{
  582. if( lpCandList->dwPageStart + lpCandList->dwPageSize -2 < 
  583. lpCandList->dwCount) {
  584. lpCandList->dwPageStart += lpCandList->dwPageSize;
  585. lpCandList->dwPageSize = CAND_PAGESIZE;
  586. GnMsg.msg = WM_IME_COMPOSITION;
  587. GnMsg.wParam = 0;
  588. GnMsg.lParam = GCS_COMPSTR;
  589. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  590. }
  591. else MessageBeep(0xFFFFFFFF );
  592. }
  593. }
  594. void SelectBackwardFromCand(HIMC hIMC,LPCANDIDATELIST lpCandList)
  595. {
  596. HDC hDC;
  597. TCHAR szTotal[200],szTemp[100];
  598. SIZE sz;
  599. WORD wCount;
  600. GENEMSG GnMsg;
  601. if(lpCandList->dwPageStart > 2) {
  602. if(wConversionSet & CONVERSION_SET_SHAPE) {
  603. hDC = GetDC(NULL);
  604. lpCandList->dwSelection = (WORD)lpCandList->dwPageStart - 2;
  605. wCount = (WORD)lpCandList->dwPageStart - 2;
  606. _tcscpy(szTotal,"<>");
  607. lpCandList->dwPageSize = 0;
  608. while(wCount > 0 && lpCandList->dwPageSize < CAND_PAGESIZE) {
  609. _stprintf(szTemp,"%d%s ",1,GETLPCANDSTR(lpCandList,wCount+2));
  610. _tcscat(szTotal,szTemp);
  611. GetTextExtentPoint(hDC,szTotal,_tcslen(szTotal),&sz);
  612. if(sz.cx > sizeCand[1].cx) {
  613. break;
  614. }
  615. (lpCandList->dwPageSize)++;
  616. wCount--;
  617. }
  618. ReleaseDC(NULL,hDC);
  619. lpCandList->dwPageStart -= (lpCandList->dwSelection - wCount);
  620. if(lpCandList->dwPageStart > 2)
  621. _tcscpy(GETLPCANDSTR(lpCandList,0),_T("<"));
  622. else
  623. _tcscpy(GETLPCANDSTR(lpCandList,0),_T(""));
  624. if(lpCandList->dwSelection < lpCandList->dwCount)
  625. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(">"));
  626. else
  627. _tcscpy(GETLPCANDSTR(lpCandList,1),_T(""));
  628. }
  629. else {
  630. if( (int)(lpCandList->dwPageStart) - (int)(lpCandList->dwPageSize)  >= 1){ 
  631. lpCandList->dwPageStart -= lpCandList->dwPageSize;
  632. }
  633. }
  634. GnMsg.msg = WM_IME_COMPOSITION;
  635. GnMsg.wParam = 0;
  636. GnMsg.lParam = GCS_COMPSTR;
  637. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  638. }
  639. else MessageBeep(0xFFFFFFFF );
  640. }
  641. void SetPaintColor(HDC hDC, WORD wMode)
  642. {
  643. if(wMode & CONVERSION_MODE_PHRASETOCHAR) {
  644. SetTextColor(hDC,RGB(0,0,128));
  645. }
  646. else if(wMode & CONVERSION_MODE_U) {
  647. SetTextColor(hDC,RGB(128,0,0));
  648. }
  649. else if(wMode & CONVERSION_MODE_I) {
  650. SetTextColor(hDC,RGB(0,128,128));
  651. }
  652. else if(wMode & CONVERSION_MODE_V) {
  653. SetTextColor(hDC,RGB(128,0,128));
  654. }
  655. else{
  656. SetTextColor(hDC,RGB(0,0,0));
  657. }
  658. }
  659. BOOL WINAPI ConfigDialogProc(
  660. HWND hWnd,
  661. UINT message,
  662. WPARAM wParam,
  663. LPARAM lParam )
  664. {
  665. HKEY hKey,hChildKey;
  666. DWORD dwConvSet;
  667. DWORD dwData = sizeof(DWORD);
  668. DWORD dwDisposition;
  669. switch(message) {
  670. case WM_INITDIALOG:
  671. if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  672. _T("Software\freepy"),
  673. 0,
  674. KEY_READ,
  675. &hKey) == ERROR_SUCCESS ){
  676. if( RegQueryValueEx( hKey,
  677. _T("ConversionSet"),
  678. NULL,
  679. NULL,
  680. (LPBYTE)&dwConvSet,
  681. &dwData) == ERROR_SUCCESS ){
  682. CheckDlgButton(hWnd,CONFIGSORT,
  683. (dwConvSet & CONVERSION_SET_SORT)? BST_CHECKED :BST_UNCHECKED );
  684. CheckDlgButton(hWnd,CONFIGPUNCT,
  685. (dwConvSet & CONVERSION_SET_PUNCT)? BST_CHECKED :BST_UNCHECKED );
  686. CheckDlgButton(hWnd,CONFIGFULLSHAPE,
  687. (dwConvSet & CONVERSION_SET_FULLSHAPE)? BST_CHECKED :BST_UNCHECKED );
  688. CheckDlgButton(hWnd,CONFIGFOLLOW,
  689. (dwConvSet & CONVERSION_SET_FOLLOW)? BST_CHECKED :BST_UNCHECKED );
  690. CheckDlgButton(hWnd,CONFIGGBK,
  691. (dwConvSet & CONVERSION_SET_GBK)? BST_CHECKED :BST_UNCHECKED );
  692. CheckDlgButton(hWnd,CONFIGFUZZYC,
  693. (dwConvSet & CONVERSION_SET_FUZZYC)? BST_CHECKED :BST_UNCHECKED );
  694. CheckDlgButton(hWnd,CONFIGFUZZYN,
  695. (dwConvSet & CONVERSION_SET_FUZZYN)? BST_CHECKED :BST_UNCHECKED );
  696. CheckDlgButton(hWnd,CONFIGFUZZYH,
  697. (dwConvSet & CONVERSION_SET_FUZZYH)? BST_CHECKED :BST_UNCHECKED );
  698. CheckDlgButton(hWnd,CONFIGFUZZYB,
  699. (dwConvSet & CONVERSION_SET_FUZZYB)? BST_CHECKED :BST_UNCHECKED );
  700. CheckDlgButton(hWnd,CONFIGSHAPE,
  701. (dwConvSet & CONVERSION_SET_SHAPE)? BST_CHECKED :BST_UNCHECKED );
  702. }
  703. RegCloseKey(hKey);
  704. }
  705. break;
  706. case WM_COMMAND:
  707. switch(wParam) {
  708. case CONFIGFUZZYC:
  709. break;
  710. case CONFIGFUZZYN:
  711. break;
  712. case CONFIGFUZZYH:
  713. break;
  714. case CONFIGSORT:
  715. break;
  716. case CONFIGPUNCT:
  717. break;
  718. case CONFIGFULLSHAPE:
  719. break;
  720. case IDOK:
  721. if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  722. _T("Software"),
  723. 0,
  724. KEY_READ,
  725. &hKey) == ERROR_SUCCESS ){
  726. if( RegCreateKeyEx( hKey,
  727. _T("freepy"),
  728. 0,
  729. NULL,
  730. REG_OPTION_NON_VOLATILE ,
  731. KEY_ALL_ACCESS ,
  732. NULL,
  733. &hChildKey,
  734. &dwDisposition ) == ERROR_SUCCESS) {
  735. dwConvSet = 0;
  736. if(IsDlgButtonChecked(hWnd,CONFIGSORT) == BST_CHECKED)
  737. dwConvSet |= CONVERSION_SET_SORT;
  738. else
  739. dwConvSet &= ~CONVERSION_SET_SORT;
  740. if(IsDlgButtonChecked(hWnd,CONFIGPUNCT) == BST_CHECKED)
  741. dwConvSet |= CONVERSION_SET_PUNCT;
  742. else
  743. dwConvSet &= ~CONVERSION_SET_PUNCT;
  744. if(IsDlgButtonChecked(hWnd,CONFIGFULLSHAPE) == BST_CHECKED)
  745. dwConvSet |= CONVERSION_SET_FULLSHAPE;
  746. else
  747. dwConvSet &= ~CONVERSION_SET_FULLSHAPE;
  748. if(IsDlgButtonChecked(hWnd,CONFIGFOLLOW) == BST_CHECKED)
  749. dwConvSet |= CONVERSION_SET_FOLLOW;
  750. else
  751. dwConvSet &= ~CONVERSION_SET_FOLLOW;
  752. if(IsDlgButtonChecked(hWnd,CONFIGGBK) == BST_CHECKED)
  753. dwConvSet |= CONVERSION_SET_GBK;
  754. else
  755. dwConvSet &= ~CONVERSION_SET_GBK;
  756. if(IsDlgButtonChecked(hWnd,CONFIGFUZZYC) == BST_CHECKED)
  757. dwConvSet |= CONVERSION_SET_FUZZYC;
  758. else
  759. dwConvSet &= ~CONVERSION_SET_FUZZYC;
  760. if(IsDlgButtonChecked(hWnd,CONFIGFUZZYN) == BST_CHECKED)
  761. dwConvSet |= CONVERSION_SET_FUZZYN;
  762. else
  763. dwConvSet &= ~CONVERSION_SET_FUZZYN;
  764. if(IsDlgButtonChecked(hWnd,CONFIGFUZZYH) == BST_CHECKED)
  765. dwConvSet |= CONVERSION_SET_FUZZYH;
  766. else
  767. dwConvSet &= ~CONVERSION_SET_FUZZYH;
  768. if(IsDlgButtonChecked(hWnd,CONFIGFUZZYB) == BST_CHECKED)
  769. dwConvSet |= CONVERSION_SET_FUZZYB;
  770. else
  771. dwConvSet &= ~CONVERSION_SET_FUZZYB;
  772. if(IsDlgButtonChecked(hWnd,CONFIGSHAPE) == BST_CHECKED)
  773. dwConvSet |= CONVERSION_SET_SHAPE;
  774. else
  775. dwConvSet &= ~CONVERSION_SET_SHAPE;
  776. wConversionSet = (WORD)dwConvSet;
  777. RegSetValueEx(hChildKey,
  778. _T("ConversionSet"),
  779. 0,
  780. REG_DWORD,
  781. (LPBYTE)&dwConvSet,
  782. sizeof(DWORD));
  783. RegCloseKey(hChildKey);
  784. }
  785. RegCloseKey(hKey);
  786. }
  787. EndDialog(hWnd,TRUE);
  788. break;
  789. case IDCANCEL:
  790. EndDialog(hWnd,TRUE);
  791. break;
  792. default:
  793. return FALSE;
  794. break;
  795. }
  796. break;
  797. default:
  798. return FALSE;
  799. break;
  800. }
  801. return TRUE;
  802. }