* Sync up to trunk head (r65074).
[reactos.git] / dll / cpl / desk / general.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/general.c
5 * PURPOSE: Advanced General settings
6 */
7
8 #include "desk.h"
9
10 static VOID
11 InitFontSizeList(HWND hWnd)
12 {
13 HINF hInf;
14 HKEY hKey;
15 HWND hFontSize;
16 INFCONTEXT Context;
17 int i, ci = 0;
18 DWORD dwSize, dwValue, dwType;
19
20 hFontSize = GetDlgItem(hWnd, IDC_FONTSIZE_COMBO);
21
22 hInf = SetupOpenInfFile(_T("font.inf"), NULL,
23 INF_STYLE_WIN4, NULL);
24
25 if (hInf != INVALID_HANDLE_VALUE)
26 {
27 if (SetupFindFirstLine(hInf, _T("Font Sizes"), NULL, &Context))
28 {
29 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontDPI"),
30 0, KEY_READ, &hKey) == ERROR_SUCCESS)
31 for (;;)
32 {
33 TCHAR Buffer[LINE_LEN];
34 TCHAR Desc[LINE_LEN];
35
36 if (SetupGetStringField(&Context, 0, Buffer, sizeof(Buffer) / sizeof(TCHAR), NULL) &&
37 SetupGetIntField(&Context, 1, &ci))
38 {
39 _stprintf(Desc, _T("%s (%d DPI)"), Buffer, ci);
40 i = SendMessage(hFontSize, CB_ADDSTRING, 0, (LPARAM)Desc);
41 if (i != CB_ERR)
42 SendMessage(hFontSize, CB_SETITEMDATA, (WPARAM)i, (LPARAM)ci);
43
44 dwSize = MAX_PATH;
45 dwType = REG_DWORD;
46
47 if (RegQueryValueEx(hKey, _T("LogPixels"), NULL,
48 &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS)
49 {
50 if ((int)dwValue == ci)
51 {
52 SendMessage(hFontSize, CB_SETCURSEL, (WPARAM)i, 0);
53 SetWindowText(GetDlgItem(hWnd, IDC_FONTSIZE_CUSTOM), Desc);
54 }
55 }
56 }
57
58 if (!SetupFindNextLine(&Context, &Context))
59 {
60 RegCloseKey(hKey);
61 break;
62 }
63 }
64 }
65 }
66
67 SetupCloseInfFile(hInf);
68 }
69
70 static VOID
71 InitRadioButtons(HWND hWnd)
72 {
73 HKEY hKey;
74
75 if (RegOpenKeyEx(HKEY_CURRENT_USER,
76 _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\Display"),
77 0, KEY_READ, &hKey) == ERROR_SUCCESS)
78 {
79 TCHAR szBuf[64];
80 DWORD dwSize = 64;
81
82 if (RegQueryValueEx(hKey, _T("DynaSettingsChange"), 0, NULL,
83 (LPBYTE)szBuf, &dwSize) == ERROR_SUCCESS)
84 {
85 switch (_ttoi(szBuf))
86 {
87 case 0:
88 SendDlgItemMessage(hWnd, IDC_RESTART_RB, BM_SETCHECK, 1, 1);
89 break;
90 case 1:
91 SendDlgItemMessage(hWnd, IDC_WITHOUTREBOOT_RB, BM_SETCHECK, 1, 1);
92 break;
93 case 3:
94 SendDlgItemMessage(hWnd, IDC_ASKME_RB, BM_SETCHECK, 1, 1);
95 break;
96 }
97 }
98 else
99 SendDlgItemMessage(hWnd, IDC_WITHOUTREBOOT_RB, BM_SETCHECK, 1, 1);
100
101 RegCloseKey(hKey);
102 }
103 else
104 SendDlgItemMessage(hWnd, IDC_WITHOUTREBOOT_RB, BM_SETCHECK, 1, 1);
105 }
106
107 INT_PTR CALLBACK
108 AdvGeneralPageProc(HWND hwndDlg,
109 UINT uMsg,
110 WPARAM wParam,
111 LPARAM lParam)
112 {
113 PDISPLAY_DEVICE_ENTRY DispDevice = NULL;
114 INT_PTR Ret = 0;
115
116 if (uMsg != WM_INITDIALOG)
117 DispDevice = (PDISPLAY_DEVICE_ENTRY)GetWindowLongPtr(hwndDlg, DWLP_USER);
118
119 switch (uMsg)
120 {
121 case WM_INITDIALOG:
122 DispDevice = (PDISPLAY_DEVICE_ENTRY)(((LPPROPSHEETPAGE)lParam)->lParam);
123 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)DispDevice);
124
125 InitFontSizeList(hwndDlg);
126 InitRadioButtons(hwndDlg);
127
128 Ret = TRUE;
129 break;
130 case WM_COMMAND:
131 switch (LOWORD(wParam))
132 {
133 case IDC_FONTSIZE_COMBO:
134 if (HIWORD(wParam) == CBN_SELCHANGE)
135 {
136 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
137 }
138 break;
139 case IDC_RESTART_RB:
140 case IDC_WITHOUTREBOOT_RB:
141 case IDC_ASKME_RB:
142 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
143 break;
144 }
145 break;
146 }
147
148 return Ret;
149 }