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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define NONAMELESSUNION
27 #include <wine/debug.h>
33 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
35 static void update_comboboxes(HWND dialog)
38 const VERSION_DESC *pVer = NULL;
42 /* retrieve the registry values */
43 winver = get(keypath("Version"), "Windows", "");
45 /* empty winver means use automatic mode (ie the builtin dll linkage heuristics) */
46 WINE_TRACE("winver is %s\n", *winver != '\0' ? winver : "null (automatic mode)");
48 /* normalize the version strings */
51 if ((pVer = getWinVersions ()))
53 for (i = 0; *pVer->szVersion || *pVer->szDescription; i++, pVer++)
55 if (!strcasecmp (pVer->szVersion, winver))
57 SendDlgItemMessage (dialog, IDC_WINVER, CB_SETCURSEL, (WPARAM) (i + 1), 0);
58 WINE_TRACE("match with %s\n", pVer->szVersion);
63 else /* no explicit setting */
65 WINE_TRACE("setting winver combobox to automatic/default\n");
66 SendDlgItemMessage (dialog, IDC_WINVER, CB_SETCURSEL, 0, 0);
69 HeapFree(GetProcessHeap(), 0, winver);
73 init_comboboxes (HWND dialog)
76 const VERSION_DESC *ver = NULL;
78 SendDlgItemMessage(dialog, IDC_WINVER, CB_RESETCONTENT, 0, 0);
80 /* add the default entries (automatic) which correspond to no setting */
83 SendDlgItemMessage(dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM) "Use global settings");
87 SendDlgItemMessage(dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM) "Automatically detect required version");
90 if ((ver = getWinVersions ()))
92 for (i = 0; *ver->szVersion || *ver->szDescription; i++, ver++)
94 SendDlgItemMessage (dialog, IDC_WINVER, CB_ADDSTRING,
95 0, (LPARAM) ver->szDescription);
100 static void add_listview_item(HWND listview, char *text, void *association)
104 ZeroMemory(&item, sizeof(LVITEM));
106 item.mask = LVIF_TEXT | LVIF_PARAM;
108 item.cchTextMax = strlen(text);
109 item.lParam = (LPARAM) association;
110 item.iItem = ListView_GetItemCount(listview);
112 ListView_InsertItem(listview, &item);
115 /* Called when the application is initialized (cannot reinit!) */
116 static void init_appsheet(HWND dialog)
126 listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
128 /* we use the lparam field of the item so we can alter the presentation later and not change code
129 * for instance, to use the tile view or to display the EXEs embedded 'display name' */
130 add_listview_item(listview, "Default Settings", NULL);
132 /* because this list is only populated once, it's safe to bypass the settings list here */
133 if (RegOpenKey(config_key, "AppDefaults", &key) == ERROR_SUCCESS)
136 size = sizeof(appname);
137 while (RegEnumKeyEx(key, i, appname, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
139 add_listview_item(listview, appname, strdupA(appname));
142 size = sizeof(appname);
148 init_comboboxes(dialog);
150 /* Select the default settings listview item */
154 ZeroMemory(&item, sizeof(item));
156 item.mask = LVIF_STATE;
158 item.state = LVIS_SELECTED | LVIS_FOCUSED;
159 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
161 ListView_SetItem(listview, &item);
166 /* there has to be an easier way than this */
167 static int get_listview_selection(HWND listview)
169 int count = ListView_GetItemCount(listview);
172 for (i = 0; i < count; i++)
174 if (ListView_GetItemState(listview, i, LVIS_SELECTED)) return i;
181 /* called when the user selects a different application */
182 static void on_selection_change(HWND dialog, HWND listview)
185 char *oldapp = current_app;
189 item.iItem = get_listview_selection(listview);
190 item.mask = LVIF_PARAM;
192 WINE_TRACE("item.iItem=%d\n", item.iItem);
194 if (item.iItem == -1) return;
196 ListView_GetItem(listview, &item);
198 current_app = (char *) item.lParam;
202 WINE_TRACE("current_app is now %s\n", current_app);
203 enable(IDC_APP_REMOVEAPP);
207 WINE_TRACE("current_app=NULL, editing global settings\n");
208 /* focus will never be on the button in this callback so it's safe */
209 disable(IDC_APP_REMOVEAPP);
212 /* reset the combo boxes if we changed from/to global/app-specific */
214 if ((oldapp && !current_app) || (!oldapp && current_app))
215 init_comboboxes(dialog);
217 update_comboboxes(dialog);
219 set_window_title(dialog);
222 static BOOL list_contains_file(HWND listview, char *filename)
224 LVFINDINFO find_info = { LVFI_STRING, filename, 0, {0, 0}, 0 };
227 index = ListView_FindItem(listview, -1, &find_info);
229 return (index != -1);
232 static void on_add_app_click(HWND dialog)
234 char filetitle[MAX_PATH];
237 OPENFILENAME ofn = { sizeof(OPENFILENAME),
238 0, /*hInst*/0, "Wine Programs (*.exe,*.exe.so)\0*.exe;*.exe.so\0", NULL, 0, 0, NULL,
239 0, NULL, 0, "c:\\", "Select a Windows executable file",
240 OFN_SHOWHELP | OFN_HIDEREADONLY, 0, 0, NULL, 0, NULL };
242 ofn.lpstrFileTitle = filetitle;
243 ofn.lpstrFileTitle[0] = '\0';
244 ofn.nMaxFileTitle = sizeof(filetitle);
245 ofn.lpstrFile = file;
246 ofn.lpstrFile[0] = '\0';
247 ofn.nMaxFile = sizeof(file);
249 if (GetOpenFileName(&ofn))
251 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
252 int count = ListView_GetItemCount(listview);
255 new_app = strdupA(filetitle);
257 if (list_contains_file(listview, new_app))
260 WINE_TRACE("adding %s\n", new_app);
262 add_listview_item(listview, new_app, new_app);
264 ListView_SetItemState(listview, count, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
268 else WINE_TRACE("user cancelled\n");
271 static void on_remove_app_click(HWND dialog)
273 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
274 int selection = get_listview_selection(listview);
275 char *section = keypath(""); /* AppDefaults\\whatever.exe\\ */
277 WINE_TRACE("selection=%d, section=%s\n", selection, section);
279 assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */
281 section[strlen(section)] = '\0'; /* remove last backslash */
282 set(section, NULL, NULL); /* delete the section */
283 ListView_DeleteItem(listview, selection);
284 ListView_SetItemState(listview, selection - 1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
288 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
291 static void on_winver_change(HWND dialog)
293 int selection = SendDlgItemMessage(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0);
294 VERSION_DESC *ver = getWinVersions();
298 WINE_TRACE("automatic/default selected so removing current setting\n");
299 set(keypath("Version"), "Windows", NULL);
303 WINE_TRACE("setting Version\\Windows key to value '%s'\n", ver[selection - 1].szVersion);
304 set(keypath("Version"), "Windows", ver[selection - 1].szVersion);
307 /* enable the apply button */
308 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
312 AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
321 set_window_title(hDlg);
325 switch (((LPNMHDR)lParam)->code)
327 case LVN_ITEMCHANGED:
328 on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW));
332 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
339 switch(HIWORD(wParam))
342 switch(LOWORD(wParam))
345 on_winver_change(hDlg);
349 switch(LOWORD(wParam))
352 on_add_app_click(hDlg);
354 case IDC_APP_REMOVEAPP:
355 on_remove_app_click(hDlg);