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 void on_add_app_click(HWND dialog)
261 char filetitle[MAX_PATH];
264 OPENFILENAME ofn = { sizeof(OPENFILENAME),
265 0, /*hInst*/0, "Wine Programs (*.exe,*.exe.so)\0*.exe;*.exe.so\0", NULL, 0, 0, NULL,
266 0, NULL, 0, "c:\\", "Select a Windows executable file",
267 OFN_SHOWHELP | OFN_HIDEREADONLY, 0, 0, NULL, 0, NULL };
269 ofn.lpstrFileTitle = filetitle;
270 ofn.lpstrFileTitle[0] = '\0';
271 ofn.nMaxFileTitle = sizeof(filetitle);
272 ofn.lpstrFile = file;
273 ofn.lpstrFile[0] = '\0';
274 ofn.nMaxFile = sizeof(file);
276 if (GetOpenFileName(&ofn))
278 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
279 int count = ListView_GetItemCount(listview);
282 new_app = strdupA(filetitle);
283 WINE_TRACE("adding %s\n", new_app);
285 add_listview_item(listview, new_app, new_app);
287 ListView_SetItemState(listview, count, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
291 else WINE_TRACE("user cancelled\n");
294 static void on_remove_app_click(HWND dialog)
296 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
297 int selection = get_listview_selection(listview);
298 char *section = keypath(""); /* AppDefaults\\whatever.exe\\ */
300 WINE_TRACE("selection=%d, section=%s\n", selection, section);
302 assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */
304 section[strlen(section)] = '\0'; /* remove last backslash */
305 set(section, NULL, NULL); /* delete the section */
306 ListView_DeleteItem(listview, selection);
307 ListView_SetItemState(listview, selection - 1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
311 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
314 static void on_winver_change(HWND dialog)
316 int selection = SendDlgItemMessage(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0);
317 VERSION_DESC *ver = getWinVersions();
321 WINE_TRACE("automatic/default selected so removing current setting\n");
322 set(keypath("Version"), "Windows", NULL);
326 WINE_TRACE("setting Version\\Windows key to value '%s'\n", ver[selection - 1].szVersion);
327 set(keypath("Version"), "Windows", ver[selection - 1].szVersion);
330 /* enable the apply button */
331 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
334 static void on_dosver_change(HWND dialog)
336 int selection = SendDlgItemMessage(dialog, IDC_DOSVER, CB_GETCURSEL, 0, 0);
337 VERSION_DESC *ver = getDOSVersions();
341 WINE_TRACE("automatic/default selected so removing current setting\n");
342 set(keypath("Version"), "DOS", NULL);
346 WINE_TRACE("setting Version\\DOS key to value '%s'\n", ver[selection - 1].szVersion);
347 set(keypath("Version"), "DOS", ver[selection - 1].szVersion);
350 /* enable the apply button */
351 SendMessage(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
355 AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
364 set_window_title(hDlg);
368 switch (((LPNMHDR)lParam)->code)
370 case LVN_ITEMCHANGED:
371 on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW));
375 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
382 switch(HIWORD(wParam))
385 switch(LOWORD(wParam))
388 on_winver_change(hDlg);
391 on_dosver_change(hDlg);
395 switch(LOWORD(wParam))
398 on_add_app_click(hDlg);
400 case IDC_APP_REMOVEAPP:
401 on_remove_app_click(hDlg);