wininet: Add a new NETCON_query_data_available function.
[wine/multimedia.git] / programs / winecfg / x11drvdlg.c
blob8fa183e122174a1d52ca70d38d97e168837e7228
1 /*
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
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <stdio.h>
30 #include <windows.h>
31 #include <wine/debug.h>
33 #include "resource.h"
34 #include "winecfg.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 struct SHADERMODE
43 UINT displayStrID;
44 const char* settingStr;
45 } const D3D_VS_Modes[] = {
46 {IDS_SHADER_MODE_HARDWARE, "hardware"},
47 {IDS_SHADER_MODE_NONE, "none"},
48 {0, 0}
52 int updating_ui;
54 static void update_gui_for_desktop_mode(HWND dialog) {
55 int desktopenabled = FALSE;
57 WINE_TRACE("\n");
58 updating_ui = TRUE;
60 if (current_app)
62 disable(IDC_ENABLE_DESKTOP);
63 disable(IDC_DESKTOP_WIDTH);
64 disable(IDC_DESKTOP_HEIGHT);
65 disable(IDC_DESKTOP_SIZE);
66 disable(IDC_DESKTOP_BY);
67 return;
69 enable(IDC_ENABLE_DESKTOP);
71 /* do we have desktop mode enabled? */
72 if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
74 char* buf, *bufindex;
75 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
77 buf = get_reg_key(config_key, keypath("X11 Driver"), "Desktop", "640x480");
78 /* note: this test must match the one in x11drv */
79 if( buf[0] != 'n' && buf[0] != 'N' && buf[0] != 'F' && buf[0] != 'f'
80 && buf[0] != '0') {
81 desktopenabled = TRUE;
82 enable(IDC_DESKTOP_WIDTH);
83 enable(IDC_DESKTOP_HEIGHT);
84 enable(IDC_DESKTOP_SIZE);
85 enable(IDC_DESKTOP_BY);
87 bufindex = strchr(buf, 'x');
88 if (bufindex) {
89 *bufindex = 0;
90 ++bufindex;
91 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
92 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
93 } else {
94 WINE_TRACE("Desktop registry entry is malformed\n");
95 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
96 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
99 HeapFree(GetProcessHeap(), 0, buf);
101 if (!desktopenabled)
103 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
105 disable(IDC_DESKTOP_WIDTH);
106 disable(IDC_DESKTOP_HEIGHT);
107 disable(IDC_DESKTOP_SIZE);
108 disable(IDC_DESKTOP_BY);
110 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
111 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
114 updating_ui = FALSE;
117 static void init_dialog(HWND dialog)
119 unsigned int it;
120 char* buf;
122 update_gui_for_desktop_mode(dialog);
124 updating_ui = TRUE;
126 SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
127 SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
129 buf = get_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
130 if (IS_OPTION_TRUE(*buf))
131 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
132 else
133 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
134 HeapFree(GetProcessHeap(), 0, buf);
136 buf = get_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
137 if (IS_OPTION_TRUE(*buf))
138 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_CHECKED);
139 else
140 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_UNCHECKED);
141 HeapFree(GetProcessHeap(), 0, buf);
143 SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_RESETCONTENT, 0, 0);
144 for (it = 0; 0 != D3D_VS_Modes[it].displayStrID; ++it) {
145 SendDlgItemMessageW (dialog, IDC_D3D_VSHADER_MODE, CB_ADDSTRING, 0,
146 (LPARAM)load_string (D3D_VS_Modes[it].displayStrID));
148 buf = get_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode", "hardware");
149 for (it = 0; NULL != D3D_VS_Modes[it].settingStr; ++it) {
150 if (strcmp(buf, D3D_VS_Modes[it].settingStr) == 0) {
151 SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_SETCURSEL, it, 0);
152 break ;
155 if (NULL == D3D_VS_Modes[it].settingStr) {
156 WINE_ERR("Invalid Direct3D VertexShader Mode read from registry (%s)\n", buf);
158 HeapFree(GetProcessHeap(), 0, buf);
160 buf = get_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
161 if (!strcmp(buf, "enabled"))
162 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_CHECKED);
163 else
164 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_UNCHECKED);
165 HeapFree(GetProcessHeap(), 0, buf);
167 updating_ui = FALSE;
170 static void set_from_desktop_edits(HWND dialog) {
171 char *width, *height, *new;
173 if (updating_ui) return;
175 WINE_TRACE("\n");
177 width = get_text(dialog, IDC_DESKTOP_WIDTH);
178 height = get_text(dialog, IDC_DESKTOP_HEIGHT);
180 if (width == NULL || strcmp(width, "") == 0) {
181 HeapFree(GetProcessHeap(), 0, width);
182 width = strdupA("640");
185 if (height == NULL || strcmp(height, "") == 0) {
186 HeapFree(GetProcessHeap(), 0, height);
187 height = strdupA("480");
190 new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
191 sprintf(new, "%sx%s", width, height);
192 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", new);
194 HeapFree(GetProcessHeap(), 0, width);
195 HeapFree(GetProcessHeap(), 0, height);
196 HeapFree(GetProcessHeap(), 0, new);
199 static void on_enable_desktop_clicked(HWND dialog) {
200 WINE_TRACE("\n");
202 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
203 set_from_desktop_edits(dialog);
204 } else {
205 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", NULL);
208 update_gui_for_desktop_mode(dialog);
211 static void on_enable_managed_clicked(HWND dialog) {
212 WINE_TRACE("\n");
214 if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
215 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
216 } else {
217 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "N");
221 static void on_dx_mouse_grab_clicked(HWND dialog) {
222 if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
223 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
224 else
225 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
228 static void on_d3d_vshader_mode_changed(HWND dialog) {
229 int selected_mode = SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_GETCURSEL, 0, 0);
230 set_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode",
231 D3D_VS_Modes[selected_mode].settingStr);
234 static void on_d3d_pshader_mode_clicked(HWND dialog) {
235 if (IsDlgButtonChecked(dialog, IDC_D3D_PSHADER_MODE) == BST_CHECKED)
236 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
237 else
238 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
241 INT_PTR CALLBACK
242 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
244 switch (uMsg) {
245 case WM_INITDIALOG:
246 break;
248 case WM_SHOWWINDOW:
249 set_window_title(hDlg);
250 break;
252 case WM_COMMAND:
253 switch(HIWORD(wParam)) {
254 case EN_CHANGE: {
255 if (updating_ui) break;
256 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
257 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
258 set_from_desktop_edits(hDlg);
259 break;
261 case BN_CLICKED: {
262 if (updating_ui) break;
263 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
264 switch(LOWORD(wParam)) {
265 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
266 case IDC_ENABLE_MANAGED: on_enable_managed_clicked(hDlg); break;
267 case IDC_DX_MOUSE_GRAB: on_dx_mouse_grab_clicked(hDlg); break;
268 case IDC_D3D_PSHADER_MODE: on_d3d_pshader_mode_clicked(hDlg); break;
270 break;
272 case CBN_SELCHANGE: {
273 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
274 switch (LOWORD(wParam)) {
275 case IDC_D3D_VSHADER_MODE: on_d3d_vshader_mode_changed(hDlg); break;
277 break;
280 default:
281 break;
283 break;
286 case WM_NOTIFY:
287 switch (((LPNMHDR)lParam)->code) {
288 case PSN_KILLACTIVE: {
289 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
290 break;
292 case PSN_APPLY: {
293 apply();
294 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
295 break;
297 case PSN_SETACTIVE: {
298 init_dialog (hDlg);
299 break;
302 break;
304 default:
305 break;
307 return FALSE;