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.

1394 lines
46 KiB

  1. // Copyright (c) 1985 - 1999, Microsoft Corporation
  2. //
  3. // MODULE: country2.c
  4. //
  5. // PURPOSE: Console IME control.
  6. // FarEast country specific module 2 for conime.
  7. //
  8. // PLATFORMS: Windows NT-FE 3.51
  9. //
  10. // FUNCTIONS:
  11. // ImeUIOpenCandidate() - routine for make system line string
  12. //
  13. // History:
  14. //
  15. // 15.Jul.1996 v-HirShi (Hirotoshi Shimizu) Created for TAIWAN & KOREA & PRC
  16. //
  17. // COMMENTS:
  18. //
  19. #include "precomp.h"
  20. #pragma hdrstop
  21. BOOL
  22. ImeUIOpenCandidate(
  23. HWND hwnd,
  24. DWORD CandList,
  25. BOOL OpenFlag
  26. )
  27. {
  28. PCONSOLE_TABLE ConTbl;
  29. HIMC hIMC;
  30. DBGPRINT(("CONIME: Get IMN_OPENCANDIDATE Message\n"));
  31. ConTbl = SearchConsole(LastConsole);
  32. if (ConTbl->fNestCandidate)
  33. return TRUE;
  34. if (ConTbl == NULL) {
  35. DBGPRINT(("CONIME: Error! Cannot found registed Console\n"));
  36. return FALSE;
  37. }
  38. hIMC = ImmGetContext( hwnd );
  39. if ( hIMC == 0 )
  40. return FALSE;
  41. //
  42. // Set fInCandidate variables.
  43. //
  44. ConTbl->fInCandidate = TRUE;
  45. switch ( HKL_TO_LANGID(ConTbl->hklActive))
  46. {
  47. case LANG_ID_JAPAN:
  48. OpenCandidateJapan(hwnd, hIMC, ConTbl, CandList, OpenFlag );
  49. break;
  50. case LANG_ID_TAIWAN:
  51. OpenCandidateTaiwan(hwnd, hIMC, ConTbl, CandList, OpenFlag );
  52. break;
  53. case LANG_ID_PRC:
  54. OpenCandidatePRC(hwnd, hIMC, ConTbl, CandList, OpenFlag );
  55. break;
  56. case LANG_ID_KOREA:
  57. OpenCandidateKorea(hwnd, hIMC, ConTbl, CandList, OpenFlag );
  58. break;
  59. default:
  60. return FALSE;
  61. }
  62. ImmReleaseContext( hwnd, hIMC );
  63. return TRUE;
  64. }
  65. BOOL
  66. OpenCandidateJapan(
  67. HWND hwnd,
  68. HIMC hIMC ,
  69. PCONSOLE_TABLE ConTbl,
  70. DWORD CandList,
  71. BOOL OpenFlag
  72. )
  73. {
  74. DWORD dwLength;
  75. DWORD dwIndex;
  76. DWORD i;
  77. DWORD j;
  78. LPWSTR lpStr;
  79. DWORD dwDspLen;
  80. DWORD width;
  81. DWORD StartIndex;
  82. DWORD CountDispWidth;
  83. DWORD AllocLength;
  84. LPCANDIDATELIST lpCandList;
  85. LPCONIME_CANDMESSAGE SystemLine;
  86. DWORD SystemLineSize;
  87. COPYDATASTRUCT CopyData;
  88. BOOL EnableCodePoint;
  89. for (dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) {
  90. if ( CandList & ( 1 << dwIndex ) ) {
  91. dwLength = ImmGetCandidateList(hIMC, dwIndex, NULL, 0);
  92. if (dwLength == 0)
  93. return FALSE;
  94. if ( (ConTbl->CandListMemAllocSize[dwIndex] != dwLength ) &&
  95. (ConTbl->lpCandListMem[dwIndex] != NULL)) {
  96. LocalFree(ConTbl->lpCandListMem[dwIndex]);
  97. ConTbl->CandListMemAllocSize[dwIndex] = 0;
  98. ConTbl->lpCandListMem[dwIndex] = NULL;
  99. }
  100. if (ConTbl->lpCandListMem[dwIndex] == NULL) {
  101. ConTbl->lpCandListMem[dwIndex] = LocalAlloc(LPTR, dwLength);
  102. if (ConTbl->lpCandListMem[dwIndex] == NULL)
  103. return FALSE;
  104. ConTbl->CandListMemAllocSize[dwIndex] = dwLength;
  105. }
  106. lpCandList = ConTbl->lpCandListMem[dwIndex];
  107. ImmGetCandidateList(hIMC, dwIndex, lpCandList, dwLength);
  108. //
  109. // check each offset value is not over than buffer size.
  110. //
  111. if ((lpCandList->dwCount > 1) &&
  112. (lpCandList->dwSelection >= dwLength ||
  113. lpCandList->dwPageStart >= dwLength ||
  114. lpCandList->dwOffset[lpCandList->dwSelection] >= dwLength ||
  115. lpCandList->dwOffset[lpCandList->dwPageStart] >= dwLength )
  116. )
  117. break;
  118. dwLength = ConTbl->ScreenBufferSize.X;
  119. dwLength = (dwLength > 128) ? 128 : dwLength ;
  120. dwLength = ((dwLength < 12) ? 12 : dwLength );
  121. j = (dwLength-7)/(DELIMITERWIDTH+sizeof(WCHAR));
  122. j = ((j > 9)?9:j);
  123. j = lpCandList->dwCount / j + 10;
  124. AllocLength = (j > DEFAULTCANDTABLE) ? j : DEFAULTCANDTABLE;
  125. if (lpCandList->dwStyle == IME_CAND_CODE){
  126. EnableCodePoint = TRUE;
  127. }
  128. else{
  129. EnableCodePoint = FALSE;
  130. }
  131. if (EnableCodePoint){
  132. CountDispWidth = CODEDISPLEN;
  133. }
  134. else {
  135. for (CountDispWidth = 0 ,j = 1; j <= lpCandList->dwCount; CountDispWidth++)
  136. j *= 10;
  137. CountDispWidth *= 2;
  138. CountDispWidth++;
  139. }
  140. if ((ConTbl->CandSepAllocSize != sizeof(DWORD)*AllocLength) &&
  141. (ConTbl->CandSep != NULL)) {
  142. LocalFree(ConTbl->CandSep);
  143. ConTbl->CandSep = NULL;
  144. ConTbl->CandSepAllocSize = 0;
  145. }
  146. if (ConTbl->CandSep == NULL) {
  147. ConTbl->CandSep= LocalAlloc(LPTR, sizeof(DWORD)*AllocLength);
  148. if (ConTbl->CandSep == NULL)
  149. return FALSE;
  150. ConTbl->CandSepAllocSize = sizeof(DWORD)*AllocLength;
  151. }
  152. if ( EnableCodePoint ){
  153. j = 0;
  154. ConTbl->CandSep[j++] = 0;
  155. if (OpenFlag) {
  156. ConTbl->CandOff = lpCandList->dwSelection % 9;
  157. }
  158. i = ConTbl->CandOff;
  159. for (; i < lpCandList->dwCount; i+= 9 ) {
  160. ConTbl->CandSep[j++] = i;
  161. }
  162. if (i > lpCandList->dwCount) {
  163. i = lpCandList->dwCount;
  164. }
  165. }
  166. else{
  167. j = 0;
  168. if (OpenFlag) {
  169. ConTbl->CandOff = 0;
  170. }
  171. ConTbl->CandSep[j++] = ConTbl->CandOff;
  172. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ 0 ]);
  173. dwDspLen = DispLenUnicode( lpStr );
  174. width = dwDspLen + DELIMITERWIDTH; // '1:xxxx 2:xxxx '
  175. for( i = 1; i < lpCandList->dwCount; i++ ) {
  176. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ i ]);
  177. dwDspLen = DispLenUnicode( lpStr );
  178. width += dwDspLen + DELIMITERWIDTH;
  179. if ((width > dwLength-CountDispWidth) ||
  180. ( i - ConTbl->CandSep[j-1] >= 9)){
  181. ConTbl->CandSep[j++] = i;
  182. width = dwDspLen + DELIMITERWIDTH;
  183. }
  184. }
  185. }
  186. ConTbl->CandSep[j] = i;
  187. ConTbl->CandMax = j;
  188. SystemLineSize = (sizeof(WCHAR)+sizeof(UCHAR))*dwLength + sizeof(DWORD);
  189. if (ConTbl->SystemLineSize < SystemLineSize ){
  190. if (ConTbl->SystemLine != NULL){
  191. LocalFree( ConTbl->SystemLine );
  192. ConTbl->SystemLine = NULL;
  193. ConTbl->SystemLineSize = 0;
  194. }
  195. ConTbl->SystemLine = (LPCONIME_CANDMESSAGE)LocalAlloc(LPTR, SystemLineSize );
  196. if (ConTbl->SystemLine == NULL) {
  197. return FALSE;
  198. }
  199. ConTbl->SystemLineSize = SystemLineSize;
  200. }
  201. SystemLine = ConTbl->SystemLine;
  202. SystemLine->AttrOff = sizeof(WCHAR) * dwLength + sizeof(DWORD);
  203. CopyData.dwData = CI_CONIMECANDINFO;
  204. CopyData.cbData = (sizeof(WCHAR)+sizeof(UCHAR))*dwLength + sizeof(DWORD);
  205. CopyData.lpData = SystemLine;
  206. StartIndex = GetSystemLineJ( lpCandList,
  207. SystemLine->String,
  208. (LPSTR)SystemLine + SystemLine->AttrOff,
  209. dwLength,
  210. CountDispWidth,
  211. ConTbl,
  212. EnableCodePoint);
  213. ConTbl->fNestCandidate = TRUE; // ImmNotyfyIME call back OpenCandidate Message
  214. // by same data.
  215. // so We ignore this mesage.
  216. ImmNotifyIME(hIMC,
  217. NI_SETCANDIDATE_PAGESTART,
  218. dwIndex,
  219. ConTbl->CandSep[StartIndex]);
  220. ImmNotifyIME(hIMC,
  221. NI_SETCANDIDATE_PAGESIZE,
  222. dwIndex,
  223. ConTbl->CandSep[StartIndex+1] -
  224. ConTbl->CandSep[StartIndex]);
  225. ConTbl->fNestCandidate = FALSE;
  226. ConsoleImeSendMessage( ConTbl->hWndCon,
  227. (WPARAM)hwnd,
  228. (LPARAM)&CopyData
  229. );
  230. }
  231. }
  232. return TRUE;
  233. }
  234. BOOL
  235. OpenCandidateTaiwan(
  236. HWND hwnd,
  237. HIMC hIMC ,
  238. PCONSOLE_TABLE ConTbl,
  239. DWORD CandList,
  240. BOOL OpenFlag
  241. )
  242. {
  243. DWORD dwLength;
  244. DWORD dwIndex;
  245. DWORD i;
  246. DWORD j;
  247. LPWSTR lpStr;
  248. DWORD dwDspLen;
  249. DWORD width;
  250. DWORD StartIndex;
  251. DWORD CountDispWidth;
  252. DWORD AllocLength;
  253. LPCANDIDATELIST lpCandList;
  254. LPCONIME_CANDMESSAGE SystemLine;
  255. DWORD SystemLineSize;
  256. COPYDATASTRUCT CopyData;
  257. LPCONIME_UIMODEINFO lpModeInfo;
  258. lpModeInfo = (LPCONIME_UIMODEINFO)LocalAlloc( LPTR, sizeof(CONIME_UIMODEINFO) );
  259. if ( lpModeInfo == NULL) {
  260. return FALSE;
  261. }
  262. for (dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) {
  263. if ( CandList & ( 1 << dwIndex ) ) {
  264. dwLength = ImmGetCandidateList(hIMC, dwIndex, NULL, 0);
  265. if (dwLength == 0)
  266. return FALSE;
  267. if ( (ConTbl->CandListMemAllocSize[dwIndex] != dwLength ) &&
  268. (ConTbl->lpCandListMem[dwIndex] != NULL)) {
  269. LocalFree(ConTbl->lpCandListMem[dwIndex]);
  270. ConTbl->CandListMemAllocSize[dwIndex] = 0;
  271. ConTbl->lpCandListMem[dwIndex] = NULL;
  272. }
  273. if (ConTbl->lpCandListMem[dwIndex] == NULL) {
  274. ConTbl->lpCandListMem[dwIndex] = LocalAlloc(LPTR, dwLength);
  275. if (ConTbl->lpCandListMem[dwIndex] == NULL)
  276. return FALSE;
  277. ConTbl->CandListMemAllocSize[dwIndex] = dwLength;
  278. }
  279. lpCandList = ConTbl->lpCandListMem[dwIndex];
  280. ImmGetCandidateList(hIMC, dwIndex, lpCandList, dwLength);
  281. //
  282. // check each offset value is not over than buffer size.
  283. //
  284. if ((lpCandList->dwCount > 1) &&
  285. (lpCandList->dwSelection >= dwLength ||
  286. lpCandList->dwPageStart >= dwLength ||
  287. lpCandList->dwOffset[lpCandList->dwSelection] >= dwLength ||
  288. lpCandList->dwOffset[lpCandList->dwPageStart] >= dwLength )
  289. )
  290. break;
  291. dwLength = ConTbl->ScreenBufferSize.X;
  292. dwLength = (dwLength > 128) ? 128 : dwLength ;
  293. dwLength = ((dwLength < 12) ? 12 : dwLength );
  294. #if defined (CANDCOUNTCHT) //for wider candidate list space v-hirshi Oct.16.1996
  295. dwLength -= 28; // 6+1+4+1+10+1+....+4+1
  296. #else
  297. dwLength -= IMECNameLength+1+IMECModeFullShapeLen*2+1; // 4+1+2+1+....
  298. #endif
  299. j = (dwLength-7)/(DELIMITERWIDTH+sizeof(WCHAR));
  300. j = ((j > 9)?9:j);
  301. j = lpCandList->dwCount / j + 10;
  302. AllocLength = (j > DEFAULTCANDTABLE) ? j : DEFAULTCANDTABLE;
  303. for (CountDispWidth = 0 ,j = 1; j <= lpCandList->dwCount; CountDispWidth++)
  304. j *= 10;
  305. CountDispWidth *= 2;
  306. CountDispWidth++;
  307. if ((ConTbl->CandSepAllocSize != sizeof(DWORD)*AllocLength) &&
  308. (ConTbl->CandSep != NULL)) {
  309. LocalFree(ConTbl->CandSep);
  310. ConTbl->CandSep = NULL;
  311. ConTbl->CandSepAllocSize = 0;
  312. }
  313. if (ConTbl->CandSep == NULL) {
  314. ConTbl->CandSep= LocalAlloc(LPTR, sizeof(DWORD)*AllocLength);
  315. if (ConTbl->CandSep == NULL)
  316. return FALSE;
  317. ConTbl->CandSepAllocSize = sizeof(DWORD)*AllocLength;
  318. }
  319. j = 0;
  320. if (OpenFlag) {
  321. ConTbl->CandOff = 0;
  322. }
  323. ConTbl->CandSep[j++] = ConTbl->CandOff;
  324. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ 0 ]);
  325. dwDspLen = DispLenUnicode( lpStr );
  326. width = dwDspLen + DELIMITERWIDTH; // '1:xxxx 2:xxxx '
  327. for( i = 1; i < lpCandList->dwCount; i++ ) {
  328. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ i ]);
  329. dwDspLen = DispLenUnicode( lpStr );
  330. width += dwDspLen + DELIMITERWIDTH;
  331. if ((width > dwLength-CountDispWidth) ||
  332. ( i - ConTbl->CandSep[j-1] >= 9)){
  333. ConTbl->CandSep[j++] = i;
  334. width = dwDspLen + DELIMITERWIDTH;
  335. }
  336. }
  337. ConTbl->CandSep[j] = i;
  338. ConTbl->CandMax = j;
  339. SystemLineSize = (sizeof(WCHAR)+sizeof(UCHAR))*dwLength + sizeof(DWORD);
  340. if (ConTbl->SystemLineSize < SystemLineSize ){
  341. if (ConTbl->SystemLine != NULL){
  342. LocalFree( ConTbl->SystemLine );
  343. ConTbl->SystemLine = NULL;
  344. ConTbl->SystemLineSize = 0;
  345. }
  346. ConTbl->SystemLine = (LPCONIME_CANDMESSAGE)LocalAlloc(LPTR, SystemLineSize );
  347. if (ConTbl->SystemLine == NULL) {
  348. return FALSE;
  349. }
  350. ConTbl->SystemLineSize = SystemLineSize;
  351. }
  352. SystemLine = ConTbl->SystemLine;
  353. SystemLine->AttrOff = sizeof(WCHAR) * dwLength + sizeof(DWORD);
  354. StartIndex = GetSystemLineT( lpCandList,
  355. SystemLine->String,
  356. (LPSTR)SystemLine + SystemLine->AttrOff,
  357. dwLength,
  358. CountDispWidth,
  359. ConTbl
  360. );
  361. ConTbl->fNestCandidate = TRUE; // ImmNotyfyIME call back OpenCandidate Message
  362. // by same data.
  363. // so We ignore this mesage.
  364. ImmNotifyIME(hIMC,
  365. NI_SETCANDIDATE_PAGESTART,
  366. dwIndex,
  367. ConTbl->CandSep[StartIndex]);
  368. ImmNotifyIME(hIMC,
  369. NI_SETCANDIDATE_PAGESIZE,
  370. dwIndex,
  371. ConTbl->CandSep[StartIndex+1] -
  372. ConTbl->CandSep[StartIndex]);
  373. ConTbl->fNestCandidate = FALSE;
  374. CopyData.dwData = CI_CONIMEMODEINFO;
  375. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  376. CopyData.lpData = lpModeInfo;
  377. if (MakeInfoStringTaiwan(ConTbl, lpModeInfo) ) {
  378. ConsoleImeSendMessage( ConTbl->hWndCon,
  379. (WPARAM)hwnd,
  380. (LPARAM)&CopyData
  381. );
  382. }
  383. }
  384. }
  385. LocalFree( lpModeInfo );
  386. return TRUE;
  387. }
  388. BOOL
  389. OpenCandidatePRC(
  390. HWND hwnd,
  391. HIMC hIMC ,
  392. PCONSOLE_TABLE ConTbl,
  393. DWORD CandList,
  394. BOOL OpenFlag
  395. )
  396. {
  397. DWORD dwLength;
  398. DWORD dwIndex;
  399. DWORD i;
  400. DWORD j;
  401. LPWSTR lpStr;
  402. DWORD dwDspLen;
  403. DWORD width;
  404. DWORD StartIndex;
  405. DWORD CountDispWidth;
  406. DWORD AllocLength;
  407. LPCANDIDATELIST lpCandList;
  408. LPCONIME_CANDMESSAGE SystemLine;
  409. DWORD SystemLineSize;
  410. COPYDATASTRUCT CopyData;
  411. LPCONIME_UIMODEINFO lpModeInfo;
  412. lpModeInfo = (LPCONIME_UIMODEINFO)LocalAlloc( LPTR, sizeof(CONIME_UIMODEINFO) );
  413. if ( lpModeInfo == NULL) {
  414. return FALSE;
  415. }
  416. for (dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) {
  417. if ( CandList & ( 1 << dwIndex ) ) {
  418. dwLength = ImmGetCandidateList(hIMC, dwIndex, NULL, 0);
  419. if (dwLength == 0)
  420. return FALSE;
  421. if ( (ConTbl->CandListMemAllocSize[dwIndex] != dwLength ) &&
  422. (ConTbl->lpCandListMem[dwIndex] != NULL)) {
  423. LocalFree(ConTbl->lpCandListMem[dwIndex]);
  424. ConTbl->CandListMemAllocSize[dwIndex] = 0;
  425. ConTbl->lpCandListMem[dwIndex] = NULL;
  426. }
  427. if (ConTbl->lpCandListMem[dwIndex] == NULL) {
  428. ConTbl->lpCandListMem[dwIndex] = LocalAlloc(LPTR, dwLength);
  429. if (ConTbl->lpCandListMem[dwIndex] == NULL)
  430. return FALSE;
  431. ConTbl->CandListMemAllocSize[dwIndex] = dwLength;
  432. }
  433. lpCandList = ConTbl->lpCandListMem[dwIndex];
  434. ImmGetCandidateList(hIMC, dwIndex, lpCandList, dwLength);
  435. //
  436. // check each offset value is not over than buffer size.
  437. //
  438. if ((lpCandList->dwCount > 1) &&
  439. (lpCandList->dwSelection >= dwLength ||
  440. lpCandList->dwPageStart >= dwLength ||
  441. lpCandList->dwOffset[lpCandList->dwSelection] >= dwLength ||
  442. lpCandList->dwOffset[lpCandList->dwPageStart] >= dwLength )
  443. )
  444. break;
  445. dwLength = ConTbl->ScreenBufferSize.X;
  446. dwLength = (dwLength > 128) ? 128 : dwLength ;
  447. dwLength = ((dwLength < 12) ? 12 : dwLength );
  448. #if defined (CANDCOUNTPRC) //for wider candidate list space v-hirshi Oct.16.1996
  449. dwLength -= (20 + PRCCOMPWIDTH); //(8+1+4+1+PRCCOMPWIDTH+1+...+5)
  450. #else
  451. dwLength -= (15 + PRCCOMPWIDTH); //(8+1+4+1+PRCCOMPWIDTH+1+...)
  452. #endif
  453. j = (dwLength-7)/(DELIMITERWIDTH+sizeof(WCHAR));
  454. j = ((j > 9)?9:j);
  455. j = lpCandList->dwCount / j + 10;
  456. AllocLength = (j > DEFAULTCANDTABLE) ? j : DEFAULTCANDTABLE;
  457. #if defined (CANDCOUNTPRC) //for wider candidate list space v-hirshi Oct.16.1996
  458. for (CountDispWidth = 0 ,j = 1; j <= lpCandList->dwCount; CountDispWidth++)
  459. j *= 10;
  460. CountDispWidth *= 2;
  461. CountDispWidth++;
  462. #else
  463. CountDispWidth = 0;
  464. #endif
  465. if ((ConTbl->CandSepAllocSize != sizeof(DWORD)*AllocLength) &&
  466. (ConTbl->CandSep != NULL)) {
  467. LocalFree(ConTbl->CandSep);
  468. ConTbl->CandSep = NULL;
  469. ConTbl->CandSepAllocSize = 0;
  470. }
  471. if (ConTbl->CandSep == NULL) {
  472. ConTbl->CandSep= LocalAlloc(LPTR, sizeof(DWORD)*AllocLength);
  473. if (ConTbl->CandSep == NULL)
  474. return FALSE;
  475. ConTbl->CandSepAllocSize = sizeof(DWORD)*AllocLength;
  476. }
  477. j = 0;
  478. if (OpenFlag) {
  479. ConTbl->CandOff = 0;
  480. }
  481. ConTbl->CandSep[j++] = ConTbl->CandOff;
  482. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ 0 ]);
  483. dwDspLen = DispLenUnicode( lpStr );
  484. width = dwDspLen + DELIMITERWIDTH; // '1:xxxx 2:xxxx '
  485. for( i = 1; i < lpCandList->dwCount; i++ ) {
  486. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ i ]);
  487. dwDspLen = DispLenUnicode( lpStr );
  488. width += dwDspLen + DELIMITERWIDTH;
  489. if ((width > dwLength-CountDispWidth) ||
  490. ( i - ConTbl->CandSep[j-1] >= 9)){
  491. ConTbl->CandSep[j++] = i;
  492. width = dwDspLen + DELIMITERWIDTH;
  493. }
  494. }
  495. ConTbl->CandSep[j] = i;
  496. ConTbl->CandMax = j;
  497. SystemLineSize = (sizeof(WCHAR)+sizeof(UCHAR))*dwLength + sizeof(DWORD);
  498. if (ConTbl->SystemLineSize < SystemLineSize ){
  499. if (ConTbl->SystemLine != NULL){
  500. LocalFree( ConTbl->SystemLine );
  501. ConTbl->SystemLine = NULL;
  502. ConTbl->SystemLineSize = 0;
  503. }
  504. ConTbl->SystemLine = (LPCONIME_CANDMESSAGE)LocalAlloc(LPTR, SystemLineSize );
  505. if (ConTbl->SystemLine == NULL) {
  506. return FALSE;
  507. }
  508. ConTbl->SystemLineSize = SystemLineSize;
  509. }
  510. SystemLine = ConTbl->SystemLine;
  511. SystemLine->AttrOff = sizeof(WCHAR) * dwLength + sizeof(DWORD);
  512. StartIndex = GetSystemLineP( lpCandList,
  513. SystemLine->String,
  514. (LPSTR)SystemLine + SystemLine->AttrOff,
  515. dwLength,
  516. CountDispWidth,
  517. ConTbl
  518. );
  519. ConTbl->fNestCandidate = TRUE; // ImmNotyfyIME call back OpenCandidate Message
  520. // by same data.
  521. // so We ignore this mesage.
  522. ImmNotifyIME(hIMC,
  523. NI_SETCANDIDATE_PAGESTART,
  524. dwIndex,
  525. ConTbl->CandSep[StartIndex]);
  526. ImmNotifyIME(hIMC,
  527. NI_SETCANDIDATE_PAGESIZE,
  528. dwIndex,
  529. ConTbl->CandSep[StartIndex+1] -
  530. ConTbl->CandSep[StartIndex]);
  531. ConTbl->fNestCandidate = FALSE;
  532. CopyData.dwData = CI_CONIMEMODEINFO;
  533. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  534. CopyData.lpData = lpModeInfo;
  535. if (MakeInfoStringPRC(ConTbl, lpModeInfo) ) {
  536. ConsoleImeSendMessage( ConTbl->hWndCon,
  537. (WPARAM)hwnd,
  538. (LPARAM)&CopyData
  539. );
  540. }
  541. }
  542. }
  543. LocalFree( lpModeInfo );
  544. return TRUE;
  545. }
  546. BOOL
  547. OpenCandidateKorea(
  548. HWND hwnd,
  549. HIMC hIMC ,
  550. PCONSOLE_TABLE ConTbl,
  551. DWORD CandList,
  552. BOOL OpenFlag
  553. )
  554. {
  555. DWORD dwLength;
  556. DWORD dwIndex;
  557. DWORD i;
  558. DWORD j;
  559. LPWSTR lpStr;
  560. DWORD dwDspLen;
  561. DWORD width;
  562. DWORD StartIndex;
  563. DWORD CountDispWidth;
  564. DWORD AllocLength;
  565. LPCANDIDATELIST lpCandList;
  566. LPCONIME_CANDMESSAGE SystemLine;
  567. DWORD SystemLineSize;
  568. COPYDATASTRUCT CopyData;
  569. BOOL EnableCodePoint;
  570. for (dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) {
  571. if ( CandList & ( 1 << dwIndex ) ) {
  572. dwLength = ImmGetCandidateList(hIMC, dwIndex, NULL, 0);
  573. if (dwLength == 0)
  574. return FALSE;
  575. if ( (ConTbl->CandListMemAllocSize[dwIndex] != dwLength ) &&
  576. (ConTbl->lpCandListMem[dwIndex] != NULL)) {
  577. LocalFree(ConTbl->lpCandListMem[dwIndex]);
  578. ConTbl->CandListMemAllocSize[dwIndex] = 0;
  579. ConTbl->lpCandListMem[dwIndex] = NULL;
  580. }
  581. if (ConTbl->lpCandListMem[dwIndex] == NULL) {
  582. ConTbl->lpCandListMem[dwIndex] = LocalAlloc(LPTR, dwLength);
  583. if (ConTbl->lpCandListMem[dwIndex] == NULL)
  584. return FALSE;
  585. ConTbl->CandListMemAllocSize[dwIndex] = dwLength;
  586. }
  587. lpCandList = ConTbl->lpCandListMem[dwIndex];
  588. ImmGetCandidateList(hIMC, dwIndex, lpCandList, dwLength);
  589. //
  590. // check each offset value is not over than buffer size.
  591. //
  592. if ((lpCandList->dwCount > 1) &&
  593. (lpCandList->dwSelection >= dwLength ||
  594. lpCandList->dwPageStart >= dwLength ||
  595. lpCandList->dwOffset[lpCandList->dwSelection] >= dwLength ||
  596. lpCandList->dwOffset[lpCandList->dwPageStart] >= dwLength )
  597. )
  598. break;
  599. dwLength = ConTbl->ScreenBufferSize.X;
  600. dwLength = (dwLength > 128) ? 128 : dwLength ;
  601. dwLength = ((dwLength < 12) ? 12 : dwLength );
  602. j = (dwLength-7)/(DELIMITERWIDTH+sizeof(WCHAR));
  603. j = ((j > 9)?9:j);
  604. j = lpCandList->dwCount / j + 10;
  605. AllocLength = (j > DEFAULTCANDTABLE) ? j : DEFAULTCANDTABLE;
  606. if (lpCandList->dwStyle == IME_CAND_CODE){
  607. EnableCodePoint = TRUE;
  608. }
  609. else{
  610. EnableCodePoint = FALSE;
  611. }
  612. if (EnableCodePoint){
  613. CountDispWidth = CODEDISPLEN;
  614. }
  615. else {
  616. for (CountDispWidth = 0 ,j = 1; j <= lpCandList->dwCount; CountDispWidth++)
  617. j *= 10;
  618. CountDispWidth *= 2;
  619. CountDispWidth++;
  620. }
  621. if ((ConTbl->CandSepAllocSize != sizeof(DWORD)*AllocLength) &&
  622. (ConTbl->CandSep != NULL)) {
  623. LocalFree(ConTbl->CandSep);
  624. ConTbl->CandSep = NULL;
  625. ConTbl->CandSepAllocSize = 0;
  626. }
  627. if (ConTbl->CandSep == NULL) {
  628. ConTbl->CandSep= LocalAlloc(LPTR, sizeof(DWORD)*AllocLength);
  629. if (ConTbl->CandSep == NULL)
  630. return FALSE;
  631. ConTbl->CandSepAllocSize = sizeof(DWORD)*AllocLength;
  632. }
  633. if ( EnableCodePoint ){
  634. j = 0;
  635. ConTbl->CandSep[j++] = 0;
  636. if (OpenFlag) {
  637. ConTbl->CandOff = lpCandList->dwSelection % 9;
  638. }
  639. i = ConTbl->CandOff;
  640. for (; i < lpCandList->dwCount; i+= 9 ) {
  641. ConTbl->CandSep[j++] = i;
  642. }
  643. if (i > lpCandList->dwCount) {
  644. i = lpCandList->dwCount;
  645. }
  646. }
  647. else{
  648. j = 0;
  649. if (OpenFlag) {
  650. ConTbl->CandOff = 0;
  651. }
  652. ConTbl->CandSep[j++] = ConTbl->CandOff;
  653. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ 0 ]);
  654. dwDspLen = DispLenUnicode( lpStr );
  655. width = dwDspLen + DELIMITERWIDTH; // '1:xxxx 2:xxxx '
  656. for( i = 1; i < lpCandList->dwCount; i++ ) {
  657. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ i ]);
  658. dwDspLen = DispLenUnicode( lpStr );
  659. width += dwDspLen + DELIMITERWIDTH;
  660. if ((width > dwLength-CountDispWidth) ||
  661. ( i - ConTbl->CandSep[j-1] >= 9)){
  662. ConTbl->CandSep[j++] = i;
  663. width = dwDspLen + DELIMITERWIDTH;
  664. }
  665. }
  666. }
  667. ConTbl->CandSep[j] = i;
  668. ConTbl->CandMax = j;
  669. SystemLineSize = (sizeof(WCHAR)+sizeof(UCHAR))*dwLength + sizeof(DWORD);
  670. if (ConTbl->SystemLineSize < SystemLineSize ){
  671. if (ConTbl->SystemLine != NULL){
  672. LocalFree( ConTbl->SystemLine );
  673. ConTbl->SystemLine = NULL;
  674. ConTbl->SystemLineSize = 0;
  675. }
  676. ConTbl->SystemLine = (LPCONIME_CANDMESSAGE)LocalAlloc(LPTR, SystemLineSize );
  677. if (ConTbl->SystemLine == NULL) {
  678. return FALSE;
  679. }
  680. ConTbl->SystemLineSize = SystemLineSize;
  681. }
  682. SystemLine = ConTbl->SystemLine;
  683. SystemLine->AttrOff = sizeof(WCHAR) * dwLength + sizeof(DWORD);
  684. CopyData.dwData = CI_CONIMECANDINFO;
  685. CopyData.cbData = (sizeof(WCHAR)+sizeof(UCHAR))*dwLength + sizeof(DWORD);
  686. CopyData.lpData = SystemLine;
  687. StartIndex = GetSystemLineJ( lpCandList,
  688. SystemLine->String,
  689. (LPSTR)SystemLine + SystemLine->AttrOff,
  690. dwLength,
  691. CountDispWidth,
  692. ConTbl,
  693. EnableCodePoint);
  694. ConTbl->fNestCandidate = TRUE; // ImmNotyfyIME call back OpenCandidate Message
  695. // by same data.
  696. // so We ignore this mesage.
  697. ImmNotifyIME(hIMC,
  698. NI_SETCANDIDATE_PAGESTART,
  699. dwIndex,
  700. ConTbl->CandSep[StartIndex]);
  701. ImmNotifyIME(hIMC,
  702. NI_SETCANDIDATE_PAGESIZE,
  703. dwIndex,
  704. ConTbl->CandSep[StartIndex+1] -
  705. ConTbl->CandSep[StartIndex]);
  706. ConTbl->fNestCandidate = FALSE;
  707. ConsoleImeSendMessage( ConTbl->hWndCon,
  708. (WPARAM)hwnd,
  709. (LPARAM)&CopyData
  710. );
  711. }
  712. }
  713. return TRUE;
  714. }
  715. DWORD
  716. DispLenUnicode(
  717. LPWSTR lpString )
  718. {
  719. DWORD i;
  720. DWORD Length;
  721. Length = 0;
  722. for ( i = 0; lpString[i] != 0; i++) {
  723. Length += IsUnicodeFullWidth(lpString[i]) ? 2 : 1;
  724. }
  725. return Length;
  726. }
  727. DWORD
  728. GetSystemLineJ(
  729. LPCANDIDATELIST lpCandList ,
  730. LPWSTR String,
  731. LPSTR Attr,
  732. DWORD dwLength,
  733. DWORD CountDispWidth,
  734. PCONSOLE_TABLE FocusedConsole,
  735. BOOL EnableCodePoint)
  736. {
  737. DWORD dwStrLen;
  738. DWORD dwDspLen;
  739. DWORD i;
  740. DWORD j;
  741. DWORD SepIndex;
  742. DWORD SelCount;
  743. DWORD Length;
  744. DWORD dwWholeLen;
  745. BOOL lfBreak = FALSE;
  746. LPWSTR StrToWrite;
  747. LPSTR AttrToSel;
  748. LPWSTR lpStr;
  749. USHORT MultiChar;
  750. USHORT TempMulti;
  751. if (lpCandList->dwSelection > lpCandList->dwCount) {
  752. lpCandList->dwSelection = 0;
  753. }
  754. for ( SepIndex = FocusedConsole->CandMax; SepIndex > 0; SepIndex--) {
  755. if (lpCandList->dwSelection >= FocusedConsole->CandSep[SepIndex])
  756. break;
  757. }
  758. if (SepIndex == FocusedConsole->CandMax)
  759. SepIndex = 0;
  760. for ( i = 0; i < dwLength; i++) {
  761. Attr[i] = 0x0000;
  762. }
  763. StrToWrite = String;
  764. AttrToSel = Attr;
  765. dwWholeLen = 0;
  766. #if 1
  767. // HACK HACK ntbug #69699
  768. // MS-IME97 & MS-IME97A does not return correct value for IME_PROP_CANDLIST_START_FROM_1.
  769. // These always return its starting from 0.
  770. // Currently there is not IME starting from 0. So we hack.
  771. // Actually IME should be fixed.
  772. SelCount = 1;
  773. #else
  774. if (FocusedConsole->ImmGetProperty & IME_PROP_CANDLIST_START_FROM_1)
  775. SelCount = 1;
  776. else
  777. SelCount = 0;
  778. #endif
  779. if (EnableCodePoint){
  780. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[lpCandList->dwSelection]);
  781. WideCharToMultiByte(CP_OEMCP, 0, lpStr, 1, (PBYTE)&TempMulti, 2, NULL, NULL);
  782. *StrToWrite = UNICODE_LEFT;
  783. StrToWrite++;
  784. MultiChar = (USHORT)(HIBYTE(TempMulti)| LOBYTE(TempMulti)<<8);
  785. for (i = 0; i < 4; i++) {
  786. j = (MultiChar & 0xf000 ) >> 12;
  787. if ( j <= 9)
  788. *StrToWrite = (USHORT)(j + UNICODE_ZERO);
  789. else
  790. *StrToWrite = (USHORT)(j + UNICODE_HEXBASE);
  791. StrToWrite++;
  792. MultiChar = (USHORT)(MultiChar << 4);
  793. }
  794. *StrToWrite = UNICODE_RIGHT;
  795. StrToWrite++;
  796. *StrToWrite = UNICODE_SPACE;
  797. StrToWrite++;
  798. AttrToSel += CountDispWidth;
  799. dwWholeLen += CountDispWidth;
  800. CountDispWidth = 0;
  801. }
  802. for (i = FocusedConsole->CandSep[SepIndex]; i < FocusedConsole->CandSep[SepIndex+1]; i++) {
  803. //
  804. // check each offset value is not over than buffer size.
  805. //
  806. if (lpCandList->dwOffset[i] >= lpCandList->dwSize)
  807. break;
  808. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ i ]);
  809. dwStrLen = lstrlenW( lpStr );
  810. dwDspLen = DispLenUnicode( lpStr );
  811. if ( dwWholeLen + dwDspLen + DELIMITERWIDTH > dwLength - CountDispWidth ){
  812. Length = 0;
  813. lfBreak = TRUE;
  814. for (j = 0; j < dwStrLen; j++ ){
  815. Length += IsUnicodeFullWidth(lpStr[j]) ? 2 : 1;
  816. if (dwWholeLen + Length > dwLength - (CountDispWidth + DELIMITERWIDTH)){
  817. dwStrLen = j-1;
  818. dwDspLen = Length - IsUnicodeFullWidth(lpStr[j]) ? 2 : 1;
  819. break;
  820. }
  821. }
  822. }
  823. if ((dwWholeLen + dwDspLen + DELIMITERWIDTH + CountDispWidth ) <= dwLength ) // if minus value
  824. dwWholeLen += (dwDspLen + DELIMITERWIDTH);
  825. else {
  826. break;
  827. }
  828. if (i == lpCandList->dwSelection) {
  829. for (j = 0; j < dwStrLen+2; j++)
  830. *(AttrToSel+j) = 1;
  831. }
  832. *StrToWrite = (USHORT)(SelCount + UNICODE_ZERO);
  833. StrToWrite++;
  834. *StrToWrite = UNICODE_COLON;
  835. StrToWrite++;
  836. CopyMemory(StrToWrite, lpStr, dwStrLen * sizeof(WCHAR));
  837. StrToWrite += dwStrLen;
  838. *StrToWrite = UNICODE_SPACE;
  839. StrToWrite++;
  840. AttrToSel += dwStrLen+DELIMITERWIDTH;
  841. SelCount++;
  842. if (lfBreak)
  843. break;
  844. }
  845. *StrToWrite = 0;
  846. dwDspLen = DispLenUnicode( String );
  847. if (dwDspLen > (dwLength - CountDispWidth))
  848. return SepIndex;
  849. if (EnableCodePoint){
  850. for (i = dwDspLen; i < dwLength; i++) {
  851. *StrToWrite = UNICODE_SPACE;
  852. StrToWrite++;
  853. }
  854. }
  855. else {
  856. for (i = dwDspLen; i < (dwLength - CountDispWidth); i++) {
  857. *StrToWrite = UNICODE_SPACE;
  858. StrToWrite++;
  859. }
  860. i = (CountDispWidth-1) / 2;
  861. NumString(StrToWrite,lpCandList->dwSelection+1,i);
  862. StrToWrite+=i;
  863. *StrToWrite = UNICODE_SLASH;
  864. StrToWrite++;
  865. NumString(StrToWrite,lpCandList->dwCount, i);
  866. StrToWrite+=i;
  867. }
  868. *StrToWrite = 0;
  869. return SepIndex;
  870. }
  871. DWORD
  872. GetSystemLineT(
  873. LPCANDIDATELIST lpCandList ,
  874. LPWSTR String,
  875. LPSTR Attr,
  876. DWORD dwLength,
  877. DWORD CountDispWidth,
  878. PCONSOLE_TABLE FocusedConsole
  879. )
  880. {
  881. DWORD dwStrLen;
  882. DWORD dwDspLen;
  883. DWORD i;
  884. DWORD j;
  885. DWORD SepIndex;
  886. DWORD SelCount;
  887. DWORD Length;
  888. DWORD dwWholeLen;
  889. BOOL lfBreak = FALSE;
  890. LPWSTR StrToWrite;
  891. LPSTR AttrToSel;
  892. LPWSTR lpStr;
  893. USHORT MultiChar;
  894. USHORT TempMulti;
  895. if (lpCandList->dwSelection > lpCandList->dwCount) {
  896. lpCandList->dwSelection = 0;
  897. }
  898. for ( SepIndex = FocusedConsole->CandMax; SepIndex > 0; SepIndex--) {
  899. if (lpCandList->dwSelection >= FocusedConsole->CandSep[SepIndex])
  900. break;
  901. }
  902. if (SepIndex == FocusedConsole->CandMax)
  903. SepIndex = 0;
  904. for ( i = 0; i < dwLength; i++) {
  905. Attr[i] = 0x0000;
  906. }
  907. StrToWrite = String;
  908. AttrToSel = Attr;
  909. dwWholeLen = 0;
  910. if (FocusedConsole->ImmGetProperty & IME_PROP_CANDLIST_START_FROM_1)
  911. SelCount = 1;
  912. else
  913. SelCount = 0;
  914. for (i = FocusedConsole->CandSep[SepIndex]; i < FocusedConsole->CandSep[SepIndex+1]; i++) {
  915. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ i ]);
  916. dwStrLen = lstrlenW( lpStr );
  917. dwDspLen = DispLenUnicode( lpStr );
  918. if ( dwWholeLen + dwDspLen + DELIMITERWIDTH > dwLength - CountDispWidth ){
  919. Length = 0;
  920. lfBreak = TRUE;
  921. for (j = 0; j < dwStrLen; j++ ){
  922. Length += IsUnicodeFullWidth(lpStr[j]) ? 2 : 1;
  923. if (dwWholeLen + Length > dwLength - (CountDispWidth + DELIMITERWIDTH)){
  924. dwStrLen = j-1;
  925. dwDspLen = Length - IsUnicodeFullWidth(lpStr[j]) ? 2 : 1;
  926. break;
  927. }
  928. }
  929. }
  930. if ((dwWholeLen + dwDspLen + DELIMITERWIDTH + CountDispWidth ) <= dwLength ) // if minus value
  931. dwWholeLen += (dwDspLen + DELIMITERWIDTH);
  932. else {
  933. break;
  934. }
  935. if (i == lpCandList->dwSelection) {
  936. for (j = 0; j < dwStrLen+2; j++)
  937. *(AttrToSel+j) = 1;
  938. }
  939. *StrToWrite = (USHORT)(SelCount + UNICODE_ZERO);
  940. StrToWrite++;
  941. *StrToWrite = UNICODE_COLON;
  942. StrToWrite++;
  943. CopyMemory(StrToWrite, lpStr, dwStrLen * sizeof(WCHAR));
  944. StrToWrite += dwStrLen;
  945. *StrToWrite = UNICODE_SPACE;
  946. StrToWrite++;
  947. AttrToSel += dwStrLen+DELIMITERWIDTH;
  948. SelCount++;
  949. if (lfBreak)
  950. break;
  951. }
  952. *StrToWrite = 0;
  953. dwDspLen = DispLenUnicode( String );
  954. if (dwDspLen > (dwLength - CountDispWidth))
  955. return SepIndex;
  956. *StrToWrite = UNICODE_SPACE;
  957. StrToWrite++;
  958. i = (CountDispWidth-1) / 2;
  959. NumString(StrToWrite,lpCandList->dwSelection+1,i);
  960. StrToWrite+=i;
  961. *StrToWrite = UNICODE_SLASH;
  962. StrToWrite++;
  963. NumString(StrToWrite,lpCandList->dwCount, i);
  964. StrToWrite+=i;
  965. *StrToWrite = 0;
  966. return SepIndex;
  967. }
  968. DWORD
  969. GetSystemLineP(
  970. LPCANDIDATELIST lpCandList ,
  971. LPWSTR String,
  972. LPSTR Attr,
  973. DWORD dwLength,
  974. DWORD CountDispWidth,
  975. PCONSOLE_TABLE FocusedConsole
  976. )
  977. {
  978. DWORD dwStrLen;
  979. DWORD dwDspLen;
  980. DWORD i;
  981. DWORD j;
  982. DWORD SepIndex;
  983. DWORD SelCount;
  984. DWORD Length;
  985. DWORD dwWholeLen;
  986. BOOL lfBreak = FALSE;
  987. LPWSTR StrToWrite;
  988. LPSTR AttrToSel;
  989. LPWSTR lpStr;
  990. USHORT MultiChar;
  991. USHORT TempMulti;
  992. if (lpCandList->dwSelection > lpCandList->dwCount) {
  993. lpCandList->dwSelection = 0;
  994. }
  995. for ( SepIndex = FocusedConsole->CandMax; SepIndex > 0; SepIndex--) {
  996. if (lpCandList->dwSelection >= FocusedConsole->CandSep[SepIndex])
  997. break;
  998. }
  999. if (SepIndex == FocusedConsole->CandMax)
  1000. SepIndex = 0;
  1001. for ( i = 0; i < dwLength; i++) {
  1002. Attr[i] = 0x0000;
  1003. }
  1004. StrToWrite = String;
  1005. AttrToSel = Attr;
  1006. dwWholeLen = 0;
  1007. if (FocusedConsole->ImmGetProperty & IME_PROP_CANDLIST_START_FROM_1)
  1008. SelCount = 1;
  1009. else
  1010. SelCount = 0;
  1011. for (i = FocusedConsole->CandSep[SepIndex]; i < FocusedConsole->CandSep[SepIndex+1]; i++) {
  1012. lpStr = (LPWSTR)((LPSTR)lpCandList + lpCandList->dwOffset[ i ]);
  1013. dwStrLen = lstrlenW( lpStr );
  1014. dwDspLen = DispLenUnicode( lpStr );
  1015. if ( dwWholeLen + dwDspLen + DELIMITERWIDTH > dwLength - CountDispWidth ){
  1016. Length = 0;
  1017. lfBreak = TRUE;
  1018. for (j = 0; j < dwStrLen; j++ ){
  1019. Length += IsUnicodeFullWidth(lpStr[j]) ? 2 : 1;
  1020. if (dwWholeLen + Length > dwLength - (CountDispWidth + DELIMITERWIDTH)){
  1021. dwStrLen = j-1;
  1022. dwDspLen = Length - IsUnicodeFullWidth(lpStr[j]) ? 2 : 1;
  1023. break;
  1024. }
  1025. }
  1026. }
  1027. if ((dwWholeLen + dwDspLen + DELIMITERWIDTH + CountDispWidth ) <= dwLength ) // if minus value
  1028. dwWholeLen += (dwDspLen + DELIMITERWIDTH);
  1029. else {
  1030. break;
  1031. }
  1032. if (i == lpCandList->dwSelection) {
  1033. for (j = 0; j < dwStrLen+2; j++)
  1034. *(AttrToSel+j) = 1;
  1035. }
  1036. *StrToWrite = (USHORT)(SelCount + UNICODE_ZERO);
  1037. StrToWrite++;
  1038. *StrToWrite = UNICODE_COLON;
  1039. StrToWrite++;
  1040. CopyMemory(StrToWrite, lpStr, dwStrLen * sizeof(WCHAR));
  1041. StrToWrite += dwStrLen;
  1042. *StrToWrite = UNICODE_SPACE;
  1043. StrToWrite++;
  1044. AttrToSel += dwStrLen+DELIMITERWIDTH;
  1045. SelCount++;
  1046. if (lfBreak)
  1047. break;
  1048. }
  1049. *StrToWrite = 0;
  1050. dwDspLen = DispLenUnicode( String );
  1051. if (dwDspLen > (dwLength - CountDispWidth))
  1052. return SepIndex;
  1053. #if defined (CANDCOUNTPRC) //for wider candidate list space v-hirshi Oct.16.1996
  1054. *StrToWrite = UNICODE_SPACE;
  1055. StrToWrite++;
  1056. i = (CountDispWidth-1) / 2;
  1057. NumString(StrToWrite,lpCandList->dwSelection+1,i);
  1058. StrToWrite+=i;
  1059. *StrToWrite = UNICODE_SLASH;
  1060. StrToWrite++;
  1061. NumString(StrToWrite,lpCandList->dwCount, i);
  1062. StrToWrite+=i;
  1063. #endif
  1064. *StrToWrite = 0;
  1065. return SepIndex;
  1066. }
  1067. VOID
  1068. NumString(
  1069. LPWSTR StrToWrite,
  1070. DWORD NumToDisp,
  1071. DWORD CountDispWidth)
  1072. {
  1073. DWORD i;
  1074. DWORD k;
  1075. k = 1;
  1076. for (i = 1; i < CountDispWidth; i++)
  1077. k *= 10;
  1078. for (i = k; i > 0; i /= 10){
  1079. k = (NumToDisp / i);
  1080. *StrToWrite = (USHORT)(k + UNICODE_ZERO);
  1081. if ((*StrToWrite == UNICODE_ZERO) &&
  1082. ((*(StrToWrite-1) == UNICODE_SPACE)||(*(StrToWrite-1) == UNICODE_SLASH)) )
  1083. *StrToWrite = UNICODE_SPACE;
  1084. StrToWrite++;
  1085. NumToDisp -= (i*k);
  1086. }
  1087. }
  1088. BOOL
  1089. ImeUICloseCandidate(
  1090. HWND hwnd,
  1091. DWORD CandList
  1092. )
  1093. {
  1094. HIMC hIMC;
  1095. PCONSOLE_TABLE ConTbl;
  1096. DBGPRINT(("CONIME: Get IMN_CLOSECANDIDATE Message\n"));
  1097. ConTbl = SearchConsole(LastConsole);
  1098. if (ConTbl == NULL) {
  1099. DBGPRINT(("CONIME: Error! Cannot found registed Console\n"));
  1100. return FALSE;
  1101. }
  1102. hIMC = ImmGetContext( hwnd );
  1103. if ( hIMC == 0 )
  1104. return FALSE;
  1105. //
  1106. // Reset fInCandidate variables.
  1107. //
  1108. ConTbl->fInCandidate = FALSE;
  1109. switch ( HKL_TO_LANGID(ConTbl->hklActive))
  1110. {
  1111. case LANG_ID_JAPAN:
  1112. CloseCandidateJapan(hwnd, hIMC, ConTbl, CandList );
  1113. break;
  1114. case LANG_ID_TAIWAN:
  1115. CloseCandidateTaiwan(hwnd, hIMC, ConTbl, CandList );
  1116. break;
  1117. case LANG_ID_PRC:
  1118. CloseCandidatePRC(hwnd, hIMC, ConTbl, CandList );
  1119. break;
  1120. case LANG_ID_KOREA:
  1121. CloseCandidateKorea(hwnd, hIMC, ConTbl, CandList );
  1122. break;
  1123. default:
  1124. return FALSE;
  1125. break;
  1126. }
  1127. ImmReleaseContext( hwnd, hIMC );
  1128. return TRUE;
  1129. }
  1130. BOOL
  1131. CloseCandidateJapan(
  1132. HWND hwnd,
  1133. HIMC hIMC,
  1134. PCONSOLE_TABLE ConTbl,
  1135. DWORD CandList
  1136. )
  1137. {
  1138. DWORD dwIndex;
  1139. COPYDATASTRUCT CopyData;
  1140. for (dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) {
  1141. if ( CandList & ( 1 << dwIndex ) ) {
  1142. if (ConTbl->lpCandListMem[dwIndex] != NULL ) {
  1143. LocalFree(ConTbl->lpCandListMem[dwIndex]);
  1144. ConTbl->lpCandListMem[dwIndex] = NULL;
  1145. ConTbl->CandListMemAllocSize[dwIndex] = 0;
  1146. }
  1147. }
  1148. }
  1149. CopyData.dwData = CI_CONIMECANDINFO;
  1150. CopyData.cbData = 0;
  1151. CopyData.lpData = NULL;
  1152. ConsoleImeSendMessage( ConTbl->hWndCon,
  1153. (WPARAM)hwnd,
  1154. (LPARAM)&CopyData
  1155. );
  1156. return TRUE;
  1157. }
  1158. BOOL
  1159. CloseCandidateTaiwan(
  1160. HWND hwnd,
  1161. HIMC hIMC,
  1162. PCONSOLE_TABLE ConTbl,
  1163. DWORD CandList
  1164. )
  1165. {
  1166. DWORD dwIndex;
  1167. COPYDATASTRUCT CopyData;
  1168. LPCONIME_UIMODEINFO lpModeInfo;
  1169. lpModeInfo = (LPCONIME_UIMODEINFO)LocalAlloc( LPTR, sizeof(CONIME_UIMODEINFO) );
  1170. if ( lpModeInfo == NULL) {
  1171. return FALSE;
  1172. }
  1173. for (dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) {
  1174. if ( CandList & ( 1 << dwIndex ) ) {
  1175. if (ConTbl->lpCandListMem[dwIndex] != NULL ) {
  1176. LocalFree(ConTbl->lpCandListMem[dwIndex]);
  1177. ConTbl->lpCandListMem[dwIndex] = NULL;
  1178. ConTbl->CandListMemAllocSize[dwIndex] = 0;
  1179. }
  1180. }
  1181. }
  1182. CopyData.dwData = CI_CONIMEMODEINFO;
  1183. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  1184. CopyData.lpData = lpModeInfo;
  1185. if (MakeInfoStringTaiwan(ConTbl, lpModeInfo) ) {
  1186. ConsoleImeSendMessage( ConTbl->hWndCon,
  1187. (WPARAM)hwnd,
  1188. (LPARAM)&CopyData
  1189. );
  1190. }
  1191. LocalFree( lpModeInfo );
  1192. return TRUE;
  1193. }
  1194. BOOL
  1195. CloseCandidatePRC(
  1196. HWND hwnd,
  1197. HIMC hIMC,
  1198. PCONSOLE_TABLE ConTbl,
  1199. DWORD CandList
  1200. )
  1201. {
  1202. DWORD dwIndex;
  1203. COPYDATASTRUCT CopyData;
  1204. LPCONIME_UIMODEINFO lpModeInfo;
  1205. lpModeInfo = (LPCONIME_UIMODEINFO)LocalAlloc( LPTR, sizeof(CONIME_UIMODEINFO) );
  1206. if ( lpModeInfo == NULL) {
  1207. return FALSE;
  1208. }
  1209. for (dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) {
  1210. if ( CandList & ( 1 << dwIndex ) ) {
  1211. if (ConTbl->lpCandListMem[dwIndex] != NULL ) {
  1212. LocalFree(ConTbl->lpCandListMem[dwIndex]);
  1213. ConTbl->lpCandListMem[dwIndex] = NULL;
  1214. ConTbl->CandListMemAllocSize[dwIndex] = 0;
  1215. }
  1216. }
  1217. }
  1218. CopyData.dwData = CI_CONIMEMODEINFO;
  1219. CopyData.cbData = sizeof(CONIME_UIMODEINFO);
  1220. CopyData.lpData = lpModeInfo;
  1221. if (MakeInfoStringPRC(ConTbl, lpModeInfo) ) {
  1222. ConsoleImeSendMessage( ConTbl->hWndCon,
  1223. (WPARAM)hwnd,
  1224. (LPARAM)&CopyData
  1225. );
  1226. }
  1227. LocalFree( lpModeInfo );
  1228. return TRUE;
  1229. }
  1230. BOOL
  1231. CloseCandidateKorea(
  1232. HWND hwnd,
  1233. HIMC hIMC,
  1234. PCONSOLE_TABLE ConTbl,
  1235. DWORD CandList
  1236. )
  1237. {
  1238. DWORD dwIndex;
  1239. COPYDATASTRUCT CopyData;
  1240. for (dwIndex = 0; dwIndex < MAX_LISTCAND ; dwIndex ++ ) {
  1241. if ( CandList & ( 1 << dwIndex ) ) {
  1242. if (ConTbl->lpCandListMem[dwIndex] != NULL ) {
  1243. LocalFree(ConTbl->lpCandListMem[dwIndex]);
  1244. ConTbl->lpCandListMem[dwIndex] = NULL;
  1245. ConTbl->CandListMemAllocSize[dwIndex] = 0;
  1246. }
  1247. }
  1248. }
  1249. CopyData.dwData = CI_CONIMECANDINFO;
  1250. CopyData.cbData = 0;
  1251. CopyData.lpData = NULL;
  1252. ConsoleImeSendMessage( ConTbl->hWndCon,
  1253. (WPARAM)hwnd,
  1254. (LPARAM)&CopyData
  1255. );
  1256. return TRUE;
  1257. }