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.

890 lines
28 KiB

  1. /**************************************************************************\
  2. * Module Name: regword.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * Word registration into IME dictionary
  7. *
  8. * History:
  9. * 03-Jan-1996 wkwok Created
  10. \**************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. /***************************************************************************\
  14. * ImmRegisterWordA
  15. *
  16. * Registers a string into the dictionary of the IME with the specified hKL.
  17. *
  18. * History:
  19. * 01-Mar-1996 wkwok Created
  20. \***************************************************************************/
  21. BOOL WINAPI ImmRegisterWordA(
  22. HKL hKL,
  23. LPCSTR lpszReading,
  24. DWORD dwStyle,
  25. LPCSTR lpszString)
  26. {
  27. PIMEDPI pImeDpi;
  28. LPWSTR lpwszReading;
  29. LPWSTR lpwszString;
  30. INT cchReading;
  31. INT cchString;
  32. INT i;
  33. BOOL fRet;
  34. pImeDpi = FindOrLoadImeDpi(hKL);
  35. if (pImeDpi == NULL) {
  36. RIPMSG0(RIP_WARNING, "ImmRegisterWordA: no pImeDpi entry.");
  37. return FALSE;
  38. }
  39. if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE)) {
  40. /*
  41. * Doesn't need A/W conversion. Calls directly to IME to
  42. * register the string.
  43. */
  44. fRet = (*pImeDpi->pfn.ImeRegisterWord.a)(lpszReading, dwStyle, lpszString);
  45. ImmUnlockImeDpi(pImeDpi);
  46. return fRet;
  47. }
  48. /*
  49. * ANSI caller, Unicode IME. Needs A/W conversion on
  50. * lpszReading and lpszString.
  51. */
  52. if (lpszReading != NULL) {
  53. cchReading = strlen(lpszReading) + sizeof(CHAR);
  54. lpwszReading = ImmLocalAlloc(0, cchReading * sizeof(WCHAR));
  55. if (lpwszReading == NULL) {
  56. RIPMSG0(RIP_WARNING, "ImmRegisterWordA: memory failure.");
  57. ImmUnlockImeDpi(pImeDpi);
  58. return FALSE;
  59. }
  60. i = MultiByteToWideChar(IMECodePage(pImeDpi),
  61. (DWORD)MB_PRECOMPOSED,
  62. (LPSTR)lpszReading, // src
  63. (INT)strlen(lpszReading),
  64. (LPWSTR)lpwszReading, // dest
  65. cchReading);
  66. lpwszReading[i] = L'\0';
  67. }
  68. else {
  69. lpwszReading = NULL;
  70. }
  71. if (lpszString != NULL) {
  72. cchString = strlen(lpszString) + sizeof(CHAR);
  73. lpwszString = ImmLocalAlloc(0, cchString * sizeof(WCHAR));
  74. if (lpwszString == NULL) {
  75. RIPMSG0(RIP_WARNING, "ImmRegisterWordA: memory failure.");
  76. if (lpwszReading != NULL)
  77. ImmLocalFree(lpwszReading);
  78. ImmUnlockImeDpi(pImeDpi);
  79. return FALSE;
  80. }
  81. i = MultiByteToWideChar(IMECodePage(pImeDpi),
  82. (DWORD)MB_PRECOMPOSED,
  83. (LPSTR)lpszString, // src
  84. (INT)strlen(lpszString),
  85. (LPWSTR)lpwszString, // dest
  86. cchString);
  87. lpwszString[i] = L'\0';
  88. }
  89. else {
  90. lpwszString = NULL;
  91. }
  92. fRet = ImmRegisterWordW(hKL, lpwszReading, dwStyle, lpwszString);
  93. if (lpwszReading != NULL)
  94. ImmLocalFree(lpwszReading);
  95. if (lpwszString != NULL)
  96. ImmLocalFree(lpwszString);
  97. ImmUnlockImeDpi(pImeDpi);
  98. return fRet;
  99. }
  100. BOOL WINAPI ImmRegisterWordW(
  101. HKL hKL,
  102. LPCWSTR lpwszReading,
  103. DWORD dwStyle,
  104. LPCWSTR lpwszString)
  105. {
  106. PIMEDPI pImeDpi;
  107. LPSTR lpszReading;
  108. LPSTR lpszString;
  109. INT cchReading;
  110. INT cchString;
  111. INT i;
  112. BOOL fRet;
  113. pImeDpi = FindOrLoadImeDpi(hKL);
  114. if (pImeDpi == NULL) {
  115. RIPMSG0(RIP_WARNING, "ImmRegisterWordW: no pImeDpi entry.");
  116. return FALSE;
  117. }
  118. if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) {
  119. /*
  120. * Doesn't need W/A conversion. Calls directly to IME to
  121. * register the string.
  122. */
  123. fRet = (*pImeDpi->pfn.ImeRegisterWord.w)(lpwszReading, dwStyle, lpwszString);
  124. ImmUnlockImeDpi(pImeDpi);
  125. return fRet;
  126. }
  127. /*
  128. * Unicode caller, ANSI IME. Needs W/A conversion on
  129. * lpwszReading and lpwszString.
  130. */
  131. if (lpwszReading != NULL) {
  132. cchReading = (wcslen(lpwszReading) + 1) * sizeof(WCHAR);
  133. lpszReading = ImmLocalAlloc(0, cchReading);
  134. if (lpszReading == NULL) {
  135. RIPMSG0(RIP_WARNING, "ImmRegisterWordW: memory failure.");
  136. ImmUnlockImeDpi(pImeDpi);
  137. return FALSE;
  138. }
  139. i = WideCharToMultiByte(IMECodePage(pImeDpi),
  140. (DWORD)0,
  141. (LPWSTR)lpwszReading, // src
  142. (INT)wcslen(lpwszReading),
  143. (LPSTR)lpszReading, // dest
  144. cchReading,
  145. (LPSTR)NULL,
  146. (LPBOOL)NULL);
  147. lpszReading[i] = '\0';
  148. }
  149. else {
  150. lpszReading = NULL;
  151. }
  152. if (lpwszString != NULL) {
  153. cchString = (wcslen(lpwszString) + 1) * sizeof(WCHAR);
  154. lpszString = ImmLocalAlloc(0, cchString);
  155. if (lpszString == NULL) {
  156. RIPMSG0(RIP_WARNING, "ImmRegisterWordW: memory failure.");
  157. if (lpszReading != NULL)
  158. ImmLocalFree(lpszReading);
  159. ImmUnlockImeDpi(pImeDpi);
  160. return FALSE;
  161. }
  162. i = WideCharToMultiByte(IMECodePage(pImeDpi),
  163. (DWORD)0,
  164. (LPWSTR)lpwszString, // src
  165. (INT)wcslen(lpwszString),
  166. (LPSTR)lpszString, // dest
  167. cchString,
  168. (LPSTR)NULL,
  169. (LPBOOL)NULL);
  170. lpszString[i] = '\0';
  171. }
  172. else {
  173. lpszString = NULL;
  174. }
  175. fRet = ImmRegisterWordA(hKL, lpszReading, dwStyle, lpszString);
  176. if (lpszReading != NULL)
  177. ImmLocalFree(lpszReading);
  178. if (lpszString != NULL)
  179. ImmLocalFree(lpszString);
  180. ImmUnlockImeDpi(pImeDpi);
  181. return fRet;
  182. }
  183. BOOL WINAPI ImmUnregisterWordA(
  184. HKL hKL,
  185. LPCSTR lpszReading,
  186. DWORD dwStyle,
  187. LPCSTR lpszString)
  188. {
  189. PIMEDPI pImeDpi;
  190. LPWSTR lpwszReading;
  191. LPWSTR lpwszString;
  192. INT cchReading;
  193. INT cchString;
  194. INT i;
  195. BOOL fRet;
  196. pImeDpi = FindOrLoadImeDpi(hKL);
  197. if (pImeDpi == NULL) {
  198. RIPMSG0(RIP_WARNING, "ImmUnregisterWordA: no pImeDpi entry.");
  199. return FALSE;
  200. }
  201. if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE)) {
  202. /*
  203. * Doesn't need A/W conversion. Calls directly to IME to
  204. * un-register the string.
  205. */
  206. fRet = (*pImeDpi->pfn.ImeUnregisterWord.a)(lpszReading, dwStyle, lpszString);
  207. ImmUnlockImeDpi(pImeDpi);
  208. return fRet;
  209. }
  210. /*
  211. * ANSI caller, Unicode IME. Needs A/W conversion on
  212. * lpszReading and lpszString.
  213. */
  214. if (lpszReading != NULL) {
  215. cchReading = strlen(lpszReading) + sizeof(CHAR);
  216. lpwszReading = ImmLocalAlloc(0, cchReading * sizeof(WCHAR));
  217. if (lpwszReading == NULL) {
  218. RIPMSG0(RIP_WARNING, "ImmUnregisterWordA: memory failure.");
  219. ImmUnlockImeDpi(pImeDpi);
  220. return FALSE;
  221. }
  222. i = MultiByteToWideChar(IMECodePage(pImeDpi),
  223. (DWORD)MB_PRECOMPOSED,
  224. (LPSTR)lpszReading, // src
  225. (INT)strlen(lpszReading),
  226. (LPWSTR)lpwszReading, // dest
  227. cchReading);
  228. lpwszReading[i] = L'\0';
  229. }
  230. else {
  231. lpwszReading = NULL;
  232. }
  233. if (lpszString != NULL) {
  234. cchString = strlen(lpszString) + sizeof(CHAR);
  235. lpwszString = ImmLocalAlloc(0, cchString * sizeof(WCHAR));
  236. if (lpwszString == NULL) {
  237. RIPMSG0(RIP_WARNING, "ImmUnregisterWordA: memory failure.");
  238. if (lpwszReading != NULL)
  239. ImmLocalFree(lpwszReading);
  240. ImmUnlockImeDpi(pImeDpi);
  241. return FALSE;
  242. }
  243. i = MultiByteToWideChar(IMECodePage(pImeDpi),
  244. (DWORD)MB_PRECOMPOSED,
  245. (LPSTR)lpszString, // src
  246. (INT)strlen(lpszString),
  247. (LPWSTR)lpwszString, // dest
  248. cchString);
  249. lpwszString[i] = L'\0';
  250. }
  251. else {
  252. lpwszString = NULL;
  253. }
  254. fRet = ImmUnregisterWordW(hKL, lpwszReading, dwStyle, lpwszString);
  255. if (lpwszReading != NULL)
  256. ImmLocalFree(lpwszReading);
  257. if (lpwszString != NULL)
  258. ImmLocalFree(lpwszString);
  259. ImmUnlockImeDpi(pImeDpi);
  260. return fRet;
  261. }
  262. BOOL WINAPI ImmUnregisterWordW(
  263. HKL hKL,
  264. LPCWSTR lpwszReading,
  265. DWORD dwStyle,
  266. LPCWSTR lpwszString)
  267. {
  268. PIMEDPI pImeDpi;
  269. LPSTR lpszReading;
  270. LPSTR lpszString;
  271. INT cchReading;
  272. INT cchString;
  273. INT i;
  274. BOOL fRet;
  275. pImeDpi = FindOrLoadImeDpi(hKL);
  276. if (pImeDpi == NULL) {
  277. RIPMSG0(RIP_WARNING, "ImmUnregisterWordW: no pImeDpi entry.");
  278. return FALSE;
  279. }
  280. if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) {
  281. /*
  282. * Doesn't need W/A conversion. Calls directly to IME to
  283. * register the string.
  284. */
  285. fRet = (*pImeDpi->pfn.ImeUnregisterWord.w)(lpwszReading, dwStyle, lpwszString);
  286. ImmUnlockImeDpi(pImeDpi);
  287. return fRet;
  288. }
  289. /*
  290. * Unicode caller, ANSI IME. Needs W/A conversion on
  291. * lpwszReading and lpwszString.
  292. */
  293. if (lpwszReading != NULL) {
  294. cchReading = (wcslen(lpwszReading) + 1) * sizeof(WCHAR);
  295. lpszReading = ImmLocalAlloc(0, cchReading);
  296. if (lpszReading == NULL) {
  297. RIPMSG0(RIP_WARNING, "ImmUnregisterWordW: memory failure.");
  298. ImmUnlockImeDpi(pImeDpi);
  299. return FALSE;
  300. }
  301. i = WideCharToMultiByte(IMECodePage(pImeDpi),
  302. (DWORD)0,
  303. (LPWSTR)lpwszReading, // src
  304. (INT)wcslen(lpwszReading),
  305. (LPSTR)lpszReading, // dest
  306. cchReading,
  307. (LPSTR)NULL,
  308. (LPBOOL)NULL);
  309. lpszReading[i] = '\0';
  310. }
  311. else {
  312. lpszReading = NULL;
  313. }
  314. if (lpwszString != NULL) {
  315. cchString = (wcslen(lpwszString) + 1) * sizeof(WCHAR);
  316. lpszString = ImmLocalAlloc(0, cchString);
  317. if (lpszString == NULL) {
  318. RIPMSG0(RIP_WARNING, "ImmUnregisterWordW: memory failure.");
  319. if (lpszReading != NULL)
  320. ImmLocalFree(lpszReading);
  321. ImmUnlockImeDpi(pImeDpi);
  322. return FALSE;
  323. }
  324. i = WideCharToMultiByte(IMECodePage(pImeDpi),
  325. (DWORD)0,
  326. (LPWSTR)lpwszString, // src
  327. (INT)wcslen(lpwszString),
  328. (LPSTR)lpszString, // dest
  329. cchString,
  330. (LPSTR)NULL,
  331. (LPBOOL)NULL);
  332. lpszString[i] = '\0';
  333. }
  334. else {
  335. lpszString = NULL;
  336. }
  337. fRet = ImmUnregisterWordA(hKL, lpszReading, dwStyle, lpszString);
  338. if (lpszReading != NULL)
  339. ImmLocalFree(lpszReading);
  340. if (lpszString != NULL)
  341. ImmLocalFree(lpszString);
  342. ImmUnlockImeDpi(pImeDpi);
  343. return fRet;
  344. }
  345. UINT WINAPI ImmGetRegisterWordStyleA(
  346. HKL hKL,
  347. UINT nItem,
  348. LPSTYLEBUFA lpStyleBufA)
  349. {
  350. PIMEDPI pImeDpi;
  351. LPSTYLEBUFW lpStyleBufW;
  352. UINT uRet;
  353. pImeDpi = FindOrLoadImeDpi(hKL);
  354. if (pImeDpi == NULL) {
  355. RIPMSG0(RIP_WARNING, "ImmGetRegisterWordStyleA: no pImeDpi entry.");
  356. return 0;
  357. }
  358. if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE)) {
  359. /*
  360. * Doesn't need A/W conversion. Calls directly to IME to
  361. * get the available style.
  362. */
  363. uRet = (*pImeDpi->pfn.ImeGetRegisterWordStyle.a)(nItem, lpStyleBufA);
  364. ImmUnlockImeDpi(pImeDpi);
  365. return uRet;
  366. }
  367. /*
  368. * ANSI caller, Unicode IME. Needs A/W conversion on
  369. * lpStyleBufA.
  370. */
  371. lpStyleBufW = NULL;
  372. if (nItem != 0) {
  373. lpStyleBufW = ImmLocalAlloc(0, nItem * sizeof(STYLEBUFW));
  374. if (lpStyleBufW == NULL) {
  375. RIPMSG0(RIP_WARNING, "ImmGetRegisterWordStyleA: memory failure.");
  376. ImmUnlockImeDpi(pImeDpi);
  377. return 0;
  378. }
  379. }
  380. uRet = ImmGetRegisterWordStyleW(hKL, nItem, lpStyleBufW);
  381. if (nItem != 0) {
  382. LPSTYLEBUFW lpsbw;
  383. INT i, j;
  384. for (i = 0, lpsbw = lpStyleBufW; i < (INT)uRet; i++, lpsbw++) {
  385. lpStyleBufA->dwStyle = lpsbw->dwStyle;
  386. j = WideCharToMultiByte(IMECodePage(pImeDpi),
  387. (DWORD)0,
  388. (LPWSTR)lpsbw->szDescription, // src
  389. (INT)wcslen(lpsbw->szDescription),
  390. (LPSTR)lpStyleBufA->szDescription, // dest
  391. (INT)sizeof(lpStyleBufA->szDescription),
  392. (LPSTR)NULL,
  393. (LPBOOL)NULL);
  394. lpStyleBufA->szDescription[j] = '\0';
  395. lpStyleBufA++;
  396. }
  397. }
  398. if (lpStyleBufW != NULL)
  399. ImmLocalFree(lpStyleBufW);
  400. ImmUnlockImeDpi(pImeDpi);
  401. return uRet;
  402. }
  403. UINT WINAPI ImmGetRegisterWordStyleW(
  404. HKL hKL,
  405. UINT nItem,
  406. LPSTYLEBUFW lpStyleBufW)
  407. {
  408. PIMEDPI pImeDpi;
  409. LPSTYLEBUFA lpStyleBufA;
  410. UINT uRet;
  411. pImeDpi = FindOrLoadImeDpi(hKL);
  412. if (pImeDpi == NULL) {
  413. RIPMSG0(RIP_WARNING, "ImmGetRegisterWordStyleA: no pImeDpi entry.");
  414. return 0;
  415. }
  416. if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) {
  417. /*
  418. * Doesn't need W/A conversion. Calls directly to IME to
  419. * get the available style.
  420. */
  421. uRet = (*pImeDpi->pfn.ImeGetRegisterWordStyle.w)(nItem, lpStyleBufW);
  422. ImmUnlockImeDpi(pImeDpi);
  423. return uRet;
  424. }
  425. /*
  426. * Unicode caller, ANSI IME. Needs W/A conversion on
  427. * lpStyleBufW.
  428. */
  429. lpStyleBufA = NULL;
  430. if (nItem != 0) {
  431. lpStyleBufA = ImmLocalAlloc(0, nItem * sizeof(STYLEBUFA));
  432. if (lpStyleBufA == NULL) {
  433. RIPMSG0(RIP_WARNING, "ImmGetRegisterWordStyleW: memory failure.");
  434. ImmUnlockImeDpi(pImeDpi);
  435. return 0;
  436. }
  437. }
  438. uRet = ImmGetRegisterWordStyleA(hKL, nItem, lpStyleBufA);
  439. if (nItem != 0) {
  440. LPSTYLEBUFA lpsba;
  441. INT i, j;
  442. for (i = 0, lpsba = lpStyleBufA; i < (INT)uRet; i++, lpsba++) {
  443. lpStyleBufW->dwStyle = lpsba->dwStyle;
  444. j = MultiByteToWideChar(IMECodePage(pImeDpi),
  445. (DWORD)MB_PRECOMPOSED,
  446. (LPSTR)lpsba->szDescription, // src
  447. (INT)strlen(lpsba->szDescription),
  448. (LPWSTR)lpStyleBufW->szDescription, // dest
  449. (INT)(sizeof(lpStyleBufW->szDescription)/sizeof(WCHAR)));
  450. lpStyleBufW->szDescription[j] = L'\0';
  451. lpStyleBufW++;
  452. }
  453. }
  454. if (lpStyleBufA != NULL)
  455. ImmLocalFree(lpStyleBufA);
  456. ImmUnlockImeDpi(pImeDpi);
  457. return uRet;
  458. }
  459. UINT WINAPI ImmEnumRegisterWordA(
  460. HKL hKL,
  461. REGISTERWORDENUMPROCA lpfnRegisterWordEnumProcA,
  462. LPCSTR lpszReading,
  463. DWORD dwStyle,
  464. LPCSTR lpszString,
  465. LPVOID lpData)
  466. {
  467. PIMEDPI pImeDpi;
  468. LPWSTR lpwszReading;
  469. LPWSTR lpwszString;
  470. INT cchReading;
  471. INT cchString;
  472. INT i;
  473. ENUMREGWORDDATA erwData;
  474. UINT uRet;
  475. pImeDpi = FindOrLoadImeDpi(hKL);
  476. if (pImeDpi == NULL) {
  477. RIPMSG0(RIP_WARNING, "ImmEnumRegisterWordA: no pImeDpi entry.");
  478. return 0;
  479. }
  480. if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE)) {
  481. /*
  482. * Doesn't need A/W conversion. Calls directly to IME to
  483. * enumerate registered strings.
  484. */
  485. uRet = (*pImeDpi->pfn.ImeEnumRegisterWord.a)(lpfnRegisterWordEnumProcA,
  486. lpszReading,
  487. dwStyle,
  488. lpszString,
  489. lpData);
  490. ImmUnlockImeDpi(pImeDpi);
  491. return uRet;
  492. }
  493. /*
  494. * ANSI caller, Unicode IME. Needs A/W conversion on
  495. * lpszReading and lpszString.
  496. */
  497. if (lpszReading != NULL) {
  498. cchReading = strlen(lpszReading) + sizeof(CHAR);
  499. lpwszReading = ImmLocalAlloc(0, cchReading * sizeof(WCHAR));
  500. if (lpwszReading == NULL) {
  501. RIPMSG0(RIP_WARNING, "ImmEnumRegisterWordA: memory failure.");
  502. ImmUnlockImeDpi(pImeDpi);
  503. return 0;
  504. }
  505. i = MultiByteToWideChar(IMECodePage(pImeDpi),
  506. (DWORD)MB_PRECOMPOSED,
  507. (LPSTR)lpszReading, // src
  508. (INT)strlen(lpszReading),
  509. (LPWSTR)lpwszReading, // dest
  510. cchReading);
  511. lpwszReading[i] = L'\0';
  512. }
  513. else {
  514. lpwszReading = NULL;
  515. }
  516. if (lpszString != NULL) {
  517. cchString = strlen(lpszString) + sizeof(CHAR);
  518. lpwszString = ImmLocalAlloc(0, cchString * sizeof(WCHAR));
  519. if (lpwszString == NULL) {
  520. RIPMSG0(RIP_WARNING, "ImmEnumRegisterWordA: memory failure.");
  521. if (lpwszReading != NULL)
  522. ImmLocalFree(lpwszReading);
  523. ImmUnlockImeDpi(pImeDpi);
  524. return 0;
  525. }
  526. i = MultiByteToWideChar(IMECodePage(pImeDpi),
  527. (DWORD)MB_PRECOMPOSED,
  528. (LPSTR)lpszString, // src
  529. (INT)strlen(lpszString),
  530. (LPWSTR)lpwszString, // dest
  531. cchString);
  532. lpwszString[i] = L'\0';
  533. }
  534. else {
  535. lpwszString = NULL;
  536. }
  537. erwData.lpfn.a = lpfnRegisterWordEnumProcA;
  538. erwData.lpData = lpData;
  539. erwData.dwCodePage = IMECodePage(pImeDpi);
  540. uRet = ImmEnumRegisterWordW(hKL, EnumRegisterWordProcW,
  541. lpwszReading, dwStyle, lpwszString, (LPVOID)&erwData);
  542. if (lpwszReading != NULL)
  543. ImmLocalFree(lpwszReading);
  544. if (lpwszString != NULL)
  545. ImmLocalFree(lpwszString);
  546. ImmUnlockImeDpi(pImeDpi);
  547. return uRet;
  548. }
  549. UINT WINAPI ImmEnumRegisterWordW(
  550. HKL hKL,
  551. REGISTERWORDENUMPROCW lpfnRegisterWordEnumProcW,
  552. LPCWSTR lpwszReading,
  553. DWORD dwStyle,
  554. LPCWSTR lpwszString,
  555. LPVOID lpData)
  556. {
  557. PIMEDPI pImeDpi;
  558. LPSTR lpszReading;
  559. LPSTR lpszString;
  560. INT cchReading;
  561. INT cchString;
  562. INT i;
  563. ENUMREGWORDDATA erwData;
  564. UINT uRet;
  565. pImeDpi = FindOrLoadImeDpi(hKL);
  566. if (pImeDpi == NULL) {
  567. RIPMSG0(RIP_WARNING, "ImmEnumRegisterWordW: no pImeDpi entry.");
  568. return FALSE;
  569. }
  570. if (pImeDpi->ImeInfo.fdwProperty & IME_PROP_UNICODE) {
  571. /*
  572. * Doesn't need W/A conversion. Calls directly to IME to
  573. * enumerate registered strings.
  574. */
  575. uRet = (*pImeDpi->pfn.ImeEnumRegisterWord.w)(lpfnRegisterWordEnumProcW,
  576. lpwszReading,
  577. dwStyle,
  578. lpwszString,
  579. lpData);
  580. ImmUnlockImeDpi(pImeDpi);
  581. return uRet;
  582. }
  583. /*
  584. * Unicode caller, ANSI IME. Needs W/A conversion on
  585. * lpwszReading and lpwszString.
  586. */
  587. if (lpwszReading != NULL) {
  588. cchReading = (wcslen(lpwszReading) + 1) * sizeof(WCHAR);
  589. lpszReading = ImmLocalAlloc(0, cchReading);
  590. if (lpszReading == NULL) {
  591. RIPMSG0(RIP_WARNING, "ImmEnumRegisterWordW: memory failure.");
  592. ImmUnlockImeDpi(pImeDpi);
  593. return 0;
  594. }
  595. i = WideCharToMultiByte(IMECodePage(pImeDpi),
  596. (DWORD)0,
  597. (LPWSTR)lpwszReading, // src
  598. (INT)wcslen(lpwszReading),
  599. (LPSTR)lpszReading, // dest
  600. cchReading,
  601. (LPSTR)NULL,
  602. (LPBOOL)NULL);
  603. lpszReading[i] = '\0';
  604. }
  605. else {
  606. lpszReading = NULL;
  607. }
  608. if (lpwszString != NULL) {
  609. cchString = (wcslen(lpwszString) + 1) * sizeof(WCHAR);
  610. lpszString = ImmLocalAlloc(0, cchString);
  611. if (lpszString == NULL) {
  612. RIPMSG0(RIP_WARNING, "ImmEnumRegisterWordW: memory failure.");
  613. if (lpszReading != NULL)
  614. ImmLocalFree(lpszReading);
  615. ImmUnlockImeDpi(pImeDpi);
  616. return 0;
  617. }
  618. i = WideCharToMultiByte(IMECodePage(pImeDpi),
  619. (DWORD)0,
  620. (LPWSTR)lpwszString, // src
  621. (INT)wcslen(lpwszString),
  622. (LPSTR)lpszString, // dest
  623. cchString,
  624. (LPSTR)NULL,
  625. (LPBOOL)NULL);
  626. lpszString[i] = '\0';
  627. }
  628. else {
  629. lpszString = NULL;
  630. }
  631. erwData.lpfn.w = lpfnRegisterWordEnumProcW;
  632. erwData.lpData = lpData;
  633. erwData.dwCodePage = IMECodePage(pImeDpi);
  634. uRet = ImmEnumRegisterWordA(hKL, EnumRegisterWordProcA,
  635. lpszReading, dwStyle, lpszString, (LPVOID)&erwData);
  636. if (lpszReading != NULL)
  637. ImmLocalFree(lpszReading);
  638. if (lpszString != NULL)
  639. ImmLocalFree(lpszString);
  640. ImmUnlockImeDpi(pImeDpi);
  641. return uRet;
  642. }
  643. UINT CALLBACK EnumRegisterWordProcA(
  644. LPCSTR lpszReading,
  645. DWORD dwStyle,
  646. LPCSTR lpszString,
  647. PENUMREGWORDDATA pEnumRegWordData)
  648. {
  649. LPWSTR lpwszReading;
  650. LPWSTR lpwszString;
  651. INT cchReading;
  652. INT cchString;
  653. INT i;
  654. UINT uRet;
  655. ImmAssert(pEnumRegWordData != NULL);
  656. if (lpszReading != NULL) {
  657. cchReading = strlen(lpszReading) + sizeof(CHAR);
  658. lpwszReading = ImmLocalAlloc(0, cchReading * sizeof(WCHAR));
  659. if (lpwszReading == NULL) {
  660. RIPMSG0(RIP_WARNING, "EnumRegisterWordProcA: memory failure.");
  661. return 0;
  662. }
  663. i = MultiByteToWideChar(pEnumRegWordData->dwCodePage,
  664. (DWORD)MB_PRECOMPOSED,
  665. (LPSTR)lpszReading, // src
  666. (INT)strlen(lpszReading),
  667. (LPWSTR)lpwszReading, // dest
  668. cchReading);
  669. lpwszReading[i] = L'\0';
  670. }
  671. else {
  672. lpwszReading = NULL;
  673. }
  674. if (lpszString != NULL) {
  675. cchString = strlen(lpszString) + sizeof(CHAR);
  676. lpwszString = ImmLocalAlloc(0, cchString * sizeof(WCHAR));
  677. if (lpwszString == NULL) {
  678. RIPMSG0(RIP_WARNING, "EnumRegisterWordProcA: memory failure.");
  679. if (lpwszReading != NULL)
  680. ImmLocalFree(lpwszReading);
  681. return 0;
  682. }
  683. i = MultiByteToWideChar(pEnumRegWordData->dwCodePage,
  684. (DWORD)MB_PRECOMPOSED,
  685. (LPSTR)lpszString, // src
  686. (INT)strlen(lpszString),
  687. (LPWSTR)lpwszString, // dest
  688. cchString);
  689. lpwszString[i] = L'\0';
  690. }
  691. else {
  692. lpwszString = NULL;
  693. }
  694. uRet = (*pEnumRegWordData->lpfn.w)(lpwszReading, dwStyle,
  695. lpwszString, pEnumRegWordData->lpData);
  696. if (lpwszReading != NULL)
  697. ImmLocalFree(lpwszReading);
  698. if (lpwszString != NULL)
  699. ImmLocalFree(lpwszString);
  700. return uRet;
  701. }
  702. UINT CALLBACK EnumRegisterWordProcW(
  703. LPCWSTR lpwszReading,
  704. DWORD dwStyle,
  705. LPCWSTR lpwszString,
  706. PENUMREGWORDDATA pEnumRegWordData)
  707. {
  708. LPSTR lpszReading;
  709. LPSTR lpszString;
  710. INT cchReading;
  711. INT cchString;
  712. INT i;
  713. UINT uRet;
  714. ImmAssert(pEnumRegWordData != NULL);
  715. if (lpwszReading != NULL) {
  716. cchReading = (wcslen(lpwszReading) + 1) * sizeof(WCHAR);
  717. lpszReading = ImmLocalAlloc(0, cchReading);
  718. if (lpszReading == NULL) {
  719. RIPMSG0(RIP_WARNING, "ImmRegisterWordW: memory failure.");
  720. return 0;
  721. }
  722. i = WideCharToMultiByte(pEnumRegWordData->dwCodePage,
  723. (DWORD)0,
  724. (LPWSTR)lpwszReading, // src
  725. (INT)wcslen(lpwszReading),
  726. (LPSTR)lpszReading, // dest
  727. cchReading,
  728. (LPSTR)NULL,
  729. (LPBOOL)NULL);
  730. lpszReading[i] = '\0';
  731. }
  732. else {
  733. lpszReading = NULL;
  734. }
  735. if (lpwszString != NULL) {
  736. cchString = (wcslen(lpwszString) + 1) * sizeof(WCHAR);
  737. lpszString = ImmLocalAlloc(0, cchString);
  738. if (lpszString == NULL) {
  739. RIPMSG0(RIP_WARNING, "ImmRegisterWordW: memory failure.");
  740. if (lpszReading != NULL)
  741. ImmLocalFree(lpszReading);
  742. return 0;
  743. }
  744. i = WideCharToMultiByte(pEnumRegWordData->dwCodePage,
  745. (DWORD)0,
  746. (LPWSTR)lpwszString, // src
  747. (INT)wcslen(lpwszString),
  748. (LPSTR)lpszString, // dest
  749. cchString,
  750. (LPSTR)NULL,
  751. (LPBOOL)NULL);
  752. lpszString[i] = '\0';
  753. }
  754. else {
  755. lpszString = NULL;
  756. }
  757. uRet = (*pEnumRegWordData->lpfn.a)(lpszReading, dwStyle,
  758. lpszString, pEnumRegWordData->lpData);
  759. if (lpszReading != NULL)
  760. ImmLocalFree(lpszReading);
  761. if (lpszString != NULL)
  762. ImmLocalFree(lpszString);
  763. return uRet;
  764. }