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.

1360 lines
42 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* Chinese IME List Dialog Class */
  5. /* */
  6. /* */
  7. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  8. /**************************************************/
  9. #include <windows.h>
  10. #include <windowsx.h>
  11. #include "imm.h"
  12. #include "imelist.h"
  13. #include "resource.h"
  14. static const TCHAR szRegWordCls[] = TEXT("Radical");
  15. static const TCHAR szImeLinkDlg[] = TEXT("ImeLinkDlg");
  16. static HINSTANCE hAppInst;
  17. static DWORD aIds[] =
  18. {
  19. IDD_RADICAL, IDH_EUDC_LINK_IMELIST,
  20. 0, 0
  21. };
  22. static const COUNTRYSETTING sCountry[] = {
  23. {
  24. BIG5_CP, TEXT("BIG5")
  25. }
  26. , {
  27. ALT_BIG5_CP, TEXT("BIG5")
  28. }
  29. #if defined(UNICODE)
  30. , {
  31. UNICODE_CP, TEXT("UNICODE")
  32. }
  33. #endif
  34. , {
  35. GB2312_CP, TEXT("GB2312")
  36. }
  37. };
  38. /****************************************/
  39. /* */
  40. /* Create IME string listbox */
  41. /* */
  42. /****************************************/
  43. LPIMELINKREGWORD
  44. RegWordCreate(
  45. HWND hWnd)
  46. {
  47. LPIMERADICALRECT lpImeLinkRadical;
  48. LPIMELINKREGWORD lpImeLinkRegWord;
  49. LPREGWORDSTRUCT lpRegWordStructTmp;
  50. HDC hDC;
  51. HWND hEudcEditWnd;
  52. UINT nLayouts, i, nIMEs;
  53. HKL FAR *lphKL;
  54. DWORD dwSize;
  55. TCHAR szStrBuf[16];
  56. SIZE lTextSize;
  57. RECT rcRect;
  58. TCHAR szTitle[32];
  59. TCHAR szMessage[256];
  60. hEudcEditWnd = GetWindow( GetParent( hWnd), GW_OWNER);
  61. nLayouts = GetKeyboardLayoutList( 0, NULL);
  62. if( !(lphKL = GlobalAlloc(GPTR, sizeof(HKL)*nLayouts)))
  63. return NULL;
  64. lpImeLinkRegWord = NULL;
  65. GetKeyboardLayoutList( nLayouts, lphKL);
  66. for( i = 0, nIMEs = 0; i < nLayouts; i++) {
  67. LRESULT lRet;
  68. HKL hKL;
  69. TCHAR szImeEudcDic[MAX_PATH];
  70. hKL = *(lphKL + i);
  71. if( !(lRet = ImmIsIME( hKL)))
  72. continue;
  73. szImeEudcDic[0] = '\0';
  74. lRet = ImmEscape( hKL, (HIMC)NULL, IME_ESC_GET_EUDC_DICTIONARY,
  75. szImeEudcDic);
  76. if( !lRet){
  77. continue;
  78. }else if( szImeEudcDic[0]){
  79. }else{
  80. continue;
  81. }
  82. *(lphKL + nIMEs) = hKL;
  83. nIMEs++;
  84. }
  85. if( !nIMEs){
  86. LoadString( hAppInst, IDS_NOIME_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  87. LoadString( hAppInst, IDS_NOIME_MSG, szMessage, sizeof(szMessage) / sizeof(TCHAR));
  88. MessageBox( hEudcEditWnd, szMessage, szTitle, MB_OK);
  89. goto RegWordCreateFreeHKL;
  90. }
  91. dwSize = sizeof( IMELINKREGWORD) - sizeof( REGWORDSTRUCT) +
  92. sizeof( REGWORDSTRUCT) * nIMEs;
  93. lpImeLinkRegWord = (LPIMELINKREGWORD)GlobalAlloc( GPTR, dwSize);
  94. if( !lpImeLinkRegWord){
  95. LoadString( hAppInst, IDS_NOMEM_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  96. LoadString( hAppInst, IDS_NOMEM_MSG, szMessage, sizeof(szMessage) / sizeof(TCHAR));
  97. MessageBox( hEudcEditWnd, szMessage, szTitle, MB_OK);
  98. goto RegWordCreateFreeHKL;
  99. }
  100. lpImeLinkRegWord->nEudcIMEs = nIMEs;
  101. lpRegWordStructTmp = &lpImeLinkRegWord->sRegWordStruct[0];
  102. for( i = 0; i < nIMEs; i++){
  103. LRESULT lRet;
  104. #ifndef UNICODE
  105. UINT j, uInternal;
  106. #endif
  107. UINT uReadingSize;
  108. lpRegWordStructTmp->hKL = *(lphKL + i);
  109. if( !(lRet = ImmEscape(lpRegWordStructTmp->hKL, (HIMC)NULL,
  110. IME_ESC_MAX_KEY, NULL))){
  111. lpImeLinkRegWord->nEudcIMEs--;
  112. continue;
  113. }
  114. uReadingSize = sizeof(TCHAR);
  115. #ifndef UNICODE
  116. for (j = 0; j < 256; j++) {
  117. uInternal = ImmEscape(lpRegWordStructTmp->hKL, (HIMC)NULL,
  118. IME_ESC_SEQUENCE_TO_INTERNAL, &j);
  119. if (uInternal > 255) {
  120. uReadingSize = sizeof(WCHAR);
  121. break;
  122. }
  123. }
  124. #endif
  125. if( lRet * uReadingSize > sizeof(lpRegWordStructTmp->szReading) - sizeof(TCHAR)){
  126. lpImeLinkRegWord->nEudcIMEs--;
  127. continue;
  128. }
  129. if( !(lRet = ImmEscape(lpRegWordStructTmp->hKL, (HIMC)NULL,
  130. IME_ESC_IME_NAME, lpRegWordStructTmp->szIMEName))){
  131. lpImeLinkRegWord->nEudcIMEs--;
  132. continue;
  133. }
  134. lpRegWordStructTmp->szIMEName[
  135. sizeof(lpRegWordStructTmp->szIMEName) / sizeof(TCHAR) - 1] = '\0';
  136. lpRegWordStructTmp->uIMENameLen =
  137. lstrlen( lpRegWordStructTmp->szIMEName);
  138. lpRegWordStructTmp++;
  139. }
  140. if( !lpImeLinkRegWord->nEudcIMEs){
  141. LoadString( hAppInst, IDS_NOIME_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  142. LoadString( hAppInst, IDS_NOIME_MSG, szMessage, sizeof(szMessage) / sizeof(TCHAR));
  143. MessageBox( hEudcEditWnd, szMessage, szTitle, MB_OK);
  144. goto RegWordCreateFreeRegWord;
  145. }
  146. LoadString( hAppInst, IDS_CHINESE_CHAR, szStrBuf, sizeof( szStrBuf) / sizeof(TCHAR));
  147. hDC = GetDC(NULL);
  148. GetTextExtentPoint( hDC, szStrBuf, lstrlen( szStrBuf), &lTextSize);
  149. ReleaseDC(NULL, hDC);
  150. GetWindowRect( hWnd, &rcRect);
  151. nIMEs = (rcRect.bottom - rcRect.top) / (2 * lTextSize.cy);
  152. if( lpImeLinkRegWord->nEudcIMEs <= nIMEs){
  153. nIMEs = lpImeLinkRegWord->nEudcIMEs;
  154. }
  155. dwSize = sizeof(IMERADICALRECT) - sizeof(RECT) + sizeof(RECT) *
  156. RECT_NUMBER * nIMEs;
  157. lpImeLinkRadical = (LPIMERADICALRECT)GlobalAlloc( GPTR, dwSize);
  158. if( !lpImeLinkRadical){
  159. lpImeLinkRegWord->nEudcIMEs = 0;
  160. LoadString( hAppInst, IDS_NOMEM_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  161. LoadString( hAppInst, IDS_NOMEM_MSG, szMessage, sizeof(szMessage) / sizeof(TCHAR));
  162. MessageBox( hEudcEditWnd, szMessage, szTitle, MB_OK);
  163. goto RegWordCreateFreeRegWord;
  164. }
  165. lpImeLinkRadical->nStartIME = 0;
  166. lpImeLinkRadical->nPerPageIMEs = nIMEs;
  167. lpImeLinkRadical->lTextSize = lTextSize;
  168. if( lpImeLinkRegWord->nEudcIMEs > nIMEs) {
  169. SCROLLINFO scInfo;
  170. lpImeLinkRadical->hScrollWnd = CreateWindowEx( 0,
  171. TEXT("scrollbar"), NULL, WS_CHILD|WS_VISIBLE|SBS_VERT,
  172. rcRect.right - rcRect.left - lTextSize.cx, 0,
  173. lTextSize.cx, rcRect.bottom - rcRect.top,
  174. hWnd, 0, hAppInst, NULL);
  175. scInfo.cbSize = sizeof(SCROLLINFO);
  176. scInfo.fMask = SIF_ALL;
  177. scInfo.nMin = 0;
  178. scInfo.nMax = lpImeLinkRegWord->nEudcIMEs - 1 + (nIMEs - 1);
  179. scInfo.nPage = nIMEs;
  180. scInfo.nPos = 0;
  181. scInfo.nTrackPos = 0;
  182. SetScrollInfo( lpImeLinkRadical->hScrollWnd,
  183. SB_CTL, &scInfo, FALSE);
  184. }
  185. for( i = 0; i < nIMEs; i++){
  186. UINT j, k;
  187. j = i * RECT_NUMBER + RECT_IMENAME;
  188. lpImeLinkRadical->rcRadical[j].left = lTextSize.cx;
  189. lpImeLinkRadical->rcRadical[j].top = lTextSize.cy *
  190. (i * 4 + 1) / 2 - UI_MARGIN;
  191. lpImeLinkRadical->rcRadical[j].right =
  192. lpImeLinkRadical->rcRadical[j].left + lTextSize.cx * 6;
  193. lpImeLinkRadical->rcRadical[j].bottom =
  194. lpImeLinkRadical->rcRadical[j].top + lTextSize.cy +
  195. UI_MARGIN * 2;
  196. k = i * RECT_NUMBER + RECT_RADICAL;
  197. lpImeLinkRadical->rcRadical[k].left =
  198. lpImeLinkRadical->rcRadical[j].right + lTextSize.cx;
  199. lpImeLinkRadical->rcRadical[k].top =
  200. lpImeLinkRadical->rcRadical[j].top;
  201. lpImeLinkRadical->rcRadical[k].right =
  202. lpImeLinkRadical->rcRadical[k].left + lTextSize.cx *
  203. (sizeof(lpRegWordStructTmp->szReading) / sizeof(TCHAR) / 2 - 1);
  204. lpImeLinkRadical->rcRadical[k].bottom =
  205. lpImeLinkRadical->rcRadical[k].top + lTextSize.cy +
  206. UI_MARGIN * 2;
  207. }
  208. SetWindowLongPtr(hWnd, GWLP_RADICALRECT, (LONG_PTR)lpImeLinkRadical);
  209. RegWordCreateFreeRegWord:
  210. if( !lpImeLinkRegWord->nEudcIMEs){
  211. GlobalFree((HGLOBAL)lpImeLinkRegWord);
  212. lpImeLinkRegWord = NULL;
  213. }
  214. RegWordCreateFreeHKL:
  215. GlobalFree((HGLOBAL)lphKL);
  216. return( lpImeLinkRegWord);
  217. }
  218. /****************************************/
  219. /* */
  220. /* Switch To Mouse Clicked IME */
  221. /* */
  222. /****************************************/
  223. void
  224. SwitchToThisIME(
  225. HWND hWnd,
  226. UINT uIndex)
  227. {
  228. LPIMELINKREGWORD lpImeLinkRegWord;
  229. LPREGWORDSTRUCT lpRegWordStructTmp;
  230. LPIMERADICALRECT lpImeLinkRadical;
  231. DWORD fdwConversionMode, fdwSentenceMode;
  232. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr( hWnd,
  233. GWLP_IMELINKREGWORD);
  234. if( lpImeLinkRegWord->nCurrIME == uIndex)
  235. return;
  236. if( uIndex >= lpImeLinkRegWord->nEudcIMEs){
  237. MessageBeep((UINT)-1);
  238. return;
  239. }
  240. lpImeLinkRadical = (LPIMERADICALRECT)GetWindowLongPtr(hWnd,
  241. GWLP_RADICALRECT);
  242. if( uIndex < lpImeLinkRadical->nStartIME){
  243. lpImeLinkRadical->nStartIME = uIndex;
  244. }else if(( uIndex - lpImeLinkRadical->nStartIME) >=
  245. lpImeLinkRadical->nPerPageIMEs){
  246. lpImeLinkRadical->nStartIME = uIndex -
  247. (lpImeLinkRadical->nPerPageIMEs - 1);
  248. }else{
  249. }
  250. SendMessage(hWnd, WM_EUDC_COMPMSG, 0, FALSE);
  251. lpRegWordStructTmp = &lpImeLinkRegWord->sRegWordStruct[uIndex];
  252. ActivateKeyboardLayout(lpRegWordStructTmp->hKL, 0);
  253. if( !ImmGetConversionStatus(lpImeLinkRegWord->hRegWordIMC,
  254. &fdwConversionMode, &fdwSentenceMode))
  255. {
  256. return;
  257. }
  258. fdwConversionMode = (fdwConversionMode | IME_CMODE_EUDC |
  259. IME_CMODE_NATIVE) | (fdwConversionMode & IME_CMODE_SOFTKBD);
  260. ImmSetConversionStatus(lpImeLinkRegWord->hRegWordIMC,
  261. fdwConversionMode, fdwSentenceMode);
  262. SendMessage(hWnd, WM_EUDC_COMPMSG, 0, TRUE);
  263. lpImeLinkRegWord->nCurrIME = uIndex;
  264. if(lpImeLinkRadical->hScrollWnd){
  265. SCROLLINFO scInfo;
  266. scInfo.cbSize = sizeof(SCROLLINFO);
  267. scInfo.fMask = SIF_POS;
  268. scInfo.nPos = lpImeLinkRegWord->nCurrIME;
  269. SetScrollInfo(lpImeLinkRadical->hScrollWnd,
  270. SB_CTL, &scInfo, FALSE);
  271. }
  272. InvalidateRect(hWnd, NULL, TRUE);
  273. *(LPTSTR)&lpRegWordStructTmp->szReading[
  274. lpRegWordStructTmp->dwReadingLen] = '\0';
  275. ImmSetCompositionString(lpImeLinkRegWord->hRegWordIMC, SCS_SETSTR,
  276. NULL, 0, lpRegWordStructTmp->szReading,
  277. lpRegWordStructTmp->dwReadingLen * sizeof(TCHAR));
  278. SetFocus(hWnd);
  279. return;
  280. }
  281. /****************************************/
  282. /* */
  283. /* MESSAGE "WM_IMECOMPOSITION" */
  284. /* */
  285. /****************************************/
  286. void
  287. WmImeComposition(
  288. HWND hWnd,
  289. LPARAM lParam)
  290. {
  291. LPIMELINKREGWORD lpImeLinkRegWord;
  292. LPREGWORDSTRUCT lpRegWordStructTmp;
  293. TCHAR szReading[sizeof(lpRegWordStructTmp->szReading)/sizeof(TCHAR)];
  294. LONG lRet;
  295. BOOL bUpdate;
  296. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr( hWnd,
  297. GWLP_IMELINKREGWORD);
  298. lpRegWordStructTmp = &lpImeLinkRegWord->sRegWordStruct[
  299. lpImeLinkRegWord->nCurrIME];
  300. lRet = ImmGetCompositionString(lpImeLinkRegWord->hRegWordIMC,
  301. GCS_COMPREADSTR, szReading, sizeof(szReading));
  302. if (lRet < 0) {
  303. lpRegWordStructTmp->bUpdate = UPDATE_ERROR;
  304. return;
  305. }
  306. if (lRet > (sizeof(szReading) - sizeof(TCHAR))) {
  307. lRet = sizeof(szReading) - sizeof(TCHAR);
  308. }
  309. szReading[lRet / sizeof(TCHAR)] = '\0';
  310. if( lpRegWordStructTmp->dwReadingLen != (DWORD)lRet / sizeof(TCHAR)){
  311. bUpdate = TRUE;
  312. }else if( lstrcmp(lpRegWordStructTmp->szReading, szReading)){
  313. bUpdate = TRUE;
  314. }else bUpdate = FALSE;
  315. if( bUpdate){
  316. LPIMERADICALRECT lpImeLinkRadical;
  317. UINT i;
  318. UINT j, k;
  319. lpImeLinkRadical = (LPIMERADICALRECT)GetWindowLongPtr(hWnd,
  320. GWLP_RADICALRECT);
  321. lstrcpy( lpRegWordStructTmp->szReading, szReading);
  322. if( lParam & GCS_RESULTSTR){
  323. lpRegWordStructTmp->bUpdate = UPDATE_FINISH;
  324. }else{
  325. lpRegWordStructTmp->bUpdate = UPDATE_START;
  326. }
  327. lpRegWordStructTmp->dwReadingLen = (DWORD)lRet / sizeof(TCHAR);
  328. if( !IsWindowEnabled(lpImeLinkRadical->hRegWordButton)){
  329. EnableWindow(lpImeLinkRadical->hRegWordButton, TRUE);
  330. }
  331. i = lpImeLinkRegWord->nCurrIME - lpImeLinkRadical->nStartIME;
  332. j = i * RECT_NUMBER + RECT_IMENAME;
  333. InvalidateRect(hWnd, &lpImeLinkRadical->rcRadical[j], FALSE);
  334. k = i * RECT_NUMBER + RECT_RADICAL;
  335. InvalidateRect(hWnd, &lpImeLinkRadical->rcRadical[k], FALSE);
  336. }else if( lParam & GCS_RESULTSTR){
  337. LPIMERADICALRECT lpImeLinkRadical;
  338. UINT i;
  339. UINT j, k;
  340. lpImeLinkRadical = (LPIMERADICALRECT)GetWindowLongPtr(hWnd,
  341. GWLP_RADICALRECT);
  342. if( lpRegWordStructTmp->bUpdate){
  343. lpRegWordStructTmp->bUpdate = UPDATE_FINISH;
  344. }
  345. i = lpImeLinkRegWord->nCurrIME - lpImeLinkRadical->nStartIME;
  346. j = i * RECT_NUMBER + RECT_IMENAME;
  347. InvalidateRect(hWnd, &lpImeLinkRadical->rcRadical[j], FALSE);
  348. k = i * RECT_NUMBER + RECT_RADICAL;
  349. InvalidateRect(hWnd, &lpImeLinkRadical->rcRadical[k], FALSE);
  350. }
  351. return;
  352. }
  353. /************************************************************/
  354. /* */
  355. /* lstrcmpn */
  356. /* */
  357. /************************************************************/
  358. int lstrcmpn(
  359. LPCTSTR lpctszStr1,
  360. LPCTSTR lpctszStr2,
  361. int cCount)
  362. {
  363. int i;
  364. for (i = 0; i < cCount; i++) {
  365. int iCmp = *lpctszStr1++ - *lpctszStr2++;
  366. if (iCmp) { return iCmp; }
  367. }
  368. return 0;
  369. }
  370. /****************************************/
  371. /* */
  372. /* CALLBACK ENUMREADING */
  373. /* */
  374. /****************************************/
  375. int CALLBACK
  376. EnumReading(
  377. LPCTSTR lpszReading,
  378. DWORD dwStyle,
  379. LPCTSTR lpszString,
  380. LPREGWORDSTRUCT lpRegWordStructTmp)
  381. {
  382. int iLen;
  383. DWORD dwZeroSeq;
  384. LRESULT lRet;
  385. TCHAR tszZeroSeq[8];
  386. iLen = lstrlen(lpszReading);
  387. if (iLen * sizeof(TCHAR) > sizeof(lpRegWordStructTmp->szReading) -
  388. sizeof(WORD)) {
  389. return (0);
  390. }
  391. lpRegWordStructTmp->dwReadingLen = (DWORD)iLen;
  392. lstrcpy(lpRegWordStructTmp->szReading, lpszReading);
  393. dwZeroSeq = 0;
  394. lRet = ImmEscape(lpRegWordStructTmp->hKL, (HIMC)NULL,
  395. IME_ESC_SEQUENCE_TO_INTERNAL, &dwZeroSeq);
  396. if (!lRet) { goto Over; }
  397. iLen = 0;
  398. if (LOWORD(lRet)) {
  399. #ifdef UNICODE
  400. tszZeroSeq[iLen++] = LOWORD(lRet);
  401. #else
  402. if (LOWORD(lRet) > 0xFF) {
  403. tszZeroSeq[iLen++] = HIBYTE(LOWORD(lRet));
  404. tszZeroSeq[iLen++] = LOBYTE(LOWORD(lRet));
  405. } else {
  406. tszZeroSeq[iLen++] = LOBYTE(LOWORD(lRet));
  407. }
  408. #endif
  409. }
  410. if (HIWORD(lRet) == 0xFFFF) {
  411. // This is caused by sign extent in Win9x in the return value of
  412. // ImmEscape, it causes an invalid internal code.
  413. } else if (HIWORD(lRet)) {
  414. #ifdef UNICODE
  415. tszZeroSeq[iLen++] = HIWORD(lRet);
  416. #else
  417. if (HIWORD(lRet) > 0xFF) {
  418. tszZeroSeq[iLen++] = HIBYTE(HIWORD(lRet));
  419. tszZeroSeq[iLen++] = LOBYTE(HIWORD(lRet));
  420. } else {
  421. tszZeroSeq[iLen++] = LOBYTE(HIWORD(lRet));
  422. }
  423. #endif
  424. } else {
  425. }
  426. for (; lpRegWordStructTmp->dwReadingLen > 0;
  427. lpRegWordStructTmp->dwReadingLen -= iLen) {
  428. if (lstrcmpn(&lpRegWordStructTmp->szReading[
  429. lpRegWordStructTmp->dwReadingLen - iLen], tszZeroSeq, iLen) != 0) {
  430. break;
  431. }
  432. }
  433. Over:
  434. lpRegWordStructTmp->szReading[lpRegWordStructTmp->dwReadingLen] = '\0';
  435. return (1);
  436. }
  437. /****************************************/
  438. /* */
  439. /* EUDC CODE Calcurater */
  440. /* */
  441. /****************************************/
  442. void
  443. EudcCode(
  444. HWND hWnd,
  445. DWORD dwComboCode)
  446. {
  447. LPIMELINKREGWORD lpImeLinkRegWord;
  448. LPREGWORDSTRUCT lpRegWordStructTmp;
  449. UINT i, uCode;
  450. BOOL bUnicodeMode=FALSE;
  451. WCHAR TmpCode[1];
  452. CHAR TmpCodeAnsi[2];
  453. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr(hWnd,
  454. GWLP_IMELINKREGWORD);
  455. uCode = LOWORD(dwComboCode);
  456. if (HIWORD(dwComboCode)) // the code is in unicode
  457. bUnicodeMode = TRUE;
  458. #ifdef UNICODE
  459. if (bUnicodeMode) {
  460. lpImeLinkRegWord->szEudcCodeString[0] = (WCHAR)uCode;
  461. lpImeLinkRegWord->szEudcCodeString[1] = TEXT('\0');
  462. }else{
  463. TmpCodeAnsi[0] = HIBYTE(uCode);
  464. TmpCodeAnsi[1] = LOBYTE(uCode);
  465. //
  466. // convert to Unicode string
  467. //
  468. MultiByteToWideChar(GetACP(), MB_PRECOMPOSED,
  469. (LPCSTR)TmpCodeAnsi, 2,
  470. (LPWSTR)TmpCode, 1);
  471. lpImeLinkRegWord->szEudcCodeString[0] = (WCHAR)TmpCode[0];
  472. lpImeLinkRegWord->szEudcCodeString[1] = TEXT('\0');
  473. }
  474. #else //UNICODE
  475. if (bUnicodeMode) {
  476. TmpCode[0] = (WCHAR) uCode;
  477. //
  478. // Convert to Ansi byte string
  479. //
  480. WideCharToMultiByte(GetACP(), WC_COMPOSITECHECK,
  481. (LPWSTR)TmpCode, 1,
  482. (LPSTR)TmpCodeAnsi, 2,
  483. NULL, NULL);
  484. lpImeLinkRegWord->szEudcCodeString[0] = TmpCodeAnsi[0];
  485. lpImeLinkRegWord->szEudcCodeString[1] = TmpCodeAnsi[1];
  486. }else{
  487. lpImeLinkRegWord->szEudcCodeString[0] = HIBYTE(uCode);
  488. lpImeLinkRegWord->szEudcCodeString[1] = LOBYTE(uCode);
  489. }
  490. #endif //UNICODE
  491. lpImeLinkRegWord->szEudcCodeString[2] =
  492. lpImeLinkRegWord->szEudcCodeString[3] = '\0';
  493. lpRegWordStructTmp = &lpImeLinkRegWord->sRegWordStruct[0];
  494. for( i = 0; i < lpImeLinkRegWord->nEudcIMEs; i++){
  495. lpRegWordStructTmp->bUpdate = UPDATE_NONE;
  496. lpRegWordStructTmp->szReading[0] = '\0';
  497. lpRegWordStructTmp->dwReadingLen = 0;
  498. ImmEnumRegisterWord(lpRegWordStructTmp->hKL, EnumReading,
  499. NULL, IME_REGWORD_STYLE_EUDC,
  500. lpImeLinkRegWord->szEudcCodeString,
  501. lpRegWordStructTmp);
  502. lpRegWordStructTmp->dwReadingLen =
  503. lstrlen( lpRegWordStructTmp->szReading);
  504. lpRegWordStructTmp++;
  505. }
  506. lpRegWordStructTmp = &lpImeLinkRegWord->sRegWordStruct[
  507. lpImeLinkRegWord->nCurrIME];
  508. ImmSetCompositionString(lpImeLinkRegWord->hRegWordIMC, SCS_SETSTR,
  509. NULL, 0, lpRegWordStructTmp->szReading,
  510. lpRegWordStructTmp->dwReadingLen * sizeof(TCHAR));
  511. InvalidateRect(hWnd, NULL, FALSE);
  512. return;
  513. }
  514. /****************************************/
  515. /* */
  516. /* Change To Mouse Clicked IME */
  517. /* */
  518. /****************************************/
  519. void
  520. ChangeToOtherIME(
  521. HWND hWnd,
  522. LPARAM lMousePos)
  523. {
  524. LPIMERADICALRECT lpImeLinkRadical;
  525. POINT ptMouse;
  526. UINT i;
  527. BOOL bFound;
  528. ptMouse.x = GET_X_LPARAM( lMousePos);
  529. ptMouse.y = GET_Y_LPARAM( lMousePos);
  530. lpImeLinkRadical = (LPIMERADICALRECT)GetWindowLongPtr( hWnd,
  531. GWLP_RADICALRECT);
  532. bFound = FALSE;
  533. for( i = 0; i < lpImeLinkRadical->nPerPageIMEs; i++){
  534. UINT j;
  535. j = i * RECT_NUMBER + RECT_RADICAL;
  536. if( PtInRect(&lpImeLinkRadical->rcRadical[j], ptMouse)){
  537. bFound = TRUE;
  538. break;
  539. }
  540. }
  541. if( !bFound) return;
  542. SwitchToThisIME( hWnd, lpImeLinkRadical->nStartIME + i);
  543. return;
  544. }
  545. /****************************************/
  546. /* */
  547. /* ScrollUP or Down IME LISTBOX */
  548. /* */
  549. /****************************************/
  550. void
  551. ScrollIME(
  552. HWND hWnd,
  553. WPARAM wParam)
  554. {
  555. LPIMELINKREGWORD lpImeLinkRegWord;
  556. LPIMERADICALRECT lpImeLinkRadical;
  557. int iLines;
  558. UINT uIndex;
  559. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr( hWnd,
  560. GWLP_IMELINKREGWORD);
  561. lpImeLinkRadical = (LPIMERADICALRECT)GetWindowLongPtr( hWnd,
  562. GWLP_RADICALRECT);
  563. switch( LOWORD( wParam)){
  564. case SB_PAGEDOWN:
  565. iLines = lpImeLinkRadical->nPerPageIMEs - 1;
  566. break;
  567. case SB_LINEDOWN:
  568. iLines = 1;
  569. break;
  570. case SB_PAGEUP:
  571. iLines = 1 - lpImeLinkRadical->nPerPageIMEs;
  572. break;
  573. case SB_LINEUP:
  574. iLines = -1;
  575. break;
  576. case SB_TOP:
  577. SwitchToThisIME(hWnd, 0);
  578. return;
  579. case SB_BOTTOM:
  580. SwitchToThisIME(hWnd, lpImeLinkRegWord->nEudcIMEs - 1);
  581. return;
  582. case SB_THUMBPOSITION:
  583. SwitchToThisIME(hWnd, HIWORD(wParam));
  584. return;
  585. default:
  586. return;
  587. }
  588. uIndex = lpImeLinkRegWord->nCurrIME;
  589. if( iLines > 0){
  590. uIndex += (UINT)iLines;
  591. if( uIndex >= lpImeLinkRegWord->nEudcIMEs){
  592. uIndex = lpImeLinkRegWord->nEudcIMEs - 1;
  593. }
  594. }else{
  595. UINT uLines;
  596. uLines = -iLines;
  597. if( uLines > uIndex){
  598. uIndex = 0;
  599. }else uIndex -= uLines;
  600. }
  601. SwitchToThisIME(hWnd, uIndex);
  602. return;
  603. }
  604. /****************************************/
  605. /* */
  606. /* ScrollUP or Down IME LISTBOX */
  607. /* */
  608. /****************************************/
  609. void
  610. ScrollIMEByKey(
  611. HWND hWnd,
  612. WPARAM wParam)
  613. {
  614. switch( wParam){
  615. case VK_NEXT:
  616. ScrollIME( hWnd, SB_PAGEDOWN);
  617. break;
  618. case VK_DOWN:
  619. ScrollIME( hWnd, SB_LINEDOWN);
  620. break;
  621. case VK_PRIOR:
  622. ScrollIME(hWnd, SB_PAGEUP);
  623. break;
  624. case VK_UP:
  625. ScrollIME(hWnd, SB_LINEUP);
  626. break;
  627. default:
  628. return;
  629. }
  630. return;
  631. }
  632. /****************************************/
  633. /* */
  634. /* Get Focus in RegWord List */
  635. /* */
  636. /****************************************/
  637. void
  638. RegWordGetFocus(
  639. HWND hWnd)
  640. {
  641. LPIMELINKREGWORD lpImeLinkRegWord;
  642. LPIMERADICALRECT lpImeLinkRadical;
  643. UINT i;
  644. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr( hWnd,
  645. GWLP_IMELINKREGWORD);
  646. lpImeLinkRadical = (LPIMERADICALRECT)GetWindowLongPtr( hWnd,
  647. GWLP_RADICALRECT);
  648. CreateCaret( hWnd, NULL, 2, lpImeLinkRadical->lTextSize.cy +
  649. CARET_MARGIN * 2);
  650. if( lpImeLinkRegWord->nCurrIME < lpImeLinkRadical->nStartIME){
  651. lpImeLinkRegWord->nCurrIME = lpImeLinkRadical->nStartIME;
  652. }else if(( lpImeLinkRegWord->nCurrIME - lpImeLinkRadical->nStartIME) >=
  653. lpImeLinkRadical->nPerPageIMEs) {
  654. lpImeLinkRegWord->nCurrIME = lpImeLinkRadical->nStartIME +
  655. lpImeLinkRadical->nPerPageIMEs - 1;
  656. }
  657. i = lpImeLinkRegWord->nCurrIME - lpImeLinkRadical->nStartIME;
  658. i = (i * RECT_NUMBER) + RECT_RADICAL;
  659. SetCaretPos(lpImeLinkRadical->rcRadical[i].left +
  660. lpImeLinkRadical->lCurrReadingExtent.cx + 2,
  661. lpImeLinkRadical->rcRadical[i].top + UI_MARGIN - CARET_MARGIN);
  662. ShowCaret(hWnd);
  663. return;
  664. }
  665. /****************************************/
  666. /* */
  667. /* MESSAGE "WM_PAINT" */
  668. /* */
  669. /****************************************/
  670. void RegWordPaint(
  671. HWND hWnd)
  672. {
  673. LPIMERADICALRECT lpImeLinkRadical;
  674. LPIMELINKREGWORD lpImeLinkRegWord;
  675. LPREGWORDSTRUCT lpRegWordStructTmp;
  676. PAINTSTRUCT ps;
  677. HDC hDC;
  678. UINT i;
  679. UINT nShowIMEs;
  680. lpImeLinkRadical = (LPIMERADICALRECT)GetWindowLongPtr(hWnd,
  681. GWLP_RADICALRECT);
  682. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr(hWnd,
  683. GWLP_IMELINKREGWORD);
  684. lpRegWordStructTmp = &lpImeLinkRegWord->sRegWordStruct[
  685. lpImeLinkRadical->nStartIME];
  686. HideCaret(hWnd);
  687. hDC = BeginPaint(hWnd, &ps);
  688. nShowIMEs = lpImeLinkRegWord->nEudcIMEs - lpImeLinkRadical->nStartIME;
  689. if( nShowIMEs > lpImeLinkRadical->nPerPageIMEs){
  690. nShowIMEs = lpImeLinkRadical->nPerPageIMEs;
  691. }
  692. for( i = 0; i < nShowIMEs; i++){
  693. RECT rcSunken;
  694. UINT j, k;
  695. k = i * RECT_NUMBER + RECT_RADICAL;
  696. rcSunken = lpImeLinkRadical->rcRadical[k];
  697. rcSunken.left -= 2;
  698. rcSunken.top -= 2;
  699. rcSunken.right += 2;
  700. rcSunken.bottom += 2;
  701. DrawEdge(hDC, &rcSunken, BDR_SUNKENOUTER, BF_RECT);
  702. SetBkColor(hDC, GetSysColor(COLOR_BTNFACE));
  703. if( lpRegWordStructTmp->bUpdate == UPDATE_ERROR){
  704. SetTextColor(hDC, RGB(0xFF, 0x00, 0x00));
  705. }else if(lpRegWordStructTmp->bUpdate == UPDATE_START){
  706. SetTextColor(hDC, RGB(0xFF, 0xFF, 0x00));
  707. }else if(lpRegWordStructTmp->bUpdate == UPDATE_REGISTERED){
  708. SetTextColor(hDC, RGB(0x00, 0x80, 0x00));
  709. }else{
  710. SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
  711. }
  712. j = i * RECT_NUMBER + RECT_IMENAME;
  713. ExtTextOut(hDC, lpImeLinkRadical->rcRadical[j].left,
  714. lpImeLinkRadical->rcRadical[j].top,
  715. ETO_OPAQUE | ETO_CLIPPED, &lpImeLinkRadical->rcRadical[j],
  716. lpRegWordStructTmp->szIMEName,
  717. lpRegWordStructTmp->uIMENameLen, NULL);
  718. if(( lpImeLinkRegWord->nCurrIME - lpImeLinkRadical->nStartIME) == i){
  719. SetBkColor(hDC, GetSysColor(COLOR_WINDOW));
  720. SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
  721. GetTextExtentPoint(hDC, lpRegWordStructTmp->szReading,
  722. lpRegWordStructTmp->dwReadingLen,
  723. &lpImeLinkRadical->lCurrReadingExtent);
  724. SetCaretPos(lpImeLinkRadical->rcRadical[k].left +
  725. lpImeLinkRadical->lCurrReadingExtent.cx + 2,
  726. lpImeLinkRadical->rcRadical[k].top +
  727. UI_MARGIN - CARET_MARGIN);
  728. }else{
  729. SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
  730. }
  731. ExtTextOut(hDC, lpImeLinkRadical->rcRadical[k].left,
  732. lpImeLinkRadical->rcRadical[k].top + UI_MARGIN,
  733. ETO_OPAQUE, &lpImeLinkRadical->rcRadical[k],
  734. lpRegWordStructTmp->szReading,
  735. lpRegWordStructTmp->dwReadingLen, NULL);
  736. lpRegWordStructTmp++;
  737. }
  738. EndPaint(hWnd, &ps);
  739. ShowCaret(hWnd);
  740. return;
  741. }
  742. /****************************************/
  743. /* */
  744. /* Registry Word Window Proc */
  745. /* */
  746. /****************************************/
  747. LRESULT CALLBACK
  748. RegWordWndProc(
  749. HWND hWnd,
  750. UINT uMsg,
  751. WPARAM wParam,
  752. LPARAM lParam)
  753. {
  754. switch( uMsg){
  755. case WM_CREATE:
  756. {
  757. LPIMELINKREGWORD lpImeLinkRegWord;
  758. UINT uIndex;
  759. SetWindowLongPtr( hWnd, GWLP_IMELINKREGWORD, 0L);
  760. SetWindowLongPtr( hWnd, GWLP_RADICALRECT, 0L);
  761. if( !(lpImeLinkRegWord = RegWordCreate( hWnd)))
  762. return (-1);
  763. lpImeLinkRegWord->fCompMsg = TRUE;
  764. lpImeLinkRegWord->nCurrIME = 0xFFFFFFFF;
  765. lpImeLinkRegWord->hRegWordIMC = ImmCreateContext();
  766. if( !lpImeLinkRegWord->hRegWordIMC){
  767. return (-1);
  768. }
  769. lpImeLinkRegWord->hOldIMC = ImmAssociateContext( hWnd,
  770. lpImeLinkRegWord->hRegWordIMC);
  771. SetWindowLongPtr(hWnd, GWLP_IMELINKREGWORD, (LONG_PTR)lpImeLinkRegWord);
  772. uIndex = 0;
  773. SwitchToThisIME(hWnd, 0);
  774. PostMessage( hWnd, WM_EUDC_SWITCHIME, 0, uIndex);
  775. }
  776. break;
  777. case WM_EUDC_COMPMSG:
  778. {
  779. LPIMELINKREGWORD lpImeLinkRegWord;
  780. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr(hWnd,
  781. GWLP_IMELINKREGWORD);
  782. lpImeLinkRegWord->fCompMsg = (BOOL)lParam;
  783. }
  784. break;
  785. case WM_EUDC_SWITCHIME:
  786. {
  787. LPIMELINKREGWORD lpImeLinkRegWord;
  788. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr( hWnd,
  789. GWLP_IMELINKREGWORD);
  790. lpImeLinkRegWord->nCurrIME = 0xFFFFFFFF;
  791. SwitchToThisIME( hWnd, (UINT)lParam);
  792. }
  793. break;
  794. case WM_IME_STARTCOMPOSITION:
  795. case WM_IME_ENDCOMPOSITION:
  796. break;
  797. case WM_IME_COMPOSITION:
  798. {
  799. LPIMELINKREGWORD lpImeLinkRegWord;
  800. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr(hWnd,
  801. GWLP_IMELINKREGWORD);
  802. if( lpImeLinkRegWord->fCompMsg){
  803. WmImeComposition(hWnd, lParam);
  804. }
  805. }
  806. break;
  807. case WM_IME_NOTIFY:
  808. switch( wParam){
  809. case IMN_OPENSTATUSWINDOW:
  810. case IMN_CLOSESTATUSWINDOW:
  811. case IMN_OPENCANDIDATE:
  812. case IMN_CHANGECANDIDATE:
  813. case IMN_CLOSECANDIDATE:
  814. break;
  815. default:
  816. return DefWindowProc( hWnd, uMsg, wParam, lParam);
  817. }
  818. break;
  819. case WM_IME_SETCONTEXT:
  820. return DefWindowProc( hWnd, uMsg, wParam,
  821. lParam & ~(ISC_SHOWUIALL));
  822. case WM_EUDC_REGISTER_BUTTON:
  823. {
  824. LPIMERADICALRECT lpImeRadicalRect;
  825. lpImeRadicalRect = (LPIMERADICALRECT)GetWindowLongPtr(hWnd,
  826. GWLP_RADICALRECT);
  827. lpImeRadicalRect->hRegWordButton = (HWND)lParam;
  828. }
  829. break;
  830. case WM_EUDC_CODE:
  831. EudcCode(hWnd, (DWORD)lParam);
  832. break;
  833. case WM_LBUTTONDOWN:
  834. ChangeToOtherIME(hWnd, lParam);
  835. break;
  836. case WM_VSCROLL:
  837. ScrollIME(hWnd, wParam);
  838. break;
  839. case WM_KEYDOWN:
  840. ScrollIMEByKey(hWnd, wParam);
  841. break;
  842. case WM_SETFOCUS:
  843. RegWordGetFocus(hWnd);
  844. break;
  845. case WM_KILLFOCUS:
  846. DestroyCaret();
  847. break;
  848. case WM_PAINT:
  849. RegWordPaint(hWnd);
  850. break;
  851. case WM_DESTROY:
  852. {
  853. LPIMERADICALRECT lpImeRadicalRect;
  854. LPIMELINKREGWORD lpImeLinkRegWord;
  855. lpImeRadicalRect = (LPIMERADICALRECT)GetWindowLongPtr(hWnd,
  856. GWLP_RADICALRECT);
  857. if( lpImeRadicalRect){
  858. GlobalFree((HGLOBAL)lpImeRadicalRect);
  859. }
  860. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr(hWnd,
  861. GWLP_IMELINKREGWORD);
  862. if (!lpImeLinkRegWord) {
  863. break;
  864. }
  865. ImmAssociateContext(hWnd, lpImeLinkRegWord->hOldIMC);
  866. ImmDestroyContext(lpImeLinkRegWord->hRegWordIMC);
  867. GlobalFree((HGLOBAL)lpImeLinkRegWord);
  868. }
  869. break;
  870. default:
  871. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  872. }
  873. return (0L);
  874. }
  875. /****************************************/
  876. /* */
  877. /* Regist IME String */
  878. /* */
  879. /****************************************/
  880. int
  881. RegisterThisEudc(
  882. HWND hWnd)
  883. {
  884. LPIMELINKREGWORD lpImeLinkRegWord;
  885. LPREGWORDSTRUCT lpRegWordStructTmp;
  886. UINT i;
  887. int iRet;
  888. lpImeLinkRegWord = (LPIMELINKREGWORD)GetWindowLongPtr(hWnd,
  889. GWLP_IMELINKREGWORD);
  890. lpRegWordStructTmp = &lpImeLinkRegWord->sRegWordStruct[0];
  891. iRet = -1;
  892. for( i = 0; i < lpImeLinkRegWord->nEudcIMEs; i++, lpRegWordStructTmp++){
  893. if (( lpRegWordStructTmp->bUpdate == UPDATE_NONE) ||
  894. ( lpRegWordStructTmp->bUpdate == UPDATE_REGISTERED))
  895. {
  896. }
  897. else if( lpRegWordStructTmp->bUpdate != UPDATE_FINISH){
  898. TCHAR szStrBuf[128];
  899. int iYesNo;
  900. if( iRet != -1){
  901. continue;
  902. }
  903. LoadString( hAppInst, IDS_QUERY_NOTFINISH, szStrBuf,
  904. sizeof(szStrBuf) / sizeof(TCHAR));
  905. iYesNo = MessageBox(hWnd, szStrBuf,
  906. lpRegWordStructTmp->szIMEName,
  907. MB_APPLMODAL|MB_YESNO|MB_DEFBUTTON1);
  908. if( iYesNo == IDYES){
  909. iRet = i;
  910. }
  911. }else{
  912. BOOL fRet;
  913. TCHAR szStrBuf[128];
  914. int iYesNo;
  915. fRet = ImmRegisterWord(lpRegWordStructTmp->hKL,
  916. lpRegWordStructTmp->szReading,
  917. IME_REGWORD_STYLE_EUDC,
  918. lpImeLinkRegWord->szEudcCodeString);
  919. if( fRet){
  920. lpRegWordStructTmp->bUpdate = UPDATE_REGISTERED;
  921. continue;
  922. }else{
  923. lpRegWordStructTmp->bUpdate = UPDATE_ERROR;
  924. }
  925. if( iRet != -1){
  926. continue;
  927. }
  928. LoadString(hAppInst, IDS_QUERY_REGISTER, szStrBuf,
  929. sizeof(szStrBuf) / sizeof(TCHAR));
  930. iYesNo = MessageBox(hWnd, szStrBuf,
  931. lpRegWordStructTmp->szIMEName,
  932. MB_APPLMODAL|MB_YESNO|MB_DEFBUTTON1);
  933. if( iYesNo == IDYES){
  934. iRet = i;
  935. }
  936. }
  937. }
  938. InvalidateRect( hWnd, NULL, FALSE);
  939. return (iRet);
  940. }
  941. /****************************************/
  942. /* */
  943. /* CodePage Info */
  944. /* */
  945. /****************************************/
  946. int CodePageInfo(
  947. UINT uCodePage)
  948. {
  949. int i;
  950. for (i = 0; i < sizeof(sCountry) / sizeof(COUNTRYSETTING); i++) {
  951. if (sCountry[i].uCodePage == uCodePage) {
  952. return(i);
  953. }
  954. }
  955. return (-1);
  956. }
  957. /****************************************/
  958. /* */
  959. /* IME LINK LISTBOX DIALOG */
  960. /* */
  961. /****************************************/
  962. INT_PTR CALLBACK
  963. ImeLinkDlgProc(
  964. HWND hDlg,
  965. UINT uMsg,
  966. WPARAM wParam,
  967. LPARAM lParam)
  968. {
  969. switch( uMsg){
  970. case WM_INITDIALOG:
  971. {
  972. HWND hRadicalWnd, hRegWordButton;
  973. int cbString;
  974. UINT uCode;
  975. BOOL bUnicodeMode=FALSE;
  976. #ifdef UNICODE
  977. UINT uCodePage, uNativeCode;
  978. int i;
  979. #endif
  980. TCHAR szTitle[128];
  981. // LONG WindowStyle;
  982. // WindowStyle = GetWindowLong( hDlg, GWL_EXSTYLE);
  983. // WindowStyle |= WS_EX_CONTEXTHELP;
  984. // SetWindowLong( hDlg, GWL_EXSTYLE, WindowStyle);
  985. cbString = GetWindowText(hDlg, szTitle, sizeof(szTitle) /
  986. sizeof(TCHAR));
  987. uCode = LOWORD((DWORD)lParam);
  988. if (HIWORD((DWORD)lParam))
  989. bUnicodeMode = TRUE;
  990. #ifdef UNICODE
  991. if (bUnicodeMode){
  992. uCodePage = GetACP();
  993. i = CodePageInfo(uCodePage);
  994. if (uCodePage == UNICODE_CP || i == -1) {
  995. wsprintf(&szTitle[cbString], TEXT("%4X"), (UINT)lParam);
  996. } else {
  997. uNativeCode = 0;
  998. WideCharToMultiByte(uCodePage, WC_COMPOSITECHECK,
  999. (LPCWSTR)&uCode, 1,
  1000. (LPSTR)&uNativeCode, sizeof(uNativeCode),
  1001. NULL, NULL);
  1002. // convert to multi byte string
  1003. uNativeCode = LOBYTE(uNativeCode) << 8 | HIBYTE(uNativeCode);
  1004. wsprintf(&szTitle[cbString], TEXT("%4X (%s - %4X)"),
  1005. (UINT)uCode, sCountry[i].szCodePage, (UINT)uNativeCode);
  1006. }
  1007. }else{
  1008. wsprintf( &szTitle[cbString], TEXT("%4X"), (UINT)uCode);
  1009. }
  1010. #else
  1011. wsprintf( &szTitle[cbString], "%4X", (UINT)uCode);
  1012. #endif
  1013. SetWindowText( hDlg, szTitle);
  1014. hRadicalWnd = GetDlgItem(hDlg, IDD_RADICAL);
  1015. SendMessage( hRadicalWnd, WM_EUDC_CODE, 0, lParam);
  1016. hRegWordButton = GetDlgItem(hDlg, IDOK);
  1017. EnableWindow( hRegWordButton, FALSE);
  1018. SendMessage( hRadicalWnd, WM_EUDC_REGISTER_BUTTON, 0,
  1019. (LPARAM)hRegWordButton);
  1020. }
  1021. return (TRUE);
  1022. case WM_COMMAND:
  1023. switch( wParam){
  1024. case IDOK:
  1025. {
  1026. HWND hRadicalWnd;
  1027. hRadicalWnd = GetDlgItem(hDlg, IDD_RADICAL);
  1028. if( RegisterThisEudc(hRadicalWnd) == -1){
  1029. EndDialog(hDlg, TRUE);
  1030. }else SetFocus(hRadicalWnd);
  1031. }
  1032. break;
  1033. case IDCANCEL:
  1034. EndDialog(hDlg, FALSE);
  1035. break;
  1036. default:
  1037. return (FALSE);
  1038. }
  1039. return( TRUE);
  1040. case WM_IME_NOTIFY:
  1041. switch( wParam){
  1042. case IMN_OPENSTATUSWINDOW:
  1043. case IMN_CLOSESTATUSWINDOW:
  1044. return (TRUE);
  1045. default:
  1046. return (FALSE);
  1047. }
  1048. case WM_HELP:
  1049. {/*
  1050. TCHAR HelpPath[MAX_PATH];
  1051. if( !GetSystemWindowsDirectory( HelpPath, MAX_PATH))
  1052. return FALSE;
  1053. lstrcat(HelpPath, TEXT("\\HELP\\EUDCEDIT.HLP"));
  1054. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  1055. HelpPath, HELP_WM_HELP, (DWORD_PTR)(LPDWORD)aIds);
  1056. */
  1057. }
  1058. return FALSE;
  1059. case WM_CONTEXTMENU:
  1060. {/*
  1061. TCHAR HelpPath[MAX_PATH];
  1062. if( !GetSystemWindowsDirectory( HelpPath, MAX_PATH))
  1063. return FALSE;
  1064. lstrcat(HelpPath, TEXT("\\HELP\\EUDCEDIT.HLP"));
  1065. WinHelp((HWND)wParam, HelpPath,
  1066. HELP_CONTEXTMENU, (DWORD_PTR)(LPDWORD)aIds);
  1067. */
  1068. }
  1069. return FALSE;
  1070. default:
  1071. return( FALSE);
  1072. }
  1073. return (TRUE);
  1074. }
  1075. /****************************************/
  1076. /* */
  1077. /* COMMAND "IME LINK" */
  1078. /* */
  1079. /****************************************/
  1080. void
  1081. ImeLink(
  1082. HWND hWnd,
  1083. UINT uCode,
  1084. BOOL bUnicodeMode,
  1085. HINSTANCE hInst)
  1086. {
  1087. static BOOL bFirstTime[20];
  1088. int ii;
  1089. WNDCLASSEX wcClass;
  1090. UINT nLayouts;
  1091. HKL FAR *lphKL;
  1092. TCHAR szTitle[32];
  1093. TCHAR szMessage[256];
  1094. UINT i, nIMEs;
  1095. HKL hOldKL;
  1096. for (ii = 0; ii < ARRAYLEN(bFirstTime); ii++)
  1097. bFirstTime[ii] = TRUE;
  1098. hAppInst = hInst;
  1099. //
  1100. // user32!GetKeyboardLayoutList sometimes return huge number when an AV occurs in IME
  1101. //
  1102. nLayouts = GetKeyboardLayoutList(0, NULL);
  1103. if (nLayouts > ARRAYLEN(bFirstTime))
  1104. {
  1105. return;
  1106. }
  1107. lphKL = GlobalAlloc(GPTR, sizeof(HKL) * nLayouts);
  1108. if (!lphKL) {
  1109. LoadString(hAppInst, IDS_NOMEM_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  1110. LoadString(hAppInst, IDS_NOMEM_MSG, szMessage, sizeof(szMessage) /sizeof(TCHAR));
  1111. MessageBox(hWnd, szMessage, szTitle, MB_OK);
  1112. return;
  1113. }
  1114. GetKeyboardLayoutList(nLayouts, lphKL);
  1115. for (i = 0, nIMEs = 0; i < nLayouts; i++) {
  1116. LRESULT lRet;
  1117. HKL hKL;
  1118. TCHAR szImeEudcDic[80];
  1119. hKL = *(lphKL + i);
  1120. lRet = ImmIsIME(hKL);
  1121. if (!lRet) {
  1122. continue;
  1123. }
  1124. szImeEudcDic[0] = '\0';
  1125. lRet = ImmEscape(hKL, (HIMC)NULL, IME_ESC_GET_EUDC_DICTIONARY,
  1126. szImeEudcDic);
  1127. if (!lRet) {
  1128. continue;
  1129. }
  1130. if (szImeEudcDic[0]) {
  1131. lRet = TRUE;
  1132. }
  1133. else if( !bFirstTime[i]) {
  1134. }
  1135. else {
  1136. lRet = ImmConfigureIME(hKL, hWnd, IME_CONFIG_SELECTDICTIONARY, NULL);
  1137. }
  1138. if (!lRet) {
  1139. continue;
  1140. }
  1141. else {
  1142. bFirstTime[i] = FALSE;
  1143. }
  1144. if (szImeEudcDic[0] == '\0') {
  1145. lRet = ImmEscape(hKL, (HIMC)NULL, IME_ESC_GET_EUDC_DICTIONARY,
  1146. szImeEudcDic);
  1147. if (!lRet) {
  1148. continue;
  1149. } else if (szImeEudcDic[0] == '\0') {
  1150. continue;
  1151. } else {
  1152. }
  1153. } else {
  1154. }
  1155. nIMEs++;
  1156. }
  1157. GlobalFree((HGLOBAL)lphKL);
  1158. if (!nIMEs) {
  1159. LoadString(hAppInst, IDS_NOIME_TITLE, szTitle, sizeof(szTitle) / sizeof(TCHAR));
  1160. LoadString(hAppInst, IDS_NOIME_MSG, szMessage, sizeof(szMessage) / sizeof(TCHAR));
  1161. MessageBox(hWnd, szMessage, szTitle, MB_OK);
  1162. return;
  1163. }
  1164. if( !GetClassInfoEx( hAppInst, szRegWordCls, &wcClass)){
  1165. wcClass.cbSize = sizeof(WNDCLASSEX);
  1166. wcClass.style = CS_HREDRAW|CS_VREDRAW;
  1167. wcClass.lpfnWndProc = RegWordWndProc;
  1168. wcClass.cbClsExtra = 0;
  1169. wcClass.cbWndExtra = 2 * sizeof(PVOID);
  1170. wcClass.hInstance = hAppInst;
  1171. wcClass.hIcon = NULL;
  1172. wcClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  1173. wcClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  1174. wcClass.lpszMenuName = NULL;
  1175. wcClass.lpszClassName = szRegWordCls;
  1176. wcClass.hIconSm = NULL;
  1177. RegisterClassEx( &wcClass);
  1178. }
  1179. hOldKL = GetKeyboardLayout(0);
  1180. DialogBoxParam(hAppInst, szImeLinkDlg, hWnd, ImeLinkDlgProc,
  1181. (LPARAM) MAKELONG(uCode , bUnicodeMode ? 0xffff : 0));
  1182. ActivateKeyboardLayout(hOldKL, 0);
  1183. return;
  1184. }