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? */
41 static const char* D3D_VS_Modes[] = {
51 static void update_gui_for_desktop_mode(HWND dialog) {
52 int desktopenabled = FALSE;
59 disable(IDC_ENABLE_DESKTOP);
60 disable(IDC_DESKTOP_WIDTH);
61 disable(IDC_DESKTOP_HEIGHT);
62 disable(IDC_DESKTOP_SIZE);
63 disable(IDC_DESKTOP_BY);
66 enable(IDC_ENABLE_DESKTOP);
68 /* do we have desktop mode enabled? */
69 if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
72 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
74 buf = get_reg_key(config_key, keypath("X11 Driver"), "Desktop", "640x480");
75 /* note: this test must match the one in x11drv */
76 if( buf[0] != 'n' && buf[0] != 'N' && buf[0] != 'F' && buf[0] != 'f'
78 desktopenabled = TRUE;
79 enable(IDC_DESKTOP_WIDTH);
80 enable(IDC_DESKTOP_HEIGHT);
81 enable(IDC_DESKTOP_SIZE);
82 enable(IDC_DESKTOP_BY);
84 bufindex = strchr(buf, 'x');
88 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
89 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
91 WINE_TRACE("Desktop registry entry is malformed");
92 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
93 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
96 HeapFree(GetProcessHeap(), 0, buf);
100 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
102 disable(IDC_DESKTOP_WIDTH);
103 disable(IDC_DESKTOP_HEIGHT);
104 disable(IDC_DESKTOP_SIZE);
105 disable(IDC_DESKTOP_BY);
107 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
108 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
114 static void init_dialog(HWND dialog)
119 update_gui_for_desktop_mode(dialog);
123 SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
124 SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
126 buf = get_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
127 if (IS_OPTION_TRUE(*buf))
128 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
130 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
131 HeapFree(GetProcessHeap(), 0, buf);
133 buf = get_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
134 if (IS_OPTION_TRUE(*buf))
135 CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_CHECKED);
137 CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, 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; NULL != D3D_VS_Modes[it]; ++it) {
149 SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_ADDSTRING, 0, (LPARAM) D3D_VS_Modes[it]);
151 buf = get_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode", "hardware");
152 for (it = 0; NULL != D3D_VS_Modes[it]; ++it) {
153 if (strcmp(buf, D3D_VS_Modes[it]) == 0) {
154 SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_SETCURSEL, it, 0);
158 if (NULL == D3D_VS_Modes[it]) {
159 WINE_ERR("Invalid Direct3D VertexShader Mode read from registry (%s)\n", buf);
161 HeapFree(GetProcessHeap(), 0, buf);
163 buf = get_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
164 if (!strcmp(buf, "enabled"))
165 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_CHECKED);
167 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_UNCHECKED);
168 HeapFree(GetProcessHeap(), 0, buf);
173 static void set_from_desktop_edits(HWND dialog) {
174 char *width, *height, *new;
176 if (updating_ui) return;
180 width = get_text(dialog, IDC_DESKTOP_WIDTH);
181 height = get_text(dialog, IDC_DESKTOP_HEIGHT);
183 if (width == NULL || strcmp(width, "") == 0) {
184 HeapFree(GetProcessHeap(), 0, width);
185 width = strdupA("640");
188 if (height == NULL || strcmp(height, "") == 0) {
189 HeapFree(GetProcessHeap(), 0, height);
190 height = strdupA("480");
193 new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
194 sprintf(new, "%sx%s", width, height);
195 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", new);
197 HeapFree(GetProcessHeap(), 0, width);
198 HeapFree(GetProcessHeap(), 0, height);
199 HeapFree(GetProcessHeap(), 0, new);
202 static void on_enable_desktop_clicked(HWND dialog) {
205 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
206 set_from_desktop_edits(dialog);
208 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", NULL);
211 update_gui_for_desktop_mode(dialog);
214 static void on_enable_managed_clicked(HWND dialog) {
217 if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
218 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
220 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "N");
224 static void on_dx_mouse_grab_clicked(HWND dialog) {
225 if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
226 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
228 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
232 static void on_double_buffer_clicked(HWND dialog) {
233 if (IsDlgButtonChecked(dialog, IDC_DOUBLE_BUFFER) == BST_CHECKED)
234 set_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
236 set_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "N");
239 static void on_d3d_vshader_mode_changed(HWND dialog) {
240 int selected_mode = SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_GETCURSEL, 0, 0);
241 set_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode", D3D_VS_Modes[selected_mode]);
244 static void on_d3d_pshader_mode_clicked(HWND dialog) {
245 if (IsDlgButtonChecked(dialog, IDC_D3D_PSHADER_MODE) == BST_CHECKED)
246 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
248 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
252 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
259 set_window_title(hDlg);
263 switch(HIWORD(wParam)) {
265 if (updating_ui) break;
266 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
267 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
268 set_from_desktop_edits(hDlg);
272 if (updating_ui) break;
273 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
274 switch(LOWORD(wParam)) {
275 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
276 case IDC_ENABLE_MANAGED: on_enable_managed_clicked(hDlg); break;
277 case IDC_DX_MOUSE_GRAB: on_dx_mouse_grab_clicked(hDlg); break;
278 case IDC_DOUBLE_BUFFER: on_double_buffer_clicked(hDlg); break;
279 case IDC_D3D_PSHADER_MODE: on_d3d_pshader_mode_clicked(hDlg); break;
283 case CBN_SELCHANGE: {
284 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
285 switch (LOWORD(wParam)) {
286 case IDC_D3D_VSHADER_MODE: on_d3d_vshader_mode_changed(hDlg); break;
298 switch (((LPNMHDR)lParam)->code) {
299 case PSN_KILLACTIVE: {
300 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
305 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
308 case PSN_SETACTIVE: {