include/mshtmhst: Add CGID_ScriptSite and CMDIDs for it.
[wine.git] / programs / winecfg / x11drvdlg.c
bloba480eac7ead5b837938ff8b2cc79746adc8636fb
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 /* max number of digits in a screen dimension. 5 digits should be plenty */
39 #define MINDPI 96
40 #define MAXDPI 480
41 #define DEFDPI 96
43 #define IDT_DPIEDIT 0x1234
45 static const UINT dpi_values[] = { 96, 120, 144, 168, 192, 216, 240, 288, 336, 384, 432, 480 };
47 static BOOL updating_ui;
49 /* convert the x11 desktop key to the new explorer config */
50 static void convert_x11_desktop_key(void)
52 WCHAR *buf;
54 if (!(buf = get_reg_key(config_key, L"X11 Driver", L"Desktop", NULL))) return;
55 set_reg_key(config_key, L"Explorer\\Desktops", L"Default", buf);
56 set_reg_key(config_key, L"Explorer", L"Desktop", L"Default");
57 set_reg_key(config_key, L"X11 Driver", L"Desktop", NULL);
58 HeapFree(GetProcessHeap(), 0, buf);
61 static void update_gui_for_desktop_mode(HWND dialog)
63 WCHAR *buf, *bufindex;
64 const WCHAR *desktop_name = current_app ? current_app : L"Default";
66 WINE_TRACE("\n");
67 updating_ui = TRUE;
69 buf = get_reg_key(config_key, L"Explorer\\Desktops", desktop_name, NULL);
70 if (buf && (bufindex = wcschr(buf, 'x')))
72 *bufindex++ = 0;
74 SetDlgItemTextW(dialog, IDC_DESKTOP_WIDTH, buf);
75 SetDlgItemTextW(dialog, IDC_DESKTOP_HEIGHT, bufindex);
76 } else {
77 SetDlgItemTextW(dialog, IDC_DESKTOP_WIDTH, L"800");
78 SetDlgItemTextW(dialog, IDC_DESKTOP_HEIGHT, L"600");
80 HeapFree(GetProcessHeap(), 0, buf);
82 /* do we have desktop mode enabled? */
83 if (reg_key_exists(config_key, keypath(L"Explorer"), L"Desktop"))
85 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
86 enable(IDC_DESKTOP_WIDTH);
87 enable(IDC_DESKTOP_HEIGHT);
88 enable(IDC_DESKTOP_SIZE);
89 enable(IDC_DESKTOP_BY);
91 else
93 CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
94 disable(IDC_DESKTOP_WIDTH);
95 disable(IDC_DESKTOP_HEIGHT);
96 disable(IDC_DESKTOP_SIZE);
97 disable(IDC_DESKTOP_BY);
100 updating_ui = FALSE;
103 static BOOL can_enable_desktop(void)
105 WCHAR *value;
106 UINT guid_atom;
107 BOOL ret = FALSE;
108 WCHAR key[sizeof("System\\CurrentControlSet\\Control\\Video\\{}\\0000") + 40];
110 guid_atom = HandleToULong(GetPropW(GetDesktopWindow(), L"__wine_display_device_guid"));
111 wcscpy( key, L"System\\CurrentControlSet\\Control\\Video\\{" );
112 if (!GlobalGetAtomNameW(guid_atom, key + wcslen(key), 40)) return ret;
113 wcscat( key, L"}\\0000" );
114 if ((value = get_reg_key(HKEY_LOCAL_MACHINE, key, L"GraphicsDriver", NULL)))
116 if(wcscmp(value, L"winemac.drv"))
117 ret = TRUE;
118 HeapFree(GetProcessHeap(), 0, value);
120 return ret;
123 static void init_dialog(HWND dialog)
125 WCHAR *buf;
126 BOOL enable_desktop;
128 convert_x11_desktop_key();
129 if ((enable_desktop = can_enable_desktop()))
130 update_gui_for_desktop_mode(dialog);
131 else
132 disable(IDC_ENABLE_DESKTOP);
134 updating_ui = TRUE;
136 if (enable_desktop)
138 SendDlgItemMessageW(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
139 SendDlgItemMessageW(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
142 buf = get_reg_key(config_key, keypath(L"X11 Driver"), L"GrabFullscreen", L"N");
143 if (IS_OPTION_TRUE(*buf))
144 CheckDlgButton(dialog, IDC_FULLSCREEN_GRAB, BST_CHECKED);
145 else
146 CheckDlgButton(dialog, IDC_FULLSCREEN_GRAB, BST_UNCHECKED);
147 HeapFree(GetProcessHeap(), 0, buf);
149 buf = get_reg_key(config_key, keypath(L"X11 Driver"), L"Managed", L"Y");
150 if (IS_OPTION_TRUE(*buf))
151 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_CHECKED);
152 else
153 CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_UNCHECKED);
154 HeapFree(GetProcessHeap(), 0, buf);
156 buf = get_reg_key(config_key, keypath(L"X11 Driver"), L"Decorated", L"Y");
157 if (IS_OPTION_TRUE(*buf))
158 CheckDlgButton(dialog, IDC_ENABLE_DECORATED, BST_CHECKED);
159 else
160 CheckDlgButton(dialog, IDC_ENABLE_DECORATED, BST_UNCHECKED);
161 HeapFree(GetProcessHeap(), 0, buf);
163 updating_ui = FALSE;
166 static void set_from_desktop_edits(HWND dialog)
168 WCHAR *width, *height;
169 int w = 800, h = 600;
170 WCHAR buffer[32];
171 const WCHAR *desktop_name = current_app ? current_app : L"Default";
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 && width[0]) w = max( 640, wcstol(width, NULL, 10) );
181 if (height && height[0]) h = max( 480, wcstol(height, NULL, 10) );
183 swprintf( buffer, ARRAY_SIZE(buffer), L"%ux%u", w, h );
184 set_reg_key(config_key, L"Explorer\\Desktops", desktop_name, buffer);
185 set_reg_key(config_key, keypath(L"Explorer"), L"Desktop", desktop_name);
187 HeapFree(GetProcessHeap(), 0, width);
188 HeapFree(GetProcessHeap(), 0, height);
191 static void on_enable_desktop_clicked(HWND dialog) {
192 WINE_TRACE("\n");
194 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
195 set_from_desktop_edits(dialog);
196 } else {
197 set_reg_key(config_key, keypath(L"Explorer"), L"Desktop", NULL);
200 update_gui_for_desktop_mode(dialog);
203 static void on_enable_managed_clicked(HWND dialog) {
204 WINE_TRACE("\n");
206 if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
207 set_reg_key(config_key, keypath(L"X11 Driver"), L"Managed", L"Y");
208 } else {
209 set_reg_key(config_key, keypath(L"X11 Driver"), L"Managed", L"N");
213 static void on_enable_decorated_clicked(HWND dialog) {
214 WINE_TRACE("\n");
216 if (IsDlgButtonChecked(dialog, IDC_ENABLE_DECORATED) == BST_CHECKED) {
217 set_reg_key(config_key, keypath(L"X11 Driver"), L"Decorated", L"Y");
218 } else {
219 set_reg_key(config_key, keypath(L"X11 Driver"), L"Decorated", L"N");
223 static void on_fullscreen_grab_clicked(HWND dialog)
225 if (IsDlgButtonChecked(dialog, IDC_FULLSCREEN_GRAB) == BST_CHECKED)
226 set_reg_key(config_key, keypath(L"X11 Driver"), L"GrabFullscreen", L"Y");
227 else
228 set_reg_key(config_key, keypath(L"X11 Driver"), L"GrabFullscreen", L"N");
231 static INT read_logpixels_reg(void)
233 DWORD dwLogPixels;
234 WCHAR *buf = get_reg_key(HKEY_CURRENT_USER, L"Control Panel\\Desktop", L"LogPixels", NULL);
235 if (!buf) buf = get_reg_key(HKEY_CURRENT_CONFIG, L"Software\\Fonts", L"LogPixels", NULL);
236 dwLogPixels = buf ? *buf : DEFDPI;
237 HeapFree(GetProcessHeap(), 0, buf);
238 return dwLogPixels;
241 static void init_dpi_editbox(HWND hDlg)
243 DWORD dwLogpixels;
245 updating_ui = TRUE;
247 dwLogpixels = read_logpixels_reg();
248 WINE_TRACE("%lu\n", dwLogpixels);
250 SetDlgItemInt(hDlg, IDC_RES_DPIEDIT, dwLogpixels, FALSE);
252 updating_ui = FALSE;
255 static int get_trackbar_pos( UINT dpi )
257 UINT i;
259 for (i = 0; i < ARRAY_SIZE(dpi_values) - 1; i++)
260 if ((dpi_values[i] + dpi_values[i + 1]) / 2 >= dpi) break;
261 return i;
264 static void init_trackbar(HWND hDlg)
266 HWND hTrackBar = GetDlgItem(hDlg, IDC_RES_TRACKBAR);
267 DWORD dwLogpixels;
269 updating_ui = TRUE;
271 dwLogpixels = read_logpixels_reg();
273 SendMessageW(hTrackBar, TBM_SETRANGE, TRUE, MAKELONG(0, ARRAY_SIZE(dpi_values)-1));
274 SendMessageW(hTrackBar, TBM_SETPAGESIZE, 0, 1);
275 SendMessageW(hTrackBar, TBM_SETPOS, TRUE, get_trackbar_pos(dwLogpixels));
277 updating_ui = FALSE;
280 static void update_dpi_trackbar_from_edit(HWND hDlg, BOOL fix)
282 DWORD dpi;
284 updating_ui = TRUE;
286 dpi = GetDlgItemInt(hDlg, IDC_RES_DPIEDIT, NULL, FALSE);
288 if (fix)
290 DWORD fixed_dpi = dpi;
292 if (dpi < MINDPI) fixed_dpi = MINDPI;
293 if (dpi > MAXDPI) fixed_dpi = MAXDPI;
295 if (fixed_dpi != dpi)
297 dpi = fixed_dpi;
298 SetDlgItemInt(hDlg, IDC_RES_DPIEDIT, dpi, FALSE);
302 if (dpi >= MINDPI && dpi <= MAXDPI)
304 SendDlgItemMessageW(hDlg, IDC_RES_TRACKBAR, TBM_SETPOS, TRUE, get_trackbar_pos(dpi));
305 set_reg_key_dword(HKEY_CURRENT_USER, L"Control Panel\\Desktop", L"LogPixels", dpi);
308 updating_ui = FALSE;
311 static void update_font_preview(HWND hDlg)
313 DWORD dpi;
315 updating_ui = TRUE;
317 dpi = GetDlgItemInt(hDlg, IDC_RES_DPIEDIT, NULL, FALSE);
319 if (dpi >= MINDPI && dpi <= MAXDPI)
321 static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
322 LOGFONTW lf;
323 HFONT hfont;
325 hfont = (HFONT)SendDlgItemMessageW(hDlg, IDC_RES_FONT_PREVIEW, WM_GETFONT, 0, 0);
327 GetObjectW(hfont, sizeof(lf), &lf);
329 if (wcscmp(lf.lfFaceName, tahomaW) != 0)
330 lstrcpyW(lf.lfFaceName, tahomaW);
331 else
332 DeleteObject(hfont);
333 lf.lfHeight = MulDiv(-10, dpi, 72);
334 hfont = CreateFontIndirectW(&lf);
335 SendDlgItemMessageW(hDlg, IDC_RES_FONT_PREVIEW, WM_SETFONT, (WPARAM)hfont, 1);
338 updating_ui = FALSE;
341 INT_PTR CALLBACK
342 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
344 switch (uMsg) {
345 case WM_INITDIALOG:
346 init_dpi_editbox(hDlg);
347 init_trackbar(hDlg);
348 update_font_preview(hDlg);
349 break;
351 case WM_SHOWWINDOW:
352 set_window_title(hDlg);
353 break;
355 case WM_TIMER:
356 if (wParam == IDT_DPIEDIT)
358 KillTimer(hDlg, IDT_DPIEDIT);
359 update_dpi_trackbar_from_edit(hDlg, TRUE);
360 update_font_preview(hDlg);
362 break;
364 case WM_COMMAND:
365 switch(HIWORD(wParam)) {
366 case EN_CHANGE: {
367 if (updating_ui) break;
368 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
369 if ( ((LOWORD(wParam) == IDC_DESKTOP_WIDTH) || (LOWORD(wParam) == IDC_DESKTOP_HEIGHT)) && !updating_ui )
370 set_from_desktop_edits(hDlg);
371 else if (LOWORD(wParam) == IDC_RES_DPIEDIT)
373 update_dpi_trackbar_from_edit(hDlg, FALSE);
374 update_font_preview(hDlg);
375 SetTimer(hDlg, IDT_DPIEDIT, 1500, NULL);
377 break;
379 case BN_CLICKED: {
380 if (updating_ui) break;
381 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
382 switch(LOWORD(wParam)) {
383 case IDC_ENABLE_DESKTOP: on_enable_desktop_clicked(hDlg); break;
384 case IDC_ENABLE_MANAGED: on_enable_managed_clicked(hDlg); break;
385 case IDC_ENABLE_DECORATED: on_enable_decorated_clicked(hDlg); break;
386 case IDC_FULLSCREEN_GRAB: on_fullscreen_grab_clicked(hDlg); break;
388 break;
390 case CBN_SELCHANGE: {
391 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
392 break;
395 default:
396 break;
398 break;
401 case WM_NOTIFY:
402 switch (((LPNMHDR)lParam)->code) {
403 case PSN_KILLACTIVE: {
404 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, FALSE);
405 break;
407 case PSN_APPLY: {
408 apply();
409 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
410 break;
412 case PSN_SETACTIVE: {
413 init_dialog (hDlg);
414 break;
417 break;
419 case WM_HSCROLL:
420 switch (wParam) {
421 default: {
422 int i = SendMessageW(GetDlgItem(hDlg, IDC_RES_TRACKBAR), TBM_GETPOS, 0, 0);
423 SetDlgItemInt(hDlg, IDC_RES_DPIEDIT, dpi_values[i], TRUE);
424 update_font_preview(hDlg);
425 set_reg_key_dword(HKEY_CURRENT_USER, L"Control Panel\\Desktop", L"LogPixels", dpi_values[i]);
426 break;
429 break;
431 default:
432 break;
434 return FALSE;