Source code of Windows XP (NT5)
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.

1897 lines
56 KiB

  1. /*++
  2. Copyright (c) 1995-1999 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. DDIS.C
  5. ++*/
  6. #include <windows.h>
  7. #include <windowsx.h>
  8. #include <winerror.h>
  9. #ifdef CROSSREF
  10. #include <winuser.h>
  11. #endif
  12. #include <immdev.h>
  13. #include <string.h>
  14. #include <regstr.h>
  15. #include <ctype.h>
  16. #include <shlobj.h>
  17. #include "imedefs.h"
  18. #include "resource.h"
  19. LPTSTR _rtcschr(LPTSTR string, TCHAR c);
  20. LONG lLock = 0; // this variable is for Lock and Unlock.
  21. //we must init hprivate->mb_name
  22. //*******************************************************************
  23. // InitMbName(hIMC);
  24. //*******************************************************************
  25. void InitMbName(HIMC hIMC)
  26. {
  27. LPINPUTCONTEXT lpIMC;
  28. if (!hIMC) {
  29. return ;
  30. }
  31. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  32. if(!lpIMC){
  33. return;
  34. }
  35. StartEngine(lpIMC->hPrivate);
  36. ImmUnlockIMC(hIMC);
  37. return;
  38. }
  39. // Get the current user's EMB file path, and IME's MB path
  40. // fill global variable sImeG.szIMESystemPath and sImeG.szIMEUserPath
  41. void GetCurrentUserEMBPath( )
  42. {
  43. PSECURITY_ATTRIBUTES psa = NULL;
  44. TCHAR szModuleName[MAX_PATH], *lpszStart, *lpszDot;
  45. int i;
  46. // Get the path for MB and EMB
  47. GetSystemDirectory(sImeG.szIMESystemPath, MAX_PATH);
  48. GetModuleFileName(hInst, szModuleName, sizeof(szModuleName)/sizeof(TCHAR) );
  49. lpszStart = szModuleName + lstrlen(szModuleName) - 1;
  50. while ( (lpszStart != szModuleName) && ( *lpszStart != TEXT('\\') ) ) {
  51. if ( *lpszStart == TEXT('.') ) {
  52. lpszDot = lpszStart;
  53. *lpszDot = TEXT('\0');
  54. }
  55. lpszStart --;
  56. }
  57. if ( *lpszStart == TEXT('\\') ) {
  58. lpszStart ++;
  59. }
  60. if ( lpszStart != szModuleName ) {
  61. for (i=0; i<lstrlen(lpszStart); i++)
  62. szModuleName[i] = lpszStart[i];
  63. szModuleName[i] = TEXT('\0');
  64. }
  65. // psa = CreateSecurityAttributes();
  66. SHGetSpecialFolderPath(NULL,sImeG.szIMEUserPath,CSIDL_APPDATA, FALSE);
  67. if ( sImeG.szIMEUserPath[lstrlen(sImeG.szIMEUserPath)-1] == TEXT('\\') )
  68. sImeG.szIMEUserPath[lstrlen(sImeG.szIMEUserPath) - 1] = TEXT('\0');
  69. // Because CreateDirectory( ) cannot create directory like \AA\BB,
  70. // if AA and BB both do not exist. It can create only one layer of
  71. // directory each time. so we must call twice CreateDirectory( ) for
  72. // \AA\BB
  73. lstrcat(sImeG.szIMEUserPath, TEXT("\\Microsoft") );
  74. if ( GetFileAttributes(sImeG.szIMEUserPath) != FILE_ATTRIBUTE_DIRECTORY)
  75. CreateDirectory(sImeG.szIMEUserPath, psa);
  76. lstrcat(sImeG.szIMEUserPath, TEXT("\\IME") );
  77. if ( GetFileAttributes(sImeG.szIMEUserPath) != FILE_ATTRIBUTE_DIRECTORY)
  78. CreateDirectory(sImeG.szIMEUserPath, psa);
  79. lstrcat(sImeG.szIMEUserPath, TEXT("\\") );
  80. lstrcat(sImeG.szIMEUserPath, szModuleName);
  81. //
  82. // Create the directory, so that CreateFile( ) can work fine later.
  83. // ortherwise, if the directory does not exist, and you try to create
  84. // a file under that dir, CreateFile will return error.
  85. //
  86. if ( GetFileAttributes(sImeG.szIMEUserPath) != FILE_ATTRIBUTE_DIRECTORY)
  87. CreateDirectory(sImeG.szIMEUserPath, psa);
  88. // FreeSecurityAttributes(psa);
  89. return;
  90. }
  91. /**********************************************************************/
  92. /* ImeInquire() */
  93. /* Return Value: */
  94. /* TRUE - successful, FALSE - failure */
  95. /**********************************************************************/
  96. BOOL WINAPI ImeInquire( // initialized data structure of IME
  97. LPIMEINFO lpImeInfo, // IME specific data report to IMM
  98. LPTSTR lpszWndCls, // the class name of UI
  99. DWORD dwSystemInfoFlags)
  100. {
  101. if (!lpImeInfo) {
  102. return (FALSE);
  103. }
  104. lpImeInfo->dwPrivateDataSize = sizeof(PRIVCONTEXT);
  105. lpImeInfo->fdwProperty = IME_PROP_KBD_CHAR_FIRST|
  106. #ifdef UNICODE
  107. IME_PROP_UNICODE|
  108. #endif
  109. IME_PROP_CANDLIST_START_FROM_1|
  110. IME_PROP_IGNORE_UPKEYS;
  111. lpImeInfo->fdwConversionCaps = IME_CMODE_NATIVE|IME_CMODE_FULLSHAPE|
  112. IME_CMODE_CHARCODE|IME_CMODE_SOFTKBD|IME_CMODE_NOCONVERSION|
  113. IME_CMODE_EUDC;
  114. lpImeInfo->fdwSentenceCaps = 0;
  115. // IME will have different distance base multiple of 900 escapement
  116. lpImeInfo->fdwUICaps = UI_CAP_ROT90|UI_CAP_SOFTKBD;
  117. // composition string is the reading string for simple IME
  118. lpImeInfo->fdwSCSCaps = SCS_CAP_COMPSTR|SCS_CAP_MAKEREAD;
  119. // IME want to decide conversion mode on ImeSelect
  120. lpImeInfo->fdwSelectCaps = (DWORD) 0;
  121. lstrcpy(lpszWndCls, (LPTSTR)szUIClassName);
  122. if ( lpImeL )
  123. {
  124. if ( dwSystemInfoFlags & IME_SYSINFO_WINLOGON )
  125. {
  126. // the client app is running in logon mode.
  127. lpImeL->fWinLogon = TRUE;
  128. }
  129. else
  130. lpImeL->fWinLogon = FALSE;
  131. }
  132. return (TRUE);
  133. }
  134. /**********************************************************************/
  135. /* SetImeDlgProc() */
  136. /* Return Value: */
  137. /* TRUE - successful, FALSE - failure */
  138. /**********************************************************************/
  139. BOOL FAR PASCAL SetImeDlgProc(
  140. HWND hDlg,
  141. UINT uMessage,
  142. DWORD wParam,
  143. LONG lParam)
  144. {
  145. RECT rc;
  146. LONG DlgWidth, DlgHeight;
  147. HIMC hIMC;
  148. #ifdef CROSSREF
  149. HWND hLayoutListBox;
  150. static HIMC hOldIMC;
  151. #endif //CROSSREF
  152. switch (uMessage) {
  153. case WM_INITDIALOG:
  154. hCrtDlg = hDlg;
  155. // reset position
  156. GetWindowRect(hDlg, &rc);
  157. DlgWidth = rc.right - rc.left;
  158. DlgHeight = rc.bottom - rc.top;
  159. SetWindowPos(hDlg, HWND_TOP,
  160. (int)(sImeG.rcWorkArea.right - DlgWidth)/2,
  161. (int)(sImeG.rcWorkArea.bottom - DlgHeight)/2,
  162. (int) 0, (int) 0, SWP_NOSIZE);
  163. // Init CheckFrame State
  164. SetImeCharac(hDlg, (int) 0, SIC_READY, 0);
  165. CheckDlgButton (hDlg, IDC_LX,
  166. MBIndex.IMEChara[0].IC_LX);
  167. CheckDlgButton (hDlg, IDC_CZ,
  168. MBIndex.IMEChara[0].IC_CZ);
  169. CheckDlgButton (hDlg, IDC_TS,
  170. MBIndex.IMEChara[0].IC_TS);
  171. CheckDlgButton (hDlg, IDC_CTS,
  172. MBIndex.IMEChara[0].IC_CTC);
  173. CheckDlgButton (hDlg, IDC_TC,
  174. MBIndex.IMEChara[0].IC_Trace);
  175. //CHP
  176. #ifdef FUSSYMODE
  177. CheckDlgButton (hDlg, IDC_FCSR,
  178. MBIndex.IMEChara[0].IC_FCSR);
  179. CheckDlgButton (hDlg, IDC_FCTS,
  180. MBIndex.IMEChara[0].IC_FCTS);
  181. EnableWindow(GetDlgItem(hDlg, IDC_CZ), FALSE);
  182. #endif //FUSSYMODE
  183. #if defined(COMBO_IME)
  184. if (MBIndex.IMEChara[0].IC_GB)
  185. SendMessage(GetDlgItem(hDlg, IDC_GB),
  186. BM_SETCHECK,
  187. TRUE,
  188. 0L);
  189. else
  190. SendMessage(GetDlgItem(hDlg, IDC_GBK),
  191. BM_SETCHECK,
  192. TRUE,
  193. 0L);
  194. #endif //COMBO_IME
  195. if(MBIndex.IMEChara[0].IC_TS) {
  196. EnableWindow(GetDlgItem(hDlg, IDC_CTS), TRUE);
  197. } else {
  198. EnableWindow(GetDlgItem(hDlg, IDC_CTS), FALSE);
  199. }
  200. #ifdef CROSSREF
  201. hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
  202. hIMC = ImmGetContext(hLayoutListBox);
  203. if(hIMC){
  204. ImmSetOpenStatus(hIMC, FALSE);
  205. }
  206. ImmReleaseContext(hLayoutListBox, hIMC);
  207. // put all reverse conversion hKL into this list
  208. ReverseConversionList(hLayoutListBox);
  209. #endif //CROSSREF
  210. return (TRUE); // don't want to set focus to special control
  211. case WM_COMMAND:
  212. switch (LOWORD(wParam)) {
  213. case IDOK:
  214. SetImeCharac(hDlg, (int) 0, SIC_SAVE1, 0);
  215. #ifdef CROSSREF
  216. hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
  217. hIMC = ImmGetContext(hLayoutListBox);
  218. if(hIMC) {
  219. ImmSetOpenStatus(hIMC, TRUE);
  220. }
  221. ImmReleaseContext(hLayoutListBox, hIMC);
  222. #endif //CROSSREF
  223. EndDialog(hDlg, FALSE);
  224. break;
  225. case IDCANCEL:
  226. #ifdef CROSSREF
  227. hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
  228. hIMC = ImmGetContext(hLayoutListBox);
  229. if(hIMC) {
  230. ImmSetOpenStatus(hIMC, TRUE);
  231. }
  232. ImmReleaseContext(hLayoutListBox, hIMC);
  233. #endif //CROSSREF
  234. EndDialog(hDlg, FALSE);
  235. break;
  236. case IDC_LX:
  237. case IDC_CZ:
  238. case IDC_TS:
  239. case IDC_CTS:
  240. case IDC_TC:
  241. //CHP
  242. #ifdef FUSSYMODE
  243. case IDC_FCSR:
  244. case IDC_FCTS:
  245. #endif //FUSSYMODE
  246. // Set Current InputMode Param(temp)
  247. SetImeCharac(hDlg, (wParam - IDC_LX), SIC_MODIFY, (int) 0);
  248. break;
  249. #if defined(COMBO_IME)
  250. case IDC_GB:
  251. case IDC_GBK:
  252. // Set Current InputMode Param(temp)
  253. SetImeCharac(hDlg, 7, SIC_MODIFY, (int) 0);
  254. break;
  255. #endif //COMBO_IME
  256. default:
  257. return (FALSE);
  258. }
  259. return (TRUE);
  260. case WM_PAINT:
  261. {
  262. RECT rc;
  263. GetClientRect(hDlg, &rc);
  264. DrawConvexRect(GetDC(hDlg),
  265. rc.left + 6,
  266. rc.top + 8,
  267. rc.right - 6 - 1,
  268. rc.bottom - 40 - 1);
  269. DrawConvexRectP(GetDC(hDlg),
  270. rc.left + 6,
  271. rc.top + 8,
  272. rc.right - 6,
  273. rc.bottom - 40);
  274. }
  275. return (FALSE);
  276. case WM_CLOSE:
  277. #ifdef CROSSREF
  278. hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
  279. hIMC = ImmGetContext(hLayoutListBox);
  280. if(hIMC) {
  281. ImmSetOpenStatus(hIMC, TRUE);
  282. }
  283. ImmReleaseContext(hLayoutListBox, hIMC);
  284. #endif //CROSSREF
  285. EndDialog(hDlg, FALSE);
  286. return (TRUE);
  287. default:
  288. return (FALSE);
  289. }
  290. return (TRUE);
  291. }
  292. /**********************************************************************/
  293. /* SetImeCharac() */
  294. /* Return Value: voide */
  295. /* Entry: */
  296. /* code=0, init */
  297. /* code=1, Save temp */
  298. /* code=2, Save resault */
  299. /**********************************************************************/
  300. void SetImeCharac (
  301. HWND hDlg,
  302. int ParamNum,
  303. int Mode,
  304. DWORD ObjImeIndex)
  305. {
  306. HIMC hIMC;
  307. LPINPUTCONTEXT lpIMC;
  308. LPPRIVCONTEXT lpImcP;
  309. #if defined(COMBO_IME)
  310. static DWORD TempParam[8];
  311. #else
  312. static DWORD TempParam[7];
  313. #endif //COMBO_IME
  314. HKEY hKeyCurrVersion;
  315. HKEY hKey;
  316. DWORD retCode;
  317. #ifdef UNICODE
  318. TCHAR ValueName[][9] = {
  319. {0x8BCD, 0x8BED, 0x8054, 0x60F3, 0x0000},
  320. {0x8BCD, 0x8BED, 0x8F93, 0x5165, 0x0000},
  321. {0x9010, 0x6E10, 0x63D0, 0x793A, 0x0000},
  322. {0x5916, 0x7801, 0x63D0, 0x793A, 0x0000},
  323. {0x5149, 0x6807, 0x8DDF, 0x968F, 0x0000},
  324. #else
  325. TCHAR ValueName[][9] = {
  326. TEXT("��������"),
  327. TEXT("��������"),
  328. TEXT("������ʾ"),
  329. TEXT("������ʾ"),
  330. TEXT("��������"),
  331. #endif
  332. TEXT("FC input"),
  333. TEXT("FC aid"),
  334. #if defined(COMBO_IME)
  335. TEXT("GB/GBK")
  336. #endif //COMBO_IME
  337. };
  338. UINT i;
  339. switch (Mode)
  340. {
  341. case SIC_READY:
  342. InitImeCharac(ObjImeIndex);
  343. //CHP
  344. #ifdef FUSSYMODE
  345. if (MBIndex.IMEChara[ObjImeIndex].IC_FCSR)
  346. {
  347. if (MBIndex.IMEChara[ObjImeIndex].IC_FCTS)
  348. EnableWindow(GetDlgItem(hDlg, IDD_LAYOUT_LIST), FALSE);
  349. }
  350. else
  351. EnableWindow(GetDlgItem(hDlg, IDC_FCTS), FALSE);
  352. #endif //FUSSYMODE
  353. TempParam[0] = MBIndex.IMEChara[ObjImeIndex].IC_LX;
  354. TempParam[1] = MBIndex.IMEChara[ObjImeIndex].IC_CZ;
  355. TempParam[2] = MBIndex.IMEChara[ObjImeIndex].IC_TS;
  356. TempParam[3] = MBIndex.IMEChara[ObjImeIndex].IC_CTC;
  357. TempParam[4] = MBIndex.IMEChara[ObjImeIndex].IC_Trace;
  358. //CHP
  359. TempParam[5] = MBIndex.IMEChara[ObjImeIndex].IC_FCSR;
  360. TempParam[6] = MBIndex.IMEChara[ObjImeIndex].IC_FCTS;
  361. #if defined(COMBO_IME)
  362. TempParam[7] = MBIndex.IMEChara[ObjImeIndex].IC_GB;
  363. #endif //COMBO_IME
  364. break;
  365. case SIC_MODIFY:
  366. TempParam[ParamNum] = (TempParam[ParamNum] ^ 0x00000001) & 0x00000001;
  367. if(TempParam[2]) {
  368. EnableWindow(GetDlgItem(hDlg, IDC_CTS), TRUE);
  369. } else {
  370. EnableWindow(GetDlgItem(hDlg, IDC_CTS), FALSE);
  371. TempParam[3] = 0;
  372. CheckDlgButton (hDlg, IDC_CTS, FALSE);
  373. }
  374. //CHP
  375. #ifdef FUSSYMODE
  376. if (TempParam[5])
  377. {
  378. EnableWindow(GetDlgItem(hDlg, IDC_FCTS), TRUE);
  379. if (TempParam[6])
  380. EnableWindow(GetDlgItem(hDlg, IDD_LAYOUT_LIST), FALSE);
  381. else
  382. EnableWindow(GetDlgItem(hDlg, IDD_LAYOUT_LIST), TRUE);
  383. }
  384. else
  385. {
  386. EnableWindow(GetDlgItem(hDlg, IDC_FCTS), FALSE);
  387. EnableWindow(GetDlgItem(hDlg, IDD_LAYOUT_LIST), TRUE);
  388. }
  389. #endif //FUSSYMODE
  390. break;
  391. case SIC_SAVE1:
  392. MBIndex.IMEChara[ObjImeIndex].IC_LX = TempParam[0];
  393. MBIndex.IMEChara[ObjImeIndex].IC_CZ = TempParam[1];
  394. MBIndex.IMEChara[ObjImeIndex].IC_TS = TempParam[2];
  395. MBIndex.IMEChara[ObjImeIndex].IC_CTC = TempParam[3];
  396. MBIndex.IMEChara[ObjImeIndex].IC_Trace = TempParam[4];
  397. // CHP
  398. #ifdef FUSSYMODE
  399. MBIndex.IMEChara[ObjImeIndex].IC_FCSR = TempParam[5];
  400. MBIndex.IMEChara[ObjImeIndex].IC_FCTS = TempParam[6];
  401. #endif //FUSSYMODE
  402. #if defined(COMBO_IME)
  403. MBIndex.IMEChara[ObjImeIndex].IC_GB = TempParam[7];
  404. #endif //COMBO_IME
  405. retCode = OpenReg_PathSetup(&hKeyCurrVersion);
  406. if (retCode) {
  407. RegCreateKey(HKEY_CURRENT_USER, REGSTR_PATH_SETUP, &hKeyCurrVersion);
  408. }
  409. if ( hKeyCurrVersion )
  410. retCode = RegCreateKeyEx(hKeyCurrVersion, MBIndex.MBDesc[ObjImeIndex].szName, 0,
  411. NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS , NULL, &hKey, NULL);
  412. else
  413. return;
  414. if ( hKey == NULL )
  415. {
  416. RegCloseKey(hKeyCurrVersion);
  417. return;
  418. }
  419. #if defined(COMBO_IME)
  420. for(i=0; i<8; i++) {
  421. #else
  422. for(i=0; i<7; i++) {
  423. #endif //COMBO_IME
  424. DWORD Value;
  425. switch (i)
  426. {
  427. case 0:
  428. Value = MBIndex.IMEChara[ObjImeIndex].IC_LX;
  429. break;
  430. case 1:
  431. Value = MBIndex.IMEChara[ObjImeIndex].IC_CZ;
  432. break;
  433. case 2:
  434. Value = MBIndex.IMEChara[ObjImeIndex].IC_TS;
  435. break;
  436. case 3:
  437. Value = MBIndex.IMEChara[ObjImeIndex].IC_CTC;
  438. break;
  439. case 4:
  440. Value = MBIndex.IMEChara[ObjImeIndex].IC_Trace;
  441. break;
  442. //CHP
  443. #ifdef FUSSYMODE
  444. case 5:
  445. Value = MBIndex.IMEChara[ObjImeIndex].IC_FCSR;
  446. break;
  447. case 6:
  448. Value = MBIndex.IMEChara[ObjImeIndex].IC_FCTS;
  449. break;
  450. #endif //FUSSYMODE
  451. #if defined(COMBO_IME)
  452. case 7:
  453. Value = MBIndex.IMEChara[ObjImeIndex].IC_GB;
  454. break;
  455. #endif //COMBO_IME
  456. }
  457. if ( hKey != NULL )
  458. {
  459. RegSetValueEx (hKey, ValueName[i],
  460. (DWORD) 0,
  461. REG_DWORD,
  462. (LPBYTE)&Value,
  463. sizeof(DWORD));
  464. }
  465. }
  466. RegCloseKey(hKey);
  467. RegCloseKey(hKeyCurrVersion);
  468. #ifdef CROSSREF
  469. {
  470. HWND hLayoutListBox;
  471. int iCurSel;
  472. HKL hKL;
  473. DWORD retCode;
  474. hLayoutListBox = GetDlgItem(hDlg, IDD_LAYOUT_LIST);
  475. iCurSel = (int)SendMessage(hLayoutListBox, LB_GETCURSEL, 0, 0);
  476. hKL = (HKL)SendMessage(hLayoutListBox, LB_GETITEMDATA,
  477. iCurSel, 0);
  478. //CHP
  479. #ifdef FUSSYMODE
  480. if (MBIndex.IMEChara[ObjImeIndex].IC_FCSR &&
  481. MBIndex.IMEChara[ObjImeIndex].IC_FCTS)
  482. hKL = GetKeyboardLayout(0);
  483. #endif //FUSSYMODE
  484. if (MBIndex.hRevKL != hKL) {
  485. WORD nRevMaxKey;
  486. HKEY hKeyAppUser, hKeyIMEUser;
  487. LPPRIVCONTEXT lpImcP;
  488. MBIndex.hRevKL = hKL;
  489. //set reverse layout to registry
  490. retCode = OpenReg_PathSetup(&hKeyAppUser);
  491. if (retCode) {
  492. RegCreateKey(HKEY_CURRENT_USER, REGSTR_PATH_SETUP, &hKeyCurrVersion);
  493. }
  494. retCode = RegCreateKeyEx(hKeyAppUser, MBIndex.MBDesc[0].szName, 0,
  495. NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS , NULL, &hKeyIMEUser, NULL);
  496. if (retCode) {
  497. DWORD dwDisposition;
  498. retCode = RegCreateKeyEx (hKeyCurrVersion,
  499. MBIndex.MBDesc[0].szName,
  500. 0,
  501. 0,
  502. REG_OPTION_NON_VOLATILE,
  503. KEY_ALL_ACCESS,
  504. NULL,
  505. &hKey,
  506. &dwDisposition);
  507. }
  508. RegSetValueEx(hKeyIMEUser, szRegRevKL, 0, REG_DWORD, (LPBYTE)&hKL,sizeof(hKL));
  509. // get the new size
  510. nRevMaxKey = (WORD)ImmEscape(hKL, (HIMC)NULL, IME_ESC_MAX_KEY,
  511. NULL);
  512. if (lpImeL->nMaxKey != nRevMaxKey) {
  513. if(lpImeL->nMaxKey < nRevMaxKey)
  514. lpImeL->nMaxKey = nRevMaxKey;
  515. // set the width & height for composition window
  516. lpImeL->rcCompText.right = lpImeL->rcCompText.left +
  517. sImeG.xChiCharWi * ((lpImeL->nMaxKey+2)/2);
  518. lpImeL->xCompWi = lpImeL->rcCompText.right + lpImeL->cxCompBorder * (2 + 4);
  519. //generate message to broadcast change comp win size
  520. hIMC = (HIMC)ImmGetContext(hDlg);
  521. if (!hIMC) {
  522. return;
  523. }
  524. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  525. if (!lpIMC) {
  526. return;
  527. }
  528. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  529. if (!lpImcP) {
  530. goto ChgConfigUnlockIMC;
  531. }
  532. lpImcP->fdwImeMsg |= MSG_IMN_COMPOSITIONPOS;
  533. GenerateMessage(hIMC, lpIMC, lpImcP);
  534. ImmUnlockIMCC(lpIMC->hPrivate);
  535. ChgConfigUnlockIMC:
  536. ImmUnlockIMC(hIMC);
  537. } //end of change nMaxKey
  538. RegSetValueEx(hKeyIMEUser, szRegRevMaxKey, 0, REG_DWORD, (LPBYTE)&lpImeL->nMaxKey,sizeof(DWORD));
  539. RegCloseKey(hKeyAppUser);
  540. RegCloseKey(hKeyIMEUser);
  541. } //end of change RegRevKL
  542. }
  543. #endif //CROSSREF
  544. break;
  545. }
  546. return;
  547. }
  548. #if defined(CROSSREF)
  549. /**********************************************************************/
  550. /* ReverseConversionList() */
  551. /**********************************************************************/
  552. void PASCAL ReverseConversionList(HWND hLayoutListBox)
  553. {
  554. int nLayouts, i, nIMEs;
  555. TCHAR szImeName[16];
  556. HKL FAR *lpKLMem;
  557. LoadString(hInst, IDS_NONE, szImeName, sizeof(szImeName)/sizeof(TCHAR));
  558. SendMessage(hLayoutListBox, LB_INSERTSTRING,
  559. 0, (LPARAM)szImeName);
  560. SendMessage(hLayoutListBox, LB_SELECTSTRING,
  561. 0, (LPARAM)szImeName);
  562. SendMessage(hLayoutListBox, LB_SETITEMDATA,
  563. 0, (LPARAM)(HKL)NULL);
  564. nLayouts = GetKeyboardLayoutList(0, NULL);
  565. lpKLMem = GlobalAlloc(GPTR, sizeof(HKL) * nLayouts);
  566. if (!lpKLMem) {
  567. return;
  568. }
  569. GetKeyboardLayoutList(nLayouts, lpKLMem);
  570. for (i = 0, nIMEs = 0; i < nLayouts; i++) {
  571. HKL hKL;
  572. hKL = *(lpKLMem + i);
  573. if (LOWORD(hKL) != NATIVE_LANGUAGE) {
  574. // not support other language
  575. continue;
  576. }
  577. // NULL hIMC ???????
  578. if (!ImmGetConversionList(hKL, (HIMC)NULL, NULL,
  579. NULL, 0, GCL_REVERSECONVERSION)) {
  580. // this IME not support reverse conversion
  581. continue;
  582. }
  583. if (!ImmEscape(hKL, (HIMC)NULL, IME_ESC_IME_NAME,
  584. szImeName)) {
  585. // this IME does not report the IME name
  586. continue;
  587. }
  588. if( lstrcmp(szImeName, MBIndex.MBDesc[0].szName) == 0)
  589. continue;
  590. nIMEs++;
  591. SendMessage(hLayoutListBox, LB_INSERTSTRING,
  592. nIMEs, (LPARAM)szImeName);
  593. if (hKL == MBIndex.hRevKL) {
  594. SendMessage(hLayoutListBox, LB_SELECTSTRING, nIMEs,
  595. (LPARAM)szImeName);
  596. }
  597. SendMessage(hLayoutListBox, LB_SETITEMDATA,
  598. nIMEs, (LPARAM)hKL);
  599. }
  600. GlobalFree((HGLOBAL)lpKLMem);
  601. return;
  602. }
  603. #endif //CROSSREF
  604. #ifdef EUDC
  605. //**********************************************************************
  606. //BOOL EUDCDicName( HWND hWnd)
  607. //**********************************************************************
  608. BOOL EUDCDicName( HWND hWnd)
  609. {
  610. HANDLE hUsrDicFile;
  611. BOOL fRet;
  612. TCHAR szFileName[MAX_PATH];
  613. TCHAR szMapFileName[MAX_PATH];
  614. TCHAR EUDCMB_PathAndName[MAX_PATH];
  615. TCHAR *tepstr;
  616. HKEY hKeyCurrVersion,hKey;
  617. PSECURITY_ATTRIBUTES psa;
  618. LoadString(hInst, IDS_IMEMBFILENAME, szFileName, MAX_PATH);
  619. tepstr = _rtcschr(szFileName,TEXT('.'));
  620. if ( tepstr != NULL )
  621. lstrcpy(tepstr,TEXT(".EMB"));
  622. lstrcpy(EUDCMB_PathAndName, sImeG.szIMEUserPath);
  623. lstrcat(EUDCMB_PathAndName, TEXT("\\") );
  624. lstrcat(EUDCMB_PathAndName, szFileName);
  625. psa = CreateSecurityAttributes();
  626. hUsrDicFile = CreateFile(EUDCMB_PathAndName,
  627. GENERIC_WRITE,
  628. FILE_SHARE_READ|FILE_SHARE_WRITE,
  629. psa,
  630. OPEN_ALWAYS,
  631. FILE_ATTRIBUTE_NORMAL,
  632. (HANDLE)NULL);
  633. if (hUsrDicFile == INVALID_HANDLE_VALUE) {
  634. FreeSecurityAttributes(psa);
  635. return (FALSE);
  636. }
  637. CloseHandle(hUsrDicFile);
  638. FreeSecurityAttributes(psa);
  639. lstrcpy(MBIndex.EUDCData.szEudcDictName, EUDCMB_PathAndName);
  640. // if we have already got a map file, we just use it.
  641. if (MBIndex.EUDCData.szEudcMapFileName[0]) {
  642. return (TRUE);
  643. }
  644. // Otherwise, generate the Map File Name, which is Basic Filename plus EUDC
  645. lstrcpy(szMapFileName, szFileName);
  646. tepstr = _rtcschr(szMapFileName,TEXT('.'));
  647. lstrcpy(tepstr, TEXT("EUDC"));
  648. lstrcpy(MBIndex.EUDCData.szEudcMapFileName, szMapFileName);
  649. fRet = OpenReg_PathSetup(&hKeyCurrVersion);
  650. if (fRet) return FALSE;
  651. fRet = OpenReg_User (hKeyCurrVersion,
  652. MBIndex.MBDesc[0].szName,
  653. &hKey);
  654. if (fRet) {
  655. DWORD dwDisposition;
  656. fRet = RegCreateKeyEx (hKeyCurrVersion,
  657. MBIndex.MBDesc[0].szName,
  658. 0,
  659. 0,
  660. REG_OPTION_NON_VOLATILE,
  661. KEY_ALL_ACCESS,
  662. NULL,
  663. &hKey,
  664. &dwDisposition);
  665. if (fRet != ERROR_SUCCESS) return FALSE;
  666. }
  667. fRet = RegSetValueEx (hKey,
  668. szRegEudcDictName,
  669. (DWORD) 0,
  670. REG_SZ,
  671. (const unsigned char *)MBIndex.EUDCData.szEudcDictName,
  672. lstrlen(MBIndex.EUDCData.szEudcDictName)*sizeof(TCHAR));
  673. if (fRet != ERROR_SUCCESS ) return FALSE;
  674. fRet = RegSetValueEx (hKey,
  675. szRegEudcMapFileName,
  676. (DWORD) 0,
  677. REG_SZ,
  678. (const unsigned char *)MBIndex.EUDCData.szEudcMapFileName,
  679. lstrlen(MBIndex.EUDCData.szEudcMapFileName)*sizeof(TCHAR));
  680. if (fRet) return FALSE;
  681. return (TRUE);
  682. }
  683. #endif //EUDC
  684. /**********************************************************************/
  685. /* ImeConfigure() */
  686. /* Return Value: */
  687. /* TRUE - successful, FALSE - failure */
  688. /**********************************************************************/
  689. BOOL WINAPI ImeConfigure( // configurate the IME setting
  690. HKL hKL, // hKL of this IME
  691. HWND hAppWnd, // the owner window
  692. DWORD dwMode, // mode of dialog
  693. LPVOID lpData)
  694. {
  695. switch (dwMode) {
  696. case IME_CONFIG_GENERAL:
  697. DialogBox(hInst, TEXT("SETIME"), hAppWnd, (DLGPROC) SetImeDlgProc);
  698. break;
  699. #ifdef EUDC
  700. case IME_CONFIG_SELECTDICTIONARY:
  701. return(EUDCDicName(hAppWnd));
  702. break;
  703. #endif //EUDC
  704. default:
  705. return (FALSE);
  706. break;
  707. }
  708. return (TRUE);
  709. }
  710. /**********************************************************************/
  711. /* ForwordConversion() */
  712. /**********************************************************************/
  713. UINT PASCAL ForwordConversion(
  714. HIMC hIMC,
  715. LPCTSTR lpszSrc,
  716. LPCANDIDATELIST lpCandList,
  717. UINT uBufLen)
  718. {
  719. unsigned int i;
  720. LPTSTR wCode;
  721. LPINPUTCONTEXT lpIMC;
  722. UINT uMaxCand;
  723. DWORD dwSize;
  724. wCode = ConverList.szSelectBuffer;
  725. ConverList.szSelectBuffer[0] =TEXT('\0');
  726. ConverList.szInBuffer[0] =TEXT('\0');
  727. ConverList.Candi_Cnt =0;
  728. ConverList.Candi_Pos[0] =TEXT('\0');
  729. if (!hIMC) {
  730. return (0);
  731. }
  732. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  733. if (!lpIMC) {
  734. return (0);
  735. }
  736. if (!Conversion (lpIMC->hPrivate,lpszSrc,0)) {
  737. return (0);
  738. }
  739. ConverList.szSelectBuffer [lstrlen(ConverList.szSelectBuffer)-1]
  740. =TEXT('\0');
  741. dwSize =
  742. // header length
  743. sizeof(CANDIDATELIST) +
  744. // candidate string pointers
  745. sizeof(DWORD) * ConverList.Candi_Cnt+
  746. // string plus NULL terminator
  747. sizeof(TCHAR) * lstrlen (wCode);
  748. if (!uBufLen) {
  749. return (dwSize);
  750. }
  751. uMaxCand = uBufLen - sizeof(CANDIDATELIST);
  752. uMaxCand /= sizeof(DWORD) + lstrlen (wCode);
  753. if (!uMaxCand) {
  754. // can not even put one string
  755. return (0);
  756. }
  757. lpCandList->dwSize = dwSize;
  758. lpCandList->dwStyle = IME_CAND_READ; // candidate having same reading
  759. lpCandList->dwCount = 0;
  760. lpCandList->dwSelection = 0;
  761. lpCandList->dwPageSize = CANDPERPAGE;
  762. lpCandList->dwOffset[0] = sizeof(CANDIDATELIST) + sizeof(DWORD) *
  763. (uMaxCand - 1);
  764. lstrcpy((LPTSTR)((LPBYTE)lpCandList + lpCandList->dwOffset[0]),
  765. (LPTSTR)wCode);
  766. lpCandList->dwCount =(DWORD)ConverList.Candi_Cnt;
  767. for (i=1;i<lpCandList->dwCount;i++) {
  768. lpCandList->dwOffset[i] = lpCandList->dwOffset[0]
  769. +(DWORD)ConverList.Candi_Pos[i+1];
  770. *(LPTSTR)((LPBYTE)lpCandList + lpCandList->dwOffset[i]-1) = TEXT('\0');
  771. }
  772. return (dwSize);
  773. }
  774. #if defined(CROSSREF)
  775. //*******************************************************************
  776. // The parameters are inherited from SelectOneCand
  777. // CrossReverseConv()
  778. //*******************************************************************
  779. int CrossReverseConv(
  780. LPINPUTCONTEXT lpIMC,
  781. LPCOMPOSITIONSTRING lpCompStr,
  782. LPPRIVCONTEXT lpImcP,
  783. LPCANDIDATELIST lpCandList)
  784. {
  785. LPGUIDELINE lpGuideLine;
  786. UINT uSize=0;
  787. if (!MBIndex.hRevKL) {
  788. return 0;
  789. }
  790. lpGuideLine = ImmLockIMCC(lpIMC->hGuideLine);
  791. if (!lpGuideLine) {
  792. return 0;
  793. }
  794. if (lpCompStr->dwResultStrLen != 2/sizeof(TCHAR)) {
  795. // we only can reverse convert one DBCS character for now
  796. lpGuideLine->dwLevel = GL_LEVEL_NOGUIDELINE;
  797. lpGuideLine->dwIndex = GL_ID_UNKNOWN;
  798. } else {
  799. TCHAR szStrBuf[4];
  800. LPCANDIDATELIST lpRevCandList;
  801. if(lpImcP->hRevCandList == (HIMCC)NULL){
  802. //we alloc memory in lpImcP->hRevCandList, for reverse convert
  803. //result codes; When finish reconvert, should read out this info.
  804. REALLOC:
  805. lpImcP->hRevCandList = (HIMCC)GlobalAlloc(GHND, sizeof(CANDIDATELIST)+1*sizeof(DWORD)+MAXCODE*sizeof(TCHAR)+1);
  806. if (lpImcP->hRevCandList == (HIMCC)NULL) {
  807. return 0 ;
  808. }
  809. lpRevCandList = (LPCANDIDATELIST)GlobalLock((HGLOBAL)lpImcP->hRevCandList);
  810. if (lpRevCandList == NULL) {
  811. return 0 ;
  812. }
  813. }else{
  814. lpRevCandList = (LPCANDIDATELIST)GlobalLock((HGLOBAL)lpImcP->hRevCandList);
  815. if (lpRevCandList == NULL) {
  816. goto REALLOC;
  817. }
  818. }
  819. *(LPUNAWORD)szStrBuf = *(LPUNAWORD)((LPBYTE)lpCompStr + lpCompStr->dwResultStrOffset);
  820. szStrBuf[2/sizeof(TCHAR)] = TEXT('\0');
  821. memset(lpRevCandList, 0, sizeof(CANDIDATELIST)+1*sizeof(DWORD)+MAXCODE*sizeof(TCHAR)+1);
  822. lpRevCandList->dwSize = sizeof(CANDIDATELIST)+1*sizeof(DWORD)+MAXCODE*sizeof(TCHAR)+1;
  823. uSize = ImmGetConversionList(MBIndex.hRevKL, (HIMC)NULL, szStrBuf,
  824. (LPCANDIDATELIST)lpRevCandList,
  825. lpRevCandList->dwSize, GCL_REVERSECONVERSION);
  826. GlobalUnlock((HGLOBAL)lpImcP->hRevCandList);
  827. if (uSize) {
  828. if (lpImcP->fdwImeMsg & MSG_ALREADY_START) {
  829. lpImcP->fdwImeMsg &= ~(MSG_END_COMPOSITION|
  830. MSG_START_COMPOSITION);
  831. } else {
  832. lpImcP->fdwImeMsg = (lpImcP->fdwImeMsg|
  833. MSG_START_COMPOSITION) & ~(MSG_END_COMPOSITION);
  834. }
  835. } else {
  836. GlobalFree((HGLOBAL)lpImcP->hRevCandList);
  837. lpImcP->hRevCandList = (HIMCC)NULL;
  838. }
  839. }
  840. ImmUnlockIMCC(lpIMC->hGuideLine);
  841. //CHP
  842. //We need to know the result.
  843. return uSize;
  844. }
  845. #endif //CROSSREF
  846. /**********************************************************************/
  847. /* ReverseConversion() */
  848. /**********************************************************************/
  849. UINT PASCAL ReverseConversion(
  850. HIMCC hPrivate,
  851. LPCTSTR lpszSrc,
  852. LPCANDIDATELIST lpCandList,
  853. UINT uBufLen)
  854. {
  855. LPTSTR wCode;
  856. UINT uMaxCand;
  857. DWORD dwSize;
  858. wCode = ConverList.szInBuffer;
  859. ConverList.szSelectBuffer[0] =TEXT('\0');
  860. ConverList.szInBuffer[0] =TEXT('\0');
  861. ConverList.Candi_Cnt =0;
  862. ConverList.Candi_Pos[0] =TEXT('\0');
  863. dwSize =
  864. // header length
  865. sizeof(CANDIDATELIST) +
  866. // candidate string pointers
  867. sizeof(DWORD) +
  868. // string plus NULL terminator
  869. MAXCODE*sizeof(TCHAR);
  870. if (!uBufLen) {
  871. return (dwSize);
  872. }
  873. if(lpszSrc ==NULL){
  874. return (0);
  875. }
  876. if (!Conversion (hPrivate,lpszSrc,1)) {
  877. return (0);
  878. }
  879. uMaxCand = uBufLen - sizeof(CANDIDATELIST);
  880. uMaxCand /= sizeof(DWORD) + lstrlen (wCode);
  881. if (!uMaxCand) {
  882. // can not even put one string
  883. return (0);
  884. }
  885. lpCandList->dwSize = dwSize;
  886. lpCandList->dwStyle = IME_CAND_READ; // candidate having same reading
  887. lpCandList->dwCount = 1;
  888. lpCandList->dwSelection = 0;
  889. lpCandList->dwPageSize = CANDPERPAGE;
  890. lpCandList->dwOffset[0] = sizeof(CANDIDATELIST) + sizeof(DWORD) *
  891. (uMaxCand - 1);
  892. lstrcpy((LPTSTR)((LPBYTE)lpCandList + lpCandList->dwOffset[0]),
  893. (LPTSTR)wCode);
  894. return (dwSize);
  895. }
  896. /**********************************************************************/
  897. /* ImeConversionList() */
  898. /**********************************************************************/
  899. DWORD WINAPI ImeConversionList(
  900. HIMC hIMC,
  901. LPCTSTR lpszSrc,
  902. LPCANDIDATELIST lpCandList,
  903. DWORD dwBufLen,
  904. UINT uFlag)
  905. {
  906. if (!dwBufLen) {
  907. } else if (!lpszSrc) {
  908. return (0);
  909. } else if (!*lpszSrc) {
  910. return (0);
  911. } else if (!lpCandList) {
  912. return (0);
  913. } else if (dwBufLen <= sizeof(CANDIDATELIST)) {
  914. // buffer size can not even put the header information
  915. return (0);
  916. } else {
  917. }
  918. switch (uFlag) {
  919. case GCL_CONVERSION:
  920. return ForwordConversion(hIMC,lpszSrc, lpCandList, dwBufLen);
  921. break;
  922. case GCL_REVERSECONVERSION:
  923. if (!dwBufLen) {
  924. return ReverseConversion(NULL,0, lpCandList, dwBufLen);
  925. } else {
  926. DWORD fRet=0;
  927. HIMCC hPrivate;
  928. hPrivate = (HIMCC)ImmCreateIMCC(sizeof(PRIVCONTEXT));
  929. if(hPrivate == (HIMCC)NULL){
  930. return 0;
  931. }
  932. StartEngine(hPrivate);
  933. fRet = ReverseConversion(hPrivate,lpszSrc, lpCandList, dwBufLen);
  934. EndEngine(hPrivate);
  935. ImmDestroyIMCC(hPrivate);
  936. return fRet;
  937. }
  938. break;
  939. default:
  940. return (0);
  941. break;
  942. }
  943. }
  944. /**********************************************************************/
  945. /* ImeDestroy() */
  946. /* Return Value: */
  947. /* TRUE - successful, FALSE - failure */
  948. /**********************************************************************/
  949. BOOL WINAPI ImeDestroy( // this dll is unloaded
  950. UINT uReserved)
  951. {
  952. if (uReserved) {
  953. return (FALSE);
  954. }
  955. return (TRUE);
  956. }
  957. /**********************************************************************/
  958. /* ImeEscape() */
  959. /* Return Value: */
  960. /* TRUE - successful, FALSE - failure */
  961. /**********************************************************************/
  962. #define IME_INPUTKEYTOSEQUENCE 0x22
  963. LRESULT WINAPI ImeEscape( // escape function of IMEs
  964. HIMC hIMC,
  965. UINT uSubFunc,
  966. LPVOID lpData)
  967. {
  968. LRESULT lRet;
  969. switch (uSubFunc) {
  970. case IME_ESC_QUERY_SUPPORT:
  971. if (lpData == NULL)
  972. return FALSE;
  973. switch (*(LPUINT)lpData) {
  974. case IME_ESC_QUERY_SUPPORT:
  975. #ifdef EUDC
  976. case IME_ESC_GET_EUDC_DICTIONARY:
  977. case IME_ESC_SET_EUDC_DICTIONARY:
  978. #endif //EUDC
  979. case IME_ESC_SEQUENCE_TO_INTERNAL:
  980. case IME_ESC_MAX_KEY:
  981. case IME_ESC_IME_NAME:
  982. case IME_ESC_GETHELPFILENAME:
  983. return (TRUE);
  984. default:
  985. return (FALSE);
  986. }
  987. break;
  988. case IME_ESC_SEQUENCE_TO_INTERNAL:
  989. if (!lpData || (*(LPBYTE)lpData) == '\0') {
  990. return (FALSE);
  991. }
  992. lRet = *(LPWORD)lpData;
  993. return (lRet);
  994. #ifdef EUDC
  995. case IME_ESC_GET_EUDC_DICTIONARY:
  996. if (!lpData) {
  997. return (FALSE);
  998. }
  999. if (MBIndex.EUDCData.szEudcDictName[0] == TEXT('\0')) {
  1000. *(LPTSTR)lpData = TEXT('\0');
  1001. return(TRUE);
  1002. } else {
  1003. lstrcpy((LPTSTR)lpData,MBIndex.EUDCData.szEudcDictName);
  1004. return TRUE;
  1005. }
  1006. case IME_ESC_SET_EUDC_DICTIONARY:
  1007. return TRUE;
  1008. #endif //EUDC
  1009. case IME_ESC_MAX_KEY:
  1010. #ifdef EUDC
  1011. {
  1012. TCHAR szFullFileName[MAX_PATH], szFileName[MAX_PATH];
  1013. unsigned int cb;
  1014. cb = MAX_PATH;
  1015. if (lpImeL->nMaxKey > EUDC_MAX_READING) {
  1016. GetModuleFileName(NULL,szFullFileName ,cb);
  1017. GetFileTitle(szFullFileName, szFileName, (WORD)cb);
  1018. #ifdef UNICODE
  1019. // Compare first 8 chars only
  1020. if (_wcsnicmp(szFileName,TEXT("EUDCEDIT.EXE"),8))
  1021. #else
  1022. if (_strnicmp(szFileName,"EUDCEDIT.EXE",8))
  1023. #endif
  1024. return (lpImeL->nMaxKey);
  1025. else
  1026. return EUDC_MAX_READING;
  1027. } else {
  1028. return (lpImeL->nMaxKey);
  1029. }
  1030. }
  1031. #else
  1032. return (lpImeL->nMaxKey);
  1033. #endif //EUDC
  1034. case IME_ESC_IME_NAME:
  1035. if ( lpData == NULL )
  1036. return FALSE;
  1037. lstrcpy(lpData,MBIndex.MBDesc[0].szName);
  1038. return (TRUE);
  1039. case IME_ESC_GETHELPFILENAME :
  1040. {
  1041. TCHAR szIMEGUDHlpName[MAX_PATH];
  1042. int iLen;
  1043. if (lpData == NULL )
  1044. return FALSE;
  1045. szIMEGUDHlpName[0] = 0;
  1046. GetWindowsDirectory((LPTSTR)szIMEGUDHlpName, MAX_PATH);
  1047. lstrcat((LPTSTR)szIMEGUDHlpName, TEXT("\\HELP\\"));
  1048. lstrcat((LPTSTR)szIMEGUDHlpName, (LPTSTR)szImeMBFileName);
  1049. iLen = lstrlen(szIMEGUDHlpName);
  1050. szIMEGUDHlpName[iLen-3] = 0;
  1051. lstrcat((LPTSTR)szIMEGUDHlpName, TEXT(".CHM"));
  1052. lstrcpy(lpData, szIMEGUDHlpName);
  1053. return TRUE;
  1054. }
  1055. default:
  1056. return (FALSE);
  1057. }
  1058. return (lRet);
  1059. }
  1060. /**********************************************************************/
  1061. /* InitCompStr() */
  1062. /**********************************************************************/
  1063. void PASCAL InitCompStr( // init setting for composing string
  1064. LPCOMPOSITIONSTRING lpCompStr)
  1065. {
  1066. if (!lpCompStr) {
  1067. return;
  1068. }
  1069. lpCompStr->dwCompReadAttrLen = 0;
  1070. lpCompStr->dwCompReadClauseLen = 0;
  1071. lpCompStr->dwCompReadStrLen = 0;
  1072. lpCompStr->dwCompAttrLen = 0;
  1073. lpCompStr->dwCompClauseLen = 0;
  1074. lpCompStr->dwCompStrLen = 0;
  1075. lpCompStr->dwCursorPos = 0;
  1076. lpCompStr->dwDeltaStart = 0;
  1077. lpCompStr->dwResultReadClauseLen = 0;
  1078. lpCompStr->dwResultReadStrLen = 0;
  1079. lpCompStr->dwResultClauseLen = 0;
  1080. lpCompStr->dwResultStrLen = 0;
  1081. return;
  1082. }
  1083. /**********************************************************************/
  1084. /* ClearCompStr() */
  1085. /* Return Value: */
  1086. /* TRUE - successful, FALSE - failure */
  1087. /**********************************************************************/
  1088. BOOL PASCAL ClearCompStr(
  1089. LPINPUTCONTEXT lpIMC)
  1090. {
  1091. HIMCC hMem;
  1092. LPCOMPOSITIONSTRING lpCompStr;
  1093. DWORD dwSize;
  1094. if(!lpIMC) {
  1095. return (FALSE);
  1096. }
  1097. dwSize =
  1098. // header length
  1099. sizeof(COMPOSITIONSTRING) +
  1100. // composition reading attribute plus NULL terminator
  1101. lpImeL->nMaxKey * sizeof(BYTE) + sizeof(BYTE) +
  1102. // composition reading clause
  1103. sizeof(DWORD) + sizeof(DWORD) +
  1104. // composition reading string plus NULL terminator
  1105. lpImeL->nMaxKey * sizeof(WORD) + sizeof(WORD) +
  1106. // result reading clause
  1107. sizeof(DWORD) + sizeof(DWORD) +
  1108. // result reading string plus NULL terminateor
  1109. lpImeL->nMaxKey * sizeof(WORD) + sizeof(WORD) +
  1110. // result clause
  1111. sizeof(DWORD) + sizeof(DWORD) +
  1112. // result string plus NULL terminateor
  1113. MAXSTRLEN * sizeof(WORD) + sizeof(WORD);
  1114. if (!lpIMC->hCompStr) {
  1115. // it maybe free by other IME, init it
  1116. lpIMC->hCompStr = ImmCreateIMCC(dwSize);
  1117. } else if (hMem = ImmReSizeIMCC(lpIMC->hCompStr, dwSize)) {
  1118. lpIMC->hCompStr = hMem;
  1119. } else {
  1120. ImmDestroyIMCC(lpIMC->hCompStr);
  1121. lpIMC->hCompStr = ImmCreateIMCC(dwSize);
  1122. return (FALSE);
  1123. }
  1124. if (!lpIMC->hCompStr) {
  1125. return (FALSE);
  1126. }
  1127. lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
  1128. if (!lpCompStr) {
  1129. ImmDestroyIMCC(lpIMC->hCompStr);
  1130. lpIMC->hCompStr = ImmCreateIMCC(dwSize);
  1131. return (FALSE);
  1132. }
  1133. lpCompStr->dwSize = dwSize;
  1134. // 1. composition (reading) string - simple IME
  1135. // 2. result reading string
  1136. // 3. result string
  1137. lpCompStr->dwCompReadAttrLen = 0;
  1138. lpCompStr->dwCompReadAttrOffset = sizeof(COMPOSITIONSTRING);
  1139. lpCompStr->dwCompReadClauseLen = 0;
  1140. lpCompStr->dwCompReadClauseOffset = lpCompStr->dwCompReadAttrOffset +
  1141. lpImeL->nMaxKey * sizeof(TCHAR) + sizeof(TCHAR);
  1142. lpCompStr->dwCompReadStrLen = 0;
  1143. lpCompStr->dwCompReadStrOffset = lpCompStr->dwCompReadClauseOffset +
  1144. sizeof(DWORD) + sizeof(DWORD);
  1145. // composition string is the same with composition reading string
  1146. // for simple IMEs
  1147. lpCompStr->dwCompAttrLen = 0;
  1148. lpCompStr->dwCompAttrOffset = lpCompStr->dwCompReadAttrOffset;
  1149. lpCompStr->dwCompClauseLen = 0;
  1150. lpCompStr->dwCompClauseOffset = lpCompStr->dwCompReadClauseOffset;
  1151. lpCompStr->dwCompStrLen = 0;
  1152. lpCompStr->dwCompStrOffset = lpCompStr->dwCompReadStrOffset;
  1153. lpCompStr->dwCursorPos = 0;
  1154. lpCompStr->dwDeltaStart = 0;
  1155. lpCompStr->dwResultReadClauseLen = 0;
  1156. lpCompStr->dwResultReadClauseOffset = lpCompStr->dwCompStrOffset +
  1157. lpImeL->nMaxKey * sizeof(WORD) + sizeof(WORD);
  1158. lpCompStr->dwResultReadStrLen = 0;
  1159. lpCompStr->dwResultReadStrOffset = lpCompStr->dwResultReadClauseOffset +
  1160. sizeof(DWORD) + sizeof(DWORD);
  1161. lpCompStr->dwResultClauseLen = 0;
  1162. lpCompStr->dwResultClauseOffset = lpCompStr->dwResultReadStrOffset +
  1163. lpImeL->nMaxKey * sizeof(WORD) + sizeof(WORD);
  1164. lpCompStr->dwResultStrOffset = 0;
  1165. lpCompStr->dwResultStrOffset = lpCompStr->dwResultClauseOffset +
  1166. sizeof(DWORD) + sizeof(DWORD);
  1167. GlobalUnlock((HGLOBAL)lpIMC->hCompStr);
  1168. return (TRUE);
  1169. }
  1170. /**********************************************************************/
  1171. /* ClearCand() */
  1172. /* Return Value: */
  1173. /* TRUE - successful, FALSE - failure */
  1174. /**********************************************************************/
  1175. BOOL PASCAL ClearCand(
  1176. LPINPUTCONTEXT lpIMC)
  1177. {
  1178. HIMCC hMem;
  1179. LPCANDIDATEINFO lpCandInfo;
  1180. LPCANDIDATELIST lpCandList;
  1181. DWORD dwSize =
  1182. // header length
  1183. sizeof(CANDIDATEINFO) + sizeof(CANDIDATELIST) +
  1184. // candidate string pointers
  1185. sizeof(DWORD) * (MAXCAND) +
  1186. // string plus NULL terminator
  1187. (sizeof(WORD) * MAXSTRLEN + sizeof(WORD)) * MAXCAND;
  1188. if (!lpIMC) {
  1189. return (FALSE);
  1190. }
  1191. if (!lpIMC->hCandInfo) {
  1192. // it maybe free by other IME, init it
  1193. lpIMC->hCandInfo = ImmCreateIMCC(dwSize);
  1194. } else if (hMem = ImmReSizeIMCC(lpIMC->hCandInfo, dwSize)) {
  1195. lpIMC->hCandInfo = hMem;
  1196. } else {
  1197. ImmDestroyIMCC(lpIMC->hCandInfo);
  1198. lpIMC->hCandInfo = ImmCreateIMCC(dwSize);
  1199. return (FALSE);
  1200. }
  1201. if (!lpIMC->hCandInfo) {
  1202. return (FALSE);
  1203. }
  1204. lpCandInfo = (LPCANDIDATEINFO)ImmLockIMCC(lpIMC->hCandInfo);
  1205. if (!lpCandInfo) {
  1206. ImmDestroyIMCC(lpIMC->hCandInfo);
  1207. lpIMC->hCandInfo = ImmCreateIMCC(dwSize);
  1208. return (FALSE);
  1209. }
  1210. // ordering of strings are
  1211. // buffer size
  1212. lpCandInfo->dwSize = dwSize;
  1213. lpCandInfo->dwCount = 0;
  1214. lpCandInfo->dwOffset[0] = sizeof(CANDIDATEINFO);
  1215. lpCandList = (LPCANDIDATELIST)((LPBYTE)lpCandInfo +
  1216. lpCandInfo->dwOffset[0]);
  1217. // whole candidate info size - header
  1218. lpCandList->dwSize = lpCandInfo->dwSize - sizeof(CANDIDATEINFO);
  1219. lpCandList->dwStyle = IME_CAND_READ;
  1220. lpCandList->dwCount = 0;
  1221. lpCandList->dwSelection = 0;
  1222. lpCandList->dwPageSize = CANDPERPAGE;
  1223. lpCandList->dwOffset[0] = sizeof(CANDIDATELIST) +
  1224. sizeof(DWORD) * (MAXCAND - 1);
  1225. ImmUnlockIMCC(lpIMC->hCandInfo);
  1226. return (TRUE);
  1227. }
  1228. /**********************************************************************/
  1229. /* ClearGuideLine() */
  1230. /* Return Value: */
  1231. /* TRUE - successful, FALSE - failure */
  1232. /**********************************************************************/
  1233. BOOL PASCAL ClearGuideLine(
  1234. LPINPUTCONTEXT lpIMC)
  1235. {
  1236. HIMCC hMem;
  1237. LPGUIDELINE lpGuideLine;
  1238. DWORD dwSize = sizeof(GUIDELINE) + sImeG.cbStatusErr;
  1239. if (!lpIMC->hGuideLine) {
  1240. // it maybe free by IME
  1241. lpIMC->hGuideLine = ImmCreateIMCC(dwSize);
  1242. } else if (hMem = ImmReSizeIMCC(lpIMC->hGuideLine, dwSize)) {
  1243. lpIMC->hGuideLine = hMem;
  1244. } else {
  1245. ImmDestroyIMCC(lpIMC->hGuideLine);
  1246. lpIMC->hGuideLine = ImmCreateIMCC(dwSize);
  1247. }
  1248. lpGuideLine = (LPGUIDELINE)ImmLockIMCC(lpIMC->hGuideLine);
  1249. if (!lpGuideLine) {
  1250. return (FALSE);
  1251. }
  1252. lpGuideLine->dwSize = dwSize;
  1253. lpGuideLine->dwLevel = GL_LEVEL_NOGUIDELINE;
  1254. lpGuideLine->dwIndex = GL_ID_UNKNOWN;
  1255. lpGuideLine->dwStrLen = 0;
  1256. lpGuideLine->dwStrOffset = sizeof(GUIDELINE);
  1257. CopyMemory((LPBYTE)lpGuideLine + lpGuideLine->dwStrOffset,
  1258. sImeG.szStatusErr, sImeG.cbStatusErr);
  1259. ImmUnlockIMCC(lpIMC->hGuideLine);
  1260. return (TRUE);
  1261. }
  1262. /**********************************************************************/
  1263. /* InitContext() */
  1264. /**********************************************************************/
  1265. void PASCAL InitContext(
  1266. LPINPUTCONTEXT lpIMC)
  1267. {
  1268. if (lpIMC->fdwInit & INIT_STATUSWNDPOS) {
  1269. } else if (!lpIMC->hWnd) {
  1270. } else {
  1271. #if 0 // MultiMonitor support
  1272. POINT ptWnd;
  1273. // 10.10 modify
  1274. //ptWnd.x = sImeG.rcWorkArea.left;
  1275. //ptWnd.y = sImeG.rcWorkArea.top;
  1276. ptWnd.x = 0;
  1277. ptWnd.y = 0;
  1278. ClientToScreen(lpIMC->hWnd, &ptWnd);
  1279. if (ptWnd.x < sImeG.rcWorkArea.left) {
  1280. lpIMC->ptStatusWndPos.x = sImeG.rcWorkArea.left;
  1281. } else if (ptWnd.x + sImeG.xStatusWi > sImeG.rcWorkArea.right) {
  1282. lpIMC->ptStatusWndPos.x = sImeG.rcWorkArea.right -
  1283. sImeG.xStatusWi;
  1284. } else {
  1285. lpIMC->ptStatusWndPos.x = ptWnd.x;
  1286. }
  1287. lpIMC->ptStatusWndPos.y = sImeG.rcWorkArea.bottom -
  1288. sImeG.yStatusHi;
  1289. #else
  1290. RECT rcWorkArea;
  1291. rcWorkArea = ImeMonitorWorkAreaFromWindow(lpIMC->hWnd);
  1292. lpIMC->ptStatusWndPos.x = rcWorkArea.left;
  1293. lpIMC->ptStatusWndPos.y = rcWorkArea.bottom -
  1294. sImeG.yStatusHi;
  1295. #endif
  1296. lpIMC->fdwInit |= INIT_STATUSWNDPOS;
  1297. }
  1298. if (!(lpIMC->fdwInit & INIT_COMPFORM)) {
  1299. lpIMC->cfCompForm.dwStyle = CFS_DEFAULT;
  1300. }
  1301. if (lpIMC->cfCompForm.dwStyle != CFS_DEFAULT) {
  1302. } else if (!lpIMC->hWnd) {
  1303. } else {
  1304. POINT ptWnd;
  1305. ptWnd = lpImeL->ptDefComp;
  1306. ScreenToClient(lpIMC->hWnd, &ptWnd);
  1307. lpIMC->cfCompForm.dwStyle = CFS_DEFAULT;
  1308. lpIMC->cfCompForm.ptCurrentPos = ptWnd;
  1309. lpIMC->fdwInit |= INIT_COMPFORM;
  1310. }
  1311. return;
  1312. }
  1313. /**********************************************************************/
  1314. /* Select() */
  1315. /* Return Value: */
  1316. /* TRUE - successful, FALSE - failure */
  1317. /**********************************************************************/
  1318. BOOL PASCAL Select(
  1319. HIMC hIMC,
  1320. LPINPUTCONTEXT lpIMC,
  1321. BOOL fSelect)
  1322. {
  1323. LPPRIVCONTEXT lpImcP;
  1324. if (fSelect) {
  1325. if (!ClearCompStr(lpIMC))
  1326. return FALSE;
  1327. if (!ClearCand(lpIMC))
  1328. return FALSE;
  1329. ClearGuideLine(lpIMC);
  1330. }
  1331. if (lpIMC->cfCandForm[0].dwIndex != 0)
  1332. lpIMC->cfCandForm[0].dwStyle = CFS_DEFAULT;
  1333. // We add this hack for switching from other IMEs, this IME has a bug.
  1334. // Before this bug fixed in this IME, it depends on this hack.
  1335. if (lpIMC->cfCandForm[0].dwStyle == CFS_DEFAULT) {
  1336. lpIMC->cfCandForm[0].dwIndex = (DWORD)-1;
  1337. }
  1338. if (!lpIMC->hPrivate)
  1339. return FALSE;
  1340. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  1341. if (!lpImcP)
  1342. return FALSE;
  1343. if (fSelect) {
  1344. static BOOL bFirstTimeCallHere = TRUE;
  1345. //
  1346. // Init. ime character
  1347. //
  1348. InitImeCharac(0);
  1349. InterlockedIncrement( &lLock );
  1350. if ( bFirstTimeCallHere == TRUE ) {
  1351. GetCurrentUserEMBPath( );
  1352. bFirstTimeCallHere = FALSE;
  1353. }
  1354. InterlockedDecrement( &lLock );
  1355. //
  1356. // init fields of hPrivate
  1357. //
  1358. lpImcP->iImeState = CST_INIT;
  1359. lpImcP->fdwImeMsg = (DWORD) 0;
  1360. lpImcP->dwCompChar = (DWORD) 0;
  1361. lpImcP->fdwGcsFlag = (DWORD) 0;
  1362. lpImcP->uSYHFlg = 0x00000000;
  1363. lpImcP->uDYHFlg = 0x00000000;
  1364. lpImcP->uDSMHCount = 0x00000000;
  1365. lpImcP->uDSMHFlg = 0x00000000;
  1366. lpImcP->iActMBIndex = 0;
  1367. lstrcpy(lpImcP->MB_Name, HMapTab[0].MB_Name);
  1368. lpImcP->PrivateArea.Comp_Status.dwSTLX = 0;
  1369. lpImcP->PrivateArea.Comp_Status.dwSTMULCODE = 0;
  1370. lpImcP->PrivateArea.Comp_Status.dwInvalid = 0;
  1371. lpImcP->PrivateArea.Comp_Status.OnLineCreWord = 0;
  1372. //
  1373. // Set IME properties
  1374. //
  1375. lpImcP->PrivateArea.Comp_Status.dwPPTLX = MBIndex.IMEChara[lpImcP->iActMBIndex].IC_LX;
  1376. lpImcP->PrivateArea.Comp_Status.dwPPCZ = MBIndex.IMEChara[lpImcP->iActMBIndex].IC_CZ;
  1377. lpImcP->PrivateArea.Comp_Status.dwPPTS = MBIndex.IMEChara[lpImcP->iActMBIndex].IC_TS;
  1378. lpImcP->PrivateArea.Comp_Status.dwPPCTS = MBIndex.IMEChara[lpImcP->iActMBIndex].IC_CTC;
  1379. lpImcP->PrivateArea.Comp_Status.dwTraceCusr = MBIndex.IMEChara[lpImcP->iActMBIndex].IC_Trace;
  1380. CWCodeStr[0] = 0;
  1381. CWDBCSStr[0] = 0;
  1382. lpIMC->fOpen = TRUE;
  1383. if (!(lpIMC->fdwInit & INIT_CONVERSION)) {
  1384. lpIMC->fdwConversion = (lpIMC->fdwConversion & IME_CMODE_SOFTKBD) |
  1385. IME_CMODE_NATIVE;
  1386. lpIMC->fdwInit |= INIT_CONVERSION;
  1387. }
  1388. if (!(lpIMC->fdwInit & INIT_LOGFONT)) {
  1389. HDC hDC;
  1390. HGDIOBJ hSysFont;
  1391. //hSysFont = GetStockObject(SYSTEM_FONT);
  1392. hDC = GetDC(NULL);
  1393. hSysFont = GetCurrentObject(hDC, OBJ_FONT);
  1394. GetObject(hSysFont, sizeof(LOGFONT), &lpIMC->lfFont.A);
  1395. ReleaseDC(NULL, hDC);
  1396. lpIMC->fdwInit |= INIT_LOGFONT;
  1397. }
  1398. InitContext(lpIMC);
  1399. //
  1400. // Set Caps status
  1401. //
  1402. {
  1403. DWORD fdwConversion;
  1404. if (GetKeyState(VK_CAPITAL) & 0x01) {
  1405. //
  1406. // Change to alphanumeric mode.
  1407. //
  1408. fdwConversion = lpIMC->fdwConversion &
  1409. ~(IME_CMODE_NATIVE | IME_CMODE_CHARCODE | IME_CMODE_EUDC);
  1410. } else {
  1411. //
  1412. // Change to native mode
  1413. //
  1414. fdwConversion = (lpIMC->fdwConversion | IME_CMODE_NATIVE) &
  1415. ~(IME_CMODE_CHARCODE | IME_CMODE_EUDC );
  1416. }
  1417. ImmSetConversionStatus(hIMC, fdwConversion, lpIMC->fdwSentence);
  1418. }
  1419. } else {
  1420. if (lpImeL->hSKMenu) {
  1421. DestroyMenu(lpImeL->hSKMenu);
  1422. lpImeL->hSKMenu = NULL;
  1423. }
  1424. if (lpImeL->hPropMenu) {
  1425. DestroyMenu(lpImeL->hPropMenu);
  1426. lpImeL->hPropMenu = NULL;
  1427. }
  1428. if (lpImeL->hObjImeMenu) {
  1429. DestroyMenu(lpImeL->hObjImeMenu);
  1430. lpImeL->hObjImeMenu = NULL;
  1431. }
  1432. if (hCrtDlg) {
  1433. SendMessage(hCrtDlg, WM_CLOSE, (WPARAM)NULL, (LPARAM)NULL);
  1434. hCrtDlg = NULL;
  1435. }
  1436. }
  1437. //
  1438. // Start or end MB engine
  1439. //
  1440. if (fSelect) {
  1441. StartEngine(lpIMC->hPrivate);
  1442. SaTC_Trace = MBIndex.IMEChara[0].IC_Trace;
  1443. } else {
  1444. EndEngine(lpIMC->hPrivate);
  1445. }
  1446. ImmUnlockIMCC(lpIMC->hPrivate);
  1447. return (TRUE);
  1448. }
  1449. /**********************************************************************/
  1450. /* ImeSelect() */
  1451. /* Return Value: */
  1452. /* TRUE - successful, FALSE - failure */
  1453. /**********************************************************************/
  1454. BOOL WINAPI ImeSelect(
  1455. HIMC hIMC,
  1456. BOOL fSelect)
  1457. {
  1458. LPINPUTCONTEXT lpIMC;
  1459. BOOL fRet;
  1460. if (!hIMC) {
  1461. return (FALSE);
  1462. }
  1463. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  1464. if (!lpIMC) {
  1465. return (FALSE);
  1466. }
  1467. fRet = Select(hIMC, lpIMC, fSelect);
  1468. ImmUnlockIMC(hIMC);
  1469. return (fRet);
  1470. }
  1471. /**********************************************************************/
  1472. /* ImeSetActiveContext() */
  1473. /* Return Value: */
  1474. /* TRUE - successful, FALSE - failure */
  1475. /**********************************************************************/
  1476. BOOL WINAPI ImeSetActiveContext(
  1477. HIMC hIMC,
  1478. BOOL fOn)
  1479. {
  1480. if (!fOn) {
  1481. } else if (!hIMC) {
  1482. } else {
  1483. LPINPUTCONTEXT lpIMC;
  1484. LPPRIVCONTEXT lpImcP;
  1485. lpIMC = (LPINPUTCONTEXT)ImmLockIMC(hIMC);
  1486. if (!lpIMC) {
  1487. goto SetActEnd;
  1488. }
  1489. lpImcP = (LPPRIVCONTEXT)ImmLockIMCC(lpIMC->hPrivate);
  1490. if (!lpImcP) {
  1491. goto SetActUnlockIMC;
  1492. }
  1493. InitContext(lpIMC);
  1494. ImmUnlockIMCC(lpIMC->hPrivate);
  1495. SetActUnlockIMC:
  1496. ImmUnlockIMC(hIMC);
  1497. SetActEnd:
  1498. return (TRUE);
  1499. }
  1500. return (TRUE);
  1501. }
  1502. /**********************************************************************/
  1503. //OpenReg_PathSetup(HKEY *phKey);
  1504. /**********************************************************************/
  1505. LONG OpenReg_PathSetup(HKEY *phKey)
  1506. {
  1507. return RegOpenKeyEx (HKEY_CURRENT_USER,
  1508. REGSTR_PATH_SETUP,
  1509. 0,
  1510. KEY_ENUMERATE_SUB_KEYS |
  1511. KEY_EXECUTE |
  1512. KEY_QUERY_VALUE,
  1513. phKey);
  1514. }
  1515. /**********************************************************************/
  1516. //LONG OpenReg_User(HKEY hKey, // handle of open key
  1517. // LPCTSTR lpszSubKey, // address of name of subkey to open
  1518. // PHKEY phkResult); // address of handle of open key
  1519. /**********************************************************************/
  1520. LONG OpenReg_User(HKEY hKey, // handle of open key
  1521. LPCTSTR lpszSubKey, // address of name of subkey to open
  1522. PHKEY phkResult) // address of handle of open key
  1523. {
  1524. return RegOpenKeyEx (hKey,
  1525. lpszSubKey,
  1526. 0,
  1527. KEY_ENUMERATE_SUB_KEYS |
  1528. KEY_EXECUTE |
  1529. KEY_QUERY_VALUE|KEY_SET_VALUE,
  1530. phkResult);
  1531. }
  1532. VOID InfoMessage(HANDLE hWnd,WORD wMsgID)
  1533. {
  1534. TCHAR szStr[256];
  1535. LoadString(hInst,wMsgID,szStr, sizeof(szStr)/sizeof(TCHAR));
  1536. MessageBox(hWnd,szStr,szWarnTitle,MB_ICONINFORMATION|MB_OK);
  1537. }
  1538. VOID FatalMessage(HANDLE hWnd,WORD wMsgID)
  1539. {
  1540. TCHAR szStr[256];
  1541. LoadString(hInst,wMsgID,szStr, sizeof(szStr)/sizeof(TCHAR));
  1542. MessageBox(hWnd,szStr,szErrorTitle,MB_ICONSTOP|MB_OK);
  1543. }