Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1345 lines
46 KiB

  1. /*++
  2. Copyright (c) 1990-1999 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. toascii.c
  5. ++*/
  6. #include <windows.h>
  7. #include <immdev.h>
  8. #include <imedefs.h>
  9. /**********************************************************************/
  10. /* IsUsedCode() */
  11. /* Return Value: */
  12. /* TURE: is UsedCode; FALSE: is'nt UsedCode; */
  13. /**********************************************************************/
  14. BOOL IsUsedCode(
  15. WORD wCharCode)
  16. {
  17. WORD wFlg;
  18. for(wFlg=0; wFlg<sImeG.wNumCodes; wFlg++)
  19. if (wCharCode == sImeG.UsedCodes[wFlg])
  20. break;
  21. if(wFlg < sImeG.wNumCodes)
  22. return (TRUE);
  23. return (FALSE);
  24. }
  25. /**********************************************************************/
  26. /* GBProcessKey() */
  27. /* Return Value: */
  28. /* different state which input key will change IME to (CST_ */
  29. /**********************************************************************/
  30. UINT PASCAL GBProcessKey( // this key will cause the IME go to what state
  31. WORD wCharCode,
  32. LPPRIVCONTEXT lpImcP)
  33. {
  34. if (!lpImcP) {
  35. return (CST_INVALID);
  36. }
  37. // check space
  38. if (wCharCode == TEXT(' ')) {
  39. if (lpImcP->bSeq[0] && lpImcP->bSeq[1]) {
  40. return (CST_INPUT);
  41. } else if (!lpImcP->bSeq[0]) {
  42. return (CST_ALPHANUMERIC);
  43. } else {
  44. return (CST_INVALID_INPUT);
  45. }
  46. }
  47. // check finalize char
  48. if ((wCharCode >= TEXT('0') && wCharCode <= TEXT('9'))
  49. ||(wCharCode >= TEXT('a') && wCharCode <= TEXT('f'))
  50. ||(wCharCode == TEXT('?'))) {
  51. if (!lpImcP->bSeq[0]) {
  52. if (wCharCode == TEXT('?')){
  53. // 0x0??? - 0xF??? is OK
  54. return (CST_ALPHANUMERIC);
  55. } else {
  56. // there is no 0x0??? - 0x7???
  57. lpImcP->bSeq[1] = TEXT('\0');
  58. return (CST_INPUT);
  59. }
  60. } else if (!lpImcP->bSeq[1]) {
  61. if (lpImcP->bSeq[0] >=TEXT('0') && lpImcP->bSeq[0] <= TEXT('9')){ //Area
  62. if ((lpImcP->bSeq[0] == TEXT('0') && wCharCode == TEXT('0'))
  63. ||(lpImcP->bSeq[0] == TEXT('9') && wCharCode >= TEXT('5'))
  64. ||(wCharCode >= TEXT('a') && wCharCode <= TEXT('f'))
  65. ||(wCharCode == TEXT('?'))) {
  66. // there is less than 95 area and bigger than 0 area
  67. return (CST_INVALID_INPUT);
  68. }
  69. else {
  70. lpImcP->bSeq[2] = TEXT('\0');
  71. return (CST_INPUT);
  72. }
  73. }
  74. if (lpImcP->bSeq[0] >= TEXT('a') && lpImcP->bSeq[0] <= TEXT('f')) { //GB
  75. if ((lpImcP->bSeq[0] == TEXT('a') && wCharCode == TEXT('0'))
  76. ||(lpImcP->bSeq[0] == TEXT('f') && wCharCode == TEXT('f'))
  77. ||(wCharCode == TEXT('?'))) {
  78. // there is less than 95 area and bigger than 0 area
  79. return (CST_INVALID_INPUT);
  80. }
  81. else {
  82. lpImcP->bSeq[2] = TEXT('\0');
  83. return (CST_INPUT);
  84. }
  85. }
  86. } else if (!lpImcP->bSeq[2]) {
  87. if (wCharCode == TEXT('?')){
  88. return (CST_INPUT);
  89. }
  90. if (lpImcP->bSeq[0] >= TEXT('0') && lpImcP->bSeq[0] <= TEXT('9')){ //Area
  91. if (wCharCode >= TEXT('0') && wCharCode <= TEXT('9')) {
  92. lpImcP->bSeq[3] = TEXT('\0');
  93. return (CST_INPUT);
  94. } else {
  95. return (CST_INVALID_INPUT);
  96. }
  97. }
  98. if (lpImcP->bSeq[0] >= TEXT('a') && lpImcP->bSeq[0] <= TEXT('f')) { //GB
  99. if (wCharCode >= TEXT('a') && wCharCode <= TEXT('f')) {
  100. lpImcP->bSeq[3] = TEXT('\0');
  101. return (CST_INPUT);
  102. } else {
  103. return (CST_INVALID_INPUT);
  104. }
  105. }
  106. } else if (!lpImcP->bSeq[3]) {
  107. if (lpImcP->bSeq[2] == TEXT('?')) {
  108. if (wCharCode == TEXT('?')) {
  109. return (CST_INPUT);
  110. }else{
  111. return (CST_INVALID_INPUT);
  112. }
  113. }
  114. if (lpImcP->bSeq[0] >= TEXT('0') && lpImcP->bSeq[0] <= TEXT('9')) { //Area
  115. if ((lpImcP->bSeq[2] == TEXT('0') && wCharCode == TEXT('0'))
  116. ||(lpImcP->bSeq[2] == TEXT('9') && wCharCode >= TEXT('5'))
  117. ||(wCharCode >= TEXT('a') && wCharCode <= TEXT('f'))
  118. ||(wCharCode == TEXT('?'))) {
  119. // there is less than 95 area and bigger than 0 area
  120. return (CST_INVALID_INPUT);
  121. }
  122. else {
  123. return (CST_INPUT);
  124. }
  125. }
  126. if (lpImcP->bSeq[0] >= TEXT('a') && lpImcP->bSeq[0] <= TEXT('f')) { //GB
  127. if ((lpImcP->bSeq[2] == TEXT('a') && wCharCode == TEXT('0'))
  128. ||(lpImcP->bSeq[2] == TEXT('f') && wCharCode == TEXT('f'))
  129. ||(wCharCode == TEXT('?'))){
  130. // there is less than 95 area and bigger than 0 area
  131. return (CST_INVALID_INPUT);
  132. }
  133. else {
  134. return (CST_INPUT);
  135. }
  136. }
  137. } else {
  138. return (CST_INVALID_INPUT);
  139. }
  140. } else if (wCharCode >= TEXT(' ') && wCharCode <= TEXT('~')) {
  141. return (CST_ALPHANUMERIC);
  142. } else {
  143. return (CST_INVALID_INPUT);
  144. }
  145. return (CST_INVALID_INPUT);
  146. }
  147. #if defined(COMBO_IME)
  148. /**********************************************************************/
  149. /* UnicodeProcessKey() */
  150. /* Return Value: */
  151. /* different state which input key will change IME to (CST_ */
  152. /**********************************************************************/
  153. UINT PASCAL UnicodeProcessKey( // this key will cause the IME go to what state
  154. WORD wCharCode,
  155. LPPRIVCONTEXT lpImcP)
  156. {
  157. if (!lpImcP) {
  158. return (CST_INVALID);
  159. }
  160. if (wCharCode == TEXT(' ')) {
  161. if (lpImcP->bSeq[0] && lpImcP->bSeq[1]) {
  162. return (CST_INPUT);
  163. } else if (!lpImcP->bSeq[0]) {
  164. return (CST_ALPHANUMERIC);
  165. } else {
  166. return (CST_INVALID_INPUT);
  167. }
  168. }
  169. // check finalize char
  170. // 0000 -- ffff
  171. if ((wCharCode >= TEXT('0') && wCharCode <= TEXT('9'))
  172. ||(wCharCode >= TEXT('a') && wCharCode <= TEXT('f'))
  173. ||(wCharCode == TEXT('?'))) {
  174. if (wCharCode == TEXT('?')){
  175. if (!lpImcP->bSeq[2]) {
  176. return (CST_INPUT);
  177. }else
  178. return(CST_INVALID_INPUT);
  179. }else{
  180. return (CST_INPUT);
  181. }
  182. } else if(lpImcP->bSeq[0]){
  183. return (CST_INVALID_INPUT);
  184. } else
  185. return (CST_ALPHANUMERIC);
  186. }
  187. #endif //COMBO_IME
  188. /**********************************************************************/
  189. /* XGBProcessKey() */
  190. /* Return Value: */
  191. /* different state which input key will change IME to (CST_ */
  192. /**********************************************************************/
  193. UINT PASCAL XGBProcessKey( // this key will cause the IME go to what state
  194. WORD wCharCode,
  195. LPPRIVCONTEXT lpImcP)
  196. {
  197. if (!lpImcP) {
  198. return (CST_INVALID);
  199. }
  200. if (wCharCode == TEXT(' ')) {
  201. if (lpImcP->bSeq[0] && lpImcP->bSeq[1]) {
  202. return (CST_INPUT);
  203. } else if (!lpImcP->bSeq[0]) {
  204. return (CST_ALPHANUMERIC);
  205. } else {
  206. return (CST_INVALID_INPUT);
  207. }
  208. }
  209. // check finalize char
  210. //lead byte 81 - fe
  211. //trail byte 40 - 7e, 80 - fe
  212. if ((wCharCode >= TEXT('0') && wCharCode <= TEXT('9'))
  213. ||(wCharCode >= TEXT('a') && wCharCode <= TEXT('f'))
  214. ||(wCharCode == TEXT('?'))) {
  215. if (!lpImcP->bSeq[0]) {
  216. if (wCharCode == TEXT('?')) {
  217. // 0x0??? - 0xF??? is OK
  218. // : - @ was filted
  219. return (CST_ALPHANUMERIC);
  220. }else if (wCharCode >=TEXT('8') && wCharCode <= TEXT('f')){
  221. // 0x0??? - 0xF??? is OK
  222. lpImcP->bSeq[1] = TEXT('\0');
  223. return (CST_INPUT);
  224. } else {
  225. // there is no 0x0??? - 0x7???
  226. return (CST_INVALID_INPUT);
  227. }
  228. } else if (!lpImcP->bSeq[1]) {
  229. if ((lpImcP->bSeq[0] == TEXT('f') && wCharCode == TEXT('f'))
  230. ||(lpImcP->bSeq[0] == TEXT('8') && wCharCode == TEXT('0'))
  231. ||(wCharCode == TEXT('?'))) {
  232. //XGB is 81 - fe
  233. return (CST_INVALID_INPUT);
  234. }
  235. else {
  236. lpImcP->bSeq[2] = TEXT('\0');
  237. return (CST_INPUT);
  238. }
  239. } else if (!lpImcP->bSeq[2]) {
  240. if (wCharCode == TEXT('?')){
  241. lpImcP->bSeq[3] = TEXT('\0');
  242. return (CST_INPUT);
  243. }
  244. if (wCharCode >= TEXT('4') && wCharCode <= TEXT('f')) {
  245. lpImcP->bSeq[3] = TEXT('\0');
  246. return (CST_INPUT);
  247. } else {
  248. return (CST_INVALID_INPUT);
  249. }
  250. } else if (!lpImcP->bSeq[3]) {
  251. if (lpImcP->bSeq[2] == TEXT('?')) {
  252. if (wCharCode == TEXT('?')) {
  253. return (CST_INPUT);
  254. }else{
  255. return (CST_INVALID_INPUT);
  256. }
  257. }
  258. if ((lpImcP->bSeq[2] == TEXT('7') && wCharCode == TEXT('f'))
  259. ||(lpImcP->bSeq[2] == TEXT('f') && wCharCode == TEXT('f'))
  260. ||(wCharCode == TEXT('?'))) {
  261. //trail byte
  262. //40 - 7e, 80 - fe
  263. return (CST_INVALID_INPUT);
  264. }
  265. else {
  266. return (CST_INPUT);
  267. }
  268. } else {
  269. return (CST_INVALID_INPUT);
  270. }
  271. } else if (wCharCode >= TEXT(' ') && wCharCode <= TEXT('~')) {
  272. return (CST_ALPHANUMERIC);
  273. } else {
  274. return (CST_INVALID_INPUT);
  275. }
  276. }
  277. /**********************************************************************/
  278. /* ProcessKey() */
  279. /* Return Value: */
  280. /* different state which input key will change IME to (CST_ */
  281. /**********************************************************************/
  282. UINT PASCAL ProcessKey( // this key will cause the IME go to what state
  283. WORD wCharCode,
  284. UINT uVirtKey,
  285. UINT uScanCode,
  286. LPBYTE lpbKeyState,
  287. LPINPUTCONTEXT lpIMC,
  288. LPPRIVCONTEXT lpImcP)
  289. {
  290. if (!lpIMC) {
  291. return (CST_INVALID);
  292. }
  293. if (!lpImcP) {
  294. return (CST_INVALID);
  295. }
  296. // filter system key (alt,alt+,ctrl,shift)
  297. // and fOpen, IME_CMODE_NOCONVERSION
  298. if (uVirtKey == VK_MENU) { // ALT key
  299. return (CST_INVALID);
  300. } else if (uScanCode & KF_ALTDOWN) { // ALT-xx key
  301. return (CST_INVALID);
  302. } else if (uVirtKey == VK_CONTROL) { // CTRL key
  303. return (CST_INVALID);
  304. } else if (uVirtKey == VK_SHIFT) { // SHIFT key
  305. return (CST_INVALID);
  306. } else if (!lpIMC->fOpen) { // don't compose in
  307. // close status
  308. return (CST_INVALID);
  309. } else if (lpIMC->fdwConversion & IME_CMODE_NOCONVERSION) {
  310. // Caps on/off
  311. if(uVirtKey == VK_CAPITAL) {
  312. return (CST_CAPITAL);
  313. }else
  314. return (CST_INVALID);
  315. } else if (uVirtKey >= VK_NUMPAD0 && uVirtKey <= VK_DIVIDE) {
  316. return (CST_INVALID);
  317. } else {
  318. }
  319. // Caps on/off
  320. if(uVirtKey == VK_CAPITAL) {
  321. return (CST_CAPITAL);
  322. }
  323. if ((lpIMC->fdwConversion & IME_CMODE_SOFTKBD)
  324. && (lpImeL->dwSKWant != 0)){
  325. if (wCharCode >= TEXT(' ') && wCharCode <= TEXT('~')) {
  326. return (CST_SOFTKB);
  327. } else {
  328. return (CST_INVALID);
  329. }
  330. }
  331. // candidate alaredy open, <,>,pageup,pagedown,?,ECS,key
  332. if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
  333. if (uVirtKey == VK_PRIOR) { // PageUp
  334. return (CST_CHOOSE);
  335. } else if (uVirtKey == VK_NEXT) { // PageDown
  336. return (CST_CHOOSE);
  337. } else if (wCharCode == TEXT('-')) {
  338. return (CST_CHOOSE);
  339. } else if (wCharCode == TEXT('=')) {
  340. return (CST_CHOOSE);
  341. } else if (uVirtKey == VK_HOME) {
  342. return (CST_CHOOSE);
  343. } else if (uVirtKey == VK_END) {
  344. return (CST_CHOOSE);
  345. } else if (uVirtKey == VK_ESCAPE) { // Esc
  346. return (CST_CHOOSE);
  347. } else if (wCharCode == TEXT(' ')) {
  348. return (CST_CHOOSE);
  349. } else {
  350. }
  351. }
  352. // candidate alaredy open, shift + num key
  353. if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
  354. if ((wCharCode >= TEXT('0')) && wCharCode <= TEXT('9')) {
  355. return (CST_CHOOSE);
  356. }
  357. }
  358. // IME_CMODE_CHARCODE
  359. if (lpIMC->fdwConversion & IME_CMODE_CHARCODE) { //Code Input Mode
  360. return (CST_INVALID);
  361. }
  362. if (!(lpIMC->fdwConversion & IME_CMODE_NATIVE)) {
  363. // alphanumeric mode
  364. if (wCharCode >= TEXT(' ') && wCharCode <= TEXT('~')) {
  365. return (CST_ALPHANUMERIC);
  366. } else {
  367. return (CST_INVALID);
  368. }
  369. } else if (wCharCode == TEXT('?')) {
  370. } else if (wCharCode == TEXT(' ')) {
  371. } else if(wCharCode >= TEXT(' ') && wCharCode <= TEXT('~')) {
  372. if(!IsUsedCode(wCharCode)
  373. && lpImcP->iImeState != CST_INIT)
  374. return (CST_INVALID_INPUT);
  375. }
  376. // Esc key
  377. if (uVirtKey == VK_ESCAPE) {
  378. register LPGUIDELINE lpGuideLine;
  379. register UINT iImeState;
  380. lpGuideLine = ImmLockIMCC(lpIMC->hGuideLine);
  381. if(!lpGuideLine){
  382. return (CST_INVALID);
  383. }
  384. if (lpImcP->fdwImeMsg & MSG_ALREADY_START) {
  385. iImeState = CST_INPUT;
  386. } else if (!lpGuideLine) {
  387. iImeState = CST_INVALID;
  388. } else if (lpGuideLine->dwLevel == GL_LEVEL_NOGUIDELINE) {
  389. iImeState = CST_INVALID;
  390. } else {
  391. // need this key to clean information string or guideline state
  392. iImeState = CST_INPUT;
  393. }
  394. ImmUnlockIMCC(lpIMC->hGuideLine);
  395. return (iImeState);
  396. }
  397. // BackSpace Key
  398. else if (uVirtKey == VK_BACK) {
  399. if (lpImcP->fdwImeMsg & MSG_ALREADY_START) {
  400. return (CST_INPUT);
  401. } else {
  402. return (CST_INVALID);
  403. }
  404. }
  405. // NumPad key and Other Input vailid key
  406. else if (uVirtKey >= VK_NUMPAD0 && uVirtKey <= VK_DIVIDE) {
  407. return (CST_ALPHANUMERIC);
  408. } else if (wCharCode > TEXT('~')) {
  409. return (CST_INVALID);
  410. } else if (wCharCode < TEXT(' ')) {
  411. return (CST_INVALID);
  412. } else if (lpIMC->fdwConversion & IME_CMODE_EUDC) {
  413. }
  414. else {
  415. }
  416. if (lpIMC->fdwConversion & IME_CMODE_NATIVE) {
  417. // if (lpImcP->fdwGB & IME_SELECT_GB) {
  418. #if defined(COMBO_IME)
  419. switch(sImeL.dwRegImeIndex){
  420. case INDEX_GB:
  421. return (GBProcessKey(wCharCode,lpImcP));
  422. case INDEX_GBK:
  423. return (XGBProcessKey (wCharCode,lpImcP));
  424. case INDEX_UNICODE:
  425. return(UnicodeProcessKey(wCharCode, lpImcP));
  426. }
  427. #else //COMBO_IME
  428. #ifdef GB
  429. return (GBProcessKey(wCharCode,lpImcP));
  430. // } else {
  431. #else
  432. return (XGBProcessKey (wCharCode,lpImcP));
  433. // }
  434. #endif //GB
  435. #endif //COMBO_IME
  436. }
  437. return (CST_INVALID);
  438. }
  439. /**********************************************************************/
  440. /* ImeProcessKey() */
  441. /* Return Value: */
  442. /* TRUE - successful, FALSE - failure */
  443. /**********************************************************************/
  444. BOOL WINAPI ImeProcessKey( // if this key is need by IME?
  445. HIMC hIMC,
  446. UINT uVirtKey,
  447. LPARAM lParam,
  448. CONST LPBYTE lpbKeyState)
  449. {
  450. LPINPUTCONTEXT lpIMC;
  451. LPPRIVCONTEXT lpImcP;
  452. BYTE szAscii[4];
  453. int nChars;
  454. int iRet;
  455. BOOL fRet;
  456. // can't compose in NULL hIMC
  457. if (!hIMC) {
  458. return (FALSE);
  459. }
  460. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  461. if (!lpIMC) {
  462. return (FALSE);
  463. }
  464. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  465. if (!lpImcP) {
  466. ImmUnlockIMC(hIMC);
  467. return (FALSE);
  468. }
  469. nChars = ToAscii(uVirtKey, HIWORD(lParam), lpbKeyState,
  470. (LPVOID)szAscii, 0);
  471. if (!nChars) {
  472. szAscii[0] = 0;
  473. }
  474. iRet = ProcessKey((WORD)szAscii[0], uVirtKey, HIWORD(lParam), lpbKeyState, lpIMC, lpImcP);
  475. if(iRet == CST_INVALID) {
  476. fRet = FALSE;
  477. } else if((iRet == CST_INPUT) && (uVirtKey == TEXT('\b'))
  478. && (lpImcP->iImeState == CST_INIT)) {
  479. lpImcP->fdwImeMsg = ((lpImcP->fdwImeMsg | MSG_END_COMPOSITION)
  480. & ~(MSG_START_COMPOSITION)) & ~(MSG_IN_IMETOASCIIEX);
  481. if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
  482. ClearCand(lpIMC);
  483. lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg | MSG_CLOSE_CANDIDATE) &
  484. ~(MSG_OPEN_CANDIDATE);
  485. }
  486. GenerateMessage(hIMC, lpIMC, lpImcP);
  487. fRet = FALSE;
  488. } else if(uVirtKey == VK_CAPITAL) {
  489. DWORD fdwConversion;
  490. #ifdef LATER
  491. if (lpbKeyState[VK_CAPITAL] & 0x01) {
  492. // change to native mode
  493. fdwConversion = (lpIMC->fdwConversion | IME_CMODE_NATIVE) &
  494. ~(IME_CMODE_CHARCODE | IME_CMODE_EUDC);
  495. uCaps = 0;
  496. } else {
  497. // change to alphanumeric mode
  498. fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_CHARCODE |
  499. IME_CMODE_NATIVE | IME_CMODE_EUDC);
  500. uCaps = 1;
  501. }
  502. #else
  503. if (lpbKeyState[VK_CAPITAL] & 0x01) {
  504. // change to alphanumeric mode
  505. fdwConversion = lpIMC->fdwConversion & ~(IME_CMODE_CHARCODE |
  506. IME_CMODE_NATIVE | IME_CMODE_EUDC);
  507. uCaps = 1;
  508. } else {
  509. // change to native mode
  510. fdwConversion = (lpIMC->fdwConversion | IME_CMODE_NATIVE)&
  511. ~(IME_CMODE_CHARCODE | IME_CMODE_EUDC);
  512. uCaps = 0;
  513. }
  514. #endif //LATER
  515. ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
  516. fRet = FALSE;
  517. } else if((iRet == CST_ALPHANUMERIC)
  518. && !(lpIMC->fdwConversion & IME_CMODE_FULLSHAPE)
  519. && (uVirtKey == VK_SPACE)) {
  520. fRet = FALSE;
  521. } else {
  522. fRet = TRUE;
  523. }
  524. ImmUnlockIMCC(lpIMC->hPrivate);
  525. ImmUnlockIMC(hIMC);
  526. return (fRet);
  527. }
  528. /**********************************************************************/
  529. /* TranslateSymbolChar() */
  530. /* Return Value: */
  531. /* the number of translated chars */
  532. /**********************************************************************/
  533. UINT PASCAL TranslateSymbolChar(
  534. LPTRANSMSGLIST lpTransBuf,
  535. WORD wSymbolCharCode,
  536. BOOL SymbolMode)
  537. {
  538. UINT uRet;
  539. LPTRANSMSG lpTransMsg;
  540. uRet = 0;
  541. lpTransMsg = lpTransBuf->TransMsg;
  542. // NT need to modify this!
  543. #ifdef UNICODE
  544. lpTransMsg->message = WM_CHAR;
  545. lpTransMsg->wParam = (DWORD)wSymbolCharCode;
  546. lpTransMsg->lParam = 1UL;
  547. lpTransMsg++;
  548. uRet++;
  549. #else
  550. lpTransMsg->message = WM_CHAR;
  551. lpTransMsg->wParam = (DWORD)HIBYTE(wSymbolCharCode);
  552. lpTransMsg->lParam = 1UL;
  553. lpTransMsg++;
  554. uRet++;
  555. lpTransMsg->message = WM_CHAR;
  556. lpTransMsg->wParam = (DWORD)LOBYTE(wSymbolCharCode);
  557. lpTransMsg->lParam 1UL;
  558. uRet++;
  559. #endif
  560. if(SymbolMode) {
  561. lpTransMsg = lpTransBuf->TransMsg;
  562. #ifdef UNICODE
  563. lpTransMsg->message = WM_CHAR;
  564. lpTransMsg->wParam = (DWORD)wSymbolCharCode;
  565. lpTransMsg->lParam = 1UL;
  566. lpTransMsg++;
  567. uRet++;
  568. #else
  569. lpTransMsg->message = WM_CHAR;
  570. lpTransMsg->wParam = (DWORD)HIBYTE(wSymbolCharCode);
  571. lpTransMsg->lParam = 1UL;
  572. lpTransMsg++;
  573. uRet++;
  574. lpTransMsg->message = WM_CHAR;
  575. lpTransMsg->wParam = (DWORD)LOBYTE(wSymbolCharCode);
  576. lpTransMsg->lParam = 1UL;
  577. uRet++;
  578. #endif
  579. }
  580. return (uRet); // generate two messages
  581. }
  582. /**********************************************************************/
  583. /* TranslateFullChar() */
  584. /* Return Value: */
  585. /* the number of translated chars */
  586. /**********************************************************************/
  587. UINT PASCAL TranslateFullChar(
  588. LPTRANSMSGLIST lpTransBuf,
  589. WORD wCharCode)
  590. {
  591. // if your IME is possible to generate over ? messages,
  592. // you need to take care about it
  593. LPTRANSMSG lpTransMsg;
  594. wCharCode = sImeG.wFullABC[wCharCode - TEXT(' ')];
  595. lpTransMsg = lpTransBuf->TransMsg;
  596. // NT need to modify this!
  597. #ifdef UNICODE
  598. lpTransMsg->message = WM_CHAR;
  599. lpTransMsg->wParam = (DWORD)wCharCode;
  600. lpTransMsg->lParam = 1UL;
  601. lpTransMsg++;
  602. #else
  603. lpTransMsg->message = WM_CHAR;
  604. lpTransMsg->wParam = (DWORD)HIBYTE(wCharCode);
  605. lpTransMsg->lParam = 1UL;
  606. lpTransMsg++;
  607. lpTransMsg->message = WM_CHAR;
  608. lpTransMsg->wParam = (DWORD)LOBYTE(wCharCode);
  609. lpTransMsg->lParam = 1UL;
  610. #endif
  611. return (2); // generate two messages
  612. }
  613. /**********************************************************************/
  614. /* TranslateToAscii() */
  615. /* Return Value: */
  616. /* the number of translated chars */
  617. /**********************************************************************/
  618. UINT PASCAL TranslateToAscii( // translate the key to WM_CHAR
  619. // as keyboard driver
  620. UINT uVirtKey,
  621. UINT uScanCode,
  622. LPTRANSMSGLIST lpTransBuf,
  623. WORD wCharCode)
  624. {
  625. LPTRANSMSG lpTransMsg;
  626. lpTransMsg = lpTransBuf->TransMsg;
  627. if (wCharCode) { // one char code
  628. lpTransMsg->message = WM_CHAR;
  629. lpTransMsg->wParam = wCharCode;
  630. lpTransMsg->lParam = (uScanCode << 16) | 1UL;
  631. return (1);
  632. }
  633. // no char code case
  634. return (0);
  635. }
  636. /**********************************************************************/
  637. /* TranslateImeMessage() */
  638. /* Return Value: */
  639. /* the number of translated messages */
  640. /**********************************************************************/
  641. UINT PASCAL TranslateImeMessage(
  642. LPTRANSMSGLIST lpTransBuf,
  643. LPINPUTCONTEXT lpIMC,
  644. LPPRIVCONTEXT lpImcP)
  645. {
  646. UINT uNumMsg;
  647. UINT i;
  648. BOOL bLockMsgBuf;
  649. LPTRANSMSG lpTransMsg;
  650. uNumMsg = 0;
  651. bLockMsgBuf = FALSE;
  652. for (i = 0; i < 2; i++) {
  653. if (lpImcP->fdwImeMsg & MSG_CLOSE_CANDIDATE) {
  654. if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
  655. if (!i) {
  656. uNumMsg++;
  657. } else {
  658. lpTransMsg->message = WM_IME_NOTIFY;
  659. lpTransMsg->wParam = IMN_CLOSECANDIDATE;
  660. lpTransMsg->lParam = 0x0001;
  661. lpTransMsg++;
  662. lpImcP->fdwImeMsg &= ~(MSG_ALREADY_OPEN);
  663. }
  664. }
  665. }
  666. if (lpImcP->fdwImeMsg & MSG_END_COMPOSITION) {
  667. if (lpImcP->fdwImeMsg & MSG_ALREADY_START) {
  668. if (!i) {
  669. uNumMsg++;
  670. } else {
  671. lpTransMsg->message = WM_IME_ENDCOMPOSITION;
  672. lpTransMsg->wParam = 0;
  673. lpTransMsg->lParam = 0;
  674. lpTransMsg++;
  675. lpImcP->fdwImeMsg &= ~(MSG_ALREADY_START);
  676. }
  677. }
  678. }
  679. if (lpImcP->fdwImeMsg & MSG_START_COMPOSITION) {
  680. if (!(lpImcP->fdwImeMsg & MSG_ALREADY_START)) {
  681. if (!i) {
  682. uNumMsg++;
  683. } else {
  684. lpTransMsg->message = WM_IME_STARTCOMPOSITION;
  685. lpTransMsg->wParam = 0;
  686. lpTransMsg->lParam = 0;
  687. lpTransMsg++;
  688. lpImcP->fdwImeMsg |= MSG_ALREADY_START;
  689. }
  690. }
  691. }
  692. if (lpImcP->fdwImeMsg & MSG_IMN_COMPOSITIONPOS) {
  693. if (!i) {
  694. uNumMsg++;
  695. } else {
  696. lpTransMsg->message = WM_IME_NOTIFY;
  697. lpTransMsg->wParam = IMN_SETCOMPOSITIONWINDOW;
  698. lpTransMsg->lParam = 0;
  699. lpTransMsg++;
  700. }
  701. }
  702. if (lpImcP->fdwImeMsg & MSG_COMPOSITION) {
  703. if (!i) {
  704. uNumMsg++;
  705. } else {
  706. lpTransMsg->message = WM_IME_COMPOSITION;
  707. lpTransMsg->wParam = (DWORD)lpImcP->dwCompChar;
  708. lpTransMsg->lParam = (DWORD)lpImcP->fdwGcsFlag;
  709. lpTransMsg++;
  710. }
  711. }
  712. if (lpImcP->fdwImeMsg & MSG_GUIDELINE) {
  713. if (!i) {
  714. uNumMsg++;
  715. } else {
  716. lpTransMsg->message = WM_IME_NOTIFY;
  717. lpTransMsg->wParam = IMN_GUIDELINE;
  718. lpTransMsg->lParam = 0;
  719. lpTransMsg++;
  720. }
  721. }
  722. if (lpImcP->fdwImeMsg & MSG_OPEN_CANDIDATE) {
  723. if (!(lpImcP->fdwImeMsg & MSG_ALREADY_OPEN)) {
  724. if (!i) {
  725. uNumMsg++;
  726. } else {
  727. lpTransMsg->message = WM_IME_NOTIFY;
  728. lpTransMsg->wParam = IMN_OPENCANDIDATE;
  729. lpTransMsg->lParam = 0x0001;
  730. lpTransMsg++;
  731. lpImcP->fdwImeMsg |= MSG_ALREADY_OPEN;
  732. }
  733. }
  734. }
  735. if (lpImcP->fdwImeMsg & MSG_CHANGE_CANDIDATE) {
  736. if (!i) {
  737. uNumMsg++;
  738. } else {
  739. lpTransMsg->message = WM_IME_NOTIFY;
  740. lpTransMsg->wParam = IMN_CHANGECANDIDATE;
  741. lpTransMsg->lParam = 0x0001;
  742. lpTransMsg++;
  743. }
  744. }
  745. if (lpImcP->fdwImeMsg & MSG_IMN_UPDATE_SOFTKBD) {
  746. if (!i) {
  747. uNumMsg++;
  748. } else {
  749. lpTransMsg->message = WM_IME_NOTIFY;
  750. lpTransMsg->wParam = IMN_PRIVATE;
  751. lpTransMsg->lParam = IMN_PRIVATE_UPDATE_SOFTKBD;
  752. lpTransMsg++;
  753. }
  754. }
  755. if (lpImcP->fdwImeMsg & MSG_IMN_UPDATE_STATUS) {
  756. if (!i) {
  757. uNumMsg++;
  758. } else {
  759. lpTransMsg->message = WM_IME_NOTIFY;
  760. lpTransMsg->wParam = IMN_PRIVATE;
  761. lpTransMsg->lParam = IMN_PRIVATE_UPDATE_STATUS;
  762. lpTransMsg++;
  763. }
  764. }
  765. if (lpImcP->fdwImeMsg & MSG_IMN_DESTROYCAND) {
  766. if (!i) {
  767. uNumMsg++;
  768. } else {
  769. lpTransMsg->message = WM_IME_NOTIFY;
  770. lpTransMsg->wParam = IMN_PRIVATE;
  771. lpTransMsg->lParam = IMN_PRIVATE_DESTROYCANDWIN;
  772. lpTransMsg++;
  773. }
  774. }
  775. if (lpImcP->fdwImeMsg & MSG_BACKSPACE) {
  776. if (!i) {
  777. uNumMsg++;
  778. } else {
  779. lpTransMsg->message = WM_CHAR;
  780. lpTransMsg->wParam = TEXT('\b');
  781. lpTransMsg->lParam = 0x000e;
  782. lpTransMsg++;
  783. }
  784. }
  785. if (!i) {
  786. HIMCC hMem;
  787. if (!uNumMsg) {
  788. return (uNumMsg);
  789. }
  790. if (lpImcP->fdwImeMsg & MSG_IN_IMETOASCIIEX) {
  791. UINT uNumMsgLimit;
  792. uNumMsgLimit = lpTransBuf->uMsgCount;
  793. if (uNumMsg <= uNumMsgLimit) {
  794. lpTransMsg = lpTransBuf->TransMsg;
  795. continue;
  796. }
  797. }
  798. // we need to use message buffer
  799. if (!lpIMC->hMsgBuf) {
  800. lpIMC->hMsgBuf = ImmCreateIMCC(uNumMsg * sizeof(TRANSMSG));
  801. lpIMC->dwNumMsgBuf = 0;
  802. } else if (hMem = ImmReSizeIMCC(lpIMC->hMsgBuf,
  803. (lpIMC->dwNumMsgBuf + uNumMsg) * sizeof(TRANSMSG))) {
  804. if (hMem != lpIMC->hMsgBuf) {
  805. ImmDestroyIMCC(lpIMC->hMsgBuf);
  806. lpIMC->hMsgBuf = hMem;
  807. }
  808. } else {
  809. return (0);
  810. }
  811. lpTransMsg= (LPTRANSMSG) ImmLockIMCC(lpIMC->hMsgBuf);
  812. if (!lpTransMsg) {
  813. return (0);
  814. }
  815. lpTransMsg += lpIMC->dwNumMsgBuf;
  816. bLockMsgBuf = TRUE;
  817. } else {
  818. if (bLockMsgBuf) {
  819. ImmUnlockIMCC(lpIMC->hMsgBuf);
  820. }
  821. }
  822. }
  823. return (uNumMsg);
  824. }
  825. /**********************************************************************/
  826. /* ImeToAsciiEx() */
  827. /* Return Value: */
  828. /* the number of translated message */
  829. /**********************************************************************/
  830. UINT WINAPI ImeToAsciiEx(
  831. UINT uVirtKey,
  832. UINT uScanCode,
  833. CONST LPBYTE lpbKeyState,
  834. LPTRANSMSGLIST lpTransBuf,
  835. UINT fuState,
  836. HIMC hIMC)
  837. {
  838. WORD wCharCode;
  839. LPINPUTCONTEXT lpIMC;
  840. LPCOMPOSITIONSTRING lpCompStr;
  841. LPPRIVCONTEXT lpImcP;
  842. UINT uNumMsg;
  843. int iRet;
  844. #ifdef UNICODE
  845. wCharCode = HIWORD(uVirtKey);
  846. #else
  847. wCharCode = HIBYTE(uVirtKey);
  848. #endif
  849. uVirtKey = LOBYTE(uVirtKey);
  850. // hIMC=NULL?
  851. if (!hIMC) {
  852. uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
  853. wCharCode);
  854. return (uNumMsg);
  855. }
  856. // get lpIMC
  857. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  858. if (!lpIMC) {
  859. uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
  860. wCharCode);
  861. return (uNumMsg);
  862. }
  863. // get lpImcP
  864. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  865. if (!lpImcP) {
  866. ImmUnlockIMC(hIMC);
  867. uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
  868. wCharCode);
  869. return (uNumMsg);
  870. }
  871. // get lpCompStr and init
  872. if (lpImcP->fdwGcsFlag & (GCS_RESULTREAD|GCS_RESULT)) {
  873. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  874. if (lpCompStr) {
  875. lpCompStr->dwResultStrLen = 0;
  876. }
  877. ImmUnlockIMCC(lpIMC->hCompStr);
  878. lpImcP->fdwGcsFlag = (DWORD)0;
  879. }
  880. // Now all composition realated information already pass to app
  881. // a brand new start
  882. // init lpImcP->fdwImeMsg
  883. lpImcP->fdwImeMsg = lpImcP->fdwImeMsg & (MSG_ALREADY_OPEN|
  884. MSG_ALREADY_START) | MSG_IN_IMETOASCIIEX;
  885. // Process Key(wCharCode)
  886. iRet = ProcessKey(wCharCode, uVirtKey, uScanCode, lpbKeyState, lpIMC,
  887. lpImcP);
  888. // iRet process
  889. // CST_ALPHANUMERIC
  890. // CST_SYMBOL
  891. // CST_SOFTKB
  892. if (iRet == CST_SOFTKB) {
  893. WORD wSymbolCharCode;
  894. WORD CHIByte, CLOByte;
  895. int SKDataIndex;
  896. // Mapping VK
  897. if(uVirtKey == 0x20) {
  898. SKDataIndex = 0;
  899. } else if(uVirtKey >= 0x30 && uVirtKey <= 0x39) {
  900. SKDataIndex = uVirtKey - 0x30 + 1;
  901. } else if (uVirtKey >= 0x41 && uVirtKey <= 0x5a) {
  902. SKDataIndex = uVirtKey - 0x41 + 0x0b;
  903. } else if (uVirtKey >= 0xba && uVirtKey <= 0xbf) {
  904. SKDataIndex = uVirtKey - 0xba + 0x25;
  905. } else if (uVirtKey >= 0xdb && uVirtKey <= 0xde) {
  906. SKDataIndex = uVirtKey - 0xdb + 0x2c;
  907. } else if (uVirtKey == 0xc0) {
  908. SKDataIndex = 0x2b;
  909. } else {
  910. SKDataIndex = 0;
  911. }
  912. #ifdef UNICODE //
  913. if (lpbKeyState[VK_SHIFT] & 0x80) {
  914. wSymbolCharCode = SKLayoutS[lpImeL->dwSKWant][SKDataIndex];
  915. } else {
  916. wSymbolCharCode = SKLayout[lpImeL->dwSKWant][SKDataIndex];
  917. }
  918. if(wSymbolCharCode == 0x0020) {
  919. #else
  920. if (lpbKeyState[VK_SHIFT] & 0x80) {
  921. CHIByte = SKLayoutS[lpImeL->dwSKWant][SKDataIndex*2] & 0x00ff;
  922. CLOByte = SKLayoutS[lpImeL->dwSKWant][SKDataIndex*2 + 1] & 0x00ff;
  923. } else {
  924. CHIByte = SKLayout[lpImeL->dwSKWant][SKDataIndex*2] & 0x00ff;
  925. CLOByte = SKLayout[lpImeL->dwSKWant][SKDataIndex*2 + 1] & 0x00ff;
  926. }
  927. wSymbolCharCode = (CHIByte << 8) | CLOByte;
  928. if(wSymbolCharCode == 0x2020) {
  929. #endif
  930. MessageBeep((UINT) -1);
  931. uNumMsg = 0;
  932. } else {
  933. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  934. }
  935. }
  936. // CST_ALPHANUMERIC
  937. else if (iRet == CST_ALPHANUMERIC) {
  938. if (lpImcP->fdwImeMsg & MSG_ALREADY_OPEN) {
  939. lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg | MSG_CLOSE_CANDIDATE) &
  940. ~(MSG_OPEN_CANDIDATE) & ~(MSG_IN_IMETOASCIIEX);
  941. GenerateMessage(hIMC, lpIMC, lpImcP);
  942. }
  943. if (lpIMC->fdwConversion & IME_CMODE_SYMBOL) {
  944. WORD wSymbolCharCode;
  945. if(wCharCode == TEXT('.')) {
  946. #ifdef UNICODE
  947. wSymbolCharCode = 0x3002;
  948. #else
  949. wSymbolCharCode = TEXT('');
  950. #endif
  951. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  952. } else if(wCharCode == TEXT(',')) {
  953. #ifdef UNICODE
  954. wSymbolCharCode = 0xff0c;
  955. #else
  956. wSymbolCharCode = TEXT('');
  957. #endif
  958. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  959. } else if(wCharCode == TEXT(';')) {
  960. #ifdef UNICODE
  961. wSymbolCharCode = 0xff1b;
  962. #else
  963. wSymbolCharCode = TEXT('');
  964. #endif
  965. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  966. } else if(wCharCode == TEXT(':')) {
  967. #ifdef UNICODE
  968. wSymbolCharCode = 0xff1a;
  969. #else
  970. wSymbolCharCode = TEXT('');
  971. #endif
  972. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  973. } else if(wCharCode == TEXT('?')) {
  974. #ifdef UNICODE
  975. wSymbolCharCode = 0xff1f;
  976. #else
  977. wSymbolCharCode = TEXT('');
  978. #endif
  979. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  980. } else if(wCharCode == TEXT('!')) {
  981. #ifdef UNICODE
  982. wSymbolCharCode = 0xff01;
  983. #else
  984. wSymbolCharCode = TEXT('');
  985. #endif
  986. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  987. } else if(wCharCode == TEXT('(')) {
  988. #ifdef UNICODE
  989. wSymbolCharCode = 0xff08;
  990. #else
  991. wSymbolCharCode = TEXT('');
  992. #endif
  993. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  994. } else if(wCharCode == TEXT(')')) {
  995. #ifdef UNICODE
  996. wSymbolCharCode = 0xff09;
  997. #else
  998. wSymbolCharCode = TEXT('');
  999. #endif
  1000. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1001. } else if(wCharCode == TEXT('\\')) {
  1002. #ifdef UNICODE
  1003. wSymbolCharCode = 0x3001;
  1004. #else
  1005. wSymbolCharCode = TEXT('');
  1006. #endif
  1007. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1008. } else if(wCharCode == TEXT('@')) {
  1009. #ifdef UNICODE
  1010. wSymbolCharCode = 0x00b7;
  1011. #else
  1012. wSymbolCharCode = TEXT('');
  1013. #endif
  1014. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1015. } else if(wCharCode == TEXT('&')) {
  1016. #ifdef UNICODE
  1017. wSymbolCharCode = 0x2014;
  1018. #else
  1019. wSymbolCharCode = TEXT('');
  1020. #endif
  1021. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1022. } else if(wCharCode == TEXT('$')) {
  1023. #ifdef UNICODE
  1024. wSymbolCharCode = 0xffe5;
  1025. #else
  1026. wSymbolCharCode = TEXT('');
  1027. #endif
  1028. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1029. } else if(wCharCode == TEXT('_')) {
  1030. #ifdef UNICODE
  1031. wSymbolCharCode = 0x2014;
  1032. #else
  1033. wSymbolCharCode = TEXT('');
  1034. #endif
  1035. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, TRUE);
  1036. } else if(wCharCode == TEXT('^')) {
  1037. #ifdef UNICODE
  1038. wSymbolCharCode = 0x2026;
  1039. #else
  1040. wSymbolCharCode = TEXT('');
  1041. #endif
  1042. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, TRUE);
  1043. } else if(wCharCode == TEXT('"')) {
  1044. if(lpImcP->uSYHFlg) {
  1045. #ifdef UNICODE
  1046. wSymbolCharCode = 0x201d;
  1047. } else {
  1048. wSymbolCharCode = 0x201c;
  1049. #else
  1050. wSymbolCharCode = TEXT('');
  1051. } else {
  1052. wSymbolCharCode = TEXT('');
  1053. #endif
  1054. }
  1055. lpImcP->uSYHFlg ^= 0x00000001;
  1056. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1057. } else if(wCharCode == TEXT('\'')) {
  1058. if(lpImcP->uDYHFlg) {
  1059. #ifdef UNICODE
  1060. wSymbolCharCode = 0x2019;
  1061. } else {
  1062. wSymbolCharCode = 0x2018;
  1063. #else
  1064. wSymbolCharCode = TEXT('');
  1065. } else {
  1066. wSymbolCharCode = TEXT('');
  1067. #endif
  1068. }
  1069. lpImcP->uDYHFlg ^= 0x00000001;
  1070. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1071. } else if(wCharCode == TEXT('<')) {
  1072. if(lpImcP->uDSMHFlg) {
  1073. #ifdef UNICODE
  1074. wSymbolCharCode = 0x3008;
  1075. #else
  1076. wSymbolCharCode = TEXT('');
  1077. #endif
  1078. lpImcP->uDSMHCount++;
  1079. } else {
  1080. #ifdef UNICODE
  1081. wSymbolCharCode = 0x300a;
  1082. #else
  1083. wSymbolCharCode = TEXT('');
  1084. #endif
  1085. lpImcP->uDSMHFlg = 0x00000001;
  1086. }
  1087. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1088. } else if(wCharCode == TEXT('>')) {
  1089. if((lpImcP->uDSMHFlg) && (lpImcP->uDSMHCount)) {
  1090. #ifdef UNICODE
  1091. wSymbolCharCode = 0x3009;
  1092. #else
  1093. wSymbolCharCode = TEXT('');
  1094. #endif
  1095. lpImcP->uDSMHCount--;
  1096. } else {
  1097. #ifdef UNICODE
  1098. wSymbolCharCode = 0x300b;
  1099. #else
  1100. wSymbolCharCode = TEXT('');
  1101. #endif
  1102. lpImcP->uDSMHFlg = 0x00000000;
  1103. }
  1104. uNumMsg = TranslateSymbolChar(lpTransBuf, wSymbolCharCode, FALSE);
  1105. } else {
  1106. if (lpIMC->fdwConversion & IME_CMODE_FULLSHAPE) {
  1107. // convert to DBCS
  1108. uNumMsg = TranslateFullChar(lpTransBuf, wCharCode);
  1109. } else {
  1110. uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
  1111. wCharCode);
  1112. }
  1113. }
  1114. } else if (lpIMC->fdwConversion & IME_CMODE_FULLSHAPE) {
  1115. // convert to DBCS
  1116. uNumMsg = TranslateFullChar(lpTransBuf, wCharCode);
  1117. } else {
  1118. uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
  1119. wCharCode);
  1120. }
  1121. }
  1122. // CST_CHOOSE
  1123. else if (iRet == CST_CHOOSE) {
  1124. LPCANDIDATEINFO lpCandInfo;
  1125. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  1126. if(!lpCandInfo){
  1127. return (CST_INVALID);
  1128. }
  1129. if (uVirtKey == VK_PRIOR) {
  1130. wCharCode = TEXT('-');
  1131. } else if (uVirtKey == VK_NEXT) {
  1132. wCharCode = TEXT('=');
  1133. } else if (uVirtKey == VK_SPACE) {
  1134. wCharCode = TEXT('1');
  1135. } else if (uVirtKey <= TEXT('9')) {
  1136. // convert shift-0 ... shift-9 to 0 ... 9
  1137. wCharCode = (WORD)uVirtKey;
  1138. } else if (uVirtKey == VK_HOME) {
  1139. wCharCode = 0x24;
  1140. } else if (uVirtKey == VK_END) {
  1141. wCharCode = 0x23;
  1142. } else {
  1143. }
  1144. lpImcP->iImeState = CST_CHOOSE;
  1145. ChooseCand(wCharCode, lpIMC, lpCandInfo, lpImcP);
  1146. ImmUnlockIMCC(lpIMC->hCandInfo);
  1147. uNumMsg = TranslateImeMessage(lpTransBuf, lpIMC, lpImcP);
  1148. }
  1149. // CST_INPUT(IME_CMODE_CHARCODE)
  1150. else if (iRet == CST_INPUT &&
  1151. lpIMC->fdwConversion & IME_CMODE_CHARCODE) {
  1152. uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
  1153. wCharCode);
  1154. }
  1155. // CST_INPUT
  1156. else if (iRet == CST_INPUT) {
  1157. LPGUIDELINE lpGuideLine;
  1158. // get lpCompStr & lpGuideLine
  1159. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  1160. if(!lpCompStr){
  1161. return (CST_INVALID);
  1162. }
  1163. lpGuideLine = (LPGUIDELINE)ImmLockIMCC(lpIMC->hGuideLine);
  1164. if(!lpGuideLine){
  1165. ImmUnlockIMCC(lpIMC->hCompStr);
  1166. return (CST_INVALID);
  1167. }
  1168. // composition
  1169. CompWord(wCharCode, lpIMC, lpCompStr, lpImcP, lpGuideLine);
  1170. ImmUnlockIMCC(lpIMC->hGuideLine);
  1171. ImmUnlockIMCC(lpIMC->hCompStr);
  1172. // generate message
  1173. uNumMsg = TranslateImeMessage(lpTransBuf, lpIMC, lpImcP);
  1174. }
  1175. // ELSE
  1176. else if (iRet == CST_INVALID_INPUT) {
  1177. MessageBeep((UINT) -1);
  1178. uNumMsg = 0;
  1179. }else {
  1180. uNumMsg = TranslateToAscii(uVirtKey, uScanCode, lpTransBuf,
  1181. wCharCode);
  1182. }
  1183. // reset lpImcP->fdwImeMsg
  1184. lpImcP->fdwImeMsg &= (MSG_ALREADY_OPEN|MSG_ALREADY_START);
  1185. lpImcP->fdwGcsFlag &= (GCS_RESULTREAD|GCS_RESULT);
  1186. ImmUnlockIMCC(lpIMC->hPrivate);
  1187. ImmUnlockIMC(hIMC);
  1188. return (uNumMsg);
  1189. }