d3d11/tests: Add test for atomic instructions.
[wine.git] / programs / winecfg / x11drvdlg.c
blob9a14fb69808520b4027b79a4b37ed18dfc217aa7
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/unicode.h>
32 #include <wine/debug.h>
34 #include "resource.h"
35 #include "winecfg.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
39 #define RES_MAXLEN 5 /* max number of digits in a screen dimension. 5 digits should be plenty */
40 #define MINDPI 96
41 #define MAXDPI 480
42 #define DEFDPI 96
44 #define IDT_DPIEDIT 0x1234
46 static const WCHAR logpixels_reg[] = {'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\','H','a','r','d','w','a','r','e',' ','P','r','o','f','i','l','e','s','\\','C','u','r','r','e','n','t','\\','S','o','f','t','w','a','r','e','\\','F','o','n','t','s',0};
47 static const WCHAR logpixels[] = {'L','o','g','P','i','x','e','l','s',0};
49 static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
50 static const WCHAR defaultW[] = {'D','e','f','a','u','l','t',0};
51 static const WCHAR explorerW[] = {'E','x','p','l','o','r','e','r',0};
52 static const WCHAR explorer_desktopsW[] = {'E','x','p','l','o','r','e','r','\\',
53 'D','e','s','k','t','o','p','s',0};
56 static BOOL updating_ui;
58 /* convert the x11 desktop key to the new explorer config */
59 static void convert_x11_desktop_key(void)
61 char *buf;
63 if (!(buf = get_reg_key(config_key, "X11 Driver", "Desktop", NULL))) return;
64 set_reg_key(config_key, "Explorer\\Desktops", "Default", buf);
65 set_reg_key(config_key, "Explorer", "Desktop", "Default");
66 set_reg_key(config_key, "X11 Driver", "Desktop", NULL);
67 HeapFree(GetProcessHeap(), 0, buf);
70 static void update_gui_for_desktop_mode(HWND dialog)
72 WCHAR *buf, *bufindex;
73 const WCHAR *desktop_name = current_app ? current_app : defaultW;
75 WINE_TRACE("\n");
76 updating_ui = TRUE;
78 buf = get_reg_keyW(config_key, explorer_desktopsW, desktop_name, NULL);
79 if (buf && (bufindex = strchrW(buf, 'x')))
81 *bufindex++ = 0;
83 SetDlgItemTextW(dialog, IDC_DESKTOP_WIDTH, buf);
84 SetDlgItemTextW(dialog, IDC_DESKTOP_HEIGHT, bufindex);
85 } else {
86 SetDlgItemTextA(dialog, IDC_DESKTOP_WIDTH, "800");
87 SetDlgItemTextA(dialog, IDC_DESKTOP_HEIGHT, "600");
89 HeapFree(GetProcessHeap(), 0, buf);
91 /* do we have desktop mode enabled? */
92 if (reg_key_exists(config_key, keypath("Explorer"), "Desktop"))
94 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
95 enable(IDC_DESKTOP_WIDTH);
96 enable(IDC_DESKTOP_HEIGHT);
97 enable(IDC_DESKTOP_SIZE);
98 enable(IDC_DESKTOP_BY);
100 else
102 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
103 disable(IDC_DESKTOP_WIDTH);
104 disable(IDC_DESKTOP_HEIGHT);
105 disable(IDC_DESKTOP_SIZE);
106 disable(IDC_DESKTOP_BY);
109 updating_ui = FALSE;
112 static void init_dialog(HWND dialog)
114 char* buf;
116 convert_x11_desktop_key();
117 update_gui_for_desktop_mode(dialog);
119 updating_ui = TRUE;
121 SendDlgItemMessageW(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
122 SendDlgItemMessageW(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
124 buf = get_reg_key(config_key, keypath("X11 Driver"), "GrabFullscreen", "N");
125 if (IS_OPTION_TRUE(*buf))
126 CheckDlgButton(dialog, IDC_FULLSCREEN_GRAB, BST_CHECKED);
127 else
128 CheckDlgButton(dialog, IDC_FULLSCREEN_GRAB, BST_UNCHECKED);
129 HeapFree(GetProcessHeap(), 0, buf);
131 buf = get_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
132 if (IS_OPTION_TRUE(*buf))
133 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_CHECKED);
134 else
135 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_UNCHECKED);
136 HeapFree(GetProcessHeap(), 0, buf);
138 buf = get_reg_key(config_key, keypath("X11 Driver"), "Decorated", "Y");
139 if (IS_OPTION_TRUE(*buf))
140 CheckDlgButton(dialog, IDC_ENABLE_DECORATED, BST_CHECKED);
141 else
142 CheckDlgButton(dialog, IDC_ENABLE_DECORATED, BST_UNCHECKED);
143 HeapFree(GetProcessHeap(), 0, buf);
145 updating_ui = FALSE;
148 static void set_from_desktop_edits(HWND dialog)
150 static const WCHAR x[] = {'x',0};
151 static const WCHAR def_width[] = {'8','0','0',0};
152 static const WCHAR def_height[] = {'6','0','0',0};
153 static const WCHAR min_width[] = {'6','4','0',0};
154 static const WCHAR min_height[] = {'4','8','0',0};
155 WCHAR *width, *height, *new;
156 const WCHAR *desktop_name = current_app ? current_app : defaultW;
158 if (updating_ui) return;
160 WINE_TRACE("\n");
162 width = get_textW(dialog, IDC_DESKTOP_WIDTH);
163 height = get_textW(dialog, IDC_DESKTOP_HEIGHT);
165 if (!width || !width[0]) {
166 HeapFree(GetProcessHeap(), 0, width);
167 width = strdupW(def_width);
169 else if (atoiW(width) < atoiW(min_width))
171 HeapFree(GetProcessHeap(), 0, width);
172 width = strdupW(min_width);
174 if (!height || !height[0]) {
175 HeapFree(GetProcessHeap(), 0, height);
176 height = strdupW(def_height);
178 else if (atoiW(height) < atoiW(min_height))
180 HeapFree(GetProcessHeap(), 0, height);
181 height = strdupW(min_height);
184 new = HeapAlloc(GetProcessHeap(), 0, (strlenW(width) + strlenW(height) + 2) * sizeof(WCHAR));
185 strcpyW( new, width );
186 strcatW( new, x );
187 strcatW( new, height );
188 set_reg_keyW(config_key, explorer_desktopsW, desktop_name, new);
189 set_reg_keyW(config_key, keypathW(explorerW), desktopW, desktop_name);
191 HeapFree(GetProcessHeap(), 0, width);
192 HeapFree(GetProcessHeap(), 0, height);
193 HeapFree(GetProcessHeap(), 0, new);
196 static void on_enable_desktop_clicked(HWND dialog) {
197 WINE_TRACE("\n");
199 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
200 set_from_desktop_edits(dialog);
201 } else {
202 set_reg_key(config_key, keypath("Explorer"), "Desktop", NULL);
205 update_gui_for_desktop_mode(dialog);
208 static void on_enable_managed_clicked(HWND dialog) {
209 WINE_TRACE("\n");
211 if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
212 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
213 } else {
214 set_reg_key(config_key, keypath("X11 Driver"), "Managed", "N");
218 static void on_enable_decorated_clicked(HWND dialog) {
219 WINE_TRACE("\n");
221 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DECORATED) == BST_CHECKED) {
222 set_reg_key(config_key, keypath("X11 Driver"), "Decorated", "Y");
223 } else {
224 set_reg_key(config_key, keypath("X11 Driver"), "Decorated", "N");
228 static void on_fullscreen_grab_clicked(HWND dialog)
230 if (IsDlgButtonChecked(dialog, IDC_FULLSCREEN_GRAB) == BST_CHECKED)
231 set_reg_key(config_key, keypath("X11 Driver"), "GrabFullscreen", "Y");
232 else
233 set_reg_key(config_key, keypath("X11 Driver"), "GrabFullscreen", "N");
236 static INT read_logpixels_reg(void)
238 DWORD dwLogPixels;
239 WCHAR *buf = get_reg_keyW(HKEY_LOCAL_MACHINE, logpixels_reg, logpixels, NULL);
240 dwLogPixels = buf ? *buf : DEFDPI;
241 HeapFree(GetProcessHeap(), 0, buf);
242 return dwLogPixels;
245 static void init_dpi_editbox(HWND hDlg)
247 DWORD dwLogpixels;
249 updating_ui = TRUE;
251 dwLogpixels = read_logpixels_reg();
252 WINE_TRACE("%u\n", dwLogpixels);
254 SetDlgItemInt(hDlg, IDC_RES_DPIEDIT, dwLogpixels, FALSE);
256 updating_ui = FALSE;
259 static void init_trackbar(HWND hDlg)
261 HWND hTrackBar = GetDlgItem(hDlg, IDC_RES_TRACKBAR);
262 DWORD dwLogpixels;
264 updating_ui = TRUE;
266 dwLogpixels = read_logpixels_reg();
268 SendMessageW(hTrackBar, TBM_SETRANGE, TRUE, MAKELONG(MINDPI, MAXDPI));
269 SendMessageW(hTrackBar, TBM_SETPOS, TRUE, dwLogpixels);
271 updating_ui = FALSE;
274 static void update_dpi_trackbar_from_edit(HWND hDlg, BOOL fix)
276 DWORD dpi;
278 updating_ui = TRUE;
280 dpi = GetDlgItemInt(hDlg, IDC_RES_DPIEDIT, NULL, FALSE);
282 if (fix)
284 DWORD fixed_dpi = dpi;
286 if (dpi < MINDPI) fixed_dpi = MINDPI;
287 if (dpi > MAXDPI) fixed_dpi = MAXDPI;
289 if (fixed_dpi != dpi)
291 dpi = fixed_dpi;
292 SetDlgItemInt(hDlg, IDC_RES_DPIEDIT, dpi, FALSE);
296 if (dpi >= MINDPI && dpi <= MAXDPI)
298 SendDlgItemMessageW(hDlg, IDC_RES_TRACKBAR, TBM_SETPOS, TRUE, dpi);
299 set_reg_key_dwordW(HKEY_LOCAL_MACHINE, logpixels_reg, logpixels, dpi);
302 updating_ui = FALSE;
305 static void update_font_preview(HWND hDlg)
307 DWORD dpi;
309 updating_ui = TRUE;
311 dpi = GetDlgItemInt(hDlg, IDC_RES_DPIEDIT, NULL, FALSE);
313 if (dpi >= MINDPI && dpi <= MAXDPI)
315 static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
316 LOGFONTW lf;
317 HFONT hfont;
319 hfont = (HFONT)SendDlgItemMessageW(hDlg, IDC_RES_FONT_PREVIEW, WM_GETFONT, 0, 0);
321 GetObjectW(hfont, sizeof(lf), &lf);
323 if (strcmpW(lf.lfFaceName, tahomaW) != 0)
324 strcpyW(lf.lfFaceName, tahomaW);
325 else
326 DeleteObject(hfont);
327 lf.lfHeight = MulDiv(-10, dpi, 72);
328 hfont = CreateFontIndirectW(&lf);
329 SendDlgItemMessageW(hDlg, IDC_RES_FONT_PREVIEW, WM_SETFONT, (WPARAM)hfont, 1);
332 updating_ui = FALSE;
335 INT_PTR CALLBACK
336 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
338 switch (uMsg) {
339 case WM_INITDIALOG:
340 init_dpi_editbox(hDlg);
341 init_trackbar(hDlg);
342 update_font_preview(hDlg);
343 break;
345 case WM_SHOWWINDOW:
346 set_window_title(hDlg);
347 break;
349 case WM_TIMER:
350 if (wParam == IDT_DPIEDIT)
352 KillTimer(hDlg, IDT_DPIEDIT);
353 update_dpi_trackbar_from_edit(hDlg, TRUE);
354 update_font_preview(hDlg);
356 break;
358 case WM_COMMAND:
359 switch(HIWORD(wParam)) {
360 case EN_CHANGE: {
361 if (updating_ui) break;
362 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
363 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
364 set_from_desktop_edits(hDlg);
365 else if (LOWORD(wParam) == IDC_RES_DPIEDIT)
367 update_dpi_trackbar_from_edit(hDlg, FALSE);
368 update_font_preview(hDlg);
369 SetTimer(hDlg, IDT_DPIEDIT, 1500, NULL);
371 break;
373 case BN_CLICKED: {
374 if (updating_ui) break;
375 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
376 switch(LOWORD(wParam)) {
377 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
378 case IDC_ENABLE_MANAGED: on_enable_managed_clicked(hDlg); break;
379 case IDC_ENABLE_DECORATED: on_enable_decorated_clicked(hDlg); break;
380 case IDC_FULLSCREEN_GRAB: on_fullscreen_grab_clicked(hDlg); break;
382 break;
384 case CBN_SELCHANGE: {
385 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
386 break;
389 default:
390 break;
392 break;
395 case WM_NOTIFY:
396 switch (((LPNMHDR)lParam)->code) {
397 case PSN_KILLACTIVE: {
398 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
399 break;
401 case PSN_APPLY: {
402 apply();
403 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
404 break;
406 case PSN_SETACTIVE: {
407 init_dialog (hDlg);
408 break;
411 break;
413 case WM_HSCROLL:
414 switch (wParam) {
415 default: {
416 int i = SendMessageW(GetDlgItem(hDlg, IDC_RES_TRACKBAR), TBM_GETPOS, 0, 0);
417 SetDlgItemInt(hDlg, IDC_RES_DPIEDIT, i, TRUE);
418 update_font_preview(hDlg);
419 set_reg_key_dwordW(HKEY_LOCAL_MACHINE, logpixels_reg, logpixels, i);
420 break;
423 break;
425 default:
426 break;
428 return FALSE;