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.

1061 lines
31 KiB

  1. // Copyright (c) 1985 - 1999, Microsoft Corporation
  2. //
  3. // MODULE: country3.c
  4. //
  5. // PURPOSE: Console IME control.
  6. // FarEast country specific module for conime.
  7. //
  8. // PLATFORMS: Windows NT-FE 3.51
  9. //
  10. // FUNCTIONS:
  11. // GetCompositionStr() - routine for Get Composition String
  12. // ReDisplayCompositionStr() - foutine for re-Display Composition String
  13. //
  14. // History:
  15. //
  16. // 17.Jul.1996 v-HirShi (Hirotoshi Shimizu) Created for TAIWAN & KOREA & PRC
  17. //
  18. // COMMENTS:
  19. //
  20. #include "precomp.h"
  21. #pragma hdrstop
  22. //**********************************************************************
  23. //
  24. // void GetCompositionStr()
  25. //
  26. // This handles WM_IME_COMPOSITION message with GCS_COMPSTR flag on.
  27. //
  28. //**********************************************************************
  29. void
  30. GetCompositionStr(
  31. HWND hwnd,
  32. LPARAM CompFlag,
  33. WPARAM CompChar
  34. )
  35. {
  36. PCONSOLE_TABLE ConTbl;
  37. DBGPRINT(("CONIME: GetCompositionStr\n"));
  38. ConTbl = SearchConsole(LastConsole);
  39. if (ConTbl == NULL) {
  40. DBGPRINT(("CONIME: Error! Cannot found registed Console\n"));
  41. return;
  42. }
  43. switch (ConTbl->ConsoleOutputCP)
  44. {
  45. case JAPAN_CODEPAGE:
  46. GetCompStrJapan(hwnd, ConTbl, CompFlag);
  47. break;
  48. case TAIWAN_CODEPAGE:
  49. GetCompStrTaiwan(hwnd, ConTbl, CompFlag);
  50. break;
  51. case PRC_CODEPAGE:
  52. GetCompStrPRC(hwnd, ConTbl, CompFlag);
  53. break;
  54. case KOREA_CODEPAGE:
  55. GetCompStrKorea(hwnd, ConTbl, CompFlag, CompChar);
  56. break;
  57. default:
  58. break;
  59. }
  60. return;
  61. }
  62. void
  63. GetCompStrJapan(
  64. HWND hwnd,
  65. PCONSOLE_TABLE ConTbl,
  66. LPARAM CompFlag
  67. )
  68. {
  69. HIMC hIMC; // Input context handle.
  70. LONG lBufLen; // Storage for len. of composition str
  71. LONG lBufLenAttr;
  72. COPYDATASTRUCT CopyData;
  73. DWORD SizeToAlloc;
  74. PWCHAR TempBuf;
  75. PUCHAR TempBufA;
  76. DWORD i;
  77. DWORD CursorPos;
  78. LPCONIME_UICOMPMESSAGE lpCompStrMem;
  79. //
  80. // If fail to get input context handle then do nothing.
  81. // Applications should call ImmGetContext API to get
  82. // input context handle.
  83. //
  84. hIMC = ImmGetContext( hwnd );
  85. if ( hIMC == 0 )
  86. return;
  87. if (CompFlag & GCS_COMPSTR)
  88. {
  89. //
  90. // Determines how much memory space to store the composition string.
  91. // Applications should call ImmGetCompositionString with
  92. // GCS_COMPSTR flag on, buffer length zero, to get the bullfer
  93. // length.
  94. //
  95. lBufLen = ImmGetCompositionString( hIMC, GCS_COMPSTR, (void FAR*)NULL, 0l );
  96. if ( lBufLen < 0 ) {
  97. ImmReleaseContext( hwnd, hIMC );
  98. return;
  99. }
  100. if ( CompFlag & GCS_COMPATTR )
  101. {
  102. DBGPRINT((" GCS_COMPATTR\n"));
  103. lBufLenAttr = ImmGetCompositionString( hIMC, GCS_COMPATTR,( void FAR *)NULL, 0l );
  104. if ( lBufLenAttr < 0 ) {
  105. lBufLenAttr = 0;
  106. }
  107. }
  108. else {
  109. lBufLenAttr = 0;
  110. }
  111. }
  112. else if (CompFlag & GCS_RESULTSTR)
  113. {
  114. //
  115. // Determines how much memory space to store the result string.
  116. // Applications should call ImmGetCompositionString with
  117. // GCS_RESULTSTR flag on, buffer length zero, to get the bullfer
  118. // length.
  119. //
  120. lBufLen = ImmGetCompositionString( hIMC, GCS_RESULTSTR, (void FAR *)NULL, 0l );
  121. if ( lBufLen < 0 ) {
  122. ImmReleaseContext( hwnd, hIMC );
  123. return;
  124. }
  125. lBufLenAttr = 0;
  126. }
  127. else if (CompFlag == 0)
  128. {
  129. lBufLen = 0;
  130. lBufLenAttr = 0;
  131. }
  132. SizeToAlloc = (UINT)( sizeof(CONIME_UICOMPMESSAGE) +
  133. lBufLen + sizeof(WCHAR) +
  134. lBufLenAttr + sizeof(BYTE) );
  135. if ( ConTbl->lpCompStrMem != NULL &&
  136. SizeToAlloc > ConTbl->lpCompStrMem->dwSize
  137. )
  138. {
  139. LocalFree( ConTbl->lpCompStrMem );
  140. ConTbl->lpCompStrMem = NULL;
  141. }
  142. if (ConTbl->lpCompStrMem == NULL) {
  143. ConTbl->lpCompStrMem = (LPCONIME_UICOMPMESSAGE)LocalAlloc(LPTR, SizeToAlloc );
  144. if ( ConTbl->lpCompStrMem == NULL) {
  145. ImmReleaseContext( hwnd, hIMC );
  146. return;
  147. }
  148. ConTbl->lpCompStrMem->dwSize = SizeToAlloc;
  149. }
  150. lpCompStrMem = ConTbl->lpCompStrMem;
  151. RtlZeroMemory(&lpCompStrMem->dwCompAttrLen,
  152. lpCompStrMem->dwSize - sizeof(lpCompStrMem->dwSize)
  153. );
  154. TempBuf = (PWCHAR)((PUCHAR)lpCompStrMem + sizeof(CONIME_UICOMPMESSAGE));
  155. TempBufA = (PUCHAR)((PUCHAR)lpCompStrMem + sizeof(CONIME_UICOMPMESSAGE) +
  156. lBufLen + sizeof(WCHAR));
  157. CopyMemory(lpCompStrMem->CompAttrColor , ConTbl->CompAttrColor , 8 * sizeof(WCHAR));
  158. CopyData.dwData = CI_CONIMECOMPOSITION;
  159. CopyData.cbData = lpCompStrMem->dwSize;
  160. CopyData.lpData = lpCompStrMem;
  161. if (CompFlag & GCS_COMPSTR)
  162. {
  163. //
  164. // Reads in the composition string.
  165. //
  166. ImmGetCompositionString( hIMC, GCS_COMPSTR, TempBuf, lBufLen );
  167. //
  168. // Null terminated.
  169. //
  170. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  171. //
  172. // If GCS_COMPATTR flag is on, then we need to take care of it.
  173. //
  174. if ( lBufLenAttr != 0 )
  175. {
  176. ImmGetCompositionString( hIMC,
  177. GCS_COMPATTR,
  178. TempBufA,
  179. lBufLenAttr );
  180. TempBufA[ lBufLenAttr ] = (BYTE)0;
  181. }
  182. CursorPos = ImmGetCompositionString( hIMC, GCS_CURSORPOS, NULL, 0 );
  183. if (CursorPos == 0)
  184. TempBufA[ CursorPos ] |= (BYTE)0x20;
  185. else
  186. TempBufA[ CursorPos-1 ] |= (BYTE)0x10;
  187. #ifdef DEBUG_INFO
  188. //
  189. // Display new composition chars.
  190. //
  191. xPos = (UINT)lBufLen;
  192. xPosLast = (UINT)lBufLen;
  193. DisplayCompString( hwnd, lBufLen / sizeof(WCHAR), TempBuf, TempBufA );
  194. #endif
  195. lpCompStrMem->dwCompStrLen = lBufLen;
  196. if (lpCompStrMem->dwCompStrLen)
  197. lpCompStrMem->dwCompStrOffset = sizeof(CONIME_UICOMPMESSAGE);
  198. lpCompStrMem->dwCompAttrLen = lBufLenAttr;
  199. if (lpCompStrMem->dwCompAttrLen)
  200. lpCompStrMem->dwCompAttrOffset = sizeof(CONIME_UICOMPMESSAGE) + lBufLen + sizeof(WCHAR);
  201. }
  202. else if (CompFlag & GCS_RESULTSTR)
  203. {
  204. //
  205. // Reads in the result string.
  206. //
  207. ImmGetCompositionString( hIMC, GCS_RESULTSTR, TempBuf, lBufLen );
  208. //
  209. // Null terminated.
  210. //
  211. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  212. #ifdef DEBUG_INFO
  213. //
  214. // Displays the result string.
  215. //
  216. DisplayResultString( hwnd, TempBuf );
  217. #endif
  218. lpCompStrMem->dwResultStrLen = lBufLen;
  219. if (lpCompStrMem->dwResultStrLen)
  220. lpCompStrMem->dwResultStrOffset = sizeof(CONIME_UICOMPMESSAGE);
  221. }
  222. else if (CompFlag == 0)
  223. {
  224. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  225. TempBufA[ lBufLenAttr ] = (BYTE)0;
  226. lpCompStrMem->dwResultStrLen = lBufLen;
  227. lpCompStrMem->dwCompStrLen = lBufLen;
  228. lpCompStrMem->dwCompAttrLen = lBufLenAttr;
  229. }
  230. //
  231. // send character to Console
  232. //
  233. ConsoleImeSendMessage( ConTbl->hWndCon,
  234. (WPARAM)hwnd,
  235. (LPARAM)&CopyData
  236. );
  237. ImmReleaseContext( hwnd, hIMC );
  238. }
  239. void
  240. GetCompStrTaiwan(
  241. HWND hwnd,
  242. PCONSOLE_TABLE ConTbl,
  243. LPARAM CompFlag
  244. )
  245. {
  246. HIMC hIMC; // Input context handle.
  247. LONG lBufLen; // Storage for len. of composition str
  248. LONG lBufLenAttr;
  249. DWORD SizeToAlloc;
  250. PWCHAR TempBuf;
  251. PUCHAR TempBufA;
  252. DWORD i;
  253. DWORD CursorPos;
  254. COPYDATASTRUCT CopyData;
  255. LPCONIME_UIMODEINFO lpModeInfo;
  256. LPCONIME_UICOMPMESSAGE lpCompStrMem;
  257. //
  258. // If fail to get input context handle then do nothing.
  259. // Applications should call ImmGetContext API to get
  260. // input context handle.
  261. //
  262. hIMC = ImmGetContext( hwnd );
  263. if ( hIMC == 0 )
  264. return;
  265. lpModeInfo = (LPCONIME_UIMODEINFO)LocalAlloc(LPTR, sizeof(CONIME_UIMODEINFO) );
  266. if ( lpModeInfo == NULL) {
  267. ImmReleaseContext( hwnd, hIMC );
  268. return;
  269. }
  270. if (CompFlag & GCS_COMPSTR)
  271. {
  272. //
  273. // Determines how much memory space to store the composition string.
  274. // Applications should call ImmGetCompositionString with
  275. // GCS_COMPSTR flag on, buffer length zero, to get the bullfer
  276. // length.
  277. //
  278. lBufLen = ImmGetCompositionString( hIMC, GCS_COMPSTR, (void FAR*)NULL, 0l );
  279. if ( lBufLen < 0 ) {
  280. ImmReleaseContext( hwnd, hIMC );
  281. return;
  282. }
  283. if ( CompFlag & GCS_COMPATTR )
  284. {
  285. DBGPRINT((" GCS_COMPATTR\n"));
  286. lBufLenAttr = ImmGetCompositionString( hIMC, GCS_COMPATTR,( void FAR *)NULL, 0l );
  287. if ( lBufLenAttr < 0 ) {
  288. lBufLenAttr = 0;
  289. }
  290. }
  291. else {
  292. lBufLenAttr = 0;
  293. }
  294. }
  295. else if (CompFlag & GCS_RESULTSTR)
  296. {
  297. //
  298. // Determines how much memory space to store the result string.
  299. // Applications should call ImmGetCompositionString with
  300. // GCS_RESULTSTR flag on, buffer length zero, to get the bullfer
  301. // length.
  302. //
  303. lBufLen = ImmGetCompositionString( hIMC, GCS_RESULTSTR, (void FAR *)NULL, 0l );
  304. if ( lBufLen < 0 ) {
  305. ImmReleaseContext( hwnd, hIMC );
  306. return;
  307. }
  308. lBufLenAttr = 0;
  309. }
  310. else if (CompFlag == 0)
  311. {
  312. lBufLen = 0;
  313. lBufLenAttr = 0;
  314. }
  315. SizeToAlloc = (UINT)( sizeof(CONIME_UICOMPMESSAGE) +
  316. lBufLen + sizeof(WCHAR) +
  317. lBufLenAttr + sizeof(BYTE) );
  318. if ( ConTbl->lpCompStrMem != NULL &&
  319. SizeToAlloc > ConTbl->lpCompStrMem->dwSize
  320. )
  321. {
  322. LocalFree( ConTbl->lpCompStrMem );
  323. ConTbl->lpCompStrMem = NULL;
  324. }
  325. if (ConTbl->lpCompStrMem == NULL) {
  326. ConTbl->lpCompStrMem = (LPCONIME_UICOMPMESSAGE)LocalAlloc(LPTR, SizeToAlloc );
  327. if ( ConTbl->lpCompStrMem == NULL) {
  328. ImmReleaseContext( hwnd, hIMC );
  329. return;
  330. }
  331. ConTbl->lpCompStrMem->dwSize = SizeToAlloc;
  332. }
  333. lpCompStrMem = ConTbl->lpCompStrMem;
  334. RtlZeroMemory(&lpCompStrMem->dwCompAttrLen,
  335. lpCompStrMem->dwSize - sizeof(lpCompStrMem->dwSize)
  336. );
  337. TempBuf = (PWCHAR)((PUCHAR)lpCompStrMem + sizeof(CONIME_UICOMPMESSAGE));
  338. TempBufA = (PUCHAR)((PUCHAR)lpCompStrMem + sizeof(CONIME_UICOMPMESSAGE) +
  339. lBufLen + sizeof(WCHAR));
  340. CopyMemory(lpCompStrMem->CompAttrColor , ConTbl->CompAttrColor , 8 * sizeof(WCHAR));
  341. if (CompFlag & GCS_COMPSTR)
  342. {
  343. //
  344. // Reads in the composition string.
  345. //
  346. ImmGetCompositionString( hIMC, GCS_COMPSTR, TempBuf, lBufLen );
  347. //
  348. // Null terminated.
  349. //
  350. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  351. //
  352. // If GCS_COMPATTR flag is on, then we need to take care of it.
  353. //
  354. if ( lBufLenAttr != 0 )
  355. {
  356. ImmGetCompositionString( hIMC,
  357. GCS_COMPATTR,
  358. TempBufA,
  359. lBufLenAttr );
  360. TempBufA[ lBufLenAttr ] = (BYTE)0;
  361. }
  362. lpCompStrMem->dwCompStrLen = lBufLen;
  363. if (lpCompStrMem->dwCompStrLen)
  364. lpCompStrMem->dwCompStrOffset = sizeof(CONIME_UICOMPMESSAGE);
  365. lpCompStrMem->dwCompAttrLen = lBufLenAttr;
  366. if (lpCompStrMem->dwCompAttrLen)
  367. lpCompStrMem->dwCompAttrOffset = sizeof(CONIME_UICOMPMESSAGE) + lBufLen + sizeof(WCHAR);
  368. //
  369. // Display character to Console
  370. //
  371. CopyData.dwData = CI_CONIMEMODEINFO;
  372. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  373. CopyData.lpData = lpModeInfo;
  374. if (MakeInfoStringTaiwan(ConTbl, lpModeInfo) ) {
  375. ConsoleImeSendMessage( ConTbl->hWndCon,
  376. (WPARAM)hwnd,
  377. (LPARAM)&CopyData
  378. );
  379. }
  380. }
  381. else if (CompFlag & GCS_RESULTSTR)
  382. {
  383. //
  384. // Reads in the result string.
  385. //
  386. ImmGetCompositionString( hIMC, GCS_RESULTSTR, TempBuf, lBufLen );
  387. //
  388. // Null terminated.
  389. //
  390. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  391. lpCompStrMem->dwResultStrLen = lBufLen;
  392. if (lpCompStrMem->dwResultStrLen)
  393. lpCompStrMem->dwResultStrOffset = sizeof(CONIME_UICOMPMESSAGE);
  394. //
  395. // send character to Console
  396. //
  397. CopyData.dwData = CI_CONIMECOMPOSITION;
  398. CopyData.cbData = lpCompStrMem->dwSize;
  399. CopyData.lpData = lpCompStrMem;
  400. ConsoleImeSendMessage( ConTbl->hWndCon,
  401. (WPARAM)hwnd,
  402. (LPARAM)&CopyData
  403. );
  404. }
  405. else if (CompFlag == 0)
  406. {
  407. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  408. TempBufA[ lBufLenAttr ] = (BYTE)0;
  409. lpCompStrMem->dwResultStrLen = lBufLen;
  410. lpCompStrMem->dwCompStrLen = lBufLen;
  411. lpCompStrMem->dwCompAttrLen = lBufLenAttr;
  412. //
  413. // Display character to Console
  414. //
  415. CopyData.dwData = CI_CONIMEMODEINFO;
  416. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  417. CopyData.lpData = lpModeInfo;
  418. if (MakeInfoStringTaiwan(ConTbl, lpModeInfo) ) {
  419. ConsoleImeSendMessage( ConTbl->hWndCon,
  420. (WPARAM)hwnd,
  421. (LPARAM)&CopyData
  422. );
  423. }
  424. }
  425. LocalFree( lpModeInfo );
  426. ImmReleaseContext( hwnd, hIMC );
  427. return;
  428. }
  429. void
  430. GetCompStrPRC(
  431. HWND hwnd,
  432. PCONSOLE_TABLE ConTbl,
  433. LPARAM CompFlag
  434. )
  435. {
  436. HIMC hIMC; // Input context handle.
  437. LONG lBufLen; // Storage for len. of composition str
  438. LONG lBufLenAttr;
  439. DWORD SizeToAlloc;
  440. PWCHAR TempBuf;
  441. PUCHAR TempBufA;
  442. DWORD i;
  443. DWORD CursorPos;
  444. COPYDATASTRUCT CopyData;
  445. LPCONIME_UIMODEINFO lpModeInfo;
  446. LPCONIME_UICOMPMESSAGE lpCompStrMem;
  447. //
  448. // If fail to get input context handle then do nothing.
  449. // Applications should call ImmGetContext API to get
  450. // input context handle.
  451. //
  452. hIMC = ImmGetContext( hwnd );
  453. if ( hIMC == 0 )
  454. return;
  455. lpModeInfo = (LPCONIME_UIMODEINFO)LocalAlloc(LPTR, sizeof(CONIME_UIMODEINFO) );
  456. if ( lpModeInfo == NULL) {
  457. ImmReleaseContext( hwnd, hIMC );
  458. return;
  459. }
  460. if (CompFlag & GCS_COMPSTR)
  461. {
  462. //
  463. // Determines how much memory space to store the composition string.
  464. // Applications should call ImmGetCompositionString with
  465. // GCS_COMPSTR flag on, buffer length zero, to get the bullfer
  466. // length.
  467. //
  468. lBufLen = ImmGetCompositionString( hIMC, GCS_COMPSTR, (void FAR*)NULL, 0l );
  469. if ( lBufLen < 0 ) {
  470. ImmReleaseContext( hwnd, hIMC );
  471. return;
  472. }
  473. if ( CompFlag & GCS_COMPATTR )
  474. {
  475. DBGPRINT((" GCS_COMPATTR\n"));
  476. lBufLenAttr = ImmGetCompositionString( hIMC, GCS_COMPATTR,( void FAR *)NULL, 0l );
  477. if ( lBufLenAttr < 0 ) {
  478. lBufLenAttr = 0;
  479. }
  480. }
  481. else {
  482. lBufLenAttr = 0;
  483. }
  484. }
  485. else if (CompFlag & GCS_RESULTSTR)
  486. {
  487. //
  488. // Determines how much memory space to store the result string.
  489. // Applications should call ImmGetCompositionString with
  490. // GCS_RESULTSTR flag on, buffer length zero, to get the bullfer
  491. // length.
  492. //
  493. lBufLen = ImmGetCompositionString( hIMC, GCS_RESULTSTR, (void FAR *)NULL, 0l );
  494. if ( lBufLen < 0 ) {
  495. ImmReleaseContext( hwnd, hIMC );
  496. return;
  497. }
  498. lBufLenAttr = 0;
  499. }
  500. else if (CompFlag == 0)
  501. {
  502. lBufLen = 0;
  503. lBufLenAttr = 0;
  504. }
  505. SizeToAlloc = (UINT)( sizeof(CONIME_UICOMPMESSAGE) +
  506. lBufLen + sizeof(WCHAR) +
  507. lBufLenAttr + sizeof(BYTE) );
  508. if ( ConTbl->lpCompStrMem != NULL &&
  509. SizeToAlloc > ConTbl->lpCompStrMem->dwSize
  510. )
  511. {
  512. LocalFree( ConTbl->lpCompStrMem );
  513. ConTbl->lpCompStrMem = NULL;
  514. }
  515. if (ConTbl->lpCompStrMem == NULL) {
  516. ConTbl->lpCompStrMem = (LPCONIME_UICOMPMESSAGE)LocalAlloc(LPTR, SizeToAlloc );
  517. if ( ConTbl->lpCompStrMem == NULL) {
  518. ImmReleaseContext( hwnd, hIMC );
  519. return;
  520. }
  521. ConTbl->lpCompStrMem->dwSize = SizeToAlloc;
  522. }
  523. lpCompStrMem = ConTbl->lpCompStrMem;
  524. RtlZeroMemory(&lpCompStrMem->dwCompAttrLen,
  525. lpCompStrMem->dwSize - sizeof(lpCompStrMem->dwSize)
  526. );
  527. TempBuf = (PWCHAR)((PUCHAR)lpCompStrMem + sizeof(CONIME_UICOMPMESSAGE));
  528. TempBufA = (PUCHAR)((PUCHAR)lpCompStrMem + sizeof(CONIME_UICOMPMESSAGE) +
  529. lBufLen + sizeof(WCHAR));
  530. CopyMemory(lpCompStrMem->CompAttrColor , ConTbl->CompAttrColor , 8 * sizeof(WCHAR));
  531. if (CompFlag & GCS_COMPSTR)
  532. {
  533. //
  534. // Reads in the composition string.
  535. //
  536. ImmGetCompositionString( hIMC, GCS_COMPSTR, TempBuf, lBufLen );
  537. //
  538. // Null terminated.
  539. //
  540. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  541. //
  542. // If GCS_COMPATTR flag is on, then we need to take care of it.
  543. //
  544. if ( lBufLenAttr != 0 )
  545. {
  546. ImmGetCompositionString( hIMC,
  547. GCS_COMPATTR,
  548. TempBufA,
  549. lBufLenAttr );
  550. TempBufA[ lBufLenAttr ] = (BYTE)0;
  551. }
  552. lpCompStrMem->dwCompStrLen = lBufLen;
  553. if (lpCompStrMem->dwCompStrLen)
  554. lpCompStrMem->dwCompStrOffset = sizeof(CONIME_UICOMPMESSAGE);
  555. lpCompStrMem->dwCompAttrLen = lBufLenAttr;
  556. if (lpCompStrMem->dwCompAttrLen)
  557. lpCompStrMem->dwCompAttrOffset = sizeof(CONIME_UICOMPMESSAGE) + lBufLen + sizeof(WCHAR);
  558. //
  559. // Display character to Console
  560. //
  561. CopyData.dwData = CI_CONIMEMODEINFO;
  562. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  563. CopyData.lpData = lpModeInfo;
  564. if (MakeInfoStringPRC(ConTbl, lpModeInfo) ) {
  565. ConsoleImeSendMessage( ConTbl->hWndCon,
  566. (WPARAM)hwnd,
  567. (LPARAM)&CopyData
  568. );
  569. }
  570. }
  571. else if (CompFlag & GCS_RESULTSTR)
  572. {
  573. //
  574. // Reads in the result string.
  575. //
  576. ImmGetCompositionString( hIMC, GCS_RESULTSTR, TempBuf, lBufLen );
  577. //
  578. // Null terminated.
  579. //
  580. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  581. lpCompStrMem->dwResultStrLen = lBufLen;
  582. if (lpCompStrMem->dwResultStrLen)
  583. lpCompStrMem->dwResultStrOffset = sizeof(CONIME_UICOMPMESSAGE);
  584. //
  585. // send character to Console
  586. //
  587. CopyData.dwData = CI_CONIMECOMPOSITION;
  588. CopyData.cbData = lpCompStrMem->dwSize;
  589. CopyData.lpData = lpCompStrMem;
  590. ConsoleImeSendMessage( ConTbl->hWndCon,
  591. (WPARAM)hwnd,
  592. (LPARAM)&CopyData
  593. );
  594. }
  595. else if (CompFlag == 0)
  596. {
  597. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  598. TempBufA[ lBufLenAttr ] = (BYTE)0;
  599. lpCompStrMem->dwResultStrLen = lBufLen;
  600. lpCompStrMem->dwCompStrLen = lBufLen;
  601. lpCompStrMem->dwCompAttrLen = lBufLenAttr;
  602. //
  603. // Display character to Console
  604. //
  605. CopyData.dwData = CI_CONIMEMODEINFO;
  606. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  607. CopyData.lpData = lpModeInfo;
  608. if (MakeInfoStringPRC(ConTbl, lpModeInfo) ) {
  609. ConsoleImeSendMessage( ConTbl->hWndCon,
  610. (WPARAM)hwnd,
  611. (LPARAM)&CopyData
  612. );
  613. }
  614. }
  615. LocalFree( lpModeInfo );
  616. ImmReleaseContext( hwnd, hIMC );
  617. return;
  618. }
  619. void
  620. GetCompStrKorea(
  621. HWND hwnd,
  622. PCONSOLE_TABLE ConTbl,
  623. LPARAM CompFlag,
  624. WPARAM CompChar
  625. )
  626. {
  627. HIMC hIMC; // Input context handle.
  628. LONG lBufLen; // Storage for len. of composition str
  629. LONG lBufLenAttr;
  630. COPYDATASTRUCT CopyData;
  631. DWORD SizeToAlloc;
  632. PWCHAR TempBuf;
  633. PUCHAR TempBufA;
  634. LONG i;
  635. DWORD CursorPos;
  636. LPCONIME_UICOMPMESSAGE lpCompStrMem;
  637. //
  638. // If fail to get input context handle then do nothing.
  639. // Applications should call ImmGetContext API to get
  640. // input context handle.
  641. //
  642. hIMC = ImmGetContext( hwnd );
  643. if ( hIMC == 0 )
  644. return;
  645. // if (CompFlag & CS_INSERTCHAR)
  646. // {
  647. // lBufLen = 1;
  648. // lBufLenAttr = 1;
  649. // }
  650. // else
  651. if (CompFlag & GCS_COMPSTR)
  652. {
  653. //
  654. // Determines how much memory space to store the composition string.
  655. // Applications should call ImmGetCompositionString with
  656. // GCS_COMPSTR flag on, buffer length zero, to get the bullfer
  657. // length.
  658. //
  659. lBufLen = ImmGetCompositionString( hIMC, GCS_COMPSTR, (void FAR*)NULL, 0l );
  660. if ( lBufLen < 0 ) {
  661. ImmReleaseContext( hwnd, hIMC );
  662. return;
  663. }
  664. if ( CompFlag & GCS_COMPATTR )
  665. {
  666. DBGPRINT((" GCS_COMPATTR\n"));
  667. lBufLenAttr = ImmGetCompositionString( hIMC, GCS_COMPATTR,( void FAR *)NULL, 0l );
  668. if ( lBufLenAttr < 0 ) {
  669. lBufLenAttr = 0;
  670. }
  671. }
  672. else {
  673. lBufLenAttr = lBufLen;
  674. }
  675. }
  676. else if (CompFlag & GCS_RESULTSTR)
  677. {
  678. //
  679. // Determines how much memory space to store the result string.
  680. // Applications should call ImmGetCompositionString with
  681. // GCS_RESULTSTR flag on, buffer length zero, to get the bullfer
  682. // length.
  683. //
  684. lBufLen = ImmGetCompositionString( hIMC, GCS_RESULTSTR, (void FAR *)NULL, 0l );
  685. if ( lBufLen < 0 ) {
  686. ImmReleaseContext( hwnd, hIMC );
  687. return;
  688. }
  689. lBufLenAttr = 0;
  690. }
  691. else if (CompFlag == 0)
  692. {
  693. lBufLen = 0;
  694. lBufLenAttr = 0;
  695. }
  696. else
  697. {
  698. return;
  699. }
  700. SizeToAlloc = (UINT)( sizeof(CONIME_UICOMPMESSAGE) +
  701. lBufLen + sizeof(WCHAR) +
  702. lBufLenAttr + sizeof(BYTE) );
  703. if ( ConTbl->lpCompStrMem != NULL &&
  704. SizeToAlloc > ConTbl->lpCompStrMem->dwSize
  705. )
  706. {
  707. LocalFree( ConTbl->lpCompStrMem );
  708. ConTbl->lpCompStrMem = NULL;
  709. }
  710. if (ConTbl->lpCompStrMem == NULL) {
  711. ConTbl->lpCompStrMem = (LPCONIME_UICOMPMESSAGE)LocalAlloc(LPTR, SizeToAlloc );
  712. if ( ConTbl->lpCompStrMem == NULL) {
  713. ImmReleaseContext( hwnd, hIMC );
  714. return;
  715. }
  716. ConTbl->lpCompStrMem->dwSize = SizeToAlloc;
  717. }
  718. lpCompStrMem = ConTbl->lpCompStrMem;
  719. RtlZeroMemory(&lpCompStrMem->dwCompAttrLen,
  720. lpCompStrMem->dwSize - sizeof(lpCompStrMem->dwSize)
  721. );
  722. TempBuf = (PWCHAR)((PUCHAR)lpCompStrMem + sizeof(CONIME_UICOMPMESSAGE));
  723. TempBufA = (PUCHAR)((PUCHAR)lpCompStrMem + sizeof(CONIME_UICOMPMESSAGE) +
  724. lBufLen + sizeof(WCHAR));
  725. CopyMemory(lpCompStrMem->CompAttrColor , ConTbl->CompAttrColor , 8 * sizeof(WCHAR));
  726. CopyData.dwData = CI_CONIMECOMPOSITION;
  727. CopyData.cbData = lpCompStrMem->dwSize;
  728. CopyData.lpData = lpCompStrMem;
  729. if (CompFlag & CS_INSERTCHAR)
  730. {
  731. *TempBuf = (WORD)CompChar;
  732. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  733. *TempBufA = (BYTE)ATTR_TARGET_CONVERTED;
  734. TempBufA[ lBufLenAttr ] = (BYTE)0;
  735. }
  736. else if (CompFlag & GCS_COMPSTR)
  737. {
  738. //
  739. // Reads in the composition string.
  740. //
  741. ImmGetCompositionString( hIMC, GCS_COMPSTR, TempBuf, lBufLen );
  742. //
  743. // Null terminated.
  744. //
  745. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  746. //
  747. // If GCS_COMPATTR flag is on, then we need to take care of it.
  748. //
  749. if ( lBufLenAttr != 0 )
  750. {
  751. if ( CompFlag & GCS_COMPATTR )
  752. {
  753. ImmGetCompositionString( hIMC,
  754. GCS_COMPATTR,
  755. TempBufA,
  756. lBufLenAttr );
  757. TempBufA[ lBufLenAttr ] = (BYTE)0;
  758. }
  759. else
  760. {
  761. for (i = 0; i <= lBufLenAttr; i++)
  762. TempBufA[ i ] = (BYTE)1;
  763. }
  764. }
  765. // Korean NT does not need IME cursor. v-hirshi
  766. // CursorPos = ImmGetCompositionString( hIMC, GCS_CURSORPOS, NULL, 0 );
  767. // if (CursorPos == 0)
  768. // TempBufA[ CursorPos ] |= (BYTE)0x20;
  769. // else
  770. // TempBufA[ CursorPos-1 ] |= (BYTE)0x10;
  771. #ifdef DEBUG_INFO
  772. //
  773. // Display new composition chars.
  774. //
  775. xPos = (UINT)lBufLen;
  776. xPosLast = (UINT)lBufLen;
  777. DisplayCompString( hwnd, lBufLen / sizeof(WCHAR), TempBuf, TempBufA );
  778. #endif
  779. lpCompStrMem->dwCompStrLen = lBufLen;
  780. if (lpCompStrMem->dwCompStrLen)
  781. lpCompStrMem->dwCompStrOffset = sizeof(CONIME_UICOMPMESSAGE);
  782. lpCompStrMem->dwCompAttrLen = lBufLenAttr;
  783. if (lpCompStrMem->dwCompAttrLen)
  784. lpCompStrMem->dwCompAttrOffset = sizeof(CONIME_UICOMPMESSAGE) + lBufLen + sizeof(WCHAR);
  785. }
  786. else if (CompFlag & GCS_RESULTSTR)
  787. {
  788. //
  789. // Reads in the result string.
  790. //
  791. ImmGetCompositionString( hIMC, GCS_RESULTSTR, TempBuf, lBufLen );
  792. //
  793. // Null terminated.
  794. //
  795. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  796. #ifdef DEBUG_INFO
  797. //
  798. // Displays the result string.
  799. //
  800. DisplayResultString( hwnd, TempBuf );
  801. #endif
  802. lpCompStrMem->dwResultStrLen = lBufLen;
  803. if (lpCompStrMem->dwResultStrLen)
  804. lpCompStrMem->dwResultStrOffset = sizeof(CONIME_UICOMPMESSAGE);
  805. }
  806. else if (CompFlag == 0)
  807. {
  808. TempBuf[ lBufLen / sizeof(WCHAR) ] = TEXT('\0');
  809. TempBufA[ lBufLenAttr ] = (BYTE)0;
  810. lpCompStrMem->dwResultStrLen = lBufLen;
  811. lpCompStrMem->dwCompStrLen = lBufLen;
  812. lpCompStrMem->dwCompAttrLen = lBufLenAttr;
  813. }
  814. //
  815. // send character to Console
  816. //
  817. ConsoleImeSendMessage( ConTbl->hWndCon,
  818. (WPARAM)hwnd,
  819. (LPARAM)&CopyData
  820. );
  821. ImmReleaseContext( hwnd, hIMC );
  822. }
  823. VOID
  824. ReDisplayCompositionStr (
  825. HWND hwnd
  826. )
  827. {
  828. PCONSOLE_TABLE ConTbl;
  829. ConTbl = SearchConsole(LastConsole);
  830. if (ConTbl == NULL) {
  831. DBGPRINT(("CONIME: Error! Cannot found registed Console\n"));
  832. return;
  833. }
  834. if (! ConTbl->fInComposition)
  835. return;
  836. switch ( HKL_TO_LANGID(ConTbl->hklActive))
  837. {
  838. case LANG_ID_JAPAN:
  839. ReDisplayCompStrJapan(hwnd, ConTbl);
  840. break;
  841. case LANG_ID_TAIWAN:
  842. ReDisplayCompStrTaiwan(hwnd, ConTbl);
  843. break;
  844. case LANG_ID_PRC:
  845. ReDisplayCompStrPRC(hwnd, ConTbl);
  846. break;
  847. case LANG_ID_KOREA:
  848. ReDisplayCompStrKorea(hwnd, ConTbl);
  849. break;
  850. default:
  851. break;
  852. }
  853. return;
  854. }
  855. VOID
  856. ReDisplayCompStrJapan(
  857. HWND hwnd,
  858. PCONSOLE_TABLE ConTbl
  859. )
  860. {
  861. COPYDATASTRUCT CopyData;
  862. LPCONIME_UICOMPMESSAGE lpCompStrMem;
  863. lpCompStrMem = ConTbl->lpCompStrMem;
  864. CopyData.dwData = CI_CONIMECOMPOSITION;
  865. CopyData.cbData = lpCompStrMem->dwSize;
  866. CopyData.lpData = lpCompStrMem;
  867. ConsoleImeSendMessage( ConTbl->hWndCon,
  868. (WPARAM)hwnd,
  869. (LPARAM)&CopyData
  870. );
  871. }
  872. VOID
  873. ReDisplayCompStrTaiwan(
  874. HWND hwnd,
  875. PCONSOLE_TABLE ConTbl
  876. )
  877. {
  878. COPYDATASTRUCT CopyData;
  879. LPCONIME_UIMODEINFO lpModeInfo;
  880. lpModeInfo = (LPCONIME_UIMODEINFO)LocalAlloc(LPTR, sizeof(CONIME_UIMODEINFO) );
  881. if ( lpModeInfo == NULL) {
  882. return;
  883. }
  884. //
  885. // Display character to Console
  886. //
  887. CopyData.dwData = CI_CONIMEMODEINFO;
  888. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  889. CopyData.lpData = lpModeInfo;
  890. if (MakeInfoStringTaiwan(ConTbl, lpModeInfo) ) {
  891. ConsoleImeSendMessage( ConTbl->hWndCon,
  892. (WPARAM)hwnd,
  893. (LPARAM)&CopyData
  894. );
  895. }
  896. LocalFree( lpModeInfo );
  897. }
  898. VOID
  899. ReDisplayCompStrPRC(
  900. HWND hwnd,
  901. PCONSOLE_TABLE ConTbl
  902. )
  903. {
  904. COPYDATASTRUCT CopyData;
  905. LPCONIME_UIMODEINFO lpModeInfo;
  906. lpModeInfo = (LPCONIME_UIMODEINFO)LocalAlloc(LPTR, sizeof(CONIME_UIMODEINFO) );
  907. if ( lpModeInfo == NULL) {
  908. return;
  909. }
  910. //
  911. // Display character to Console
  912. //
  913. CopyData.dwData = CI_CONIMEMODEINFO;
  914. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  915. CopyData.lpData = lpModeInfo;
  916. if (MakeInfoStringPRC(ConTbl, lpModeInfo) ) {
  917. ConsoleImeSendMessage( ConTbl->hWndCon,
  918. (WPARAM)hwnd,
  919. (LPARAM)&CopyData
  920. );
  921. }
  922. LocalFree( lpModeInfo );
  923. }
  924. VOID
  925. ReDisplayCompStrKorea(
  926. HWND hwnd,
  927. PCONSOLE_TABLE ConTbl
  928. )
  929. {
  930. COPYDATASTRUCT CopyData;
  931. LPCONIME_UICOMPMESSAGE lpCompStrMem;
  932. lpCompStrMem = ConTbl->lpCompStrMem;
  933. CopyData.dwData = CI_CONIMECOMPOSITION;
  934. CopyData.cbData = lpCompStrMem->dwSize;
  935. CopyData.lpData = lpCompStrMem;
  936. ConsoleImeSendMessage( ConTbl->hWndCon,
  937. (WPARAM)hwnd,
  938. (LPARAM)&CopyData
  939. );
  940. }