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;
40 char *winver, *dosver;
42 /* retrieve the registry values */
43 winver = get(keypath("Version"), "Windows", "");
44 dosver = get(keypath("Version"), "DOS", "");
46 /* empty winver/dosver means use automatic mode (ie the builtin dll linkage heuristics) */
48 WINE_TRACE("winver is %s\n", *winver != '\0' ? winver : "null (automatic mode)");
49 WINE_TRACE("dosver is %s\n", *dosver != '\0' ? dosver : "null (automatic mode)");
51 /* normalize the version strings */
54 if ((pVer = getWinVersions ()))
56 for (i = 0; *pVer->szVersion || *pVer->szDescription; i++, pVer++)
58 if (!strcasecmp (pVer->szVersion, winver))
60 SendDlgItemMessage (dialog, IDC_WINVER, CB_SETCURSEL, (WPARAM) (i + 1), 0);
61 WINE_TRACE("match with %s\n", pVer->szVersion);
66 else /* no explicit setting */
68 WINE_TRACE("setting winver combobox to automatic/default\n");
69 SendDlgItemMessage (dialog, IDC_WINVER, CB_SETCURSEL, 0, 0);
74 if ((pVer = getDOSVersions ()))
76 for (i = 0; *pVer->szVersion || *pVer->szDescription; i++, pVer++)
78 if (!strcasecmp (pVer->szVersion, dosver))
80 SendDlgItemMessage (dialog, IDC_DOSVER, CB_SETCURSEL,
82 WINE_TRACE("match with %s\n", pVer->szVersion);
89 WINE_TRACE("setting dosver combobox to automatic/default\n");
90 SendDlgItemMessage (dialog, IDC_DOSVER, CB_SETCURSEL, 0, 0);
93 HeapFree(GetProcessHeap(), 0, winver);
94 HeapFree(GetProcessHeap(), 0, dosver);
98 init_comboboxes (HWND dialog)
101 const VERSION_DESC *ver = NULL;
104 SendDlgItemMessage(dialog, IDC_WINVER, CB_RESETCONTENT, 0, 0);
105 SendDlgItemMessage(dialog, IDC_DOSVER, CB_RESETCONTENT, 0, 0);
107 /* add the default entries (automatic) which correspond to no setting */
110 SendDlgItemMessage(dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM) "Use global settings");
111 SendDlgItemMessage(dialog, IDC_DOSVER, CB_ADDSTRING, 0, (LPARAM) "Use global settings");
115 SendDlgItemMessage(dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM) "Automatically detect required version");
116 SendDlgItemMessage(dialog, IDC_DOSVER, CB_ADDSTRING, 0, (LPARAM) "Automatically detect required version");
119 if ((ver = getWinVersions ()))
121 for (i = 0; *ver->szVersion || *ver->szDescription; i++, ver++)
123 SendDlgItemMessage (dialog, IDC_WINVER, CB_ADDSTRING,
124 0, (LPARAM) ver->szDescription);
127 if ((ver = getDOSVersions ()))
129 for (i = 0; *ver->szVersion || *ver->szDescription ; i++, ver++)
131 SendDlgItemMessage (dialog, IDC_DOSVER, CB_ADDSTRING,
132 0, (LPARAM) ver->szDescription);
137 static void add_listview_item(HWND listview, char *text, void *association)
141 ZeroMemory(&item, sizeof(LVITEM));
143 item.mask = LVIF_TEXT | LVIF_PARAM;
145 item.cchTextMax = strlen(text);
146 item.lParam = (LPARAM) association;
147 item.iItem = ListView_GetItemCount(listview);
149 ListView_InsertItem(listview, &item);
152 /* Called when the application is initialized (cannot reinit!) */
153 static void init_appsheet(HWND dialog)
163 listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
165 /* we use the lparam field of the item so we can alter the presentation later and not change code
166 * for instance, to use the tile view or to display the EXEs embedded 'display name' */
167 add_listview_item(listview, "Default Settings", NULL);
169 /* because this list is only populated once, it's safe to bypass the settings list here */
170 if (RegOpenKey(config_key, "AppDefaults", &key) == ERROR_SUCCESS)
173 size = sizeof(appname);
174 while (RegEnumKeyEx(key, i, appname, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
176 add_listview_item(listview, appname, strdupA(appname));
179 size = sizeof(appname);
185 init_comboboxes(dialog);
187 /* Select the default settings listview item */
191 ZeroMemory(&item, sizeof(item));
193 item.mask = LVIF_STATE;
195 item.state = LVIS_SELECTED | LVIS_FOCUSED;
196 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
198 ListView_SetItem(listview, &item);
203 /* there has to be an easier way than this */
204 static int get_listview_selection(HWND listview)
206 int count = ListView_GetItemCount(listview);
209 for (i = 0; i < count; i++)
211 if (ListView_GetItemState(listview, i, LVIS_SELECTED)) return i;
218 /* called when the user selects a different application */
219 static void on_selection_change(HWND dialog, HWND listview)
222 char *oldapp = current_app;
226 item.iItem = get_listview_selection(listview);
227 item.mask = LVIF_PARAM;
229 WINE_TRACE("item.iItem=%d\n", item.iItem);
231 if (item.iItem == -1) return;
233 ListView_GetItem(listview, &item);
235 current_app = (char *) item.lParam;
239 WINE_TRACE("current_app is now %s\n", current_app);
240 enable(IDC_APP_REMOVEAPP);
244 WINE_TRACE("current_app=NULL, editing global settings\n");
245 /* focus will never be on the button in this callback so it's safe */
246 disable(IDC_APP_REMOVEAPP);
249 /* reset the combo boxes if we changed from/to global/app-specific */
251 if ((oldapp && !current_app) || (!oldapp && current_app))
252 init_comboboxes(dialog);
254 update_comboboxes(dialog);
256 set_window_title(dialog);
259 static BOOL list_contains_file(HWND listview, char *filename)
261 LVFINDINFO find_info = { LVFI_STRING, filename, 0, {0, 0}, 0 };
264 index = ListView_FindItem(listview, -1, &find_info);
266 return (index != -1);
269 static void on_add_app_click(HWND dialog)
271 char filetitle[MAX_PATH];
274 OPENFILENAME ofn = { sizeof(OPENFILENAME),
275 0, /*hInst*/0, "Wine Programs (*.exe,*.exe.so)\0*.exe;*.exe.so\0", NULL, 0, 0, NULL,
276 0, NULL, 0, "c:\\", "Select a Windows executable file",
277 OFN_SHOWHELP | OFN_HIDEREADONLY, 0, 0, NULL, 0, NULL };
279 ofn.lpstrFileTitle = filetitle;
280 ofn.lpstrFileTitle[0] = '\0';
281 ofn.nMaxFileTitle = sizeof(filetitle);
282 ofn.lpstrFile = file;
283 ofn.lpstrFile[0] = '\0';
284 ofn.nMaxFile = sizeof(file);
286 if (GetOpenFileName(&ofn))
288 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
289 int count = ListView_GetItemCount(listview);
292 new_app = strdupA(filetitle);
294 if (list_contains_file(listview, new_app))
297 WINE_TRACE("adding %s\n", new_app);
299 add_listview_item(listview, new_app, new_app);
301 ListView_SetItemState(listview, count, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
305 else WINE_TRACE("user cancelled\n");
308 static void on_remove_app_click(HWND dialog)
310 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
311 int selection = get_listview_selection(listview);
312 char *section = keypath(""); /* AppDefaults\\whatever.exe\\ */
314 WINE_TRACE("selection=%d, section=%s\n", selection, section);
316 assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */
318 section[strlen(section)] = '\0'; /* remove last backslash */
319 set(section, NULL, NULL); /* delete the section */
320 ListView_DeleteItem(listview, selection);
321 ListView_SetItemState(listview, selection - 1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
325 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
328 static void on_winver_change(HWND dialog)
330 int selection = SendDlgItemMessage(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0);
331 VERSION_DESC *ver = getWinVersions();
335 WINE_TRACE("automatic/default selected so removing current setting\n");
336 set(keypath("Version"), "Windows", NULL);
340 WINE_TRACE("setting Version\\Windows key to value '%s'\n", ver[selection - 1].szVersion);
341 set(keypath("Version"), "Windows", ver[selection - 1].szVersion);
344 /* enable the apply button */
345 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
348 static void on_dosver_change(HWND dialog)
350 int selection = SendDlgItemMessage(dialog, IDC_DOSVER, CB_GETCURSEL, 0, 0);
351 VERSION_DESC *ver = getDOSVersions();
355 WINE_TRACE("automatic/default selected so removing current setting\n");
356 set(keypath("Version"), "DOS", NULL);
360 WINE_TRACE("setting Version\\DOS key to value '%s'\n", ver[selection - 1].szVersion);
361 set(keypath("Version"), "DOS", ver[selection - 1].szVersion);
364 /* enable the apply button */
365 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
369 AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
378 set_window_title(hDlg);
382 switch (((LPNMHDR)lParam)->code)
384 case LVN_ITEMCHANGED:
385 on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW));
389 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
396 switch(HIWORD(wParam))
399 switch(LOWORD(wParam))
402 on_winver_change(hDlg);
405 on_dosver_change(hDlg);
409 switch(LOWORD(wParam))
412 on_add_app_click(hDlg);
414 case IDC_APP_REMOVEAPP:
415 on_remove_app_click(hDlg);