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
31 #include <wine/debug.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 */
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)
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";
69 buf
= get_reg_key(config_key
, L
"Explorer\\Desktops", desktop_name
, NULL
);
70 if (buf
&& (bufindex
= wcschr(buf
, 'x')))
74 SetDlgItemTextW(dialog
, IDC_DESKTOP_WIDTH
, buf
);
75 SetDlgItemTextW(dialog
, IDC_DESKTOP_HEIGHT
, bufindex
);
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
);
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
);
103 static BOOL
can_enable_desktop(void)
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"))
118 HeapFree(GetProcessHeap(), 0, value
);
123 static void init_dialog(HWND dialog
)
128 convert_x11_desktop_key();
129 if ((enable_desktop
= can_enable_desktop()))
130 update_gui_for_desktop_mode(dialog
);
132 disable(IDC_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
);
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
);
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
);
160 CheckDlgButton(dialog
, IDC_ENABLE_DECORATED
, BST_UNCHECKED
);
161 HeapFree(GetProcessHeap(), 0, buf
);
166 static void set_from_desktop_edits(HWND dialog
)
168 WCHAR
*width
, *height
;
169 int w
= 800, h
= 600;
171 const WCHAR
*desktop_name
= current_app
? current_app
: L
"Default";
173 if (updating_ui
) return;
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
) {
194 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_DESKTOP
) == BST_CHECKED
) {
195 set_from_desktop_edits(dialog
);
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
) {
206 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_MANAGED
) == BST_CHECKED
) {
207 set_reg_key(config_key
, keypath(L
"X11 Driver"), L
"Managed", L
"Y");
209 set_reg_key(config_key
, keypath(L
"X11 Driver"), L
"Managed", L
"N");
213 static void on_enable_decorated_clicked(HWND dialog
) {
216 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_DECORATED
) == BST_CHECKED
) {
217 set_reg_key(config_key
, keypath(L
"X11 Driver"), L
"Decorated", L
"Y");
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");
228 set_reg_key(config_key
, keypath(L
"X11 Driver"), L
"GrabFullscreen", L
"N");
231 static INT
read_logpixels_reg(void)
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
);
241 static void init_dpi_editbox(HWND hDlg
)
247 dwLogpixels
= read_logpixels_reg();
248 WINE_TRACE("%lu\n", dwLogpixels
);
250 SetDlgItemInt(hDlg
, IDC_RES_DPIEDIT
, dwLogpixels
, FALSE
);
255 static int get_trackbar_pos( UINT dpi
)
259 for (i
= 0; i
< ARRAY_SIZE(dpi_values
) - 1; i
++)
260 if ((dpi_values
[i
] + dpi_values
[i
+ 1]) / 2 >= dpi
) break;
264 static void init_trackbar(HWND hDlg
)
266 HWND hTrackBar
= GetDlgItem(hDlg
, IDC_RES_TRACKBAR
);
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
));
280 static void update_dpi_trackbar_from_edit(HWND hDlg
, BOOL fix
)
286 dpi
= GetDlgItemInt(hDlg
, IDC_RES_DPIEDIT
, NULL
, FALSE
);
290 DWORD fixed_dpi
= dpi
;
292 if (dpi
< MINDPI
) fixed_dpi
= MINDPI
;
293 if (dpi
> MAXDPI
) fixed_dpi
= MAXDPI
;
295 if (fixed_dpi
!= 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
);
311 static void update_font_preview(HWND hDlg
)
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};
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
);
333 lf
.lfHeight
= MulDiv(-10, dpi
, 72);
334 hfont
= CreateFontIndirectW(&lf
);
335 SendDlgItemMessageW(hDlg
, IDC_RES_FONT_PREVIEW
, WM_SETFONT
, (WPARAM
)hfont
, 1);
342 GraphDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
346 init_dpi_editbox(hDlg
);
348 update_font_preview(hDlg
);
352 set_window_title(hDlg
);
356 if (wParam
== IDT_DPIEDIT
)
358 KillTimer(hDlg
, IDT_DPIEDIT
);
359 update_dpi_trackbar_from_edit(hDlg
, TRUE
);
360 update_font_preview(hDlg
);
365 switch(HIWORD(wParam
)) {
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
);
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;
390 case CBN_SELCHANGE
: {
391 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
402 switch (((LPNMHDR
)lParam
)->code
) {
403 case PSN_KILLACTIVE
: {
404 SetWindowLongPtrW(hDlg
, DWLP_MSGRESULT
, FALSE
);
409 SetWindowLongPtrW(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
412 case PSN_SETACTIVE
: {
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
]);