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.

435 lines
14 KiB

  1. /******************************************************************************
  2. Module name: Display.C
  3. Purpose: Display Dialog handler
  4. ******************************************************************************/
  5. #ifdef UNICODE
  6. #define _UNICODE
  7. #endif
  8. #include "tchar.h"
  9. #include "Access.h"
  10. #include "winuserp.h"
  11. #define STRSAFE_NO_DEPRECATE
  12. #include "strsafe.h"
  13. #include "shlobj.h"
  14. static BOOL s_fBlink = TRUE;
  15. static RECT s_rCursor;
  16. #define ARRAYSIZE( a ) (sizeof(a) / sizeof(a[0]))
  17. LPTSTR HelpFile()
  18. {
  19. static BOOL bFirstTime = TRUE;
  20. const TCHAR c_szHelp[] = TEXT("\\Help\\access.hlp");
  21. static TCHAR szHelpFilePath[MAX_PATH+ARRAYSIZE(c_szHelp)];
  22. if (bFirstTime)
  23. {
  24. LPTSTR pszDestEnd;
  25. size_t cchRemaining;
  26. szHelpFilePath[0] = TEXT('\0');
  27. if (GetSystemWindowsDirectory(szHelpFilePath, MAX_PATH))
  28. {
  29. int cch = lstrlen(szHelpFilePath);
  30. StringCchCopyEx(szHelpFilePath+cch, ARRAYSIZE(szHelpFilePath)-cch,
  31. c_szHelp, &pszDestEnd, &cchRemaining, STRSAFE_NULL_ON_FAILURE);
  32. }
  33. bFirstTime = FALSE;
  34. }
  35. return (LPTSTR)szHelpFilePath;
  36. }
  37. //////////////////////////////////////////////////////////////////////////////
  38. /*******************************************************************
  39. * DESCRIPTION: High Contrast dialog handler
  40. *******************************************************************/
  41. VOID FillCustonSchemeBox (HWND hwndCB) {
  42. HKEY hkey;
  43. int i;
  44. DWORD dwDisposition;
  45. // Get the class name and the value count.
  46. if (RegCreateKeyEx(HKEY_CURRENT_USER, CONTROL_KEY, 0, __TEXT(""),
  47. REG_OPTION_NON_VOLATILE, KEY_ENUMERATE_SUB_KEYS | KEY_EXECUTE | KEY_QUERY_VALUE,
  48. NULL, &hkey, &dwDisposition) != ERROR_SUCCESS) return;
  49. // Enumerate the child keys.
  50. for (i = 0; ; i++) {
  51. DWORD cbValueName;
  52. TCHAR szValueName[MAX_SCHEME_NAME_SIZE];
  53. LONG l;
  54. cbValueName = MAX_SCHEME_NAME_SIZE;
  55. l = RegEnumValue(hkey, i, szValueName, &cbValueName, NULL, NULL, NULL, NULL);
  56. if (ERROR_NO_MORE_ITEMS == l) break;
  57. // Add each value to a combobox.
  58. if (lstrlen(szValueName) == 0) lstrcpy(szValueName, __TEXT("<NO NAME>"));
  59. ComboBox_AddString(hwndCB, ((szValueName[0] == 0) ? __TEXT("<NO NAME>") : szValueName));
  60. }
  61. RegCloseKey(hkey);
  62. }
  63. // ****************************************************************************
  64. // Main HC Dialog handler
  65. // ****************************************************************************
  66. INT_PTR WINAPI HighContrastDlg (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  67. HKEY hkey;
  68. HWND hwndCB = GetDlgItem(hwnd, IDC_HC_DEFAULTSCHEME);
  69. int i;
  70. DWORD dwDisposition;
  71. BOOL fProcessed = TRUE;
  72. switch (uMsg) {
  73. case WM_INITDIALOG:
  74. CheckDlgButton(hwnd, IDC_HC_HOTKEY, (g_hc.dwFlags & HCF_HOTKEYACTIVE) ? TRUE : FALSE);
  75. //
  76. // Put possible high contrast schemes in combo
  77. // box and show the current one
  78. //
  79. // ISSUE: If MUI is enabled then displaying the strings from the registry may
  80. // be incorrect. It should be in the language currently selected.
  81. FillCustonSchemeBox(hwndCB);
  82. // Set the proper selection in the combobox (handle case where it's not set yet)
  83. if (g_hc.lpszDefaultScheme[0] == 0)
  84. {
  85. if (!IsMUI_Enabled())
  86. {
  87. // get scheme name from resources if not MUI enabled
  88. LoadString(g_hinst, IDS_WHITEBLACK_SCHEME, g_hc.lpszDefaultScheme, 200);
  89. }
  90. else
  91. {
  92. // else set scheme name in english
  93. lstrcpy(g_hc.lpszDefaultScheme, IDSENG_WHITEBLACK_SCHEME);
  94. }
  95. }
  96. if (ComboBox_SelectString(hwndCB, -1, g_hc.lpszDefaultScheme) == CB_ERR) {
  97. // Not found, select the 1st one
  98. // TODO this is bad! When MUI enabled we will rarely find the correct scheme!
  99. ComboBox_SetCurSel(hwndCB, 0);
  100. }
  101. break;
  102. case WM_HELP: // F1
  103. WinHelp(((LPHELPINFO) lParam)->hItemHandle, HelpFile(), HELP_WM_HELP, (DWORD_PTR) (LPSTR) g_aIds);
  104. break;
  105. case WM_CONTEXTMENU: // right mouse click
  106. WinHelp((HWND) wParam, HelpFile(), HELP_CONTEXTMENU, (DWORD_PTR) (LPSTR) g_aIds);
  107. break;
  108. // Handle the generic commands
  109. case WM_COMMAND:
  110. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  111. case IDC_HC_HOTKEY:
  112. g_hc.dwFlags ^= HCF_HOTKEYACTIVE;
  113. break;
  114. case IDC_HC_DEFAULTSCHEME:
  115. if (GET_WM_COMMAND_CMD(wParam, lParam) == CBN_SELCHANGE) {
  116. // Get the current string into our variable
  117. i = ComboBox_GetCurSel(hwndCB);
  118. ComboBox_GetLBText(hwndCB, i, g_hc.lpszDefaultScheme);
  119. }
  120. break;
  121. case IDOK:
  122. // Save the current custom scheme to the registry.
  123. if (ERROR_SUCCESS == RegCreateKeyEx(
  124. HKEY_CURRENT_USER,
  125. HC_KEY,
  126. 0,
  127. __TEXT(""),
  128. REG_OPTION_NON_VOLATILE,
  129. KEY_EXECUTE | KEY_QUERY_VALUE | KEY_SET_VALUE,
  130. NULL,
  131. &hkey,
  132. &dwDisposition)) {
  133. TCHAR szCust[MAX_SCHEME_NAME_SIZE];
  134. i = ComboBox_GetCurSel(hwndCB);
  135. ComboBox_GetLBText(hwndCB, i, szCust);
  136. // Abandon "Last Custom Scheme" (never written correctly (#954))
  137. RegSetValueEx(hkey
  138. , CURR_HC_SCHEME
  139. , 0, REG_SZ
  140. , (PBYTE) szCust
  141. , lstrlen(szCust)*sizeof(TCHAR));
  142. }
  143. EndDialog(hwnd, IDOK);
  144. break;
  145. case IDCANCEL:
  146. EndDialog(hwnd, IDCANCEL);
  147. break;
  148. }
  149. break;
  150. default:
  151. fProcessed = FALSE; break;
  152. }
  153. return((INT_PTR) fProcessed);
  154. }
  155. void DrawCaret(HWND hwnd, BOOL fClearFirst)
  156. {
  157. HWND hwndCursor = GetDlgItem(hwnd, IDC_KCURSOR_BLINK);
  158. HDC hDC = GetDC(hwnd);
  159. if (hDC)
  160. {
  161. HBRUSH hBrush;
  162. if (fClearFirst)
  163. {
  164. hBrush = GetSysColorBrush(COLOR_MENU);
  165. if (hBrush)
  166. {
  167. RECT rect;
  168. GetWindowRect(hwndCursor, &rect);
  169. MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&rect, 2);
  170. FillRect(hDC, &rect, hBrush);
  171. InvalidateRect(hwndCursor, &rect, TRUE);
  172. }
  173. }
  174. hBrush = GetSysColorBrush(COLOR_BTNTEXT);
  175. if (hBrush)
  176. {
  177. FillRect(hDC, &s_rCursor, hBrush);
  178. InvalidateRect(hwndCursor, &s_rCursor, TRUE);
  179. }
  180. ReleaseDC(hwnd,hDC);
  181. }
  182. }
  183. void OnTimer( HWND hwnd, WPARAM wParam, LPARAM lParam )
  184. {
  185. if (wParam == BLINK)
  186. {
  187. BOOL fNoBlinkRate = (g_cs.dwNewCaretBlinkRate == CURSORMAX)?TRUE:FALSE;
  188. if (s_fBlink || fNoBlinkRate)
  189. {
  190. DrawCaret(hwnd, fNoBlinkRate);
  191. }
  192. else
  193. {
  194. InvalidateRect(GetDlgItem(hwnd, IDC_KCURSOR_BLINK), NULL, TRUE);
  195. }
  196. if (fNoBlinkRate)
  197. KillTimer(hwnd, wParam);
  198. s_fBlink = !s_fBlink;
  199. }
  200. }
  201. void OnHScroll( HWND hwnd, WPARAM wParam, LPARAM lParam )
  202. {
  203. if ((HWND)lParam == GetDlgItem(hwnd, IDC_KCURSOR_RATE))
  204. {
  205. // blink rate setting
  206. int nCurrent = (int)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0L );
  207. g_cs.dwNewCaretBlinkRate = CURSORSUM - (nCurrent * 100);
  208. // reset the bink rate timer
  209. SetTimer(hwnd, BLINK, g_cs.dwNewCaretBlinkRate, NULL);
  210. if (g_cs.dwNewCaretBlinkRate == CURSORMAX) // draw the caret immediately; if we wait
  211. DrawCaret(hwnd, TRUE); // for the timer there is a visible delay
  212. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
  213. }
  214. else if ((HWND)lParam == GetDlgItem(hwnd, IDC_KCURSOR_WIDTH))
  215. {
  216. // cursor width setting
  217. g_cs.dwNewCaretWidth = (int)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0L );
  218. s_rCursor.right = s_rCursor.left + g_cs.dwNewCaretWidth;
  219. DrawCaret(hwnd, (g_cs.dwNewCaretBlinkRate == CURSORMAX));
  220. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
  221. }
  222. }
  223. void InitCursorCtls(HWND hwnd)
  224. {
  225. g_cs.dwNewCaretWidth = g_cs.dwCaretWidth;
  226. g_cs.dwNewCaretBlinkRate = g_cs.dwCaretBlinkRate;
  227. // Update the Caret UI
  228. SendMessage(GetDlgItem(hwnd, IDC_KCURSOR_WIDTH), TBM_SETRANGE, 0, MAKELONG(1, 20));
  229. SendMessage(GetDlgItem(hwnd, IDC_KCURSOR_WIDTH), TBM_SETPOS, TRUE, (LONG)g_cs.dwCaretWidth);
  230. SendMessage(GetDlgItem(hwnd, IDC_KCURSOR_RATE), TBM_SETRANGE, 0, MAKELONG(CURSORMIN / 100, CURSORMAX / 100));
  231. SendMessage(GetDlgItem(hwnd, IDC_KCURSOR_RATE), TBM_SETPOS, TRUE, (LONG)(CURSORSUM - g_cs.dwCaretBlinkRate) / 100);
  232. // Update Blink and caret size
  233. GetWindowRect(GetDlgItem(hwnd, IDC_KCURSOR_BLINK), &s_rCursor);
  234. MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&s_rCursor, 2);
  235. s_rCursor.right = s_rCursor.left + g_cs.dwCaretWidth;
  236. }
  237. // *******************************************************************
  238. // DisplayDialog handler
  239. // *******************************************************************
  240. INT_PTR WINAPI DisplayDlg (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  241. HIGHCONTRAST hc;
  242. TCHAR szScheme[MAX_SCHEME_NAME_SIZE];
  243. BOOL fProcessed = TRUE;
  244. switch (uMsg) {
  245. case WM_INITDIALOG:
  246. CheckDlgButton(hwnd, IDC_HC_ENABLE,
  247. (g_hc.dwFlags & HCF_HIGHCONTRASTON) ? TRUE : FALSE);
  248. if (!(g_hc.dwFlags & HCF_AVAILABLE)) {
  249. EnableWindow(GetDlgItem(hwnd, IDC_HC_SETTINGS), FALSE);
  250. EnableWindow(GetDlgItem(hwnd,IDC_HC_ENABLE), FALSE);
  251. }
  252. InitCursorCtls(hwnd);
  253. break;
  254. case WM_TIMER:
  255. OnTimer(hwnd, wParam, lParam);
  256. break;
  257. case WM_HSCROLL:
  258. OnHScroll(hwnd, wParam, lParam);
  259. break;
  260. case WM_HELP:
  261. WinHelp(((LPHELPINFO) lParam)->hItemHandle, HelpFile(), HELP_WM_HELP, (DWORD_PTR) (LPSTR) g_aIds);
  262. break;
  263. case WM_CONTEXTMENU:
  264. WinHelp((HWND) wParam, HelpFile(), HELP_CONTEXTMENU, (DWORD_PTR) (LPSTR) g_aIds);
  265. break;
  266. // sliders don't get this message so pass it on
  267. case WM_SYSCOLORCHANGE:
  268. SendMessage(GetDlgItem(hwnd, IDC_KCURSOR_WIDTH), WM_SYSCOLORCHANGE, 0, 0);
  269. SendMessage(GetDlgItem(hwnd, IDC_KCURSOR_RATE), WM_SYSCOLORCHANGE, 0, 0);
  270. break;
  271. case WM_COMMAND:
  272. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  273. case IDC_HC_ENABLE:
  274. g_hc.dwFlags ^= HCF_HIGHCONTRASTON;
  275. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM) hwnd, 0);
  276. break;
  277. case IDC_HC_SETTINGS:
  278. {
  279. INT_PTR RetValue;
  280. hc = g_hc;
  281. lstrcpy(szScheme, g_hc.lpszDefaultScheme);
  282. RetValue = DialogBox(g_hinst, MAKEINTRESOURCE(IDD_HIGHCONSETTINGS), hwnd, HighContrastDlg);
  283. if ( RetValue == IDCANCEL)
  284. {
  285. g_hc = hc;
  286. lstrcpy(g_hc.lpszDefaultScheme, szScheme);
  287. }
  288. else
  289. {
  290. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM) hwnd, 0);
  291. }
  292. }
  293. break;
  294. }
  295. break;
  296. case WM_NOTIFY:
  297. switch (((NMHDR *)lParam)->code) {
  298. case PSN_APPLY: SetAccessibilitySettings(); break;
  299. case PSN_KILLACTIVE:
  300. KillTimer(hwnd, BLINK);
  301. g_cs.dwCaretBlinkRate = g_cs.dwNewCaretBlinkRate;
  302. g_cs.dwCaretWidth = g_cs.dwNewCaretWidth;
  303. break;
  304. case PSN_SETACTIVE:
  305. SetTimer(hwnd
  306. , BLINK
  307. , (g_cs.dwNewCaretBlinkRate < CURSORMAX)?g_cs.dwNewCaretBlinkRate:0
  308. , NULL);
  309. break;
  310. }
  311. break;
  312. default:
  313. fProcessed = FALSE;
  314. break;
  315. }
  316. return(fProcessed);
  317. }
  318. BOOL IsMUI_Enabled()
  319. {
  320. OSVERSIONINFO verinfo;
  321. LANGID rcLang;
  322. HMODULE hModule;
  323. pfnGetUserDefaultUILanguage gpfnGetUserDefaultUILanguage;
  324. pfnGetSystemDefaultUILanguage gpfnGetSystemDefaultUILanguage;
  325. static g_bPFNLoaded=FALSE;
  326. static g_bMUIStatus=FALSE;
  327. if(g_bPFNLoaded)
  328. return g_bMUIStatus;
  329. g_bPFNLoaded = TRUE;
  330. verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  331. GetVersionEx( &verinfo) ;
  332. if (verinfo.dwMajorVersion == 5)
  333. {
  334. hModule = GetModuleHandle(TEXT("kernel32.dll"));
  335. if (hModule)
  336. {
  337. gpfnGetSystemDefaultUILanguage =
  338. (pfnGetSystemDefaultUILanguage)GetProcAddress(hModule,"GetSystemDefaultUILanguage");
  339. if (gpfnGetSystemDefaultUILanguage)
  340. {
  341. rcLang = (LANGID) gpfnGetSystemDefaultUILanguage();
  342. if (rcLang == 0x409 )
  343. {
  344. gpfnGetUserDefaultUILanguage =
  345. (pfnGetUserDefaultUILanguage)GetProcAddress(hModule,"GetUserDefaultUILanguage");
  346. if (gpfnGetUserDefaultUILanguage)
  347. {
  348. if (rcLang != (LANGID)gpfnGetUserDefaultUILanguage() )
  349. {
  350. g_bMUIStatus = TRUE;
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. return g_bMUIStatus;
  358. }
  359. ///////////////////////////////// End of File /////////////////////////////////