qcap/tests: Add media tests for the SmartTee filter.
[wine/multimedia.git] / programs / winecfg / appdefaults.c
blobfad9e5cddc61672e9b435aba130a53bcea010bbe
1 /*
2 * WineCfg app settings tabsheet
4 * Copyright 2004 Robert van Herk
5 * Copyright 2004 Chris Morgan
6 * Copyright 2004 Mike Hearn
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
25 #include <windows.h>
26 #include <commdlg.h>
27 #include <wine/debug.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <assert.h>
31 #include "wine/unicode.h"
32 #include "winecfg.h"
33 #include "resource.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
37 static const struct
39 const char *szVersion;
40 const char *szDescription;
41 DWORD dwMajorVersion;
42 DWORD dwMinorVersion;
43 DWORD dwBuildNumber;
44 DWORD dwPlatformId;
45 const char *szCSDVersion;
46 WORD wServicePackMajor;
47 WORD wServicePackMinor;
48 const char *szProductType;
49 } win_versions[] =
51 { "win81", "Windows 8.1", 6, 3, 0x2580,VER_PLATFORM_WIN32_NT, " ", 0, 0, "WinNT"},
52 { "win8", "Windows 8", 6, 2, 0x23F0,VER_PLATFORM_WIN32_NT, " ", 0, 0, "WinNT"},
53 { "win2008r2", "Windows 2008 R2", 6, 1, 0x1DB1,VER_PLATFORM_WIN32_NT, "Service Pack 1", 1, 0, "ServerNT"},
54 { "win7", "Windows 7", 6, 1, 0x1DB1,VER_PLATFORM_WIN32_NT, "Service Pack 1", 1, 0, "WinNT"},
55 { "win2008", "Windows 2008", 6, 0, 0x1772,VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "ServerNT"},
56 { "vista", "Windows Vista", 6, 0, 0x1772,VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "WinNT"},
57 { "win2003", "Windows 2003", 5, 2, 0xECE, VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "ServerNT"},
58 #ifdef _WIN64
59 { "winxp64", "Windows XP", 5, 2, 0xECE, VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "WinNT"},
60 #else
61 { "winxp", "Windows XP", 5, 1, 0xA28, VER_PLATFORM_WIN32_NT, "Service Pack 3", 3, 0, "WinNT"},
62 { "win2k", "Windows 2000", 5, 0, 0x893, VER_PLATFORM_WIN32_NT, "Service Pack 4", 4, 0, "WinNT"},
63 { "winme", "Windows ME", 4, 90, 0xBB8, VER_PLATFORM_WIN32_WINDOWS, " ", 0, 0, ""},
64 { "win98", "Windows 98", 4, 10, 0x8AE, VER_PLATFORM_WIN32_WINDOWS, " A ", 0, 0, ""},
65 { "win95", "Windows 95", 4, 0, 0x3B6, VER_PLATFORM_WIN32_WINDOWS, "", 0, 0, ""},
66 { "nt40", "Windows NT 4.0", 4, 0, 0x565, VER_PLATFORM_WIN32_NT, "Service Pack 6a", 6, 0, "WinNT"},
67 { "nt351", "Windows NT 3.51", 3, 51, 0x421, VER_PLATFORM_WIN32_NT, "Service Pack 5", 5, 0, "WinNT"},
68 { "win31", "Windows 3.1", 3, 10, 0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""},
69 { "win30", "Windows 3.0", 3, 0, 0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""},
70 { "win20", "Windows 2.0", 2, 0, 0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""}
71 #endif
74 #define NB_VERSIONS (sizeof(win_versions)/sizeof(win_versions[0]))
76 static const char szKey9x[] = "Software\\Microsoft\\Windows\\CurrentVersion";
77 static const char szKeyNT[] = "Software\\Microsoft\\Windows NT\\CurrentVersion";
78 static const char szKeyProdNT[] = "System\\CurrentControlSet\\Control\\ProductOptions";
80 static int get_registry_version(void)
82 int i, best = -1, platform, major, minor = 0, build = 0;
83 char *p, *ver, *type = NULL;
85 if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL )))
87 char *build_str;
89 platform = VER_PLATFORM_WIN32_NT;
91 build_str = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL );
92 build = atoi(build_str);
94 type = get_reg_key( HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL );
96 else if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL )))
97 platform = VER_PLATFORM_WIN32_WINDOWS;
98 else
99 return -1;
101 if ((p = strchr( ver, '.' )))
103 char *minor_str = p;
104 *minor_str++ = 0;
105 if ((p = strchr( minor_str, '.' )))
107 char *build_str = p;
108 *build_str++ = 0;
109 build = atoi(build_str);
111 minor = atoi(minor_str);
113 major = atoi(ver);
115 for (i = 0; i < NB_VERSIONS; i++)
117 if (win_versions[i].dwPlatformId != platform) continue;
118 if (win_versions[i].dwMajorVersion != major) continue;
119 if (type && strcasecmp(win_versions[i].szProductType, type)) continue;
120 best = i;
121 if ((win_versions[i].dwMinorVersion == minor) &&
122 (win_versions[i].dwBuildNumber == build))
123 return i;
125 return best;
128 static void update_comboboxes(HWND dialog)
130 int i, ver;
131 char *winver;
133 /* retrieve the registry values */
134 winver = get_reg_key(config_key, keypath(""), "Version", "");
135 ver = get_registry_version();
137 if (!winver || !winver[0])
139 HeapFree(GetProcessHeap(), 0, winver);
141 if (current_app) /* no explicit setting */
143 WINE_TRACE("setting winver combobox to default\n");
144 SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL, 0, 0);
145 return;
147 if (ver != -1) winver = strdupA( win_versions[ver].szVersion );
148 else winver = strdupA("winxp");
150 WINE_TRACE("winver is %s\n", winver);
152 /* normalize the version strings */
153 for (i = 0; i < NB_VERSIONS; i++)
155 if (!strcasecmp (win_versions[i].szVersion, winver))
157 SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL,
158 i + (current_app?1:0), 0);
159 WINE_TRACE("match with %s\n", win_versions[i].szVersion);
160 break;
164 HeapFree(GetProcessHeap(), 0, winver);
167 static void
168 init_comboboxes (HWND dialog)
170 int i;
172 SendDlgItemMessageW(dialog, IDC_WINVER, CB_RESETCONTENT, 0, 0);
174 /* add the default entries (automatic) which correspond to no setting */
175 if (current_app)
177 WCHAR str[256];
178 LoadStringW (GetModuleHandleW(NULL), IDS_USE_GLOBAL_SETTINGS, str,
179 sizeof(str)/sizeof(str[0]));
180 SendDlgItemMessageW (dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM)str);
183 for (i = 0; i < NB_VERSIONS; i++)
185 SendDlgItemMessageA(dialog, IDC_WINVER, CB_ADDSTRING,
186 0, (LPARAM) win_versions[i].szDescription);
190 static void add_listview_item(HWND listview, WCHAR *text, void *association)
192 LVITEMW item;
194 item.mask = LVIF_TEXT | LVIF_PARAM;
195 item.pszText = text;
196 item.cchTextMax = lstrlenW(text);
197 item.lParam = (LPARAM) association;
198 item.iItem = SendMessageW( listview, LVM_GETITEMCOUNT, 0, 0 );
199 item.iSubItem = 0;
201 SendMessageW(listview, LVM_INSERTITEMW, 0, (LPARAM) &item);
204 /* Called when the application is initialized (cannot reinit!) */
205 static void init_appsheet(HWND dialog)
207 HWND listview;
208 LVITEMW item;
209 HKEY key;
210 int i;
211 DWORD size;
212 WCHAR appname[1024];
214 WINE_TRACE("()\n");
216 listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
218 /* we use the lparam field of the item so we can alter the presentation later and not change code
219 * for instance, to use the tile view or to display the EXEs embedded 'display name' */
220 LoadStringW (GetModuleHandleW(NULL), IDS_DEFAULT_SETTINGS, appname,
221 sizeof(appname)/sizeof(appname[0]));
222 add_listview_item(listview, appname, NULL);
224 /* because this list is only populated once, it's safe to bypass the settings list here */
225 if (RegOpenKeyA(config_key, "AppDefaults", &key) == ERROR_SUCCESS)
227 i = 0;
228 size = sizeof(appname)/sizeof(appname[0]);
229 while (RegEnumKeyExW (key, i, appname, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
231 add_listview_item(listview, appname, strdupW(appname));
233 i++;
234 size = sizeof(appname)/sizeof(appname[0]);
237 RegCloseKey(key);
240 init_comboboxes(dialog);
242 /* Select the default settings listview item */
243 item.iItem = 0;
244 item.iSubItem = 0;
245 item.mask = LVIF_STATE;
246 item.state = LVIS_SELECTED | LVIS_FOCUSED;
247 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
249 SendMessageW(listview, LVM_SETITEMW, 0, (LPARAM) &item);
252 /* there has to be an easier way than this */
253 static int get_listview_selection(HWND listview)
255 int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
256 int i;
258 for (i = 0; i < count; i++)
260 if (SendMessageW( listview, LVM_GETITEMSTATE, i, LVIS_SELECTED )) return i;
263 return -1;
267 /* called when the user selects a different application */
268 static void on_selection_change(HWND dialog, HWND listview)
270 LVITEMW item;
271 WCHAR* oldapp = current_app;
273 WINE_TRACE("()\n");
275 item.iItem = get_listview_selection(listview);
276 item.iSubItem = 0;
277 item.mask = LVIF_PARAM;
279 WINE_TRACE("item.iItem=%d\n", item.iItem);
281 if (item.iItem == -1) return;
283 SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
285 current_app = (WCHAR*) item.lParam;
287 if (current_app)
289 WINE_TRACE("current_app is now %s\n", wine_dbgstr_w (current_app));
290 enable(IDC_APP_REMOVEAPP);
292 else
294 WINE_TRACE("current_app=NULL, editing global settings\n");
295 /* focus will never be on the button in this callback so it's safe */
296 disable(IDC_APP_REMOVEAPP);
299 /* reset the combo boxes if we changed from/to global/app-specific */
301 if ((oldapp && !current_app) || (!oldapp && current_app))
302 init_comboboxes(dialog);
304 update_comboboxes(dialog);
306 set_window_title(dialog);
309 static BOOL list_contains_file(HWND listview, WCHAR *filename)
311 LVFINDINFOW find_info = { LVFI_STRING, filename, 0, {0, 0}, 0 };
312 int index;
314 index = ListView_FindItemW(listview, -1, &find_info);
316 return (index != -1);
319 static void on_add_app_click(HWND dialog)
321 static const WCHAR filterW[] = {'%','s','%','c','*','.','e','x','e',';','*','.','e','x','e','.','s','o','%','c',0};
322 WCHAR filetitle[MAX_PATH];
323 WCHAR file[MAX_PATH];
324 WCHAR programsFilter[100], filter[MAX_PATH];
325 WCHAR selectExecutableStr[100];
326 static const WCHAR pathC[] = { 'c',':','\\',0 };
328 OPENFILENAMEW ofn = { sizeof(OPENFILENAMEW),
329 dialog, /*hInst*/0, 0, NULL, 0, 0, NULL,
330 0, NULL, 0, pathC, 0,
331 OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_ENABLESIZING,
332 0, 0, NULL, 0, NULL };
334 LoadStringW (GetModuleHandleW(NULL), IDS_SELECT_EXECUTABLE, selectExecutableStr,
335 sizeof(selectExecutableStr)/sizeof(selectExecutableStr[0]));
336 LoadStringW (GetModuleHandleW(NULL), IDS_EXECUTABLE_FILTER, programsFilter,
337 sizeof(programsFilter)/sizeof(programsFilter[0]));
338 snprintfW( filter, MAX_PATH, filterW, programsFilter, 0, 0 );
340 ofn.lpstrTitle = selectExecutableStr;
341 ofn.lpstrFilter = filter;
342 ofn.lpstrFileTitle = filetitle;
343 ofn.lpstrFileTitle[0] = '\0';
344 ofn.nMaxFileTitle = sizeof(filetitle)/sizeof(filetitle[0]);
345 ofn.lpstrFile = file;
346 ofn.lpstrFile[0] = '\0';
347 ofn.nMaxFile = sizeof(file)/sizeof(file[0]);
349 if (GetOpenFileNameW (&ofn))
351 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
352 int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
353 WCHAR* new_app;
354 LVITEMW item;
356 if (list_contains_file(listview, filetitle))
357 return;
359 new_app = strdupW(filetitle);
361 WINE_TRACE("adding %s\n", wine_dbgstr_w (new_app));
363 add_listview_item(listview, new_app, new_app);
365 item.mask = LVIF_STATE;
366 item.state = LVIS_SELECTED | LVIS_FOCUSED;
367 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
368 SendMessageW(listview, LVM_SETITEMSTATE, count, (LPARAM)&item );
370 SetFocus(listview);
372 else WINE_TRACE("user cancelled\n");
375 static void on_remove_app_click(HWND dialog)
377 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
378 int selection = get_listview_selection(listview);
379 LVITEMW item;
381 item.iItem = selection;
382 item.iSubItem = 0;
383 item.mask = LVIF_PARAM;
385 WINE_TRACE("selection=%d\n", selection);
387 assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */
389 set_reg_key(config_key, keypath(""), NULL, NULL); /* delete the section */
390 SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
391 HeapFree (GetProcessHeap(), 0, (void*)item.lParam);
392 SendMessageW(listview, LVM_DELETEITEM, selection, 0);
393 item.mask = LVIF_STATE;
394 item.state = LVIS_SELECTED | LVIS_FOCUSED;
395 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
396 SendMessageW(listview, LVM_SETITEMSTATE, 0, (LPARAM)&item);
398 SetFocus(listview);
399 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
402 static void on_winver_change(HWND dialog)
404 int selection = SendDlgItemMessageW(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0);
406 if (current_app)
408 if (!selection)
410 WINE_TRACE("default selected so removing current setting\n");
411 set_reg_key(config_key, keypath(""), "Version", NULL);
413 else
415 WINE_TRACE("setting Version key to value '%s'\n", win_versions[selection-1].szVersion);
416 set_reg_key(config_key, keypath(""), "Version", win_versions[selection-1].szVersion);
419 else /* global version only */
421 static const char szKeyWindNT[] = "System\\CurrentControlSet\\Control\\Windows";
422 static const char szKeyEnvNT[] = "System\\CurrentControlSet\\Control\\Session Manager\\Environment";
423 char Buffer[40];
425 switch (win_versions[selection].dwPlatformId)
427 case VER_PLATFORM_WIN32_WINDOWS:
428 snprintf(Buffer, sizeof(Buffer), "%d.%d.%d", win_versions[selection].dwMajorVersion,
429 win_versions[selection].dwMinorVersion, win_versions[selection].dwBuildNumber);
430 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", Buffer);
431 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", win_versions[selection].szCSDVersion);
432 snprintf(Buffer, sizeof(Buffer), "Microsoft %s", win_versions[selection].szDescription);
433 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", Buffer);
435 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", NULL);
436 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL);
437 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL);
438 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", NULL);
439 set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL);
440 set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion", NULL);
441 set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", NULL);
442 set_reg_key(config_key, keypath(""), "Version", NULL);
443 break;
445 case VER_PLATFORM_WIN32_NT:
446 snprintf(Buffer, sizeof(Buffer), "%d.%d", win_versions[selection].dwMajorVersion,
447 win_versions[selection].dwMinorVersion);
448 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", Buffer);
449 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", win_versions[selection].szCSDVersion);
450 snprintf(Buffer, sizeof(Buffer), "%d", win_versions[selection].dwBuildNumber);
451 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", Buffer);
452 snprintf(Buffer, sizeof(Buffer), "Microsoft %s", win_versions[selection].szDescription);
453 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", Buffer);
454 set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", win_versions[selection].szProductType);
455 set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion",
456 MAKEWORD( win_versions[selection].wServicePackMinor,
457 win_versions[selection].wServicePackMajor ));
458 set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", "Windows_NT");
460 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL);
461 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", NULL);
462 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", NULL);
463 set_reg_key(config_key, keypath(""), "Version", NULL);
464 break;
466 case VER_PLATFORM_WIN32s:
467 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", NULL);
468 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL);
469 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL);
470 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", NULL);
471 set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL);
472 set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion", NULL);
473 set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", NULL);
474 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL);
475 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", NULL);
476 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", NULL);
477 set_reg_key(config_key, keypath(""), "Version", win_versions[selection].szVersion);
478 break;
482 /* enable the apply button */
483 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
486 INT_PTR CALLBACK
487 AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
489 switch (uMsg)
491 case WM_INITDIALOG:
492 init_appsheet(hDlg);
493 break;
495 case WM_SHOWWINDOW:
496 set_window_title(hDlg);
497 break;
499 case WM_NOTIFY:
500 switch (((LPNMHDR)lParam)->code)
502 case LVN_ITEMCHANGED:
503 on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW));
504 break;
505 case PSN_APPLY:
506 apply();
507 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
508 break;
511 break;
513 case WM_COMMAND:
514 switch(HIWORD(wParam))
516 case CBN_SELCHANGE:
517 switch(LOWORD(wParam))
519 case IDC_WINVER:
520 on_winver_change(hDlg);
521 break;
523 case BN_CLICKED:
524 switch(LOWORD(wParam))
526 case IDC_APP_ADDAPP:
527 on_add_app_click(hDlg);
528 break;
529 case IDC_APP_REMOVEAPP:
530 on_remove_app_click(hDlg);
531 break;
533 break;
536 break;
539 return 0;