kernel32: GetTempPath should try the USERPROFILE and the Windows directory too.
[wine/multimedia.git] / programs / winecfg / x11drvdlg.c
blob0a4e5971022bbca2fc2faf45c71b9231ab471745
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? */
39 #define MINDPI 96
40 #define MAXDPI 120
41 #define DEFDPI 96
43 static const char logpixels_reg[] = "System\\CurrentControlSet\\Hardware Profiles\\Current\\Software\\Fonts";
45 static struct SHADERMODE
47 UINT displayStrID;
48 const char* settingStr;
49 } const D3D_VS_Modes[] = {
50 {IDS_SHADER_MODE_HARDWARE, "hardware"},
51 {IDS_SHADER_MODE_NONE, "none"},
52 {0, 0}
56 int updating_ui;
58 static void update_gui_for_desktop_mode(HWND dialog) {
59 int desktopenabled = FALSE;
61 WINE_TRACE("\n");
62 updating_ui = TRUE;
64 if (current_app)
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);
71 return;
73 enable(IDC_ENABLE_DESKTOP);
75 /* do we have desktop mode enabled? */
76 if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
78 char* buf, *bufindex;
79 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
81 buf = get_reg_key(config_key, keypath("X11 Driver"), "Desktop", "640x480");
82 /* note: this test must match the one in x11drv */
83 if( buf[0] != 'n' && buf[0] != 'N' && buf[0] != 'F' && buf[0] != 'f'
84 && buf[0] != '0') {
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');
92 if (bufindex) {
93 *bufindex = 0;
94 ++bufindex;
95 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
96 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
97 } else {
98 WINE_TRACE("Desktop registry entry is malformed\n");
99 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "640");
100 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "480");
103 HeapFree(GetProcessHeap(), 0, buf);
105 if (!desktopenabled)
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), "");
118 updating_ui = FALSE;
121 static void init_dialog(HWND dialog)
123 unsigned int it;
124 char* buf;
126 update_gui_for_desktop_mode(dialog);
128 updating_ui = TRUE;
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);
136 else
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);
143 else
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);
156 break ;
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);
167 else
168 CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_UNCHECKED);
169 HeapFree(GetProcessHeap(), 0, buf);
171 updating_ui = FALSE;
174 static void set_from_desktop_edits(HWND dialog) {
175 char *width, *height, *new;
177 if (updating_ui) return;
179 WINE_TRACE("\n");
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("640");
189 if (height == NULL || strcmp(height, "") == 0) {
190 HeapFree(GetProcessHeap(), 0, height);
191 height = strdupA("480");
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) {
204 WINE_TRACE("\n");
206 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
207 set_from_desktop_edits(dialog);
208 } else {
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) {
216 WINE_TRACE("\n");
218 if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
219 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
220 } else {
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");
228 else
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");
241 else
242 set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
244 static INT read_logpixels_reg(void)
246 DWORD dwLogPixels;
247 char *buf = get_reg_key(HKEY_LOCAL_MACHINE, logpixels_reg,
248 "LogPixels", NULL);
249 dwLogPixels = buf ? *buf : DEFDPI;
250 HeapFree(GetProcessHeap(), 0, buf);
251 return dwLogPixels;
254 static void init_dpi_editbox(HWND hDlg)
256 HWND hDpiEditBox = GetDlgItem(hDlg, IDC_RES_DPIEDIT);
257 DWORD dwLogpixels;
258 char szLogpixels[MAXBUFLEN];
260 updating_ui = TRUE;
262 dwLogpixels = read_logpixels_reg();
263 WINE_TRACE("%d\n", (int) dwLogpixels);
265 szLogpixels[0] = 0;
266 sprintf(szLogpixels, "%d", dwLogpixels);
267 SendMessage(hDpiEditBox, WM_SETTEXT, 0, (LPARAM) szLogpixels);
269 updating_ui = FALSE;
272 static void init_trackbar(HWND hDlg)
274 HWND hTrackBar = GetDlgItem(hDlg, IDC_RES_TRACKBAR);
275 DWORD dwLogpixels;
277 updating_ui = TRUE;
279 dwLogpixels = read_logpixels_reg();
281 SendMessageW(hTrackBar, TBM_SETRANGE, TRUE, MAKELONG(MINDPI, MAXDPI));
282 SendMessageW(hTrackBar, TBM_SETPOS, TRUE, dwLogpixels);
284 updating_ui = FALSE;
287 INT_PTR CALLBACK
288 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
290 switch (uMsg) {
291 case WM_INITDIALOG:
292 init_dpi_editbox(hDlg);
293 init_trackbar(hDlg);
294 break;
296 case WM_SHOWWINDOW:
297 set_window_title(hDlg);
298 break;
300 case WM_COMMAND:
301 switch(HIWORD(wParam)) {
302 case EN_CHANGE: {
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);
307 break;
309 case BN_CLICKED: {
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;
318 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;
325 break;
328 default:
329 break;
331 break;
334 case WM_NOTIFY:
335 switch (((LPNMHDR)lParam)->code) {
336 case PSN_KILLACTIVE: {
337 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
338 break;
340 case PSN_APPLY: {
341 apply();
342 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
343 break;
345 case PSN_SETACTIVE: {
346 init_dialog (hDlg);
347 break;
350 break;
352 case WM_HSCROLL:
353 switch (wParam) {
354 default: {
355 char buf[MAXBUFLEN];
356 int i = SendMessageW(GetDlgItem(hDlg, IDC_RES_TRACKBAR), TBM_GETPOS, 0, 0);
357 buf[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);
361 break;
364 break;
366 default:
367 break;
369 return FALSE;