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 /* 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? */
43 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};
44 static const WCHAR logpixels
[] = {'L','o','g','P','i','x','e','l','s',0};
46 static struct SHADERMODE
49 const char* settingStr
;
50 } const D3D_VS_Modes
[] = {
51 {IDS_SHADER_MODE_HARDWARE
, "hardware"},
52 {IDS_SHADER_MODE_NONE
, "none"},
59 static void update_gui_for_desktop_mode(HWND dialog
) {
60 int desktopenabled
= FALSE
;
67 disable(IDC_ENABLE_DESKTOP
);
68 disable(IDC_DESKTOP_WIDTH
);
69 disable(IDC_DESKTOP_HEIGHT
);
70 disable(IDC_DESKTOP_SIZE
);
71 disable(IDC_DESKTOP_BY
);
74 enable(IDC_ENABLE_DESKTOP
);
76 /* do we have desktop mode enabled? */
77 if (reg_key_exists(config_key
, keypath("X11 Driver"), "Desktop"))
80 CheckDlgButton(dialog
, IDC_ENABLE_DESKTOP
, BST_CHECKED
);
82 buf
= get_reg_key(config_key
, keypath("X11 Driver"), "Desktop", "800x600");
83 /* note: this test must match the one in x11drv */
84 if( buf
[0] != 'n' && buf
[0] != 'N' && buf
[0] != 'F' && buf
[0] != 'f'
86 desktopenabled
= TRUE
;
87 enable(IDC_DESKTOP_WIDTH
);
88 enable(IDC_DESKTOP_HEIGHT
);
89 enable(IDC_DESKTOP_SIZE
);
90 enable(IDC_DESKTOP_BY
);
92 bufindex
= strchr(buf
, 'x');
96 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_WIDTH
), buf
);
97 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_HEIGHT
), bufindex
);
99 WINE_TRACE("Desktop registry entry is malformed\n");
100 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_WIDTH
), "800");
101 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_HEIGHT
), "600");
104 HeapFree(GetProcessHeap(), 0, buf
);
108 CheckDlgButton(dialog
, IDC_ENABLE_DESKTOP
, BST_UNCHECKED
);
110 disable(IDC_DESKTOP_WIDTH
);
111 disable(IDC_DESKTOP_HEIGHT
);
112 disable(IDC_DESKTOP_SIZE
);
113 disable(IDC_DESKTOP_BY
);
115 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_WIDTH
), "");
116 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_HEIGHT
), "");
122 static void init_dialog(HWND dialog
)
127 update_gui_for_desktop_mode(dialog
);
131 SendDlgItemMessage(dialog
, IDC_DESKTOP_WIDTH
, EM_LIMITTEXT
, RES_MAXLEN
, 0);
132 SendDlgItemMessage(dialog
, IDC_DESKTOP_HEIGHT
, EM_LIMITTEXT
, RES_MAXLEN
, 0);
134 buf
= get_reg_key(config_key
, keypath("X11 Driver"), "DXGrab", "N");
135 if (IS_OPTION_TRUE(*buf
))
136 CheckDlgButton(dialog
, IDC_DX_MOUSE_GRAB
, BST_CHECKED
);
138 CheckDlgButton(dialog
, IDC_DX_MOUSE_GRAB
, BST_UNCHECKED
);
139 HeapFree(GetProcessHeap(), 0, buf
);
141 buf
= get_reg_key(config_key
, keypath("X11 Driver"), "Managed", "Y");
142 if (IS_OPTION_TRUE(*buf
))
143 CheckDlgButton(dialog
, IDC_ENABLE_MANAGED
, BST_CHECKED
);
145 CheckDlgButton(dialog
, IDC_ENABLE_MANAGED
, BST_UNCHECKED
);
146 HeapFree(GetProcessHeap(), 0, buf
);
148 SendDlgItemMessage(dialog
, IDC_D3D_VSHADER_MODE
, CB_RESETCONTENT
, 0, 0);
149 for (it
= 0; 0 != D3D_VS_Modes
[it
].displayStrID
; ++it
) {
150 SendDlgItemMessageW (dialog
, IDC_D3D_VSHADER_MODE
, CB_ADDSTRING
, 0,
151 (LPARAM
)load_string (D3D_VS_Modes
[it
].displayStrID
));
153 buf
= get_reg_key(config_key
, keypath("Direct3D"), "VertexShaderMode", "hardware");
154 for (it
= 0; NULL
!= D3D_VS_Modes
[it
].settingStr
; ++it
) {
155 if (strcmp(buf
, D3D_VS_Modes
[it
].settingStr
) == 0) {
156 SendDlgItemMessage(dialog
, IDC_D3D_VSHADER_MODE
, CB_SETCURSEL
, it
, 0);
160 if (NULL
== D3D_VS_Modes
[it
].settingStr
) {
161 WINE_ERR("Invalid Direct3D VertexShader Mode read from registry (%s)\n", buf
);
163 HeapFree(GetProcessHeap(), 0, buf
);
165 buf
= get_reg_key(config_key
, keypath("Direct3D"), "PixelShaderMode", "enabled");
166 if (!strcmp(buf
, "enabled"))
167 CheckDlgButton(dialog
, IDC_D3D_PSHADER_MODE
, BST_CHECKED
);
169 CheckDlgButton(dialog
, IDC_D3D_PSHADER_MODE
, BST_UNCHECKED
);
170 HeapFree(GetProcessHeap(), 0, buf
);
175 static void set_from_desktop_edits(HWND dialog
) {
176 char *width
, *height
, *new;
178 if (updating_ui
) return;
182 width
= get_text(dialog
, IDC_DESKTOP_WIDTH
);
183 height
= get_text(dialog
, IDC_DESKTOP_HEIGHT
);
185 if (width
== NULL
|| strcmp(width
, "") == 0) {
186 HeapFree(GetProcessHeap(), 0, width
);
187 width
= strdupA("800");
190 if (height
== NULL
|| strcmp(height
, "") == 0) {
191 HeapFree(GetProcessHeap(), 0, height
);
192 height
= strdupA("600");
195 new = HeapAlloc(GetProcessHeap(), 0, strlen(width
) + strlen(height
) + 2 /* x + terminator */);
196 sprintf(new, "%sx%s", width
, height
);
197 set_reg_key(config_key
, keypath("X11 Driver"), "Desktop", new);
199 HeapFree(GetProcessHeap(), 0, width
);
200 HeapFree(GetProcessHeap(), 0, height
);
201 HeapFree(GetProcessHeap(), 0, new);
204 static void on_enable_desktop_clicked(HWND dialog
) {
207 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_DESKTOP
) == BST_CHECKED
) {
208 set_from_desktop_edits(dialog
);
210 set_reg_key(config_key
, keypath("X11 Driver"), "Desktop", NULL
);
213 update_gui_for_desktop_mode(dialog
);
216 static void on_enable_managed_clicked(HWND dialog
) {
219 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_MANAGED
) == BST_CHECKED
) {
220 set_reg_key(config_key
, keypath("X11 Driver"), "Managed", "Y");
222 set_reg_key(config_key
, keypath("X11 Driver"), "Managed", "N");
226 static void on_dx_mouse_grab_clicked(HWND dialog
) {
227 if (IsDlgButtonChecked(dialog
, IDC_DX_MOUSE_GRAB
) == BST_CHECKED
)
228 set_reg_key(config_key
, keypath("X11 Driver"), "DXGrab", "Y");
230 set_reg_key(config_key
, keypath("X11 Driver"), "DXGrab", "N");
233 static void on_d3d_vshader_mode_changed(HWND dialog
) {
234 int selected_mode
= SendDlgItemMessage(dialog
, IDC_D3D_VSHADER_MODE
, CB_GETCURSEL
, 0, 0);
235 set_reg_key(config_key
, keypath("Direct3D"), "VertexShaderMode",
236 D3D_VS_Modes
[selected_mode
].settingStr
);
239 static void on_d3d_pshader_mode_clicked(HWND dialog
) {
240 if (IsDlgButtonChecked(dialog
, IDC_D3D_PSHADER_MODE
) == BST_CHECKED
)
241 set_reg_key(config_key
, keypath("Direct3D"), "PixelShaderMode", "enabled");
243 set_reg_key(config_key
, keypath("Direct3D"), "PixelShaderMode", "disabled");
245 static INT
read_logpixels_reg(void)
248 WCHAR
*buf
= get_reg_keyW(HKEY_LOCAL_MACHINE
, logpixels_reg
, logpixels
, NULL
);
249 dwLogPixels
= buf
? *buf
: DEFDPI
;
250 HeapFree(GetProcessHeap(), 0, buf
);
254 static void init_dpi_editbox(HWND hDlg
)
256 HWND hDpiEditBox
= GetDlgItem(hDlg
, IDC_RES_DPIEDIT
);
258 char szLogpixels
[MAXBUFLEN
];
262 dwLogpixels
= read_logpixels_reg();
263 WINE_TRACE("%d\n", (int) dwLogpixels
);
266 sprintf(szLogpixels
, "%d", dwLogpixels
);
267 SendMessage(hDpiEditBox
, WM_SETTEXT
, 0, (LPARAM
) szLogpixels
);
272 static void init_trackbar(HWND hDlg
)
274 HWND hTrackBar
= GetDlgItem(hDlg
, IDC_RES_TRACKBAR
);
279 dwLogpixels
= read_logpixels_reg();
281 SendMessageW(hTrackBar
, TBM_SETRANGE
, TRUE
, MAKELONG(MINDPI
, MAXDPI
));
282 SendMessageW(hTrackBar
, TBM_SETPOS
, TRUE
, dwLogpixels
);
288 GraphDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
292 init_dpi_editbox(hDlg
);
297 set_window_title(hDlg
);
301 switch(HIWORD(wParam
)) {
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
);
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;
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;
335 switch (((LPNMHDR
)lParam
)->code
) {
336 case PSN_KILLACTIVE
: {
337 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
342 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
345 case PSN_SETACTIVE
: {
356 int i
= SendMessageW(GetDlgItem(hDlg
, IDC_RES_TRACKBAR
), TBM_GETPOS
, 0, 0);
358 sprintf(buf
, "%d", i
);
359 SendMessage(GetDlgItem(hDlg
, IDC_RES_DPIEDIT
), WM_SETTEXT
, 0, (LPARAM
) buf
);
360 set_reg_key_dwordW(HKEY_LOCAL_MACHINE
, logpixels_reg
, logpixels
, i
);