userenv: Implement ExpandEnvironmentStringsForUser{A,W}.
[wine/wine-kai.git] / programs / winecfg / x11drvdlg.c
blob18f148a592b3de81397823a5a461e261979de5ee
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_EMULATION, "emulation"},
48 {IDS_SHADER_MODE_NONE, "none"},
49 {0, 0}
53 int updating_ui;
55 static void update_gui_for_desktop_mode(HWND dialog) {
56 int desktopenabled = FALSE;
58 WINE_TRACE("\n");
59 updating_ui = TRUE;
61 if (current_app)
63 disable(IDC_ENABLE_DESKTOP);
64 disable(IDC_DESKTOP_WIDTH);
65 disable(IDC_DESKTOP_HEIGHT);
66 disable(IDC_DESKTOP_SIZE);
67 disable(IDC_DESKTOP_BY);
68 return;
70 enable(IDC_ENABLE_DESKTOP);
72 /* do we have desktop mode enabled? */
73 if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
75 char* buf, *bufindex;
76 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
78 buf = get_reg_key(config_key, keypath("X11 Driver"), "Desktop", "640x480");
79 /* note: this test must match the one in x11drv */
80 if( buf[0] != 'n' && buf[0] != 'N' && buf[0] != 'F' && buf[0] != 'f'
81 && buf[0] != '0') {
82 desktopenabled = TRUE;
83 enable(IDC_DESKTOP_WIDTH);
84 enable(IDC_DESKTOP_HEIGHT);
85 enable(IDC_DESKTOP_SIZE);
86 enable(IDC_DESKTOP_BY);
88 bufindex = strchr(buf, 'x');
89 if (bufindex) {
90 *bufindex = 0;
91 ++bufindex;
92 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
93 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
94 } else {
95 WINE_TRACE("Desktop registry entry is malformed\n");
96 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
97 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
100 HeapFree(GetProcessHeap(), 0, buf);
102 if (!desktopenabled)
104 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
106 disable(IDC_DESKTOP_WIDTH);
107 disable(IDC_DESKTOP_HEIGHT);
108 disable(IDC_DESKTOP_SIZE);
109 disable(IDC_DESKTOP_BY);
111 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
112 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
115 updating_ui = FALSE;
118 static void init_dialog(HWND dialog)
120 unsigned int it;
121 char* buf;
123 update_gui_for_desktop_mode(dialog);
125 updating_ui = TRUE;
127 SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
128 SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
130 buf = get_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
131 if (IS_OPTION_TRUE(*buf))
132 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
133 else
134 CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
135 HeapFree(GetProcessHeap(), 0, buf);
137 buf = get_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
138 if (IS_OPTION_TRUE(*buf))
139 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_CHECKED);
140 else
141 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_UNCHECKED);
142 HeapFree(GetProcessHeap(), 0, buf);
144 SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_RESETCONTENT, 0, 0);
145 for (it = 0; 0 != D3D_VS_Modes[it].displayStrID; ++it) {
146 SendDlgItemMessageW (dialog, IDC_D3D_VSHADER_MODE, CB_ADDSTRING, 0,
147 (LPARAM)load_string (D3D_VS_Modes[it].displayStrID));
149 buf = get_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode", "hardware");
150 for (it = 0; NULL != D3D_VS_Modes[it].settingStr; ++it) {
151 if (strcmp(buf, D3D_VS_Modes[it].settingStr) == 0) {
152 SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_SETCURSEL, it, 0);
153 break ;
156 if (NULL == D3D_VS_Modes[it].settingStr) {
157 WINE_ERR("Invalid Direct3D VertexShader Mode read from registry (%s)\n", buf);
159 HeapFree(GetProcessHeap(), 0, buf);
161 buf = get_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
162 if (!strcmp(buf, "enabled"))
163 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_CHECKED);
164 else
165 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_UNCHECKED);
166 HeapFree(GetProcessHeap(), 0, buf);
168 updating_ui = FALSE;
171 static void set_from_desktop_edits(HWND dialog) {
172 char *width, *height, *new;
174 if (updating_ui) return;
176 WINE_TRACE("\n");
178 width = get_text(dialog, IDC_DESKTOP_WIDTH);
179 height = get_text(dialog, IDC_DESKTOP_HEIGHT);
181 if (width == NULL || strcmp(width, "") == 0) {
182 HeapFree(GetProcessHeap(), 0, width);
183 width = strdupA("640");
186 if (height == NULL || strcmp(height, "") == 0) {
187 HeapFree(GetProcessHeap(), 0, height);
188 height = strdupA("480");
191 new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
192 sprintf(new, "%sx%s", width, height);
193 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", new);
195 HeapFree(GetProcessHeap(), 0, width);
196 HeapFree(GetProcessHeap(), 0, height);
197 HeapFree(GetProcessHeap(), 0, new);
200 static void on_enable_desktop_clicked(HWND dialog) {
201 WINE_TRACE("\n");
203 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
204 set_from_desktop_edits(dialog);
205 } else {
206 set_reg_key(config_key, keypath("X11 Driver"), "Desktop", NULL);
209 update_gui_for_desktop_mode(dialog);
212 static void on_enable_managed_clicked(HWND dialog) {
213 WINE_TRACE("\n");
215 if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
216 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
217 } else {
218 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "N");
222 static void on_dx_mouse_grab_clicked(HWND dialog) {
223 if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
224 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
225 else
226 set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
229 static void on_d3d_vshader_mode_changed(HWND dialog) {
230 int selected_mode = SendDlgItemMessage(dialog, IDC_D3D_VSHADER_MODE, CB_GETCURSEL, 0, 0);
231 set_reg_key(config_key, keypath("Direct3D"), "VertexShaderMode",
232 D3D_VS_Modes[selected_mode].settingStr);
235 static void on_d3d_pshader_mode_clicked(HWND dialog) {
236 if (IsDlgButtonChecked(dialog, IDC_D3D_PSHADER_MODE) == BST_CHECKED)
237 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "enabled");
238 else
239 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
242 INT_PTR CALLBACK
243 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
245 switch (uMsg) {
246 case WM_INITDIALOG:
247 break;
249 case WM_SHOWWINDOW:
250 set_window_title(hDlg);
251 break;
253 case WM_COMMAND:
254 switch(HIWORD(wParam)) {
255 case EN_CHANGE: {
256 if (updating_ui) break;
257 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
258 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
259 set_from_desktop_edits(hDlg);
260 break;
262 case BN_CLICKED: {
263 if (updating_ui) break;
264 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
265 switch(LOWORD(wParam)) {
266 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
267 case IDC_ENABLE_MANAGED: on_enable_managed_clicked(hDlg); break;
268 case IDC_DX_MOUSE_GRAB: on_dx_mouse_grab_clicked(hDlg); break;
269 case IDC_D3D_PSHADER_MODE: on_d3d_pshader_mode_clicked(hDlg); break;
271 break;
273 case CBN_SELCHANGE: {
274 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
275 switch (LOWORD(wParam)) {
276 case IDC_D3D_VSHADER_MODE: on_d3d_vshader_mode_changed(hDlg); break;
278 break;
281 default:
282 break;
284 break;
287 case WM_NOTIFY:
288 switch (((LPNMHDR)lParam)->code) {
289 case PSN_KILLACTIVE: {
290 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
291 break;
293 case PSN_APPLY: {
294 apply();
295 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
296 break;
298 case PSN_SETACTIVE: {
299 init_dialog (hDlg);
300 break;
303 break;
305 default:
306 break;
308 return FALSE;