wined3d: Remove broken software shaders.
[wine] / programs / winecfg / x11drvdlg.c
1 /*
2  * Graphics configuration code
3  *
4  * Copyright 2003 Mark Westcott
5  * Copyright 2003-2004 Mike Hearn
6  * Copyright 2005 Raphael Junqueira
7  *
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.
12  *
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.
17  *
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
21  *
22  */
23
24 #define WIN32_LEAN_AND_MEAN
25
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29
30 #include <windows.h>
31 #include <wine/debug.h>
32
33 #include "resource.h"
34 #include "winecfg.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
37
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? */
39
40
41 static struct SHADERMODE
42 {
43   UINT displayStrID;
44   const char* settingStr;
45 } const D3D_VS_Modes[] = {
46   {IDS_SHADER_MODE_HARDWARE,  "hardware"},
47   {IDS_SHADER_MODE_NONE,      "none"},
48   {0, 0}
49 };
50
51
52 int updating_ui;
53
54 static void update_gui_for_desktop_mode(HWND dialog) {
55     int desktopenabled = FALSE;
56
57     WINE_TRACE("\n");
58     updating_ui = TRUE;
59
60     if (current_app)
61     {
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);
67         return;
68     }
69     enable(IDC_ENABLE_DESKTOP);
70
71     /* do we have desktop mode enabled? */
72     if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
73     {
74         char* buf, *bufindex;
75         CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
76
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'
80                 &&  buf[0] != '0') {
81             desktopenabled = TRUE;
82             enable(IDC_DESKTOP_WIDTH);
83             enable(IDC_DESKTOP_HEIGHT);
84             enable(IDC_DESKTOP_SIZE);
85             enable(IDC_DESKTOP_BY);
86
87             bufindex = strchr(buf, 'x');
88             if (bufindex) {
89                 *bufindex = 0;
90                 ++bufindex;
91                 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), buf);
92                 SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), bufindex);
93             } else {
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");
97             }
98         }
99         HeapFree(GetProcessHeap(), 0, buf);
100     }
101     if (!desktopenabled)
102     {
103         CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_UNCHECKED);
104         
105         disable(IDC_DESKTOP_WIDTH);
106         disable(IDC_DESKTOP_HEIGHT);
107         disable(IDC_DESKTOP_SIZE);
108         disable(IDC_DESKTOP_BY);
109
110         SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_WIDTH), "");
111         SetWindowText(GetDlgItem(dialog, IDC_DESKTOP_HEIGHT), "");
112     }
113
114     updating_ui = FALSE;
115 }
116
117 static void init_dialog(HWND dialog)
118 {
119     unsigned int it;
120     char* buf;
121
122     update_gui_for_desktop_mode(dialog);
123
124     updating_ui = TRUE;
125     
126     SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
127     SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
128
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);
132     else
133         CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
134     HeapFree(GetProcessHeap(), 0, buf);
135
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);
139     else
140         CheckDlgButton(dialog, IDC_ENABLE_MANAGED, BST_UNCHECKED);
141     HeapFree(GetProcessHeap(), 0, buf);
142
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));
147     }  
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);
152         break ;
153       }
154     }
155     if (NULL == D3D_VS_Modes[it].settingStr) {
156       WINE_ERR("Invalid Direct3D VertexShader Mode read from registry (%s)\n", buf);
157     }
158     HeapFree(GetProcessHeap(), 0, buf);
159
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);
163     else
164       CheckDlgButton(dialog, IDC_D3D_PSHADER_MODE, BST_UNCHECKED);
165     HeapFree(GetProcessHeap(), 0, buf);
166
167     updating_ui = FALSE;
168 }
169
170 static void set_from_desktop_edits(HWND dialog) {
171     char *width, *height, *new;
172
173     if (updating_ui) return;
174     
175     WINE_TRACE("\n");
176
177     width = get_text(dialog, IDC_DESKTOP_WIDTH);
178     height = get_text(dialog, IDC_DESKTOP_HEIGHT);
179
180     if (width == NULL || strcmp(width, "") == 0) {
181         HeapFree(GetProcessHeap(), 0, width);
182         width = strdupA("640");
183     }
184     
185     if (height == NULL || strcmp(height, "") == 0) {
186         HeapFree(GetProcessHeap(), 0, height);
187         height = strdupA("480");
188     }
189
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);
193     
194     HeapFree(GetProcessHeap(), 0, width);
195     HeapFree(GetProcessHeap(), 0, height);
196     HeapFree(GetProcessHeap(), 0, new);
197 }
198
199 static void on_enable_desktop_clicked(HWND dialog) {
200     WINE_TRACE("\n");
201     
202     if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
203         set_from_desktop_edits(dialog);
204     } else {
205         set_reg_key(config_key, keypath("X11 Driver"), "Desktop", NULL);
206     }
207     
208     update_gui_for_desktop_mode(dialog);
209 }
210
211 static void on_enable_managed_clicked(HWND dialog) {
212     WINE_TRACE("\n");
213     
214     if (IsDlgButtonChecked(dialog, IDC_ENABLE_MANAGED) == BST_CHECKED) {
215         set_reg_key(config_key, keypath("X11 Driver"), "Managed", "Y");
216     } else {
217         set_reg_key(config_key, keypath("X11 Driver"), "Managed", "N");
218     }
219 }
220
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");
224     else
225         set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
226 }
227
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); 
232 }
233
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");
237     else
238         set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
239 }
240
241 INT_PTR CALLBACK
242 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
243 {
244     switch (uMsg) {
245         case WM_INITDIALOG:
246             break;
247
248         case WM_SHOWWINDOW:
249             set_window_title(hDlg);
250             break;
251             
252         case WM_COMMAND:
253             switch(HIWORD(wParam)) {
254                 case EN_CHANGE: {
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);
259                     break;
260                 }
261                 case BN_CLICKED: {
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;
269                     }
270                     break;
271                 }
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;
276                     }
277                     break;
278                 }
279                     
280                 default:
281                     break;
282             }
283             break;
284         
285         
286         case WM_NOTIFY:
287             switch (((LPNMHDR)lParam)->code) {
288                 case PSN_KILLACTIVE: {
289                     SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
290                     break;
291                 }
292                 case PSN_APPLY: {
293                     apply();
294                     SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
295                     break;
296                 }
297                 case PSN_SETACTIVE: {
298                     init_dialog (hDlg);
299                     break;
300                 }
301             }
302             break;
303
304         default:
305             break;
306     }
307     return FALSE;
308 }