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/unicode.h>
32 #include <wine/debug.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 */
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)
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
;
78 buf
= get_reg_keyW(config_key
, explorer_desktopsW
, desktop_name
, NULL
);
79 if (buf
&& (bufindex
= strchrW(buf
, 'x')))
83 SetDlgItemTextW(dialog
, IDC_DESKTOP_WIDTH
, buf
);
84 SetDlgItemTextW(dialog
, IDC_DESKTOP_HEIGHT
, bufindex
);
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
);
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
);
112 static void init_dialog(HWND dialog
)
116 convert_x11_desktop_key();
117 update_gui_for_desktop_mode(dialog
);
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
);
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
);
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
);
142 CheckDlgButton(dialog
, IDC_ENABLE_DECORATED
, BST_UNCHECKED
);
143 HeapFree(GetProcessHeap(), 0, buf
);
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;
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
);
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
) {
199 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_DESKTOP
) == BST_CHECKED
) {
200 set_from_desktop_edits(dialog
);
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
) {
211 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_MANAGED
) == BST_CHECKED
) {
212 set_reg_key(config_key
, keypath("X11 Driver"), "Managed", "Y");
214 set_reg_key(config_key
, keypath("X11 Driver"), "Managed", "N");
218 static void on_enable_decorated_clicked(HWND dialog
) {
221 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_DECORATED
) == BST_CHECKED
) {
222 set_reg_key(config_key
, keypath("X11 Driver"), "Decorated", "Y");
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");
233 set_reg_key(config_key
, keypath("X11 Driver"), "GrabFullscreen", "N");
236 static INT
read_logpixels_reg(void)
239 WCHAR
*buf
= get_reg_keyW(HKEY_LOCAL_MACHINE
, logpixels_reg
, logpixels
, NULL
);
240 dwLogPixels
= buf
? *buf
: DEFDPI
;
241 HeapFree(GetProcessHeap(), 0, buf
);
245 static void init_dpi_editbox(HWND hDlg
)
251 dwLogpixels
= read_logpixels_reg();
252 WINE_TRACE("%u\n", dwLogpixels
);
254 SetDlgItemInt(hDlg
, IDC_RES_DPIEDIT
, dwLogpixels
, FALSE
);
259 static void init_trackbar(HWND hDlg
)
261 HWND hTrackBar
= GetDlgItem(hDlg
, IDC_RES_TRACKBAR
);
266 dwLogpixels
= read_logpixels_reg();
268 SendMessageW(hTrackBar
, TBM_SETRANGE
, TRUE
, MAKELONG(MINDPI
, MAXDPI
));
269 SendMessageW(hTrackBar
, TBM_SETPOS
, TRUE
, dwLogpixels
);
274 static void update_dpi_trackbar_from_edit(HWND hDlg
, BOOL fix
)
280 dpi
= GetDlgItemInt(hDlg
, IDC_RES_DPIEDIT
, NULL
, FALSE
);
284 DWORD fixed_dpi
= dpi
;
286 if (dpi
< MINDPI
) fixed_dpi
= MINDPI
;
287 if (dpi
> MAXDPI
) fixed_dpi
= MAXDPI
;
289 if (fixed_dpi
!= 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
);
305 static void update_font_preview(HWND hDlg
)
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};
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
);
327 lf
.lfHeight
= MulDiv(-10, dpi
, 72);
328 hfont
= CreateFontIndirectW(&lf
);
329 SendDlgItemMessageW(hDlg
, IDC_RES_FONT_PREVIEW
, WM_SETFONT
, (WPARAM
)hfont
, 1);
336 GraphDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
340 init_dpi_editbox(hDlg
);
342 update_font_preview(hDlg
);
346 set_window_title(hDlg
);
350 if (wParam
== IDT_DPIEDIT
)
352 KillTimer(hDlg
, IDT_DPIEDIT
);
353 update_dpi_trackbar_from_edit(hDlg
, TRUE
);
354 update_font_preview(hDlg
);
359 switch(HIWORD(wParam
)) {
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
);
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;
384 case CBN_SELCHANGE
: {
385 SendMessageW(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
396 switch (((LPNMHDR
)lParam
)->code
) {
397 case PSN_KILLACTIVE
: {
398 SetWindowLongPtrW(hDlg
, DWLP_MSGRESULT
, FALSE
);
403 SetWindowLongPtrW(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
406 case PSN_SETACTIVE
: {
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
);