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? */
41 static struct SHADERMODE
44 const char* settingStr
;
45 } const D3D_VS_Modes
[] = {
46 {IDS_SHADER_MODE_HARDWARE
, "hardware"},
47 {IDS_SHADER_MODE_NONE
, "none"},
54 static void update_gui_for_desktop_mode(HWND dialog
) {
55 int desktopenabled
= FALSE
;
62 disable(IDC_ENABLE_DESKTOP
);
63 disable(IDC_DESKTOP_WIDTH
);
64 disable(IDC_DESKTOP_HEIGHT
);
65 disable(IDC_DESKTOP_SIZE
);
66 disable(IDC_DESKTOP_BY
);
69 enable(IDC_ENABLE_DESKTOP
);
71 /* do we have desktop mode enabled? */
72 if (reg_key_exists(config_key
, keypath("X11 Driver"), "Desktop"))
75 CheckDlgButton(dialog
, IDC_ENABLE_DESKTOP
, BST_CHECKED
);
77 buf
= get_reg_key(config_key
, keypath("X11 Driver"), "Desktop", "640x480");
78 /* note: this test must match the one in x11drv */
79 if( buf
[0] != 'n' && buf
[0] != 'N' && buf
[0] != 'F' && buf
[0] != 'f'
81 desktopenabled
= TRUE
;
82 enable(IDC_DESKTOP_WIDTH
);
83 enable(IDC_DESKTOP_HEIGHT
);
84 enable(IDC_DESKTOP_SIZE
);
85 enable(IDC_DESKTOP_BY
);
87 bufindex
= strchr(buf
, 'x');
91 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_WIDTH
), buf
);
92 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_HEIGHT
), bufindex
);
94 WINE_TRACE("Desktop registry entry is malformed\n");
95 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_WIDTH
), "640");
96 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_HEIGHT
), "480");
99 HeapFree(GetProcessHeap(), 0, buf
);
103 CheckDlgButton(dialog
, IDC_ENABLE_DESKTOP
, BST_UNCHECKED
);
105 disable(IDC_DESKTOP_WIDTH
);
106 disable(IDC_DESKTOP_HEIGHT
);
107 disable(IDC_DESKTOP_SIZE
);
108 disable(IDC_DESKTOP_BY
);
110 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_WIDTH
), "");
111 SetWindowText(GetDlgItem(dialog
, IDC_DESKTOP_HEIGHT
), "");
117 static void init_dialog(HWND dialog
)
122 update_gui_for_desktop_mode(dialog
);
126 SendDlgItemMessage(dialog
, IDC_DESKTOP_WIDTH
, EM_LIMITTEXT
, RES_MAXLEN
, 0);
127 SendDlgItemMessage(dialog
, IDC_DESKTOP_HEIGHT
, EM_LIMITTEXT
, RES_MAXLEN
, 0);
129 buf
= get_reg_key(config_key
, keypath("X11 Driver"), "DXGrab", "N");
130 if (IS_OPTION_TRUE(*buf
))
131 CheckDlgButton(dialog
, IDC_DX_MOUSE_GRAB
, BST_CHECKED
);
133 CheckDlgButton(dialog
, IDC_DX_MOUSE_GRAB
, BST_UNCHECKED
);
134 HeapFree(GetProcessHeap(), 0, buf
);
136 buf
= get_reg_key(config_key
, keypath("X11 Driver"), "Managed", "Y");
137 if (IS_OPTION_TRUE(*buf
))
138 CheckDlgButton(dialog
, IDC_ENABLE_MANAGED
, BST_CHECKED
);
140 CheckDlgButton(dialog
, IDC_ENABLE_MANAGED
, BST_UNCHECKED
);
141 HeapFree(GetProcessHeap(), 0, buf
);
143 SendDlgItemMessage(dialog
, IDC_D3D_VSHADER_MODE
, CB_RESETCONTENT
, 0, 0);
144 for (it
= 0; 0 != D3D_VS_Modes
[it
].displayStrID
; ++it
) {
145 SendDlgItemMessageW (dialog
, IDC_D3D_VSHADER_MODE
, CB_ADDSTRING
, 0,
146 (LPARAM
)load_string (D3D_VS_Modes
[it
].displayStrID
));
148 buf
= get_reg_key(config_key
, keypath("Direct3D"), "VertexShaderMode", "hardware");
149 for (it
= 0; NULL
!= D3D_VS_Modes
[it
].settingStr
; ++it
) {
150 if (strcmp(buf
, D3D_VS_Modes
[it
].settingStr
) == 0) {
151 SendDlgItemMessage(dialog
, IDC_D3D_VSHADER_MODE
, CB_SETCURSEL
, it
, 0);
155 if (NULL
== D3D_VS_Modes
[it
].settingStr
) {
156 WINE_ERR("Invalid Direct3D VertexShader Mode read from registry (%s)\n", buf
);
158 HeapFree(GetProcessHeap(), 0, buf
);
160 buf
= get_reg_key(config_key
, keypath("Direct3D"), "PixelShaderMode", "enabled");
161 if (!strcmp(buf
, "enabled"))
162 CheckDlgButton(dialog
, IDC_D3D_PSHADER_MODE
, BST_CHECKED
);
164 CheckDlgButton(dialog
, IDC_D3D_PSHADER_MODE
, BST_UNCHECKED
);
165 HeapFree(GetProcessHeap(), 0, buf
);
170 static void set_from_desktop_edits(HWND dialog
) {
171 char *width
, *height
, *new;
173 if (updating_ui
) return;
177 width
= get_text(dialog
, IDC_DESKTOP_WIDTH
);
178 height
= get_text(dialog
, IDC_DESKTOP_HEIGHT
);
180 if (width
== NULL
|| strcmp(width
, "") == 0) {
181 HeapFree(GetProcessHeap(), 0, width
);
182 width
= strdupA("640");
185 if (height
== NULL
|| strcmp(height
, "") == 0) {
186 HeapFree(GetProcessHeap(), 0, height
);
187 height
= strdupA("480");
190 new = HeapAlloc(GetProcessHeap(), 0, strlen(width
) + strlen(height
) + 2 /* x + terminator */);
191 sprintf(new, "%sx%s", width
, height
);
192 set_reg_key(config_key
, keypath("X11 Driver"), "Desktop", new);
194 HeapFree(GetProcessHeap(), 0, width
);
195 HeapFree(GetProcessHeap(), 0, height
);
196 HeapFree(GetProcessHeap(), 0, new);
199 static void on_enable_desktop_clicked(HWND dialog
) {
202 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_DESKTOP
) == BST_CHECKED
) {
203 set_from_desktop_edits(dialog
);
205 set_reg_key(config_key
, keypath("X11 Driver"), "Desktop", NULL
);
208 update_gui_for_desktop_mode(dialog
);
211 static void on_enable_managed_clicked(HWND dialog
) {
214 if (IsDlgButtonChecked(dialog
, IDC_ENABLE_MANAGED
) == BST_CHECKED
) {
215 set_reg_key(config_key
, keypath("X11 Driver"), "Managed", "Y");
217 set_reg_key(config_key
, keypath("X11 Driver"), "Managed", "N");
221 static void on_dx_mouse_grab_clicked(HWND dialog
) {
222 if (IsDlgButtonChecked(dialog
, IDC_DX_MOUSE_GRAB
) == BST_CHECKED
)
223 set_reg_key(config_key
, keypath("X11 Driver"), "DXGrab", "Y");
225 set_reg_key(config_key
, keypath("X11 Driver"), "DXGrab", "N");
228 static void on_d3d_vshader_mode_changed(HWND dialog
) {
229 int selected_mode
= SendDlgItemMessage(dialog
, IDC_D3D_VSHADER_MODE
, CB_GETCURSEL
, 0, 0);
230 set_reg_key(config_key
, keypath("Direct3D"), "VertexShaderMode",
231 D3D_VS_Modes
[selected_mode
].settingStr
);
234 static void on_d3d_pshader_mode_clicked(HWND dialog
) {
235 if (IsDlgButtonChecked(dialog
, IDC_D3D_PSHADER_MODE
) == BST_CHECKED
)
236 set_reg_key(config_key
, keypath("Direct3D"), "PixelShaderMode", "enabled");
238 set_reg_key(config_key
, keypath("Direct3D"), "PixelShaderMode", "disabled");
242 GraphDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
249 set_window_title(hDlg
);
253 switch(HIWORD(wParam
)) {
255 if (updating_ui
) break;
256 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
257 if ( ((LOWORD(wParam
) == IDC_DESKTOP_WIDTH
) || (LOWORD(wParam
) == IDC_DESKTOP_HEIGHT
)) && !updating_ui
)
258 set_from_desktop_edits(hDlg
);
262 if (updating_ui
) break;
263 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
264 switch(LOWORD(wParam
)) {
265 case IDC_ENABLE_DESKTOP
: on_enable_desktop_clicked(hDlg
); break;
266 case IDC_ENABLE_MANAGED
: on_enable_managed_clicked(hDlg
); break;
267 case IDC_DX_MOUSE_GRAB
: on_dx_mouse_grab_clicked(hDlg
); break;
268 case IDC_D3D_PSHADER_MODE
: on_d3d_pshader_mode_clicked(hDlg
); break;
272 case CBN_SELCHANGE
: {
273 SendMessage(GetParent(hDlg
), PSM_CHANGED
, 0, 0);
274 switch (LOWORD(wParam
)) {
275 case IDC_D3D_VSHADER_MODE
: on_d3d_vshader_mode_changed(hDlg
); break;
287 switch (((LPNMHDR
)lParam
)->code
) {
288 case PSN_KILLACTIVE
: {
289 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
294 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
297 case PSN_SETACTIVE
: {