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

输入法编程

开发平台:

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 CharHandleNormal( HIMC hIMC,WORD wParam,LONG lParam)
  23. {
  24. if( (wParam >= _T('a') && wParam <= _T('z')) || wParam == _T(''') ) {
  25. return AddChar(hIMC,wParam,EDIT_ADD);
  26. }
  27. else if( wParam == _T('=') || wParam == _T('.') || wParam == _T('>')) {
  28. return ForwardPage(hIMC);
  29. }
  30. else if( wParam == _T('-') || wParam == _T(',') || wParam == _T('<')) {
  31. return BackwardPage(hIMC);
  32. }
  33. else if( wParam >= _T('0') && wParam <= _T('9') ){
  34. return SelectCand(hIMC,wParam);
  35. }
  36. switch ( wParam ){
  37. case _T('!'):
  38. case _T('@'):
  39. case _T('#'):
  40. case _T('$'):
  41. case _T('%'):
  42. case _T('^'):
  43. case _T('&'):
  44. case _T('*'):
  45. case _T('('):
  46. case _T(')'):
  47. return DeletePhrase(hIMC,wParam);
  48. default:
  49. break;
  50. }
  51. return FALSE;
  52. }
  53. BOOL AddChar( HIMC hIMC, WORD wCode, WORD wEditMode)
  54. {
  55.     LPINPUTCONTEXT lpIMC;
  56.     LPCOMPOSITIONSTRING lpCompStr;
  57. LPCANDIDATEINFO lpCandInfo;
  58. LPCANDIDATELIST lpCandList;
  59. LPFREEPYCAND lpPYCand;
  60. LPTSTR lpStr;
  61. LPTSTR lpConvStr;
  62. LPTSTR lpPaintStr;
  63. TCHAR  szTemp[150];
  64.     GENEMSG GnMsg;
  65. LPTSTR lpPYArray;
  66. WORD *lpwPYArrayLen;
  67. WORD *lpwPYArrayCurPos;
  68. SHORT *lpwUnConvPos;
  69. SHORT *lpwEditCaret;
  70. TCHAR cTempChar;
  71. WORD wPYCount;
  72. int i;
  73. BOOL fRet = FALSE;
  74. TCHAR szPreStr[150];
  75. WORD  wPreUnConvPos;
  76. WORD  wPreEditCaret;
  77.     lpIMC = ImmLockIMC(hIMC);
  78. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  79. lpStr = GETLPCOMPSTR(lpCompStr);
  80. lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
  81. lpPaintStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  82. lpPYArray = (LPTSTR)(((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPYArray);
  83. lpwPYArrayLen = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wPYArrayLen);
  84. lpwPYArrayCurPos = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wPYArrayCurPos);
  85. lpwUnConvPos = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos);
  86. lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
  87. _tcscpy(szPreStr,lpStr);
  88. wPreUnConvPos = *lpwUnConvPos;
  89. wPreEditCaret = *lpwEditCaret;
  90.     if( wEditMode == EDIT_BACK ){
  91. if(!_tcslen(lpStr) || (*lpwEditCaret) < 1 ){
  92. MessageBeep(0xFFFFFFFF );
  93. fRet = TRUE;
  94. goto my_exit;
  95. }
  96. else if(*lpwEditCaret <= *lpwUnConvPos){
  97. *lpConvStr = _T('');
  98. *lpwUnConvPos = 0;
  99. }
  100. else{
  101. _tcscpy(szTemp,lpStr + *lpwEditCaret);
  102. _tcscpy(lpStr + *lpwEditCaret -1,szTemp);
  103. *lpwEditCaret -= 1;
  104. if( !_tcslen(lpStr)){
  105. MakeResultString(hIMC,FALSE);
  106. fRet = TRUE;
  107. goto my_exit;
  108. }
  109. }
  110.     }
  111.     else if( wEditMode == EDIT_DELETE ){
  112. if(!_tcslen(lpStr) || (*lpwEditCaret) == (SHORT)_tcslen(lpStr) ){
  113. MessageBeep(0xFFFFFFFF );
  114. fRet = TRUE;
  115. goto my_exit;
  116. }
  117. else{
  118. _tcscpy(szTemp,lpStr + *lpwEditCaret + 1);
  119. _tcscpy(lpStr + *lpwEditCaret,szTemp);
  120. if( !_tcslen(lpStr)){
  121. MakeResultString(hIMC,FALSE);
  122. fRet = TRUE;
  123. goto my_exit;
  124. }
  125. }
  126.     }
  127.     else if( wEditMode == EDIT_ADD ){
  128. _tcscpy(szTemp,lpStr + *lpwEditCaret);
  129. *(lpStr + *lpwEditCaret) = (TCHAR)wCode;
  130. _tcscpy(lpStr + *lpwEditCaret +1,szTemp);
  131. *lpwEditCaret += 1;
  132.     }
  133. else{
  134. MessageBeep(0xFFFFFFFF );
  135. fRet = TRUE;
  136. goto my_exit;
  137. }
  138.     lpCompStr->dwCompStrLen = _tcslen(lpStr);
  139.     if(!_tcslen(lpConvStr)){
  140. *lpwPYArrayCurPos = 0;
  141.     }
  142.     wPYCount=ParsePY(lpStr + *lpwUnConvPos,lpPYArray + (*lpwPYArrayCurPos)*MAX_PY_LEN,MAX_PY_LEN);
  143. *lpwPYArrayLen = *lpwPYArrayCurPos + wPYCount;
  144. i = *lpwPYArrayLen;
  145. while(i--){
  146. if((cTempChar = *(lpPYArray + i*MAX_PY_LEN)) == _T('i') || 
  147. cTempChar == _T('u') || cTempChar == _T('v') ){
  148. _tcscpy(lpStr,szPreStr);
  149. *lpwEditCaret = wPreEditCaret;
  150. *lpwUnConvPos = wPreUnConvPos;
  151. *lpwPYArrayLen = *lpwPYArrayLen - 1;
  152. MessageBeep(0xFFFFFFFF );
  153. fRet = TRUE;
  154. goto my_exit;
  155. }
  156. }
  157.     if(EffectPYArrayLen(lpPYArray,MAX_PY_LEN,*lpwPYArrayLen) > MAX_PHRASE_LEN) {
  158. _tcscpy(lpStr,szPreStr);
  159. *lpwEditCaret = wPreEditCaret;
  160. *lpwUnConvPos = wPreUnConvPos;
  161. *lpwPYArrayLen = *lpwPYArrayLen - 1;
  162. MessageBeep(0xFFFFFFFF );
  163. fRet = TRUE;
  164. goto my_exit;
  165.     }
  166. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  167. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo  + lpCandInfo->dwOffset[0]);
  168. lpPYCand = (LPFREEPYCAND)(&((LPMYCAND)lpCandInfo)->FreePYCand);
  169. ConvertPY( lpPYArray + (*lpwPYArrayCurPos)*MAX_PY_LEN,
  170. MAX_PY_LEN,wPYCount,lpPYCand);
  171.     lpPYCand->awBeforePos[1] = 0;
  172. lpPYCand->awBeforePos[0] = 0;
  173. lpPYCand->awCurrentPos[1] = 0;
  174. lpPYCand->awCurrentPos[0] = 0;
  175. lpPYCand->wSelectDirect = SELECT_FORWARD;
  176.     lpPYCand->wSelectStatus = 1;
  177. lpCandList->dwCount = CreateCandStr(lpPYCand, SELECT_FORWARD, (LPTSTR)(((LPMYCAND)lpCandInfo)->szCandStr),MAXCANDSTRSIZE);
  178. lpCandList->dwPageStart = 2;
  179. lpCandList->dwPageSize = 10;
  180. CreatePaintStr( lpPYArray + (*lpwPYArrayCurPos)*MAX_PY_LEN,
  181. MAX_PY_LEN,(WORD)((*lpwPYArrayLen)-(*lpwPYArrayCurPos)),lpConvStr,lpPaintStr);
  182.     GnMsg.msg = WM_IME_COMPOSITION;
  183.     GnMsg.wParam = 0;
  184.     GnMsg.lParam = GCS_COMPSTR;
  185.     GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  186. ImmUnlockIMCC(lpIMC->hCandInfo);
  187. fRet = TRUE;
  188. my_exit:
  189.     ImmUnlockIMCC(lpIMC->hCompStr);
  190.     ImmUnlockIMC(hIMC);
  191. return fRet;
  192. }
  193. BOOL ForwardPage(HIMC hIMC)
  194. {
  195.     LPINPUTCONTEXT lpIMC;
  196. LPCANDIDATEINFO lpCandInfo;
  197. LPCANDIDATELIST lpCandList;
  198. LPFREEPYCAND lpPYCand;
  199. GENEMSG GnMsg;
  200. if( !IsCompStr(hIMC) ) return FALSE;
  201. lpIMC = ImmLockIMC(hIMC);
  202. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  203. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo  + lpCandInfo->dwOffset[0]);
  204. lpPYCand = (LPFREEPYCAND)(&((LPMYCAND)lpCandInfo)->FreePYCand);
  205. lpCandList->dwCount = 
  206. CreateCandStr(lpPYCand, SELECT_FORWARD, (LPTSTR)(((LPMYCAND)lpCandInfo)->szCandStr),MAXCANDSTRSIZE);
  207. lpCandList->dwPageStart = 2;
  208. lpCandList->dwPageSize = 10;
  209. if(lpCandList->dwCount) {
  210. GnMsg.msg = WM_IME_COMPOSITION;
  211. GnMsg.wParam = 0;
  212. GnMsg.lParam = GCS_COMPSTR;
  213. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  214. }
  215. ImmUnlockIMCC(lpIMC->hCandInfo);
  216.     ImmUnlockIMC(hIMC);
  217. return TRUE;
  218. }
  219. BOOL BackwardPage(HIMC hIMC)
  220. {
  221.     LPINPUTCONTEXT lpIMC;
  222. LPCANDIDATEINFO lpCandInfo;
  223. LPCANDIDATELIST lpCandList;
  224. LPFREEPYCAND lpPYCand;
  225. GENEMSG GnMsg;
  226. if( !IsCompStr(hIMC) ) return FALSE;
  227. lpIMC = ImmLockIMC(hIMC);
  228. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  229. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo  + lpCandInfo->dwOffset[0]);
  230. lpPYCand = (LPFREEPYCAND)(&((LPMYCAND)lpCandInfo)->FreePYCand);
  231. lpCandList->dwCount = 
  232. CreateCandStr(lpPYCand, SELECT_BACKWARD, (LPTSTR)(((LPMYCAND)lpCandInfo)->szCandStr),MAXCANDSTRSIZE);
  233. lpCandList->dwPageStart = 2;
  234. lpCandList->dwPageSize = 10;
  235. if(lpCandList->dwCount) {
  236. GnMsg.msg = WM_IME_COMPOSITION;
  237. GnMsg.wParam = 0;
  238. GnMsg.lParam = GCS_COMPSTR;
  239. GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  240. }
  241. ImmUnlockIMCC(lpIMC->hCandInfo);
  242.     ImmUnlockIMC(hIMC);
  243. return TRUE;
  244. }
  245. BOOL SelectCand(HIMC hIMC,WORD wParam)
  246. {
  247.     LPINPUTCONTEXT lpIMC;
  248. LPCOMPOSITIONSTRING lpCompStr;
  249. LPCANDIDATEINFO lpCandInfo;
  250. LPCANDIDATELIST lpCandList;
  251. LPFREEPYCAND lpPYCand;
  252. LPTSTR lpStr;
  253. LPTSTR lpConvStr;
  254. LPTSTR lpPaintStr;
  255. LPTSTR lpPYArray;
  256. SHORT *lpwUnConvPos;
  257. SHORT *lpwEditCaret;
  258. WORD *lpwPYArrayLen;
  259. WORD *lpwPYArrayCurPos;
  260. GENEMSG GnMsg;
  261.     WORD wIdx,awLen[2],wPosSpan,wTotal,wCount;
  262. TCHAR szTempStr[(MAX_PHRASE_LEN+1)*2];
  263. int i;
  264.     if( !IsCompStr(hIMC) ) return FALSE;
  265. lpIMC = ImmLockIMC(hIMC);
  266. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  267. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo  + lpCandInfo->dwOffset[0]);
  268. lpPYCand = (LPFREEPYCAND)(&((LPMYCAND)lpCandInfo)->FreePYCand);
  269. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  270. lpStr = GETLPCOMPSTR(lpCompStr);
  271. lpConvStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szConvCompStr;
  272. lpPaintStr = ((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPaintCompStr;
  273. lpPYArray = (LPTSTR)(((LPMYCOMPSTR)lpCompStr)->FreePYComp.szPYArray);
  274. lpwPYArrayLen = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wPYArrayLen);
  275. lpwPYArrayCurPos = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wPYArrayCurPos);
  276. lpwUnConvPos = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wUnConvPos);
  277. lpwEditCaret = &(((LPMYCOMPSTR)lpCompStr)->FreePYComp.wEditCaret);
  278.     if( wParam == (WORD)_T('0') ) wIdx=9;
  279.     else wIdx = wParam - (WORD)_T('1');
  280. if(wIdx >= lpCandList->dwCount) return FALSE;
  281. wTotal = wIdx + 1;
  282.     switch(lpPYCand->wSelectDirect){
  283.     case SELECT_FORWARD:
  284. if(wConversionSet & CONVERSION_SET_GBK) {
  285. wIdx += lpPYCand->awBeforePos[lpPYCand->wSelectStatus];
  286. }
  287. else {
  288. if(lpPYCand->wSelectStatus) {
  289. wIdx += lpPYCand->awBeforePos[lpPYCand->wSelectStatus];
  290. }
  291. else{
  292. wIdx = lpPYCand->awBeforePos[lpPYCand->wSelectStatus];
  293. wCount = 0;
  294. while( wCount != wTotal) {
  295. for(i=0;i < lpPYCand->wHZNum;i++){
  296. if((lpPYCand->aHanZi+i)->wLen > wIdx) break;
  297. }
  298. #ifdef _UNICODE
  299. if(i)
  300. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + (wIdx - (lpPYCand->aHanZi+i-1)->wLen),1);
  301. else
  302. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + wIdx,1);
  303. szTempStr[1] = _T('');
  304. #else
  305. if(i)
  306. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + 2*(wIdx - (lpPYCand->aHanZi+i-1)->wLen),2);
  307. else
  308. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ+2*wIdx,2);
  309. szTempStr[2] = _T('');
  310. #endif
  311. if( (*((LPBYTE)szTempStr) >= GB_QUFIRST && *((LPBYTE)szTempStr) <= GB_QULAST) && 
  312. (*((LPBYTE)szTempStr+1) >= GB_WEIFIRST && *((LPBYTE)szTempStr+1) <= GB_WEILAST) ) {
  313. wCount++;
  314. }
  315. wIdx++;
  316. }
  317. wIdx--;
  318. }
  319. }
  320. break;
  321.     case SELECT_BACKWARD:
  322. if(wConversionSet & CONVERSION_SET_GBK) {
  323. wIdx += lpPYCand->awCurrentPos[lpPYCand->wSelectStatus]+1;
  324. }
  325. else {
  326. if(lpPYCand->wSelectStatus) {
  327. wIdx += lpPYCand->awCurrentPos[lpPYCand->wSelectStatus]+1;
  328. }
  329. else{
  330. wIdx = lpPYCand->awBeforePos[lpPYCand->wSelectStatus];
  331. wTotal--;
  332. wCount = 10;
  333. while( wCount != wTotal) {
  334. for(i=0;i < lpPYCand->wHZNum;i++){
  335. if((lpPYCand->aHanZi+i)->wLen > wIdx) break;
  336. }
  337. #ifdef _UNICODE
  338. if(i)
  339. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + (wIdx - (lpPYCand->aHanZi+i-1)->wLen),1);
  340. else
  341. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + wIdx,1);
  342. szTempStr[1] = _T('');
  343. #else
  344. if(i)
  345. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + 2*(wIdx - (lpPYCand->aHanZi+i-1)->wLen),2);
  346. else
  347. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ+2*wIdx,2);
  348. szTempStr[2] = _T('');
  349. #endif
  350. if( (*((LPBYTE)szTempStr) >= GB_QUFIRST && *((LPBYTE)szTempStr) <= GB_QULAST) && 
  351. (*((LPBYTE)szTempStr+1) >= GB_WEIFIRST && *((LPBYTE)szTempStr+1) <= GB_WEILAST) ) {
  352. wCount--;
  353. }
  354. wIdx--;
  355. }
  356. wIdx++;
  357. }
  358. }
  359. break;
  360.     default:
  361. break;
  362.     }
  363. awLen[1] = lpPYCand->wPhraseNum;
  364. awLen[0] = (lpPYCand->aHanZi + lpPYCand->wHZNum - 1)->wLen;
  365.     if(0 < wIdx < awLen[lpPYCand->wSelectStatus]){
  366. if(lpPYCand->wSelectStatus){
  367. _tcscpy(szTempStr,(lpPYCand->aPhrase+wIdx)->lpHZPH->szHZ);
  368. _tcscat(lpConvStr,szTempStr);
  369. lpPYCand ->abKey[0] |= 
  370. (lpPYCand->aPhrase+wIdx)->lpKeyPH->abKey[0] << lpPYCand->wKeyLen;
  371. for(i=1;i<=(lpPYCand->aPhrase+wIdx)->lpKeyPH->wLen;i++){
  372. lpPYCand ->abKey[(lpPYCand->wKeyLen++) + 1] =
  373. (lpPYCand->aPhrase+wIdx)->lpKeyPH->abKey[i];
  374. }
  375. }
  376. else{
  377. for(i=0;i < lpPYCand->wHZNum;i++){
  378. if((lpPYCand->aHanZi+i)->wLen > wIdx ) break;
  379. }
  380. #ifdef _UNICODE
  381. if(i)
  382. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + (wIdx - (lpPYCand->aHanZi+i-1)->wLen),1);
  383. else
  384. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + wIdx,1);
  385. szTempStr[1] = _T('');
  386. #else
  387. if(i)
  388. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ + 2*(wIdx - (lpPYCand->aHanZi+i-1)->wLen),2);
  389. else
  390. _tcsncpy(szTempStr,(lpPYCand->aHanZi+i)->lpHZ+2*wIdx,2);
  391. szTempStr[2] = _T('');
  392. #endif
  393. _tcscat(lpConvStr,szTempStr);
  394. lpPYCand ->abKey[0] |= ((lpPYCand->aHanZi+i)->wKey & 0x0100) >>(8 - lpPYCand->wKeyLen);
  395. lpPYCand ->abKey[(lpPYCand->wKeyLen++) + 1] = (BYTE)(lpPYCand->aHanZi+i)->wKey & 0xff;
  396. }
  397. #ifdef _UNICODE
  398. if( EffectPYArrayLen(lpPYArray,MAX_PY_LEN,*lpwPYArrayLen) == _tcslen(lpConvStr) ) {
  399. if(_tcslen(szTempStr) == _tcslen(lpConvStr) && lpPYCand->wSelectStatus)
  400. (lpPYCand->aPhrase + wIdx)->lpHZPH->wAttrib++;
  401. else if(_tcslen(lpConvStr) > 1)
  402. SavePhToMapFile(lpConvStr,lpPYCand->abKey,(WORD)(_tcslen(lpConvStr)),1);
  403. #else
  404. if( EffectPYArrayLen(lpPYArray,MAX_PY_LEN,*lpwPYArrayLen) == _tcslen(lpConvStr)/2 ) {
  405. if(_tcslen(szTempStr) == _tcslen(lpConvStr) && lpPYCand->wSelectStatus)
  406. (lpPYCand->aPhrase + wIdx)->lpHZPH->dwAttrib++;
  407. else if(_tcslen(lpConvStr) > 2)
  408. SavePhToMapFile(lpConvStr,lpPYCand->abKey,(WORD)(_tcslen(lpConvStr)/2),1);
  409. #endif
  410. MakeResultString(hIMC,TRUE);
  411. goto my_exit;
  412. }
  413. else{
  414. #ifdef _UNICODE
  415. wPosSpan = CalculatePosSpan(lpPYArray+(*lpwPYArrayCurPos)*MAX_PY_LEN,
  416. MAX_PY_LEN,(WORD)((*lpwPYArrayLen)-(*lpwPYArrayCurPos)),(WORD)_tcslen(szTempStr));
  417. #else
  418. wPosSpan = CalculatePosSpan(lpPYArray+(*lpwPYArrayCurPos)*MAX_PY_LEN,
  419. MAX_PY_LEN,(WORD)((*lpwPYArrayLen)-(*lpwPYArrayCurPos)),(WORD)(_tcslen(szTempStr)/2));
  420. #endif
  421. *lpwPYArrayCurPos += wPosSpan;
  422. *lpwUnConvPos = CalculateUnConvPos(lpPYArray + (*lpwPYArrayCurPos)*MAX_PY_LEN,
  423. MAX_PY_LEN,(WORD)((*lpwPYArrayLen)-(*lpwPYArrayCurPos)),lpStr);
  424. *lpwEditCaret = (SHORT)_tcslen(lpStr);
  425. ConvertPY( lpPYArray + (*lpwPYArrayCurPos)*MAX_PY_LEN,
  426. MAX_PY_LEN,(WORD)((*lpwPYArrayLen)-(*lpwPYArrayCurPos)),lpPYCand);
  427.     lpPYCand->awBeforePos[1] = 0;
  428. lpPYCand->awBeforePos[0] = 0;
  429. lpPYCand->awCurrentPos[1] = 0;
  430. lpPYCand->awCurrentPos[0] = 0;
  431. lpPYCand->wSelectDirect = SELECT_FORWARD;
  432. lpPYCand->wSelectStatus = 1;
  433. lpCandList->dwCount = CreateCandStr(lpPYCand, SELECT_FORWARD, (LPTSTR)(((LPMYCAND)lpCandInfo)->szCandStr),MAXCANDSTRSIZE);
  434. lpCandList->dwPageStart = 2;
  435. lpCandList->dwPageSize = 10;
  436. CreatePaintStr( lpPYArray + (*lpwPYArrayCurPos)*MAX_PY_LEN,
  437. MAX_PY_LEN,(WORD)((*lpwPYArrayLen)-(*lpwPYArrayCurPos)),lpConvStr,lpPaintStr);
  438. }
  439.     }
  440.     GnMsg.msg = WM_IME_COMPOSITION;
  441.     GnMsg.wParam = 0;
  442. GnMsg.lParam = GCS_COMPSTR;
  443.     GenerateMessage(hIMC, lpdwCurTransKey,(LPGENEMSG)&GnMsg);
  444. my_exit:
  445. ImmUnlockIMCC(lpIMC->hCandInfo);
  446.     ImmUnlockIMCC(lpIMC->hCompStr);
  447.     ImmUnlockIMC(hIMC);
  448. return TRUE;
  449. }
  450. BOOL DeletePhrase(HIMC hIMC,WORD wParam)
  451. {
  452.     LPINPUTCONTEXT lpIMC;
  453. LPCANDIDATEINFO lpCandInfo;
  454. LPCANDIDATELIST lpCandList;
  455. LPFREEPYCAND lpPYCand;
  456. LPKEYPH lpKPh;
  457. LPHZPH lpHZPh,lpCurHZPh,lpPreHZPh;
  458. WORD wLen,wIdx;
  459. WORD wRet = 0;
  460.     if( !IsCompStr(hIMC) ) return FALSE;
  461. lpIMC = ImmLockIMC(hIMC);
  462. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  463. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo  + lpCandInfo->dwOffset[0]);
  464. lpPYCand = (LPFREEPYCAND)(&((LPMYCAND)lpCandInfo)->FreePYCand);
  465. if( ! lpPYCand->wSelectStatus ) {
  466. ImmUnlockIMCC(lpIMC->hCandInfo);
  467.     ImmUnlockIMC(hIMC);
  468. return FALSE;
  469. }
  470. switch( wParam ) {
  471. case _T('!'):
  472. wIdx = 0;
  473. break;
  474. case _T('@'):
  475. wIdx = 1;
  476. break;
  477. case _T('#'):
  478. wIdx = 2;
  479. break;
  480. case _T('$'):
  481. wIdx = 3;
  482. break;
  483. case _T('%'):
  484. wIdx = 4;
  485. break;
  486. case _T('^'):
  487. wIdx = 5;
  488. break;
  489. case _T('&'):
  490. wIdx = 6;
  491. break;
  492. case _T('*'):
  493. wIdx = 7;
  494. break;
  495. case _T('('):
  496. wIdx = 8;
  497. break;
  498. case _T(')'):
  499. wIdx = 9;
  500. break;
  501. default:
  502. wIdx = 0;
  503. break;
  504. }
  505.     switch(lpPYCand->wSelectDirect){
  506.     case SELECT_FORWARD:
  507. wIdx += lpPYCand->awBeforePos[lpPYCand->wSelectStatus];
  508. break;
  509.     case SELECT_BACKWARD:
  510. wIdx += lpPYCand->awCurrentPos[lpPYCand->wSelectStatus]+1;
  511. break;
  512.     default:
  513. break;
  514.     }
  515. wLen = lpPYCand->wPhraseNum;
  516.     if(0 < wIdx < wLen ){
  517. lpKPh = (lpPYCand->aPhrase+wIdx)->lpKeyPH;
  518. lpHZPh = (lpPYCand->aPhrase+wIdx)->lpHZPH;
  519. if( ((LPBYTE)lpKPh >= (LPBYTE)lpMapFileBase 
  520. && (LPBYTE)lpKPh < (LPBYTE)lpMapFileBase + MAX_PY_NUM*sizeof(KEYPH) ) ||
  521. ((LPBYTE)lpKPh >= (LPBYTE)lpMapFileBase + 2*MAX_PY_NUM*sizeof(KEYPH)
  522. &&(LPBYTE)lpKPh < (LPBYTE)lpMapFileBase + dwMapFileUsrOffset ) ) {
  523. lpHZPh->dwAttrib = 0;
  524. wRet = 1;
  525. }
  526. else{
  527. lpCurHZPh = lpKPh->lpHZPH;
  528. if( lpCurHZPh == lpHZPh) {
  529. if(lpHZPh->lpNext == NULL) lpKPh->wLen = -1;
  530. lpKPh->lpHZPH = lpHZPh->lpNext;
  531. wRet = 1;
  532. }
  533. else {
  534. lpPreHZPh = lpCurHZPh;
  535. do {
  536. lpCurHZPh = lpCurHZPh->lpNext;
  537. if(lpCurHZPh == lpHZPh) {
  538. lpPreHZPh->lpNext = lpCurHZPh->lpNext;
  539. wRet = 1;
  540. break;
  541. }
  542. lpPreHZPh = lpCurHZPh;
  543. }while(lpCurHZPh->lpNext != NULL);
  544. }
  545. }
  546. }
  547. if( wRet ) MakeResultString(hIMC,FALSE);
  548. ImmUnlockIMCC(lpIMC->hCandInfo);
  549.     ImmUnlockIMC(hIMC);
  550. return TRUE;
  551. }