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.

1626 lines
48 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. menu.c
  5. Abstract:
  6. This file implements the system menu management.
  7. Author:
  8. Therese Stowell (thereses) Jan-24-1992 (swiped from Win3.1)
  9. --*/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. BOOL InEM_UNDO=FALSE;
  13. BYTE ColorArray[4];
  14. int Index;
  15. BOOL gbSaveToRegistry;
  16. BOOL gbWriteToConsole;
  17. BOOL gbStartedFromLink;
  18. LONG gcxScreen;
  19. LONG gcyScreen;
  20. UINT gnCurrentPage;
  21. PCONSOLE_STATE_INFO gpStateInfo;
  22. BOOL g_fAutoComplete;
  23. BOOL g_fSaveAutoCompleteState;
  24. /*
  25. * Context Help Ids.
  26. */
  27. CONST DWORD gaConsoleHelpIds[] =
  28. {
  29. IDD_WINDOWED, IDH_DOS_SCREEN_USAGE_WINDOW,
  30. IDD_FULLSCREEN, IDH_DOS_SCREEN_USAGE_FULL,
  31. IDD_DISPLAY_GROUPBOX, -1,
  32. IDD_QUICKEDIT, IDH_CONSOLE_OPTIONS_QUICK_EDIT,
  33. IDD_INSERT, IDH_CONSOLE_OPTIONS_INSERT,
  34. IDD_CURSOR_SMALL, IDH_CONSOLE_OPTIONS_CURSOR,
  35. IDD_CURSOR_MEDIUM, IDH_CONSOLE_OPTIONS_CURSOR,
  36. IDD_CURSOR_LARGE, IDH_CONSOLE_OPTIONS_CURSOR,
  37. IDD_HISTORY_SIZE, IDH_CONSOLE_OPTIONS_BUFF_SIZE,
  38. IDD_HISTORY_SIZESCROLL, IDH_CONSOLE_OPTIONS_BUFF_SIZE,
  39. IDD_HISTORY_NUM, IDH_CONSOLE_OPTIONS_BUFF_NUM,
  40. IDD_HISTORY_NUMSCROLL, IDH_CONSOLE_OPTIONS_BUFF_NUM,
  41. IDD_HISTORY_NODUP, IDH_CONSOLE_OPTIONS_DISCARD_DUPS,
  42. #if defined(FE_SB)
  43. IDD_LANGUAGELIST, IDH_CONSOLE_OPTIONS_LANGUAGE,
  44. IDD_LANGUAGE, IDH_CONSOLE_OPTIONS_LANGUAGE,
  45. #endif
  46. IDD_STATIC, IDH_CONSOLE_FONT_FONT,
  47. IDD_FACENAME, IDH_CONSOLE_FONT_FONT,
  48. IDD_BOLDFONT, IDH_CONSOLE_FONT_BOLD_FONTS,
  49. IDD_PREVIEWLABEL, IDH_DOS_FONT_WINDOW_PREVIEW,
  50. IDD_PREVIEWWINDOW, IDH_DOS_FONT_WINDOW_PREVIEW,
  51. IDD_GROUP, IDH_DOS_FONT_FONT_PREVIEW,
  52. IDD_STATIC2, IDH_DOS_FONT_FONT_PREVIEW,
  53. IDD_STATIC3, IDH_DOS_FONT_FONT_PREVIEW,
  54. IDD_STATIC4, IDH_DOS_FONT_FONT_PREVIEW,
  55. IDD_FONTWIDTH, IDH_DOS_FONT_FONT_PREVIEW,
  56. IDD_FONTHEIGHT, IDH_DOS_FONT_FONT_PREVIEW,
  57. IDD_FONTWINDOW, IDH_DOS_FONT_FONT_PREVIEW,
  58. IDD_FONTSIZE, IDH_DOS_FONT_SIZE,
  59. IDD_POINTSLIST, IDH_DOS_FONT_SIZE,
  60. IDD_PIXELSLIST, IDH_DOS_FONT_SIZE,
  61. IDD_SCRBUF_WIDTH, IDH_CONSOLE_SIZE_BUFF_WIDTH,
  62. IDD_SCRBUF_WIDTHSCROLL, IDH_CONSOLE_SIZE_BUFF_WIDTH,
  63. IDD_SCRBUF_HEIGHT, IDH_CONSOLE_SIZE_BUFF_HEIGHT,
  64. IDD_SCRBUF_HEIGHTSCROLL, IDH_CONSOLE_SIZE_BUFF_HEIGHT,
  65. IDD_WINDOW_WIDTH, IDH_CONSOLE_SIZE_WIN_WIDTH,
  66. IDD_WINDOW_WIDTHSCROLL, IDH_CONSOLE_SIZE_WIN_WIDTH,
  67. IDD_WINDOW_HEIGHT, IDH_CONSOLE_SIZE_WIN_HEIGHT,
  68. IDD_WINDOW_HEIGHTSCROLL, IDH_CONSOLE_SIZE_WIN_HEIGHT,
  69. IDD_WINDOW_POSX, IDH_CONSOLE_SIZE_POS_LEFT,
  70. IDD_WINDOW_POSXSCROLL, IDH_CONSOLE_SIZE_POS_LEFT,
  71. IDD_WINDOW_POSY, IDH_CONSOLE_SIZE_POS_TOP,
  72. IDD_WINDOW_POSYSCROLL, IDH_CONSOLE_SIZE_POS_TOP,
  73. IDD_AUTO_POSITION, IDH_CONSOLE_SIZE_LET_SYS,
  74. IDD_COLOR_SCREEN_TEXT, IDH_CONSOLE_COLOR_SCR_TEXT,
  75. IDD_COLOR_SCREEN_BKGND, IDH_CONSOLE_COLOR_SCR_BACK,
  76. IDD_COLOR_POPUP_TEXT, IDH_CONSOLE_COLOR_POPUP_TEXT,
  77. IDD_COLOR_POPUP_BKGND, IDH_CONSOLE_COLOR_POPUP_BACK,
  78. IDD_COLOR_1, IDH_CONSOLE_COLOR_COLOR_BAR,
  79. IDD_COLOR_2, IDH_CONSOLE_COLOR_COLOR_BAR,
  80. IDD_COLOR_3, IDH_CONSOLE_COLOR_COLOR_BAR,
  81. IDD_COLOR_4, IDH_CONSOLE_COLOR_COLOR_BAR,
  82. IDD_COLOR_5, IDH_CONSOLE_COLOR_COLOR_BAR,
  83. IDD_COLOR_6, IDH_CONSOLE_COLOR_COLOR_BAR,
  84. IDD_COLOR_7, IDH_CONSOLE_COLOR_COLOR_BAR,
  85. IDD_COLOR_8, IDH_CONSOLE_COLOR_COLOR_BAR,
  86. IDD_COLOR_9, IDH_CONSOLE_COLOR_COLOR_BAR,
  87. IDD_COLOR_10, IDH_CONSOLE_COLOR_COLOR_BAR,
  88. IDD_COLOR_11, IDH_CONSOLE_COLOR_COLOR_BAR,
  89. IDD_COLOR_12, IDH_CONSOLE_COLOR_COLOR_BAR,
  90. IDD_COLOR_13, IDH_CONSOLE_COLOR_COLOR_BAR,
  91. IDD_COLOR_14, IDH_CONSOLE_COLOR_COLOR_BAR,
  92. IDD_COLOR_15, IDH_CONSOLE_COLOR_COLOR_BAR,
  93. IDD_COLOR_16, IDH_CONSOLE_COLOR_COLOR_BAR,
  94. IDD_COLOR_SCREEN_COLORS, IDH_CONSOLE_COLOR_SCR_COLORS,
  95. IDD_COLOR_POPUP_COLORS, IDH_CONSOLE_COLOR_WIN_COLORS,
  96. IDD_COLOR_RED, IDH_CONSOLE_COLOR_RED,
  97. IDD_COLOR_REDSCROLL, IDH_CONSOLE_COLOR_RED,
  98. IDD_COLOR_GREEN, IDH_CONSOLE_COLOR_RED,
  99. IDD_COLOR_GREENSCROLL, IDH_CONSOLE_COLOR_RED,
  100. IDD_COLOR_BLUE, IDH_CONSOLE_COLOR_RED,
  101. IDD_COLOR_BLUESCROLL, IDH_CONSOLE_COLOR_RED,
  102. IDD_AUTOCOMPLETE, IDH_CONSOLE_OPTIONS_AUTOCOMPLETE,
  103. 0, 0
  104. };
  105. VOID
  106. UpdateItem(
  107. HWND hDlg,
  108. UINT item,
  109. UINT nNum
  110. )
  111. {
  112. SetDlgItemInt(hDlg, item, nNum, TRUE);
  113. SendDlgItemMessage(hDlg, item, EM_SETSEL, 0, (DWORD)-1);
  114. }
  115. BOOL
  116. CheckNum(
  117. HWND hDlg,
  118. UINT Item)
  119. {
  120. int i;
  121. TCHAR szNum[5];
  122. BOOL fSigned;
  123. if (Item == IDD_WINDOW_POSX || Item == IDD_WINDOW_POSY) {
  124. fSigned = TRUE;
  125. } else {
  126. fSigned = FALSE;
  127. }
  128. GetDlgItemText(hDlg, Item, szNum, NELEM(szNum));
  129. for (i = 0; szNum[i]; i++) {
  130. if (!iswdigit(szNum[i]) && (!fSigned || i > 0 || szNum[i] != TEXT('-')))
  131. return FALSE;
  132. }
  133. return TRUE;
  134. }
  135. INT_PTR
  136. CommonDlgProc(
  137. HWND hDlg,
  138. UINT wMsg,
  139. WPARAM wParam,
  140. LPARAM lParam
  141. )
  142. {
  143. switch (wMsg) {
  144. case WM_HELP:
  145. WinHelp(((LPHELPINFO)lParam)->hItemHandle, NULL, HELP_WM_HELP, (ULONG_PTR)gaConsoleHelpIds);
  146. break;
  147. case WM_CONTEXTMENU:
  148. WinHelp((HWND)wParam, NULL, HELP_CONTEXTMENU, (ULONG_PTR)gaConsoleHelpIds);
  149. break;
  150. default:
  151. break;
  152. }
  153. return FALSE;
  154. }
  155. INT_PTR
  156. WINAPI
  157. SaveQueryDlgProc(
  158. HWND hDlg,
  159. UINT wMsg,
  160. WPARAM wParam,
  161. LPARAM lParam
  162. )
  163. {
  164. HFONT hFont;
  165. HWND hChild;
  166. HWND hCreator;
  167. switch (wMsg) {
  168. case WM_INITDIALOG:
  169. /*
  170. * Save the handle of the window that created us
  171. */
  172. hCreator = (HWND)lParam;
  173. SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam);
  174. /*
  175. * Get the font used in other controls
  176. */
  177. hChild = GetWindow(hCreator, GW_CHILD);
  178. hFont = GetWindowFont(hChild);
  179. /*
  180. * Now apply it to our controls
  181. */
  182. hChild = GetWindow(hDlg, GW_CHILD);
  183. while (hChild != NULL) {
  184. SetWindowFont(hChild, hFont, TRUE);
  185. hChild = GetWindow(hChild, GW_HWNDNEXT);
  186. }
  187. CheckRadioButton(hDlg, IDD_APPLY, IDD_SAVE, IDD_APPLY);
  188. gbSaveToRegistry = FALSE;
  189. gbWriteToConsole = FALSE;
  190. return TRUE;
  191. case WM_COMMAND:
  192. switch (LOWORD(wParam)) {
  193. case IDOK:
  194. if (IsDlgButtonChecked(hDlg, IDD_SAVE)) {
  195. gbSaveToRegistry = TRUE;
  196. }
  197. gbWriteToConsole = TRUE;
  198. EndDialog(hDlg, PSNRET_NOERROR);
  199. return TRUE;
  200. case IDCANCEL:
  201. EndDialog(hDlg, PSNRET_INVALID_NOCHANGEPAGE);
  202. return TRUE;
  203. }
  204. break;
  205. case WM_CTLCOLORMSGBOX:
  206. case WM_CTLCOLOREDIT:
  207. case WM_CTLCOLORLISTBOX:
  208. case WM_CTLCOLORBTN:
  209. case WM_CTLCOLORDLG:
  210. case WM_CTLCOLORSCROLLBAR:
  211. case WM_CTLCOLORSTATIC:
  212. /*
  213. * Let the window who created us decide what colors to use
  214. */
  215. hCreator = (HWND)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  216. return SendMessage(hCreator, wMsg, wParam, lParam);
  217. }
  218. return FALSE;
  219. }
  220. UINT
  221. ConsolePropSheetProc(
  222. HWND hDlg,
  223. UINT wMsg,
  224. LPARAM lParam
  225. )
  226. {
  227. DWORD dwExStyle;
  228. switch (wMsg) {
  229. case PSCB_INITIALIZED:
  230. /*
  231. * If we're connected to the server, tell him we're starting
  232. */
  233. if (gpStateInfo->hWnd != NULL) {
  234. SendMessage(gpStateInfo->hWnd, CM_PROPERTIES_START, (WPARAM)hDlg, 0);
  235. }
  236. break;
  237. default:
  238. break;
  239. }
  240. return 0;
  241. }
  242. VOID
  243. EndDlgPage(
  244. HWND hDlg
  245. )
  246. {
  247. HWND hParent;
  248. HWND hTabCtrl;
  249. INT_PTR Result;
  250. /*
  251. * If we've already made a decision, we're done
  252. */
  253. if (gbWriteToConsole || gbSaveToRegistry) {
  254. SetDlgMsgResult(hDlg, PSN_APPLY, PSNRET_NOERROR);
  255. return;
  256. }
  257. /*
  258. * Get the current page number
  259. */
  260. hParent = GetParent(hDlg);
  261. hTabCtrl = PropSheet_GetTabControl(hParent);
  262. gnCurrentPage = TabCtrl_GetCurSel(hTabCtrl);
  263. /*
  264. * If we're not connected to the server, we're done
  265. */
  266. if (gpStateInfo->hWnd == NULL) {
  267. gbSaveToRegistry = TRUE;
  268. SetDlgMsgResult(hDlg, PSN_APPLY, PSNRET_NOERROR);
  269. return;
  270. }
  271. /*
  272. * Check to show the Apply/Save dialog box
  273. */
  274. if (gbStartedFromLink)
  275. {
  276. Result = DialogBoxParam(ghInstance, MAKEINTRESOURCE(DID_SAVE_QUERY_LINK),
  277. GetParent(hDlg), SaveQueryDlgProc, (LPARAM)hDlg);
  278. SetDlgMsgResult(hDlg, PSN_APPLY, Result);
  279. }
  280. else
  281. {
  282. Result = DialogBoxParam(ghInstance, MAKEINTRESOURCE(DID_SAVE_QUERY),
  283. GetParent(hDlg), SaveQueryDlgProc, (LPARAM)hDlg);
  284. SetDlgMsgResult(hDlg, PSN_APPLY, Result);
  285. }
  286. return;
  287. }
  288. LRESULT
  289. ColorControlProc(
  290. HWND hColor,
  291. UINT wMsg,
  292. WPARAM wParam,
  293. LPARAM lParam
  294. )
  295. /*++
  296. Window proc for the color buttons
  297. --*/
  298. {
  299. PAINTSTRUCT ps;
  300. int ColorId;
  301. RECT rColor;
  302. RECT rTemp;
  303. HBRUSH hbr;
  304. HDC hdc;
  305. HWND hWnd;
  306. HWND hDlg;
  307. COLORREF rgbBrush;
  308. ColorId = GetWindowLong(hColor, GWL_ID);
  309. hDlg = GetParent(hColor);
  310. switch (wMsg) {
  311. case WM_GETDLGCODE:
  312. return DLGC_WANTARROWS | DLGC_WANTTAB;
  313. break;
  314. case WM_SETFOCUS:
  315. if (ColorArray[Index] != (BYTE)(ColorId - IDD_COLOR_1)) {
  316. hWnd = GetDlgItem(hDlg, ColorArray[Index]+IDD_COLOR_1);
  317. SetFocus(hWnd);
  318. }
  319. // Fall through
  320. case WM_KILLFOCUS:
  321. hdc = GetDC(hDlg);
  322. hWnd = GetDlgItem(hDlg, IDD_COLOR_1);
  323. GetWindowRect(hWnd, &rColor);
  324. hWnd = GetDlgItem(hDlg, IDD_COLOR_16);
  325. GetWindowRect(hWnd, &rTemp);
  326. rColor.right = rTemp.right;
  327. ScreenToClient(hDlg, (LPPOINT)&rColor.left);
  328. ScreenToClient(hDlg, (LPPOINT)&rColor.right);
  329. InflateRect(&rColor, 2, 2);
  330. DrawFocusRect(hdc, &rColor);
  331. ReleaseDC(hDlg, hdc);
  332. break;
  333. case WM_KEYDOWN:
  334. switch (wParam) {
  335. case VK_UP:
  336. case VK_LEFT:
  337. if (ColorId > IDD_COLOR_1) {
  338. SendMessage(hDlg, CM_SETCOLOR,
  339. ColorId - 1 - IDD_COLOR_1, (LPARAM)hColor);
  340. }
  341. break;
  342. case VK_DOWN:
  343. case VK_RIGHT:
  344. if (ColorId < IDD_COLOR_16) {
  345. SendMessage(hDlg, CM_SETCOLOR,
  346. ColorId + 1 - IDD_COLOR_1, (LPARAM)hColor);
  347. }
  348. break;
  349. case VK_TAB:
  350. hWnd = GetDlgItem(hDlg, IDD_COLOR_1);
  351. hWnd = GetNextDlgTabItem(hDlg, hWnd, GetKeyState(VK_SHIFT) < 0);
  352. SetFocus(hWnd);
  353. break;
  354. default:
  355. return DefWindowProc(hColor, wMsg, wParam, lParam);
  356. }
  357. break;
  358. case WM_RBUTTONDOWN:
  359. case WM_LBUTTONDOWN:
  360. SendMessage(hDlg, CM_SETCOLOR,
  361. ColorId - IDD_COLOR_1, (LPARAM)hColor);
  362. break;
  363. case WM_PAINT:
  364. BeginPaint(hColor, &ps);
  365. GetClientRect(hColor, &rColor);
  366. rgbBrush = GetNearestColor(ps.hdc, AttrToRGB(ColorId-IDD_COLOR_1));
  367. if ((hbr = CreateSolidBrush(rgbBrush)) != NULL) {
  368. //
  369. // are we the selected color for the current object?
  370. //
  371. if (ColorArray[Index] == (BYTE)(ColorId - IDD_COLOR_1)) {
  372. //
  373. // put current values in dialog box
  374. //
  375. UpdateItem(hDlg, IDD_COLOR_RED,
  376. GetRValue(AttrToRGB(ColorArray[Index])));
  377. UpdateItem(hDlg, IDD_COLOR_GREEN,
  378. GetGValue(AttrToRGB(ColorArray[Index])));
  379. UpdateItem(hDlg, IDD_COLOR_BLUE,
  380. GetBValue(AttrToRGB(ColorArray[Index])));
  381. //
  382. // highlight the selected color
  383. //
  384. FrameRect(ps.hdc, &rColor, GetStockObject(BLACK_BRUSH));
  385. InflateRect(&rColor, -1, -1);
  386. FrameRect(ps.hdc, &rColor, GetStockObject(BLACK_BRUSH));
  387. }
  388. InflateRect(&rColor, -1, -1);
  389. FillRect(ps.hdc, &rColor, hbr);
  390. DeleteObject(hbr);
  391. }
  392. EndPaint(hColor, &ps);
  393. break;
  394. default:
  395. return DefWindowProc(hColor, wMsg, wParam, lParam);
  396. break;
  397. }
  398. return TRUE;
  399. }
  400. INT_PTR
  401. WINAPI
  402. ColorDlgProc(
  403. HWND hDlg,
  404. UINT wMsg,
  405. WPARAM wParam,
  406. LPARAM lParam
  407. )
  408. /*++
  409. Dialog proc for the color selection dialog box.
  410. --*/
  411. {
  412. UINT Value;
  413. UINT Red;
  414. UINT Green;
  415. UINT Blue;
  416. UINT Item;
  417. HWND hWnd;
  418. HWND hWndOld;
  419. BOOL bOK;
  420. switch (wMsg) {
  421. case WM_INITDIALOG:
  422. ColorArray[IDD_COLOR_SCREEN_TEXT - IDD_COLOR_SCREEN_TEXT] =
  423. LOBYTE(gpStateInfo->ScreenAttributes) & 0x0F;
  424. ColorArray[IDD_COLOR_SCREEN_BKGND - IDD_COLOR_SCREEN_TEXT] =
  425. LOBYTE(gpStateInfo->ScreenAttributes >> 4);
  426. ColorArray[IDD_COLOR_POPUP_TEXT - IDD_COLOR_SCREEN_TEXT] =
  427. LOBYTE(gpStateInfo->PopupAttributes) & 0x0F;
  428. ColorArray[IDD_COLOR_POPUP_BKGND - IDD_COLOR_SCREEN_TEXT] =
  429. LOBYTE(gpStateInfo->PopupAttributes >> 4);
  430. CheckRadioButton(hDlg,IDD_COLOR_SCREEN_TEXT,IDD_COLOR_POPUP_BKGND,IDD_COLOR_SCREEN_BKGND);
  431. Index = IDD_COLOR_SCREEN_BKGND - IDD_COLOR_SCREEN_TEXT;
  432. // initialize size of edit controls
  433. SendDlgItemMessage(hDlg, IDD_COLOR_RED, EM_LIMITTEXT, 3, 0L);
  434. SendDlgItemMessage(hDlg, IDD_COLOR_GREEN, EM_LIMITTEXT, 3, 0L);
  435. SendDlgItemMessage(hDlg, IDD_COLOR_BLUE, EM_LIMITTEXT, 3, 0L);
  436. // initialize arrow controls
  437. SendDlgItemMessage(hDlg, IDD_COLOR_REDSCROLL, UDM_SETRANGE, 0,
  438. MAKELONG(255, 0));
  439. SendDlgItemMessage(hDlg, IDD_COLOR_REDSCROLL, UDM_SETPOS, 0,
  440. MAKELONG(GetRValue(AttrToRGB(ColorArray[Index])), 0));
  441. SendDlgItemMessage(hDlg, IDD_COLOR_GREENSCROLL, UDM_SETRANGE, 0,
  442. MAKELONG(255, 0));
  443. SendDlgItemMessage(hDlg, IDD_COLOR_GREENSCROLL, UDM_SETPOS, 0,
  444. MAKELONG(GetGValue(AttrToRGB(ColorArray[Index])), 0));
  445. SendDlgItemMessage(hDlg, IDD_COLOR_BLUESCROLL, UDM_SETRANGE, 0,
  446. MAKELONG(255, 0));
  447. SendDlgItemMessage(hDlg, IDD_COLOR_BLUESCROLL, UDM_SETPOS, 0,
  448. MAKELONG(GetBValue(AttrToRGB(ColorArray[Index])), 0));
  449. return TRUE;
  450. case WM_COMMAND:
  451. Item = LOWORD(wParam);
  452. switch (Item) {
  453. case IDD_COLOR_SCREEN_TEXT:
  454. case IDD_COLOR_SCREEN_BKGND:
  455. case IDD_COLOR_POPUP_TEXT:
  456. case IDD_COLOR_POPUP_BKGND:
  457. hWndOld = GetDlgItem(hDlg, ColorArray[Index]+IDD_COLOR_1);
  458. Index = Item - IDD_COLOR_SCREEN_TEXT;
  459. // repaint new color
  460. hWnd = GetDlgItem(hDlg, ColorArray[Index]+IDD_COLOR_1);
  461. InvalidateRect(hWnd, NULL, TRUE);
  462. // repaint old color
  463. if (hWndOld != hWnd) {
  464. InvalidateRect(hWndOld, NULL, TRUE);
  465. }
  466. return TRUE;
  467. case IDD_COLOR_RED:
  468. case IDD_COLOR_GREEN:
  469. case IDD_COLOR_BLUE:
  470. switch (HIWORD(wParam)) {
  471. case EN_UPDATE:
  472. if (!CheckNum (hDlg, Item)) {
  473. if (!InEM_UNDO) {
  474. InEM_UNDO = TRUE;
  475. SendMessage((HWND)lParam, EM_UNDO, 0, 0L);
  476. InEM_UNDO = FALSE;
  477. }
  478. }
  479. break;
  480. case EN_KILLFOCUS:
  481. /*
  482. * Update the state info structure
  483. */
  484. Value = GetDlgItemInt(hDlg, Item, &bOK, TRUE);
  485. if (bOK) {
  486. if (Value > 255) {
  487. UpdateItem(hDlg, Item, 255);
  488. Value = 255;
  489. }
  490. if (Item == IDD_COLOR_RED) {
  491. Red = Value;
  492. } else {
  493. Red = GetRValue(AttrToRGB(ColorArray[Index]));
  494. }
  495. if (Item == IDD_COLOR_GREEN) {
  496. Green = Value;
  497. } else {
  498. Green = GetGValue(AttrToRGB(ColorArray[Index]));
  499. }
  500. if (Item == IDD_COLOR_BLUE) {
  501. Blue = Value;
  502. } else {
  503. Blue = GetBValue(AttrToRGB(ColorArray[Index]));
  504. }
  505. UpdateStateInfo(hDlg, ColorArray[Index] + IDD_COLOR_1,
  506. RGB(Red, Green, Blue));
  507. }
  508. /*
  509. * Update the preview windows with the new value
  510. */
  511. hWnd = GetDlgItem(hDlg, IDD_COLOR_SCREEN_COLORS);
  512. InvalidateRect(hWnd, NULL, FALSE);
  513. hWnd = GetDlgItem(hDlg, IDD_COLOR_POPUP_COLORS);
  514. InvalidateRect(hWnd, NULL, FALSE);
  515. hWnd = GetDlgItem(hDlg, ColorArray[Index]+IDD_COLOR_1);
  516. InvalidateRect(hWnd, NULL, FALSE);
  517. break;
  518. }
  519. return TRUE;
  520. }
  521. break;
  522. case WM_NOTIFY:
  523. switch (((LPNMHDR)lParam)->code) {
  524. case PSN_APPLY:
  525. /*
  526. * Write out the state values and exit.
  527. */
  528. EndDlgPage(hDlg);
  529. return TRUE;
  530. case PSN_KILLACTIVE:
  531. /*
  532. * Fake the dialog proc into thinking the edit control just
  533. * lost focus so it'll update properly
  534. */
  535. if (Item = GetDlgCtrlID(GetFocus())) {
  536. SendMessage(hDlg, WM_COMMAND, MAKELONG(Item, EN_KILLFOCUS), 0);
  537. }
  538. return TRUE;
  539. }
  540. break;
  541. case WM_VSCROLL:
  542. /*
  543. * Fake the dialog proc into thinking the edit control just
  544. * lost focus so it'll update properly
  545. */
  546. Item = GetDlgCtrlID((HWND)lParam) - 1;
  547. SendMessage(hDlg, WM_COMMAND, MAKELONG(Item, EN_KILLFOCUS), 0);
  548. return TRUE;
  549. case CM_SETCOLOR:
  550. UpdateStateInfo(hDlg, Index + IDD_COLOR_SCREEN_TEXT, (UINT)wParam);
  551. hWndOld = GetDlgItem(hDlg, ColorArray[Index]+IDD_COLOR_1);
  552. ColorArray[Index] = (BYTE)wParam;
  553. /* Force the preview window to repaint */
  554. if (Index < (IDD_COLOR_POPUP_TEXT - IDD_COLOR_SCREEN_TEXT)) {
  555. hWnd = GetDlgItem(hDlg, IDD_COLOR_SCREEN_COLORS);
  556. } else {
  557. hWnd = GetDlgItem(hDlg, IDD_COLOR_POPUP_COLORS);
  558. }
  559. InvalidateRect(hWnd, NULL, TRUE);
  560. // repaint new color
  561. hWnd = GetDlgItem(hDlg, ColorArray[Index]+IDD_COLOR_1);
  562. InvalidateRect(hWnd, NULL, TRUE);
  563. SetFocus(hWnd);
  564. // repaint old color
  565. if (hWndOld != hWnd) {
  566. InvalidateRect(hWndOld, NULL, TRUE);
  567. }
  568. return TRUE;
  569. default:
  570. break;
  571. }
  572. return CommonDlgProc(hDlg, wMsg, wParam, lParam);
  573. }
  574. int
  575. GetStateInfo(
  576. HWND hDlg,
  577. UINT Item,
  578. BOOL *bOK
  579. )
  580. {
  581. int Value = 0;
  582. *bOK = TRUE;
  583. switch (Item) {
  584. case IDD_SCRBUF_WIDTH:
  585. Value = gpStateInfo->ScreenBufferSize.X;
  586. break;
  587. case IDD_SCRBUF_HEIGHT:
  588. Value = gpStateInfo->ScreenBufferSize.Y;
  589. break;
  590. case IDD_WINDOW_WIDTH:
  591. Value = gpStateInfo->WindowSize.X;
  592. break;
  593. case IDD_WINDOW_HEIGHT:
  594. Value = gpStateInfo->WindowSize.Y;
  595. break;
  596. case IDD_WINDOW_POSX:
  597. Value = gpStateInfo->WindowPosX;
  598. break;
  599. case IDD_WINDOW_POSY:
  600. Value = gpStateInfo->WindowPosY;
  601. break;
  602. default:
  603. *bOK = FALSE;
  604. break;
  605. }
  606. return Value;
  607. }
  608. BOOL
  609. UpdateStateInfo(
  610. HWND hDlg,
  611. UINT Item,
  612. int Value
  613. )
  614. {
  615. switch (Item) {
  616. case IDD_SCRBUF_WIDTH:
  617. gpStateInfo->ScreenBufferSize.X = (SHORT)Value;
  618. if (gpStateInfo->WindowSize.X > Value) {
  619. gpStateInfo->WindowSize.X = (SHORT)Value;
  620. UpdateItem(hDlg, IDD_WINDOW_WIDTH, Value);
  621. }
  622. break;
  623. case IDD_SCRBUF_HEIGHT:
  624. gpStateInfo->ScreenBufferSize.Y = (SHORT)Value;
  625. if (gpStateInfo->WindowSize.Y > Value) {
  626. gpStateInfo->WindowSize.Y = (SHORT)Value;
  627. UpdateItem(hDlg, IDD_WINDOW_HEIGHT, Value);
  628. }
  629. break;
  630. case IDD_WINDOW_WIDTH:
  631. gpStateInfo->WindowSize.X = (SHORT)Value;
  632. if (gpStateInfo->ScreenBufferSize.X < Value) {
  633. gpStateInfo->ScreenBufferSize.X = (SHORT)Value;
  634. UpdateItem(hDlg, IDD_SCRBUF_WIDTH, Value);
  635. }
  636. break;
  637. case IDD_WINDOW_HEIGHT:
  638. gpStateInfo->WindowSize.Y = (SHORT)Value;
  639. if (gpStateInfo->ScreenBufferSize.Y < Value) {
  640. gpStateInfo->ScreenBufferSize.Y = (SHORT)Value;
  641. UpdateItem(hDlg, IDD_SCRBUF_HEIGHT, Value);
  642. }
  643. break;
  644. case IDD_WINDOW_POSX:
  645. gpStateInfo->WindowPosX = Value;
  646. break;
  647. case IDD_WINDOW_POSY:
  648. gpStateInfo->WindowPosY = Value;
  649. break;
  650. case IDD_AUTO_POSITION:
  651. gpStateInfo->AutoPosition = Value;
  652. break;
  653. case IDD_COLOR_SCREEN_TEXT:
  654. gpStateInfo->ScreenAttributes =
  655. (gpStateInfo->ScreenAttributes & 0xF0) |
  656. (Value & 0x0F);
  657. break;
  658. case IDD_COLOR_SCREEN_BKGND:
  659. gpStateInfo->ScreenAttributes =
  660. (gpStateInfo->ScreenAttributes & 0x0F) |
  661. (Value << 4);
  662. break;
  663. case IDD_COLOR_POPUP_TEXT:
  664. gpStateInfo->PopupAttributes =
  665. (gpStateInfo->PopupAttributes & 0xF0) |
  666. (Value & 0x0F);
  667. break;
  668. case IDD_COLOR_POPUP_BKGND:
  669. gpStateInfo->PopupAttributes =
  670. (gpStateInfo->PopupAttributes & 0x0F) |
  671. (Value << 4);
  672. break;
  673. case IDD_COLOR_1:
  674. case IDD_COLOR_2:
  675. case IDD_COLOR_3:
  676. case IDD_COLOR_4:
  677. case IDD_COLOR_5:
  678. case IDD_COLOR_6:
  679. case IDD_COLOR_7:
  680. case IDD_COLOR_8:
  681. case IDD_COLOR_9:
  682. case IDD_COLOR_10:
  683. case IDD_COLOR_11:
  684. case IDD_COLOR_12:
  685. case IDD_COLOR_13:
  686. case IDD_COLOR_14:
  687. case IDD_COLOR_15:
  688. case IDD_COLOR_16:
  689. gpStateInfo->ColorTable[Item - IDD_COLOR_1] = Value;
  690. break;
  691. #ifdef i386
  692. case IDD_FULLSCREEN:
  693. gpStateInfo->FullScreen = TRUE;
  694. break;
  695. case IDD_WINDOWED:
  696. gpStateInfo->FullScreen = FALSE;
  697. break;
  698. #endif
  699. #if defined(FE_SB)
  700. case IDD_LANGUAGELIST:
  701. /*
  702. * Value is a code page
  703. */
  704. gpStateInfo->CodePage = Value;
  705. break;
  706. #endif
  707. case IDD_QUICKEDIT:
  708. gpStateInfo->QuickEdit = Value;
  709. break;
  710. case IDD_AUTOCOMPLETE:
  711. g_fAutoComplete = Value;
  712. g_fSaveAutoCompleteState = TRUE;
  713. break;
  714. case IDD_INSERT:
  715. gpStateInfo->InsertMode = Value;
  716. break;
  717. case IDD_HISTORY_SIZE:
  718. gpStateInfo->HistoryBufferSize = max(Value, 1);
  719. break;
  720. case IDD_HISTORY_NUM:
  721. gpStateInfo->NumberOfHistoryBuffers = max(Value, 1);
  722. break;
  723. case IDD_HISTORY_NODUP:
  724. gpStateInfo->HistoryNoDup = Value;
  725. break;
  726. case IDD_CURSOR_SMALL:
  727. gpStateInfo->CursorSize = 25;
  728. break;
  729. case IDD_CURSOR_MEDIUM:
  730. gpStateInfo->CursorSize = 50;
  731. break;
  732. case IDD_CURSOR_LARGE:
  733. gpStateInfo->CursorSize = 100;
  734. break;
  735. default:
  736. return FALSE;
  737. }
  738. return TRUE;
  739. }
  740. VOID
  741. UpdateWarningMessage(
  742. HWND hDlg,
  743. BOOL fLoadString
  744. )
  745. {
  746. static WCHAR achFormat[256];
  747. WCHAR achText[NELEM(achFormat)+4];
  748. HWND hWnd;
  749. UINT Value;
  750. /*
  751. * Load the format string, if requested.
  752. */
  753. if (fLoadString) {
  754. LoadString(ghInstance, IDS_WARNING, achFormat, NELEM(achFormat));
  755. }
  756. /*
  757. * Put up the warning message if we're using more than 1 Meg
  758. * of memory per console window, otherwise hide it.
  759. */
  760. hWnd = GetDlgItem(hDlg, IDD_WARNING);
  761. Value = (gpStateInfo->ScreenBufferSize.X *
  762. gpStateInfo->ScreenBufferSize.Y) / 0x080000;
  763. if (Value) {
  764. wsprintf(achText, achFormat, Value);
  765. SetWindowText(hWnd, achText);
  766. ShowWindow(hWnd, SW_SHOW);
  767. } else {
  768. ShowWindow(hWnd, SW_HIDE);
  769. }
  770. }
  771. INT_PTR
  772. WINAPI
  773. ScreenSizeDlgProc(
  774. HWND hDlg,
  775. UINT wMsg,
  776. WPARAM wParam,
  777. LPARAM lParam
  778. )
  779. /*++
  780. Dialog proc for the screen size dialog box.
  781. --*/
  782. {
  783. UINT Value;
  784. UINT Item;
  785. HWND hWnd;
  786. BOOL bOK;
  787. LONG xScreen;
  788. LONG yScreen;
  789. LONG cxScreen;
  790. LONG cyScreen;
  791. LONG cxFrame;
  792. LONG cyFrame;
  793. switch (wMsg) {
  794. case WM_INITDIALOG:
  795. // initialize size of edit controls
  796. SendDlgItemMessage(hDlg, IDD_SCRBUF_WIDTH, EM_LIMITTEXT, 4, 0L);
  797. SendDlgItemMessage(hDlg, IDD_SCRBUF_HEIGHT, EM_LIMITTEXT, 4, 0L);
  798. SendDlgItemMessage(hDlg, IDD_WINDOW_WIDTH, EM_LIMITTEXT, 4, 0L);
  799. SendDlgItemMessage(hDlg, IDD_WINDOW_HEIGHT, EM_LIMITTEXT, 4, 0L);
  800. SendDlgItemMessage(hDlg, IDD_WINDOW_POSX, EM_LIMITTEXT, 4, 0L);
  801. SendDlgItemMessage(hDlg, IDD_WINDOW_POSY, EM_LIMITTEXT, 4, 0L);
  802. // Get some system parameters
  803. xScreen = GetSystemMetrics(SM_XVIRTUALSCREEN);
  804. yScreen = GetSystemMetrics(SM_YVIRTUALSCREEN);
  805. cxScreen = GetSystemMetrics(SM_CXVIRTUALSCREEN);
  806. cyScreen = GetSystemMetrics(SM_CYVIRTUALSCREEN);
  807. cxFrame = GetSystemMetrics(SM_CXFRAME);
  808. cyFrame = GetSystemMetrics(SM_CYFRAME);
  809. // initialize arrow controls
  810. SendDlgItemMessage(hDlg, IDD_SCRBUF_WIDTHSCROLL, UDM_SETRANGE, 0,
  811. MAKELONG(9999, 1));
  812. SendDlgItemMessage(hDlg, IDD_SCRBUF_WIDTHSCROLL, UDM_SETPOS, 0,
  813. MAKELONG(gpStateInfo->ScreenBufferSize.X, 0));
  814. SendDlgItemMessage(hDlg, IDD_SCRBUF_HEIGHTSCROLL, UDM_SETRANGE, 0,
  815. MAKELONG(9999, 1));
  816. SendDlgItemMessage(hDlg, IDD_SCRBUF_HEIGHTSCROLL, UDM_SETPOS, 0,
  817. MAKELONG(gpStateInfo->ScreenBufferSize.Y, 0));
  818. SendDlgItemMessage(hDlg, IDD_WINDOW_WIDTHSCROLL, UDM_SETRANGE, 0,
  819. MAKELONG(9999, 1));
  820. SendDlgItemMessage(hDlg, IDD_WINDOW_WIDTHSCROLL, UDM_SETPOS, 0,
  821. MAKELONG(gpStateInfo->WindowSize.X, 0));
  822. SendDlgItemMessage(hDlg, IDD_WINDOW_HEIGHTSCROLL, UDM_SETRANGE, 0,
  823. MAKELONG(9999, 1));
  824. SendDlgItemMessage(hDlg, IDD_WINDOW_HEIGHTSCROLL, UDM_SETPOS, 0,
  825. MAKELONG(gpStateInfo->WindowSize.Y, 0));
  826. SendDlgItemMessage(hDlg, IDD_WINDOW_POSXSCROLL, UDM_SETRANGE, 0,
  827. MAKELONG(xScreen + cxScreen - cxFrame, xScreen - cxFrame));
  828. SendDlgItemMessage(hDlg, IDD_WINDOW_POSXSCROLL, UDM_SETPOS, 0,
  829. MAKELONG(gpStateInfo->WindowPosX, 0));
  830. SendDlgItemMessage(hDlg, IDD_WINDOW_POSYSCROLL, UDM_SETRANGE, 0,
  831. MAKELONG(yScreen + cyScreen - cyFrame, yScreen - cyFrame));
  832. SendDlgItemMessage(hDlg, IDD_WINDOW_POSYSCROLL, UDM_SETPOS, 0,
  833. MAKELONG(gpStateInfo->WindowPosY, 0));
  834. //
  835. // put current values in dialog box
  836. //
  837. CheckDlgButton(hDlg, IDD_AUTO_POSITION, gpStateInfo->AutoPosition);
  838. SendMessage(hDlg, WM_COMMAND, IDD_AUTO_POSITION, 0);
  839. // update the warning message
  840. UpdateWarningMessage(hDlg, TRUE);
  841. return TRUE;
  842. case WM_VSCROLL:
  843. /*
  844. * Fake the dialog proc into thinking the edit control just
  845. * lost focus so it'll update properly
  846. */
  847. Item = GetDlgCtrlID((HWND)lParam) - 1;
  848. SendMessage(hDlg, WM_COMMAND, MAKELONG(Item, EN_KILLFOCUS), 0);
  849. return TRUE;
  850. case WM_COMMAND:
  851. Item = LOWORD(wParam);
  852. switch (Item) {
  853. case IDD_SCRBUF_WIDTH:
  854. case IDD_SCRBUF_HEIGHT:
  855. case IDD_WINDOW_WIDTH:
  856. case IDD_WINDOW_HEIGHT:
  857. case IDD_WINDOW_POSX:
  858. case IDD_WINDOW_POSY:
  859. switch (HIWORD(wParam)) {
  860. case EN_UPDATE:
  861. if (!CheckNum (hDlg, Item)) {
  862. if (!InEM_UNDO) {
  863. InEM_UNDO = TRUE;
  864. SendMessage((HWND)lParam, EM_UNDO, 0, 0L);
  865. InEM_UNDO = FALSE;
  866. }
  867. }
  868. break;
  869. case EN_KILLFOCUS:
  870. /*
  871. * Update the state info structure
  872. */
  873. Value = (UINT)SendDlgItemMessage(hDlg, Item + 1, UDM_GETPOS, 0, 0);
  874. if (HIWORD(Value) == 0) {
  875. UpdateStateInfo(hDlg, Item, (SHORT)LOWORD(Value));
  876. } else {
  877. Value = GetStateInfo(hDlg, Item, &bOK);
  878. if (bOK) {
  879. UpdateItem(hDlg, Item, Value);
  880. }
  881. }
  882. /*
  883. * Update the warning message
  884. */
  885. UpdateWarningMessage(hDlg, FALSE);
  886. /*
  887. * Update the preview window with the new value
  888. */
  889. hWnd = GetDlgItem(hDlg, IDD_PREVIEWWINDOW);
  890. SendMessage(hWnd, CM_PREVIEW_UPDATE, 0, 0);
  891. break;
  892. }
  893. return TRUE;
  894. case IDD_AUTO_POSITION:
  895. Value = IsDlgButtonChecked(hDlg, IDD_AUTO_POSITION);
  896. UpdateStateInfo(hDlg, IDD_AUTO_POSITION, Value);
  897. for (Item = IDD_WINDOW_POSX; Item < IDD_AUTO_POSITION; Item++) {
  898. hWnd = GetDlgItem(hDlg, Item);
  899. EnableWindow(hWnd, (Value == FALSE));
  900. }
  901. break;
  902. default:
  903. break;
  904. }
  905. break;
  906. case WM_NOTIFY:
  907. switch (((LPNMHDR)lParam)->code) {
  908. case PSN_APPLY:
  909. /*
  910. * Write out the state values and exit.
  911. */
  912. EndDlgPage(hDlg);
  913. return TRUE;
  914. case PSN_KILLACTIVE:
  915. /*
  916. * Fake the dialog proc into thinking the edit control just
  917. * lost focus so it'll update properly
  918. */
  919. if (Item = GetDlgCtrlID(GetFocus())) {
  920. SendMessage(hDlg, WM_COMMAND, MAKELONG(Item, EN_KILLFOCUS), 0);
  921. }
  922. return TRUE;
  923. }
  924. break;
  925. default:
  926. break;
  927. }
  928. return CommonDlgProc(hDlg, wMsg, wParam, lParam);
  929. }
  930. INT_PTR
  931. WINAPI
  932. SettingsDlgProc(
  933. HWND hDlg,
  934. UINT wMsg,
  935. WPARAM wParam,
  936. LPARAM lParam
  937. )
  938. /*++
  939. Dialog proc for the settings dialog box.
  940. --*/
  941. {
  942. UINT Value;
  943. UINT Item;
  944. BOOL bOK;
  945. SYSTEM_INFO SystemInfo;
  946. switch (wMsg) {
  947. case WM_INITDIALOG:
  948. GetSystemInfo(&SystemInfo);
  949. if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) {
  950. if (gpStateInfo->FullScreen) {
  951. CheckRadioButton(hDlg,IDD_WINDOWED,IDD_FULLSCREEN,IDD_FULLSCREEN);
  952. } else {
  953. CheckRadioButton(hDlg,IDD_WINDOWED,IDD_FULLSCREEN,IDD_WINDOWED);
  954. }
  955. } else {
  956. ShowWindow(GetDlgItem(hDlg, IDD_WINDOWED), SW_HIDE);
  957. ShowWindow(GetDlgItem(hDlg, IDD_FULLSCREEN), SW_HIDE);
  958. ShowWindow(GetDlgItem(hDlg, IDD_DISPLAY_GROUPBOX), SW_HIDE);
  959. }
  960. CheckDlgButton(hDlg, IDD_HISTORY_NODUP, gpStateInfo->HistoryNoDup);
  961. CheckDlgButton(hDlg, IDD_QUICKEDIT, gpStateInfo->QuickEdit);
  962. CheckDlgButton(hDlg, IDD_INSERT, gpStateInfo->InsertMode);
  963. g_fSaveAutoCompleteState = FALSE;
  964. if (IsWindow(GetDlgItem(hDlg, IDD_AUTOCOMPLETE)))
  965. {
  966. CheckDlgButton(hDlg, IDD_AUTOCOMPLETE, g_fAutoComplete);
  967. }
  968. // initialize cursor radio buttons
  969. if (gpStateInfo->CursorSize <= 25) {
  970. Item = IDD_CURSOR_SMALL;
  971. } else if (gpStateInfo->CursorSize <= 50) {
  972. Item = IDD_CURSOR_MEDIUM;
  973. } else {
  974. Item = IDD_CURSOR_LARGE;
  975. }
  976. CheckRadioButton(hDlg, IDD_CURSOR_SMALL, IDD_CURSOR_LARGE, Item);
  977. SetDlgItemInt(hDlg, IDD_HISTORY_SIZE, gpStateInfo->HistoryBufferSize,
  978. FALSE);
  979. SendDlgItemMessage(hDlg, IDD_HISTORY_SIZE, EM_LIMITTEXT, 3, 0L);
  980. SendDlgItemMessage(hDlg, IDD_HISTORY_SIZESCROLL, UDM_SETRANGE, 0,
  981. MAKELONG(999, 1));
  982. SetDlgItemInt(hDlg, IDD_HISTORY_NUM, gpStateInfo->NumberOfHistoryBuffers,
  983. FALSE);
  984. SendDlgItemMessage(hDlg, IDD_HISTORY_NUM, EM_LIMITTEXT, 3, 0L);
  985. SendDlgItemMessage(hDlg, IDD_HISTORY_NUM, EM_SETSEL, 0, (DWORD)-1);
  986. SendDlgItemMessage(hDlg, IDD_HISTORY_NUMSCROLL, UDM_SETRANGE, 0,
  987. MAKELONG(999, 1));
  988. // FE_SB
  989. // Let users select Default CodePage.
  990. // Per request from PMs, this feature should be activated only for FE enabled NT.
  991. if (gfFESystem) {
  992. if (gpStateInfo->hWnd != NULL) {
  993. LanguageDisplay(hDlg, gpStateInfo->CodePage);
  994. }
  995. else{
  996. LanguageListCreate(hDlg, gpStateInfo->CodePage);
  997. }
  998. }
  999. else {
  1000. // If the system is not FE enabled, just disable and hide them.
  1001. HWND LangHwnd = GetDlgItem(hDlg, IDD_LANGUAGELIST);
  1002. if (LangHwnd) {
  1003. EnableWindow(LangHwnd, FALSE);
  1004. ShowWindow(LangHwnd, SW_HIDE);
  1005. }
  1006. LangHwnd = GetDlgItem(hDlg, IDD_LANGUAGE_GROUPBOX);
  1007. if (LangHwnd) {
  1008. ShowWindow(LangHwnd, SW_HIDE);
  1009. }
  1010. }
  1011. // end FE_SB
  1012. return TRUE;
  1013. case WM_COMMAND:
  1014. Item = LOWORD(wParam);
  1015. switch (Item) {
  1016. #ifdef i386
  1017. case IDD_WINDOWED:
  1018. case IDD_FULLSCREEN:
  1019. UpdateStateInfo(hDlg, Item, 0);
  1020. return TRUE;
  1021. #endif
  1022. // FE_SB
  1023. case IDD_LANGUAGELIST:
  1024. switch (HIWORD(wParam)) {
  1025. case CBN_KILLFOCUS: {
  1026. HWND hWndLanguageCombo;
  1027. LONG lListIndex;
  1028. hWndLanguageCombo = GetDlgItem(hDlg, IDD_LANGUAGELIST);
  1029. lListIndex = (LONG)SendMessage(hWndLanguageCombo, CB_GETCURSEL, 0, 0L);
  1030. Value = (UINT)SendMessage(hWndLanguageCombo, CB_GETITEMDATA, lListIndex, 0L);
  1031. if (Value != -1) {
  1032. fChangeCodePage = (Value != gpStateInfo->CodePage);
  1033. UpdateStateInfo(hDlg, Item, Value);
  1034. }
  1035. break;
  1036. }
  1037. default:
  1038. DBGFONTS(("unhandled CBN_%x from POINTSLIST\n",HIWORD(wParam)));
  1039. break;
  1040. }
  1041. return TRUE;
  1042. // end FE_SB
  1043. case IDD_CURSOR_SMALL:
  1044. case IDD_CURSOR_MEDIUM:
  1045. case IDD_CURSOR_LARGE:
  1046. UpdateStateInfo(hDlg, Item, 0);
  1047. return TRUE;
  1048. case IDD_HISTORY_NODUP:
  1049. case IDD_AUTOCOMPLETE:
  1050. case IDD_QUICKEDIT:
  1051. case IDD_INSERT:
  1052. Value = IsDlgButtonChecked(hDlg, Item);
  1053. UpdateStateInfo(hDlg, Item, Value);
  1054. return TRUE;
  1055. case IDD_HISTORY_SIZE:
  1056. case IDD_HISTORY_NUM:
  1057. switch (HIWORD(wParam)) {
  1058. case EN_UPDATE:
  1059. if (!CheckNum(hDlg, Item)) {
  1060. if (!InEM_UNDO) {
  1061. InEM_UNDO = TRUE;
  1062. SendMessage((HWND)lParam, EM_UNDO, 0, 0L);
  1063. InEM_UNDO = FALSE;
  1064. }
  1065. }
  1066. break;
  1067. case EN_KILLFOCUS:
  1068. /*
  1069. * Update the state info structure
  1070. */
  1071. Value = GetDlgItemInt(hDlg, Item, &bOK, TRUE);
  1072. if (bOK) {
  1073. UpdateStateInfo(hDlg, Item, Value);
  1074. }
  1075. break;
  1076. }
  1077. return TRUE;
  1078. default:
  1079. break;
  1080. }
  1081. break;
  1082. case WM_NOTIFY:
  1083. switch (((LPNMHDR)lParam)->code) {
  1084. case PSN_APPLY:
  1085. /*
  1086. * Write out the state values and exit.
  1087. */
  1088. EndDlgPage(hDlg);
  1089. return TRUE;
  1090. case PSN_KILLACTIVE:
  1091. /*
  1092. * Fake the dialog proc into thinking the edit control just
  1093. * lost focus so it'll update properly
  1094. */
  1095. if (Item = GetDlgCtrlID(GetFocus())) {
  1096. SendMessage(hDlg, WM_COMMAND, MAKELONG(Item, EN_KILLFOCUS), 0);
  1097. }
  1098. return TRUE;
  1099. }
  1100. break;
  1101. case WM_VSCROLL:
  1102. /*
  1103. * Fake the dialog proc into thinking the edit control just
  1104. * lost focus so it'll update properly
  1105. */
  1106. Item = GetDlgCtrlID((HWND)lParam) - 1;
  1107. SendMessage(hDlg, WM_COMMAND, MAKELONG(Item, EN_KILLFOCUS), 0);
  1108. return TRUE;
  1109. default:
  1110. break;
  1111. }
  1112. return CommonDlgProc(hDlg, wMsg, wParam, lParam);
  1113. }
  1114. INT_PTR
  1115. ConsolePropertySheet(
  1116. IN HWND hWnd
  1117. )
  1118. /*++
  1119. Creates the property sheet to change console settings.
  1120. --*/
  1121. {
  1122. PROPSHEETPAGE psp[4];
  1123. PROPSHEETHEADER psh;
  1124. INT_PTR Result = IDCANCEL;
  1125. WCHAR awchBuffer[MAX_PATH];
  1126. //
  1127. // Initialize the state information
  1128. //
  1129. gpStateInfo = InitStateValues((HANDLE)hWnd);
  1130. if (gpStateInfo == NULL) {
  1131. KdPrint(("CONSOLE: can't get state information\n"));
  1132. return IDCANCEL;
  1133. }
  1134. //
  1135. // Initialize the font cache and current font index
  1136. //
  1137. InitializeFonts();
  1138. CurrentFontIndex = FindCreateFont(gpStateInfo->FontFamily,
  1139. gpStateInfo->FaceName,
  1140. gpStateInfo->FontSize,
  1141. gpStateInfo->FontWeight,
  1142. gpStateInfo->CodePage);
  1143. //
  1144. // Get the current page number
  1145. //
  1146. gnCurrentPage = GetRegistryValues(NULL);
  1147. //
  1148. // Initialize the property sheet structures
  1149. //
  1150. RtlZeroMemory(psp, sizeof(psp));
  1151. psp[0].dwSize = sizeof(PROPSHEETPAGE);
  1152. psp[0].hInstance = ghInstance;
  1153. #if defined(FE_SB) // v-HirShi Nov.20.1996
  1154. if (gpStateInfo->hWnd != NULL) {
  1155. psp[0].pszTemplate = MAKEINTRESOURCE(DID_SETTINGS2);
  1156. }
  1157. else{
  1158. psp[0].pszTemplate = MAKEINTRESOURCE(DID_SETTINGS);
  1159. }
  1160. #else
  1161. psp[0].pszTemplate = MAKEINTRESOURCE(DID_SETTINGS);
  1162. #endif
  1163. psp[0].pfnDlgProc = SettingsDlgProc;
  1164. psp[0].lParam = 0;
  1165. psp[1].dwSize = sizeof(PROPSHEETPAGE);
  1166. psp[1].hInstance = ghInstance;
  1167. psp[1].pszTemplate = MAKEINTRESOURCE(DID_FONTDLG);
  1168. psp[1].pfnDlgProc = FontDlgProc;
  1169. psp[1].lParam = 1;
  1170. psp[2].dwSize = sizeof(PROPSHEETPAGE);
  1171. psp[2].hInstance = ghInstance;
  1172. psp[2].pszTemplate = MAKEINTRESOURCE(DID_SCRBUFSIZE);
  1173. psp[2].pfnDlgProc = ScreenSizeDlgProc;
  1174. psp[2].lParam = 2;
  1175. psp[3].dwSize = sizeof(PROPSHEETPAGE);
  1176. psp[3].hInstance = ghInstance;
  1177. psp[3].pszTemplate = MAKEINTRESOURCE(DID_COLOR);
  1178. psp[3].pfnDlgProc = ColorDlgProc;
  1179. psp[3].lParam = 3;
  1180. psh.dwSize = sizeof(PROPSHEETHEADER);
  1181. psh.dwFlags = PSH_PROPTITLE | PSH_USEICONID | PSH_PROPSHEETPAGE |
  1182. PSH_NOAPPLYNOW | PSH_USECALLBACK;
  1183. if (gpStateInfo->hWnd) {
  1184. psh.hwndParent = gpStateInfo->hWnd;
  1185. } else {
  1186. psh.hwndParent = hWnd;
  1187. }
  1188. psh.hInstance = ghInstance;
  1189. psh.pszIcon = MAKEINTRESOURCE(IDI_CONSOLE);
  1190. if (gpStateInfo->ConsoleTitle[0] != TEXT('\0')) {
  1191. wcscpy(awchBuffer, TEXT("\""));
  1192. ExpandEnvironmentStrings(gpStateInfo->ConsoleTitle, &awchBuffer[1], NELEM(awchBuffer) - 2);
  1193. wcscat(awchBuffer, TEXT("\""));
  1194. gbStartedFromLink = WereWeStartedFromALnk();
  1195. } else {
  1196. LoadString(ghInstance, IDS_TITLE, awchBuffer, NELEM(awchBuffer));
  1197. gbStartedFromLink = FALSE;
  1198. }
  1199. psh.pszCaption = awchBuffer;
  1200. psh.nPages = NELEM(psp);
  1201. psh.nStartPage = min(gnCurrentPage, NELEM(psp));
  1202. psh.ppsp = psp;
  1203. psh.pfnCallback = ConsolePropSheetProc;
  1204. //
  1205. // Create the property sheet
  1206. //
  1207. Result = PropertySheet(&psh);
  1208. //
  1209. // Send the state values to the console server
  1210. //
  1211. if (gbWriteToConsole) {
  1212. WriteStateValues(gpStateInfo);
  1213. }
  1214. //
  1215. // Save our changes to the registry
  1216. //
  1217. if (gbSaveToRegistry) {
  1218. //
  1219. // If we're looking at the default font, clear the values
  1220. // before we save them
  1221. //
  1222. if ((gpStateInfo->FontFamily == DefaultFontFamily) &&
  1223. (gpStateInfo->FontSize.X == DefaultFontSize.X) &&
  1224. (gpStateInfo->FontSize.Y == DefaultFontSize.Y) &&
  1225. (gpStateInfo->FontWeight == FW_NORMAL) &&
  1226. (wcscmp(gpStateInfo->FaceName, DefaultFaceName) == 0)) {
  1227. gpStateInfo->FontFamily = 0;
  1228. gpStateInfo->FontSize.X = 0;
  1229. gpStateInfo->FontSize.Y = 0;
  1230. gpStateInfo->FontWeight = 0;
  1231. gpStateInfo->FaceName[0] = TEXT('\0');
  1232. }
  1233. if (gbStartedFromLink) {
  1234. if (!SetLinkValues( gpStateInfo )) {
  1235. WCHAR szMessage[ MAX_PATH + 100 ];
  1236. STARTUPINFOW si;
  1237. HWND hwndTemp;
  1238. // An error occured try to save the link file,
  1239. // display a message box to that effect...
  1240. GetStartupInfoW( &si );
  1241. LoadStringW(ghInstance, IDS_LINKERROR, awchBuffer, NELEM(awchBuffer));
  1242. wsprintfW( szMessage,
  1243. awchBuffer,
  1244. si.lpTitle
  1245. );
  1246. LoadStringW(ghInstance, IDS_LINKERRCAP, awchBuffer, NELEM(awchBuffer));
  1247. if (gpStateInfo->hWnd) {
  1248. hwndTemp = gpStateInfo->hWnd;
  1249. } else {
  1250. hwndTemp = hWnd;
  1251. }
  1252. MessageBoxW( hwndTemp,
  1253. szMessage,
  1254. awchBuffer,
  1255. MB_APPLMODAL | MB_OK | MB_ICONSTOP | MB_SETFOREGROUND
  1256. );
  1257. }
  1258. } else {
  1259. SetRegistryValues(gpStateInfo, gnCurrentPage);
  1260. }
  1261. } else {
  1262. SetRegistryValues(NULL, gnCurrentPage);
  1263. }
  1264. //
  1265. // Tell the console server that we're done
  1266. //
  1267. if (gpStateInfo->hWnd) {
  1268. SendMessage(gpStateInfo->hWnd, CM_PROPERTIES_END, 0, 0);
  1269. }
  1270. //
  1271. // Free the state information
  1272. //
  1273. HeapFree(RtlProcessHeap(), 0, gpStateInfo);
  1274. //
  1275. // Destroy the font cache
  1276. //
  1277. DestroyFonts();
  1278. return Result;
  1279. }
  1280. BOOL
  1281. RegisterClasses(HANDLE hModule)
  1282. {
  1283. WNDCLASS wc;
  1284. wc.lpszClassName = TEXT("cpColor");
  1285. wc.hInstance = hModule;
  1286. wc.lpfnWndProc = ColorControlProc;
  1287. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1288. wc.hIcon = NULL;
  1289. wc.lpszMenuName = NULL;
  1290. wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  1291. wc.style = CS_HREDRAW | CS_VREDRAW;
  1292. wc.cbClsExtra = 0;
  1293. wc.cbWndExtra = 0;
  1294. if (!RegisterClass(&wc)) {
  1295. return FALSE;
  1296. }
  1297. wc.lpszClassName = TEXT("WOAWinPreview");
  1298. wc.lpfnWndProc = PreviewWndProc;
  1299. wc.hbrBackground = (HBRUSH) (COLOR_BACKGROUND + 1);
  1300. wc.style = 0L;
  1301. if (!RegisterClass(&wc)) {
  1302. return FALSE;
  1303. }
  1304. wc.lpszClassName = TEXT("WOAFontPreview");
  1305. wc.lpfnWndProc = FontPreviewWndProc;
  1306. wc.hbrBackground = GetStockObject(BLACK_BRUSH);
  1307. wc.style = 0L;
  1308. if (!RegisterClass(&wc)) {
  1309. return FALSE;
  1310. }
  1311. return TRUE;
  1312. }
  1313. void
  1314. UnregisterClasses(HANDLE hModule)
  1315. {
  1316. UnregisterClass(TEXT("cpColor"), hModule);
  1317. UnregisterClass(TEXT("WOAWinPreview"), hModule);
  1318. UnregisterClass(TEXT("WOAFontPreview"), hModule);
  1319. }
  1320. PCONSOLE_STATE_INFO
  1321. ReadStateValues(HANDLE hMap)
  1322. {
  1323. PCONSOLE_STATE_INFO pConsoleInfo;
  1324. PCONSOLE_STATE_INFO pStateInfo;
  1325. /*
  1326. * Map the shared memory block into our address space.
  1327. */
  1328. pConsoleInfo = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
  1329. if (pConsoleInfo == NULL) {
  1330. return NULL;
  1331. }
  1332. /*
  1333. * Copy the data into a locally allocated buffer.
  1334. */
  1335. pStateInfo = HeapAlloc(RtlProcessHeap(), 0, pConsoleInfo->Length);
  1336. if (pStateInfo) {
  1337. RtlCopyMemory(pStateInfo, pConsoleInfo, pConsoleInfo->Length);
  1338. }
  1339. /*
  1340. * Close any open handles.
  1341. */
  1342. UnmapViewOfFile(pConsoleInfo);
  1343. CloseHandle(hMap);
  1344. return pStateInfo;
  1345. }
  1346. BOOL
  1347. WriteStateValues(PCONSOLE_STATE_INFO pStateInfo)
  1348. {
  1349. HANDLE hMap;
  1350. PCONSOLE_STATE_INFO pConsoleInfo;
  1351. /*
  1352. * Make sure we have a console window to notify.
  1353. */
  1354. if (pStateInfo->hWnd == NULL) {
  1355. return FALSE;
  1356. }
  1357. /*
  1358. * Create the shared memory block which will contain the state info.
  1359. */
  1360. hMap = CreateFileMapping((HANDLE)-1, NULL, PAGE_READWRITE, 0,
  1361. pStateInfo->Length, NULL);
  1362. if (!hMap) {
  1363. KdPrint(("CONSOLE: error %d creating file mapping\n", GetLastError()));
  1364. return FALSE;
  1365. }
  1366. /*
  1367. * Map the shared memory block into our address space and copy the
  1368. * data into it.
  1369. */
  1370. pConsoleInfo = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
  1371. if (!pConsoleInfo) {
  1372. KdPrint(("CONSOLE: error %d mapping view of file\n", GetLastError()));
  1373. CloseHandle(hMap);
  1374. return FALSE;
  1375. }
  1376. RtlCopyMemory(pConsoleInfo, pStateInfo, pStateInfo->Length);
  1377. UnmapViewOfFile(pConsoleInfo);
  1378. /*
  1379. * Send a message to the server window telling him to read the data
  1380. * and then close any open handles.
  1381. */
  1382. SendMessage(pStateInfo->hWnd, CM_PROPERTIES_UPDATE, (WPARAM)hMap, 0);
  1383. CloseHandle(hMap);
  1384. return TRUE;
  1385. }
  1386. PCONSOLE_STATE_INFO
  1387. InitStateValues(HANDLE hMap)
  1388. {
  1389. PCONSOLE_STATE_INFO pStateInfo;
  1390. /*
  1391. * Try to open the shared memory block and read the state info
  1392. * into our address space.
  1393. */
  1394. pStateInfo = ReadStateValues(hMap);
  1395. if (pStateInfo != NULL) {
  1396. return pStateInfo;
  1397. }
  1398. /*
  1399. * Couldn't read the shared memory block so allocate and fill
  1400. * in default values in structure.
  1401. */
  1402. pStateInfo = InitRegistryValues();
  1403. if (pStateInfo == NULL) {
  1404. return NULL;
  1405. }
  1406. /*
  1407. * Now overwrite default values with values from registry
  1408. */
  1409. GetRegistryValues(pStateInfo);
  1410. return pStateInfo;
  1411. }