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.

516 lines
17 KiB

  1. /****************************************************************************
  2. CONFIG.CPP
  3. Owner: cslim
  4. Copyright (c) 1997-1999 Microsoft Corporation
  5. IME Configuration DLG and registry access functions
  6. History:
  7. 14-JUL-1999 cslim Copied from IME98 source tree
  8. *****************************************************************************/
  9. #include "private.h"
  10. #include "globals.h"
  11. #include "common.h"
  12. #include "gdata.h"
  13. #include "debug.h"
  14. #include "config.h"
  15. #include "prsht.h"
  16. #include "osver.h"
  17. #include "userex.h"
  18. #include "resource.h"
  19. // Config DLG Help ID
  20. #define IDH_GRP_STATUSWIN 1001
  21. #define IDH_JUNBAN_TOGGLE 1002
  22. #define IDH_HANJA_CONV 1003
  23. #define IDH_GRP_KEYLAYOUT 1004
  24. #define IDH_2BEOLSIK 1005
  25. #define IDH_3BEOLSIK_390 1006
  26. #define IDH_3BEOLSIK_FINAL 1007
  27. #define IDH_DELJASO 1008
  28. #define IDH_K1HANJA 1009
  29. // Private functions
  30. static void PASCAL AddPage(LPPROPSHEETHEADERW ppsh, UINT id, DLGPROC pfn);
  31. static INT_PTR CALLBACK ConfigDLGProc1(HWND hDlg, UINT message,
  32. WPARAM wParam, LPARAM lParam);
  33. static int *GetContextHelpList();
  34. static BOOL IsValidCtrlIdForHelp(INT *helpList, INT ctrlId);
  35. static void GetHelpFileName();
  36. int *GetContextHelpList()
  37. {
  38. // Context Help Ids of PropertySheet
  39. static int ProDlgCtxHelpList[] =
  40. {
  41. IDC_GRP_KEYLAYOUT, IDH_GRP_KEYLAYOUT,
  42. IDC_2BEOLSIK, IDH_2BEOLSIK,
  43. IDC_3BEOLSIK_390, IDH_3BEOLSIK_390,
  44. IDC_3BEOLSIK_FINAL, IDH_3BEOLSIK_FINAL,
  45. IDC_DELJASO, IDH_DELJASO,
  46. IDC_K1HANJA, IDH_K1HANJA,
  47. 0, 0
  48. };
  49. return ProDlgCtxHelpList;
  50. }
  51. BOOL IsValidCtrlIdForHelp(INT *helpList, INT ctrlId)
  52. {
  53. INT *p;
  54. for(p = helpList; *p != 0; p+=2)
  55. {
  56. if(ctrlId == *p)
  57. return fTrue;
  58. }
  59. return fFalse;
  60. }
  61. void GetHelpFileName(LPTSTR szHelpFileNameFull, int cchszHelpFileNameFull)
  62. {
  63. // WARNING: This only will work for NT or Win98. For Win95 need to check system locale
  64. LoadStringExA(g_hInst, IDS_CONTEXTHELP_FILENAME, szHelpFileNameFull, MAX_PATH);
  65. }
  66. static HWND hwndPropSheet = (HWND)0;
  67. static BOOL g_fDestroyPropNow = FALSE;
  68. BOOL ConfigDLG(HWND hwndParent)
  69. {
  70. static HPROPSHEETPAGE rPages[1];
  71. static PROPSHEETHEADERW psh;
  72. static WCHAR szCaption[64];
  73. MSG msg = {0};
  74. BOOL fRet = fFalse;
  75. // If config DLG already created
  76. if (IsWindow(hwndPropSheet))
  77. {
  78. SetForegroundWindow(hwndPropSheet);
  79. return fTrue;
  80. }
  81. psh.dwSize = sizeof(psh);
  82. psh.dwFlags = PSH_NOAPPLYNOW | PSH_USEICONID | PSH_MODELESS | PSH_USEPAGELANG;
  83. psh.hwndParent = hwndParent;
  84. psh.hInstance = g_hInst;
  85. if (IsOnNT())
  86. LoadStringExW(g_hInst, IDS_PROGRAM, szCaption, sizeof(szCaption)/sizeof(WCHAR));
  87. else
  88. LoadStringExA(g_hInst, IDS_PROGRAM, (LPSTR)szCaption, sizeof(szCaption));
  89. psh.pszCaption = szCaption;
  90. psh.nPages = 0;
  91. psh.nStartPage = 0;
  92. psh.phpage = rPages;
  93. AddPage(&psh, IDD_CONFIG_PAGE1, ConfigDLGProc1);
  94. if (IsOnNT())
  95. hwndPropSheet = (HWND)PropertySheetW(&psh);
  96. else
  97. hwndPropSheet = (HWND)PropertySheetA((PROPSHEETHEADERA*)&psh);
  98. while (IsWindow(hwndPropSheet) && OurGetMessage(&msg, NULL, 0x00, 0x00))
  99. {
  100. // If the modeless guy is up and is ready to be destroyed
  101. // (PropSheet_GetCurrentPageHwnd returns NULL) then destroy the dialog.
  102. // PropSheet_GetCurrentPageHwnd will return NULL after the OK or Cancel
  103. // button has been pressed and all of the pages have been notified. The
  104. // Apply button doesn't cause this to happen.
  105. if(/*g_fDestroyPropNow == fTrue || */(hwndPropSheet && (NULL == PropSheet_GetCurrentPageHwnd(hwndPropSheet))))
  106. {
  107. //enable the parent first to prevent another window from becoming the foreground window
  108. //EnableWindow(hwndParent, TRUE);
  109. DestroyWindow(hwndPropSheet);
  110. //break;
  111. }
  112. //use PropSheet_IsDialogMessage instead of IsDialogMessage
  113. if(!PropSheet_IsDialogMessage(hwndPropSheet, &msg))
  114. {
  115. TranslateMessage(&msg);
  116. if (IsOnNT())
  117. DispatchMessageW(&msg);
  118. else
  119. DispatchMessageA(&msg);
  120. }
  121. }
  122. hwndPropSheet = (HWND)0;
  123. return fTrue;
  124. }
  125. void PASCAL AddPage(LPPROPSHEETHEADERW ppsh, UINT idDlg, DLGPROC pfn)
  126. {
  127. //if (ppsh->nPages < 3)
  128. //{
  129. PROPSHEETPAGE psp;
  130. ZeroMemory(&psp, sizeof(psp));
  131. psp.dwSize = sizeof(psp);
  132. psp.dwFlags = PSP_DLGINDIRECT;
  133. psp.hInstance = g_hInst;
  134. psp.pResource = LoadDialogTemplateEx(GetSystemDefaultLangID(), g_hInst, MAKEINTRESOURCE(idDlg));
  135. psp.pfnDlgProc = pfn;
  136. psp.lParam = 0;
  137. ppsh->phpage[ppsh->nPages] = CreatePropertySheetPage(&psp);
  138. if (ppsh->phpage[ppsh->nPages])
  139. ppsh->nPages++;
  140. //}
  141. }
  142. INT_PTR CALLBACK ConfigDLGProc1(HWND hDlg, UINT message , WPARAM wParam, LPARAM lParam)
  143. {
  144. static UINT uPrevKeyboardType;
  145. static BOOL fPrevJasoDel;
  146. static BOOL fK1Hanja;
  147. BOOL fFound = fFalse;
  148. TCHAR szHelpFileNameFull[MAX_PATH];
  149. CIMEData ImeData(CIMEData::SMReadWrite);
  150. DebugMsg(DM_TRACE, TEXT("ConfigDLGProc"));
  151. // If Properties DLG invoked from Setting in Toolbar and no Tip instance exist in the system,
  152. // IMEData is not init. So make sure we load reg values here.
  153. ImeData.InitImeData();
  154. switch(message)
  155. {
  156. case WM_NOTIFY:
  157. switch (((NMHDR FAR *)lParam)->code)
  158. {
  159. case PSN_APPLY:
  160. ImeData.SetCurrentBeolsik(uPrevKeyboardType);
  161. ImeData.SetJasoDel(fPrevJasoDel);
  162. ImeData.SetKSC5657Hanja(fK1Hanja);
  163. SetRegValues(GETSET_REG_STATUS_BUTTONS|GETSET_REG_IMEKL|GETSET_REG_JASODEL|GETSET_REG_KSC5657);
  164. break;
  165. default:
  166. return fFalse;
  167. }
  168. break;
  169. case WM_INITDIALOG:
  170. uPrevKeyboardType = ImeData.GetCurrentBeolsik();
  171. CheckRadioButton(hDlg, IDC_2BEOLSIK, IDC_3BEOLSIK_FINAL, IDC_2BEOLSIK+uPrevKeyboardType);
  172. fPrevJasoDel = ImeData.GetJasoDel();
  173. if (fPrevJasoDel)
  174. CheckDlgButton(hDlg, IDC_DELJASO, BST_CHECKED);
  175. else
  176. CheckDlgButton(hDlg, IDC_DELJASO, BST_UNCHECKED);
  177. // KSC-5657 Hanja
  178. fK1Hanja = ImeData.GetKSC5657Hanja() && !IsOn95();
  179. if (fK1Hanja)
  180. CheckDlgButton(hDlg, IDC_K1HANJA, BST_CHECKED);
  181. else
  182. CheckDlgButton(hDlg, IDC_K1HANJA, BST_UNCHECKED);
  183. // If Win95, disable K1 Hanja
  184. if (IsOn95())
  185. EnableWindow(GetDlgItem(hDlg, IDC_K1HANJA), fFalse);
  186. return fTrue;
  187. case WM_COMMAND:
  188. switch (wParam)
  189. {
  190. case IDC_2BEOLSIK:
  191. //if (IsDlgButtonChecked(hDlg, IDC_2BEOLSIK)) {
  192. uPrevKeyboardType = KL_2BEOLSIK;
  193. //}
  194. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  195. break;
  196. case IDC_3BEOLSIK_390:
  197. uPrevKeyboardType = KL_3BEOLSIK_390;
  198. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  199. break;
  200. case IDC_3BEOLSIK_FINAL:
  201. uPrevKeyboardType = KL_3BEOLSIK_FINAL;
  202. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  203. break;
  204. case IDC_DELJASO:
  205. if (IsDlgButtonChecked(hDlg, IDC_DELJASO))
  206. fPrevJasoDel = fTrue;
  207. else
  208. fPrevJasoDel = fFalse;
  209. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  210. break;
  211. case IDC_K1HANJA:
  212. if (IsDlgButtonChecked(hDlg, IDC_K1HANJA))
  213. fK1Hanja = fTrue;
  214. else
  215. fK1Hanja = fFalse;
  216. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  217. break;
  218. default:
  219. return fFalse;
  220. }
  221. break;
  222. case WM_CONTEXTMENU:
  223. GetHelpFileName(szHelpFileNameFull, MAX_PATH);
  224. WinHelp((HWND)wParam,
  225. szHelpFileNameFull,
  226. HELP_CONTEXTMENU,
  227. (ULONG_PTR)(LPVOID)GetContextHelpList());
  228. return 0;
  229. case WM_HELP:
  230. INT *pHelpList;
  231. pHelpList = GetContextHelpList();
  232. if(IsValidCtrlIdForHelp(pHelpList, ((LPHELPINFO)lParam)->iCtrlId))
  233. {
  234. GetHelpFileName(szHelpFileNameFull, MAX_PATH);
  235. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  236. szHelpFileNameFull,
  237. HELP_WM_HELP,
  238. (ULONG_PTR)pHelpList);
  239. }
  240. return 0;
  241. default:
  242. return fFalse;
  243. }
  244. return fTrue;
  245. }
  246. #ifdef NEVER
  247. BOOL GetStatusWinPosReg(POINT *pptStatusWinPosReg)
  248. {
  249. HKEY hKey;
  250. DWORD dwBuf, dwCb;
  251. BOOL fSuccess = fFalse;
  252. if (RegOpenKeyEx(HKEY_CURRENT_USER, g_szIMERootKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  253. {
  254. dwCb = sizeof(dwBuf);
  255. if (RegQueryValueEx(hKey, g_szStatusPos, NULL, NULL, (LPBYTE)&dwBuf, &dwCb) == ERROR_SUCCESS)
  256. {
  257. pptStatusWinPosReg->x = HIWORD(dwBuf);
  258. pptStatusWinPosReg->y = LOWORD(dwBuf);
  259. fSuccess = fTrue;
  260. }
  261. RegCloseKey(hKey);
  262. }
  263. return fSuccess;
  264. }
  265. #endif
  266. ///////////////////////////////////////////////////////////////////////////////
  267. //
  268. BOOL GetRegValues(UINT uGetBits)
  269. {
  270. HKEY hKey;
  271. DWORD dwBuf, dwCb, dwType;
  272. CIMEData ImeData(CIMEData::SMReadWrite);
  273. BOOL fSuccess = fTrue;
  274. DebugMsg(DM_TRACE, "GetRegValues()");
  275. if (RegOpenKeyEx(HKEY_CURRENT_USER, g_szIMERootKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  276. {
  277. ///////////////////////////////////////////////////////////////////
  278. // IME Keyboard Layout
  279. if (uGetBits & GETSET_REG_IMEKL)
  280. {
  281. dwCb = sizeof(dwBuf);
  282. if (RegQueryValueEx(hKey, g_szIMEKL, NULL, NULL, (LPBYTE)&dwBuf, &dwCb) == ERROR_SUCCESS)
  283. {
  284. if (/*dwBuf >= KL_2BEOLSIK &&*/ dwBuf <= KL_3BEOLSIK_FINAL)
  285. ImeData.SetCurrentBeolsik(dwBuf);
  286. }
  287. else
  288. fSuccess = fFalse;
  289. }
  290. ///////////////////////////////////////////////////////////////////
  291. // Status window pos
  292. if (uGetBits & GETSET_REG_STATUSPOS)
  293. {
  294. dwCb = sizeof(dwBuf);
  295. if (RegQueryValueEx(hKey, g_szStatusPos, NULL, NULL, (LPBYTE)&dwBuf, &dwCb) == ERROR_SUCCESS)
  296. {
  297. ImeData->ptStatusPos.x = HIWORD(dwBuf);
  298. ImeData->ptStatusPos.y = LOWORD(dwBuf);
  299. }
  300. else
  301. fSuccess = fFalse;
  302. }
  303. ///////////////////////////////////////////////////////////////////
  304. // Status window button setting
  305. if (uGetBits & GETSET_REG_STATUS_BUTTONS)
  306. {
  307. BYTE ButtonReg[MAX_NUM_OF_STATUS_BUTTONS+1];
  308. int nButton;
  309. dwCb = sizeof(ButtonReg);
  310. dwType = REG_BINARY;
  311. if (RegQueryValueEx(hKey, g_szStatusButtons, NULL, &dwType, (LPBYTE)&ButtonReg, &dwCb) == ERROR_SUCCESS)
  312. {
  313. if (ButtonReg[0] == 0)
  314. ButtonReg[0] = 1;
  315. if (ButtonReg[0]<=MAX_NUM_OF_STATUS_BUTTONS)
  316. {
  317. for (nButton=0; nButton<ButtonReg[0]; nButton++)
  318. {
  319. // button data validity check
  320. if (ButtonReg[nButton+1] <= IME_PAD_BUTTON && ButtonReg[nButton+1] != NULL_BUTTON)
  321. ImeData->StatusButtons[nButton].m_ButtonType = (StatusButtonTypes)ButtonReg[nButton+1];
  322. else
  323. break;
  324. }
  325. ImeData->uNumOfButtons = nButton;
  326. }
  327. }
  328. else
  329. fSuccess = fFalse;
  330. }
  331. ///////////////////////////////////////////////////////////////////
  332. // Deletion by Jaso
  333. if (uGetBits & GETSET_REG_JASODEL)
  334. {
  335. dwCb = sizeof(dwBuf);
  336. if (RegQueryValueEx(hKey, g_szCompDel, NULL, NULL, (LPBYTE)&dwBuf, &dwCb) == ERROR_SUCCESS)
  337. ImeData.SetJasoDel(dwBuf);
  338. }
  339. #if 0
  340. // REVIEW: Do we still need for TIP?
  341. if (uGetBits & GETSET_REG_ISO10646)
  342. {
  343. dwCb = sizeof(dwBuf);
  344. if (RegQueryValueEx(hKey, g_szXWEnable, NULL, NULL, (LPBYTE)&dwBuf, &dwCb) == ERROR_SUCCESS)
  345. vpInstData->fISO10646 = dwBuf;
  346. else
  347. fSuccess = fFalse;
  348. // For Win95 and Win98 lookup INI file for ISO10646 setting.
  349. // ISO10646.EXE set registry
  350. if (!IsWinNT())
  351. vpInstData->fISO10646 = GetProfileInt(g_szXWEnable,
  352. OurGetModuleFileName(fFalse),
  353. vpInstData->fISO10646);
  354. }
  355. #endif
  356. // Get KSC5657 K1 Hanja flag
  357. if (uGetBits & GETSET_REG_KSC5657)
  358. {
  359. dwCb = sizeof(dwBuf);
  360. dwType = REG_DWORD;
  361. if (RegQueryValueEx(hKey, g_szEnableK1Hanja, NULL, &dwType, (LPBYTE)&dwBuf, &dwCb) == ERROR_SUCCESS)
  362. ImeData->fKSC5657Hanja = dwBuf;
  363. else
  364. ImeData->fKSC5657Hanja = fFalse;
  365. }
  366. // Get Unicode Tooltip Cand window flag
  367. // Currently this has no UI part which means hidden spec so no need SetReg now.
  368. if (uGetBits & GETSET_REG_CANDUNICODETT)
  369. {
  370. dwCb = sizeof(dwBuf);
  371. dwType = REG_DWORD;
  372. if (RegQueryValueEx(hKey, g_szEnableCandUnicodeTT, NULL, &dwType, (LPBYTE)&dwBuf, &dwCb) == ERROR_SUCCESS)
  373. ImeData->fCandUnicodeTT = dwBuf;
  374. else
  375. ImeData->fCandUnicodeTT = fFalse;
  376. }
  377. RegCloseKey(hKey);
  378. }
  379. else
  380. {
  381. fSuccess = fFalse;
  382. Assert(0);
  383. }
  384. return fSuccess;
  385. }
  386. BOOL SetRegValues(UINT uSetBits)
  387. {
  388. HKEY hKey;
  389. DWORD dwBuf, dwCb;
  390. int nButton;
  391. CIMEData ImeData;
  392. ///////////////////////////////////////////////////////////////////////////
  393. // Set status pos
  394. if (RegCreateKeyEx(HKEY_CURRENT_USER, g_szIMERootKey, 0, NULL, REG_OPTION_NON_VOLATILE,
  395. KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS)
  396. {
  397. if (uSetBits & GETSET_REG_STATUSPOS)
  398. {
  399. dwCb = sizeof(dwBuf);
  400. dwBuf = (ImeData->ptStatusPos.x << 16) | (ImeData->ptStatusPos.y & 0xFFFF); // HIWORD : X, LOWORD : Y
  401. RegSetValueEx(hKey, g_szStatusPos, 0, REG_DWORD, (LPBYTE)&dwBuf, dwCb);
  402. }
  403. if (uSetBits & GETSET_REG_STATUS_BUTTONS)
  404. {
  405. BYTE ButtonReg[MAX_NUM_OF_STATUS_BUTTONS+1];
  406. dwCb = sizeof(ButtonReg);
  407. Assert(ImeData->uNumOfButtons <= MAX_NUM_OF_STATUS_BUTTONS);
  408. // set number of button as the first element of array
  409. if (ImeData->uNumOfButtons<=MAX_NUM_OF_STATUS_BUTTONS)
  410. ButtonReg[0] = (BYTE)ImeData->uNumOfButtons;
  411. for (nButton=0; nButton < (INT)ImeData->uNumOfButtons; nButton++)
  412. ButtonReg[nButton+1] = ImeData->StatusButtons[nButton].m_ButtonType;
  413. // clear
  414. for (; nButton<MAX_NUM_OF_STATUS_BUTTONS; nButton++)
  415. ButtonReg[nButton+1] = NULL_BUTTON;
  416. RegSetValueEx(hKey, g_szStatusButtons, 0, REG_BINARY, (LPBYTE)&ButtonReg, dwCb);
  417. }
  418. if (uSetBits & GETSET_REG_IMEKL)
  419. {
  420. dwCb = sizeof(dwBuf);
  421. dwBuf = ImeData.GetCurrentBeolsik();
  422. RegSetValueEx(hKey, g_szIMEKL, 0, REG_DWORD, (LPBYTE)&dwBuf, dwCb);
  423. }
  424. if (uSetBits & GETSET_REG_JASODEL)
  425. {
  426. dwCb = sizeof(dwBuf);
  427. dwBuf = ImeData.GetJasoDel();
  428. RegSetValueEx(hKey, g_szCompDel, 0, REG_DWORD, (LPBYTE)&dwBuf, dwCb);
  429. }
  430. // Get KSC5657 K1 Hanja flag
  431. if (uSetBits & GETSET_REG_KSC5657)
  432. {
  433. dwCb = sizeof(dwBuf);
  434. dwBuf = ImeData.GetKSC5657Hanja();
  435. RegSetValueEx(hKey, g_szEnableK1Hanja, 0, REG_DWORD, (LPBYTE)&dwBuf, dwCb);
  436. }
  437. RegCloseKey(hKey);
  438. }
  439. else
  440. return fFalse;
  441. return fTrue;
  442. }