2 * Graphics configuration code
4 * Copyright 2003 Mark Westcott
5 * Copyright 2003-2004 Mike Hearn
6 * Copyright 2005 Raphael Junqueira
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_LEAN_AND_MEAN
31 #include <wine/debug.h>
36 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
38 #define RES_MAXLEN 5 /* the maximum number of characters in a screen dimension. 5 digits should be plenty, what kind of crazy person runs their screen >10,000 pixels across? */
43 static const char logpixels_reg[] = "System\\CurrentControlSet\\Hardware Profiles\\Current\\Software\\Fonts";
45 static struct SHADERMODE
48 const char* settingStr;
49 } const D3D_VS_Modes[] = {
50 {IDS_SHADER_MODE_HARDWARE, "hardware"},
51 {IDS_SHADER_MODE_NONE, "none"},
58 static void update_gui_for_desktop_mode(HWND dialog) {
59 int desktopenabled = FALSE;
66 disable(IDC_ENABLE_DESKTOP);
67 disable(IDC_DESKTOP_WIDTH);
68 disable(IDC_DESKTOP_HEIGHT);
69 disable(IDC_DESKTOP_SIZE);
70 disable(IDC_DESKTOP_BY);
73 enable(IDC_ENABLE_DESKTOP);
75 /* do we have desktop mode enabled? */
76 if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
79 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
81 buf = get_reg_key(config_key, keypath("X11 Driver"), "Desktop", "800x600");
82 /* note: this test must match the one in x11drv */
83 if( buf[0] != 'n' && buf[0] != 'N' && buf[0] != 'F' && buf[0] != 'f'
85 desktopenabled = TRUE;
86 enable(IDC_DESKTOP_WIDTH);
87 enable(IDC_DESKTOP_HEIGHT);
88 enable(IDC_DESKTOP_SIZE);
89 enable(IDC_DESKTOP_BY);
91 bufindex = strchr(buf, 'x');
95 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
96 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
98 WINE_TRACE("Desktop registry entry is malformed\n");
99 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "800");
100 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "600");
103 HeapFree(GetProcessHeap(), 0, buf);
107 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
109 disable(IDC_DESKTOP_WIDTH);
110 disable(IDC_DESKTOP_HEIGHT);
111 disable(IDC_DESKTOP_SIZE);
112 disable(IDC_DESKTOP_BY);
114 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
115 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
121 static void init_dialog(HWND dialog)
126 update_gui_for_desktop_mode(dialog);
130 SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
131 SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
133 buf = get_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
134 if (IS_OPTION_TRUE(*buf))
135 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
137 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
138 HeapFree(GetProcessHeap(), 0, buf);
140 buf = get_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
141 if (IS_OPTION_TRUE(*buf))
142 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_CHECKED);
144 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_UNCHECKED);
145 HeapFree(GetProcessHeap(), 0, buf);
147 SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_RESETCONTENT, 0, 0);
148 for (it = 0; 0 != D3D_VS_Modes[it].displayStrID; ++it) {
149 SendDlgItemMessageW (dialog, IDC_D3D_VSHADER_MODE, CB_ADDSTRING, 0,
150 (LPARAM)load_string (D3D_VS_Modes[it].displayStrID));
152 buf = get_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode", "hardware");
153 for (it = 0; NULL != D3D_VS_Modes[it].settingStr; ++it) {
154 if (strcmp(buf, D3D_VS_Modes[it].settingStr) == 0) {
155 SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_SETCURSEL, it, 0);
159 if (NULL == D3D_VS_Modes[it].settingStr) {
160 WINE_ERR("Invalid Direct3D VertexShader Mode read from registry (%s)\n", buf);
162 HeapFree(GetProcessHeap(), 0, buf);
164 buf = get_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
165 if (!strcmp(buf, "enabled"))
166 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_CHECKED);
168 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_UNCHECKED);
169 HeapFree(GetProcessHeap(), 0, buf);
174 static void set_from_desktop_edits(HWND dialog) {
175 char *width, *height, *new;
177 if (updating_ui) return;
181 width = get_text(dialog, IDC_DESKTOP_WIDTH);
182 height = get_text(dialog, IDC_DESKTOP_HEIGHT);
184 if (width == NULL || strcmp(width, "") == 0) {
185 HeapFree(GetProcessHeap(), 0, width);
186 width = strdupA("800");
189 if (height == NULL || strcmp(height, "") == 0) {
190 HeapFree(GetProcessHeap(), 0, height);
191 height = strdupA("600");
194 new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
195 sprintf(new, "%sx%s", width, height);
196 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", new);
198 HeapFree(GetProcessHeap(), 0, width);
199 HeapFree(GetProcessHeap(), 0, height);
200 HeapFree(GetProcessHeap(), 0, new);
203 static void on_enable_desktop_clicked(HWND dialog) {
206 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
207 set_from_desktop_edits(dialog);
209 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", NULL);
212 update_gui_for_desktop_mode(dialog);
215 static void on_enable_managed_clicked(HWND dialog) {
218 if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
219 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
221 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "N");
225 static void on_dx_mouse_grab_clicked(HWND dialog) {
226 if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
227 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
229 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
232 static void on_d3d_vshader_mode_changed(HWND dialog) {
233 int selected_mode = SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_GETCURSEL, 0, 0);
234 set_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode",
235 D3D_VS_Modes[selected_mode].settingStr);
238 static void on_d3d_pshader_mode_clicked(HWND dialog) {
239 if (IsDlgButtonChecked(dialog, IDC_D3D_PSHADER_MODE) == BST_CHECKED)
240 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
242 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
244 static INT read_logpixels_reg(void)
247 char *buf = get_reg_key(HKEY_LOCAL_MACHINE, logpixels_reg,
249 dwLogPixels = buf ? *buf : DEFDPI;
250 HeapFree(GetProcessHeap(), 0, buf);
254 static void init_dpi_editbox(HWND hDlg)
256 HWND hDpiEditBox = GetDlgItem(hDlg, IDC_RES_DPIEDIT);
258 char szLogpixels[MAXBUFLEN];
262 dwLogpixels = read_logpixels_reg();
263 WINE_TRACE("%d\n", (int) dwLogpixels);
266 sprintf(szLogpixels, "%d", dwLogpixels);
267 SendMessage(hDpiEditBox, WM_SETTEXT, 0, (LPARAM) szLogpixels);
272 static void init_trackbar(HWND hDlg)
274 HWND hTrackBar = GetDlgItem(hDlg, IDC_RES_TRACKBAR);
279 dwLogpixels = read_logpixels_reg();
281 SendMessageW(hTrackBar, TBM_SETRANGE, TRUE, MAKELONG(MINDPI, MAXDPI));
282 SendMessageW(hTrackBar, TBM_SETPOS, TRUE, dwLogpixels);
288 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
292 init_dpi_editbox(hDlg);
297 set_window_title(hDlg);
301 switch(HIWORD(wParam)) {
303 if (updating_ui) break;
304 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
305 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
306 set_from_desktop_edits(hDlg);
310 if (updating_ui) break;
311 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
312 switch(LOWORD(wParam)) {
313 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
314 case IDC_ENABLE_MANAGED: on_enable_managed_clicked(hDlg); break;
315 case IDC_DX_MOUSE_GRAB: on_dx_mouse_grab_clicked(hDlg); break;
316 case IDC_D3D_PSHADER_MODE: on_d3d_pshader_mode_clicked(hDlg); break;
320 case CBN_SELCHANGE: {
321 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
322 switch (LOWORD(wParam)) {
323 case IDC_D3D_VSHADER_MODE: on_d3d_vshader_mode_changed(hDlg); break;
335 switch (((LPNMHDR)lParam)->code) {
336 case PSN_KILLACTIVE: {
337 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
342 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
345 case PSN_SETACTIVE: {
356 int i = SendMessageW(GetDlgItem(hDlg, IDC_RES_TRACKBAR), TBM_GETPOS, 0, 0);
358 sprintf(buf, "%d", i);
359 SendMessage(GetDlgItem(hDlg, IDC_RES_DPIEDIT), WM_SETTEXT, 0, (LPARAM) buf);
360 set_reg_key_dword(HKEY_LOCAL_MACHINE, logpixels_reg, "LogPixels", i);