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 if (item
.iItem
== -1) return;
231 ListView_GetItem(listview
, &item
);
233 current_app
= (char *) item
.lParam
;
237 WINE_TRACE("current_app is now %s\n", current_app
);
238 enable(IDC_APP_REMOVEAPP
);
242 WINE_TRACE("current_app=NULL, editing global settings\n");
243 /* focus will never be on the button in this callback so it's safe */
244 disable(IDC_APP_REMOVEAPP
);
247 /* reset the combo boxes if we changed from/to global/app-specific */
249 if ((oldapp
&& !current_app
) || (!oldapp
&& current_app
))
250 init_comboboxes(dialog
);
252 update_comboboxes(dialog
);
254 set_window_title(dialog
);
257 static void on_add_app_click(HWND dialog
)
259 char filetitle
[MAX_PATH
];
262 OPENFILENAME ofn
= { sizeof(OPENFILENAME
),
263 0, /*hInst*/0, "Wine Programs (*.exe,*.exe.so)\0*.exe;*.exe.so\0", NULL
, 0, 0, NULL
,
264 0, NULL
, 0, "c:\\", "Select a Windows executable file",
265 OFN_SHOWHELP
| OFN_HIDEREADONLY
, 0, 0, NULL
, 0, NULL
};
267 ofn
.lpstrFileTitle
= filetitle
;
268 ofn
.lpstrFileTitle
[0] = '\0';
269 ofn
.nMaxFileTitle
= sizeof(filetitle
);
270 ofn
.lpstrFile
= file
;
271 ofn
.lpstrFile
[0] = '\0';
272 ofn
.nMaxFile
= sizeof(file
);
274 if (GetOpenFileName(&ofn
))
276 HWND listview
= GetDlgItem(dialog
, IDC_APP_LISTVIEW
);
277 int count
= ListView_GetItemCount(listview
);
279 if (current_app
) HeapFree(GetProcessHeap(), 0, current_app
);
280 current_app
= strdupA(filetitle
);
282 WINE_TRACE("adding %s\n", current_app
);
284 add_listview_item(listview
, current_app
, current_app
);
286 ListView_SetItemState(listview
, count
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
290 else WINE_TRACE("user cancelled\n");
293 static void on_remove_app_click(HWND dialog
)
295 HWND listview
= GetDlgItem(dialog
, IDC_APP_LISTVIEW
);
296 int selection
= get_listview_selection(listview
);
297 char *section
= keypath(""); /* AppDefaults\\whatever.exe\\ */
299 WINE_TRACE("selection=%d, section=%s\n", selection
, section
);
301 assert( selection
!= 0 ); /* user cannot click this button when "default settings" is selected */
303 section
[strlen(section
)] = '\0'; /* remove last backslash */
304 set(section
, NULL
, NULL
); /* delete the section */
305 ListView_DeleteItem(listview
, selection
);
310 static void on_winver_change(HWND dialog
)
312 int selection
= SendDlgItemMessage(dialog
, IDC_WINVER
, CB_GETCURSEL
, 0, 0);
313 VERSION_DESC
*ver
= getWinVersions();
317 WINE_TRACE("automatic/default selected so removing current setting\n");
318 set(keypath("Version"), "Windows", NULL
);
322 WINE_TRACE("setting Version\\Windows key to value '%s'\n", ver
[selection
- 1].szVersion
);
323 set(keypath("Version"), "Windows", ver
[selection
- 1].szVersion
);
326 /* enable the apply button */
327 SendMessage(GetParent(dialog
), PSM_CHANGED
, (WPARAM
) dialog
, 0);
330 static void on_dosver_change(HWND dialog
)
332 int selection
= SendDlgItemMessage(dialog
, IDC_DOSVER
, CB_GETCURSEL
, 0, 0);
333 VERSION_DESC
*ver
= getDOSVersions();
337 WINE_TRACE("automatic/default selected so removing current setting\n");
338 set(keypath("Version"), "DOS", NULL
);
342 WINE_TRACE("setting Version\\DOS key to value '%s'\n", ver
[selection
- 1].szVersion
);
343 set(keypath("Version"), "DOS", ver
[selection
- 1].szVersion
);
346 /* enable the apply button */
347 SendMessage(GetParent(dialog
), PSM_CHANGED
, (WPARAM
) dialog
, 0);
351 AppDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
360 set_window_title(hDlg
);
364 switch (((LPNMHDR
)lParam
)->code
)
366 case LVN_ITEMCHANGED
:
367 on_selection_change(hDlg
, GetDlgItem(hDlg
, IDC_APP_LISTVIEW
));
371 SetWindowLong(hDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
378 switch(HIWORD(wParam
))
381 switch(LOWORD(wParam
))
384 on_winver_change(hDlg
);
387 on_dosver_change(hDlg
);
391 switch(LOWORD(wParam
))
394 on_add_app_click(hDlg
);
396 case IDC_APP_REMOVEAPP
:
397 on_remove_app_click(hDlg
);