2 * WineCfg libraries tabsheet
4 * Copyright 2004 Robert van Herk
5 * Copyright 2004 Mike Hearn
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define NONAMELESSUNION
24 #define WIN32_LEAN_AND_MEAN
27 #include <wine/debug.h>
33 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
42 UNKNOWN /* Special value indicating an erronous DLL override mode */
51 /* Convert a registry string to a dllmode */
52 static enum dllmode string_to_mode(char *in)
59 out = HeapAlloc(GetProcessHeap(), 0, len);
61 /* remove the spaces */
62 for (i = j = 0; i <= len; ++i) {
68 /* parse the string */
70 if (strcmp(out, "builtin,native") == 0) res = BUILTIN_NATIVE;
71 if (strcmp(out, "native,builtin") == 0) res = NATIVE_BUILTIN;
72 if (strcmp(out, "builtin") == 0) res = BUILTIN;
73 if (strcmp(out, "native") == 0) res = NATIVE;
74 if (strcmp(out, "") == 0) res = DISABLE;
76 HeapFree(GetProcessHeap(), 0, out);
80 /* Convert a dllmode to a registry string. */
81 static const char* mode_to_string(enum dllmode mode)
85 case NATIVE: return "native";
86 case BUILTIN: return "builtin";
87 case NATIVE_BUILTIN: return "native,builtin";
88 case BUILTIN_NATIVE: return "builtin,native";
89 case DISABLE: return "";
90 default: assert(FALSE); return "";
94 /* Convert a dllmode to a pretty string for display. TODO: use translations. */
95 static const char* mode_to_label(enum dllmode mode)
97 WINE_FIXME("translate me\n");
98 return mode_to_string(mode);
101 /* Convert a control id (IDC_ constant) to a dllmode */
102 static enum dllmode id_to_mode(DWORD id)
106 case IDC_RAD_BUILTIN: return BUILTIN;
107 case IDC_RAD_NATIVE: return NATIVE;
108 case IDC_RAD_NATIVE_BUILTIN: return NATIVE_BUILTIN;
109 case IDC_RAD_BUILTIN_NATIVE: return BUILTIN_NATIVE;
110 case IDC_RAD_DISABLE: return DISABLE;
111 default: assert( FALSE ); return 0; /* should not be reached */
115 /* Convert a dllmode to a control id (IDC_ constant) */
116 static DWORD mode_to_id(enum dllmode mode)
120 case BUILTIN: return IDC_RAD_BUILTIN;
121 case NATIVE: return IDC_RAD_NATIVE;
122 case NATIVE_BUILTIN: return IDC_RAD_NATIVE_BUILTIN;
123 case BUILTIN_NATIVE: return IDC_RAD_BUILTIN_NATIVE;
124 case DISABLE: return IDC_RAD_DISABLE;
125 default: assert( FALSE ); return 0; /* should not be reached */
129 static void set_controls_from_selection(HWND dialog)
131 /* FIXME: display/update some information about the selected dll (purpose, recommended loadorder) maybe? */
134 static void clear_settings(HWND dialog)
136 int count = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCOUNT, 0, 0);
139 WINE_TRACE("count=%d\n", count);
141 for (i = 0; i < count; i++)
143 struct dll *dll = (struct dll *) SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETITEMDATA, 0, 0);
145 SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_DELETESTRING, 0, 0);
147 HeapFree(GetProcessHeap(), 0, dll->name);
148 HeapFree(GetProcessHeap(), 0, dll);
152 static void load_library_settings(HWND dialog)
154 char **overrides = enumerate_values(config_key, keypath("DllOverrides"));
158 sel = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0);
160 WINE_TRACE("sel=%d\n", sel);
162 clear_settings(dialog);
164 if (!overrides || *overrides == NULL)
166 set_controls_from_selection(dialog);
167 disable(IDC_DLLS_EDITDLL);
168 disable(IDC_DLLS_REMOVEDLL);
169 HeapFree(GetProcessHeap(), 0, overrides);
173 enable(IDC_DLLS_EDITDLL);
174 enable(IDC_DLLS_REMOVEDLL);
176 for (p = overrides; *p != NULL; p++)
183 value = get_reg_key(config_key, keypath("DllOverrides"), *p, NULL);
185 label = mode_to_label(string_to_mode(value));
187 str = HeapAlloc(GetProcessHeap(), 0, strlen(*p) + 2 + strlen(label) + 2);
193 dll = HeapAlloc(GetProcessHeap(), 0, sizeof(struct dll));
195 dll->mode = string_to_mode(value);
197 index = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_ADDSTRING, (WPARAM) -1, (LPARAM) str);
198 SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_SETITEMDATA, index, (LPARAM) dll);
200 HeapFree(GetProcessHeap(), 0, str);
205 HeapFree(GetProcessHeap(), 0, overrides);
207 /* restore the previous selection, if possible */
208 if (sel >= count - 1) sel = count - 1;
209 else if (sel == -1) sel = 0;
211 SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_SETCURSEL, sel, 0);
213 set_controls_from_selection(dialog);
216 /* Called when the application is initialized (cannot reinit!) */
217 static void init_libsheet(HWND dialog)
219 /* clear the add dll controls */
220 SendDlgItemMessage(dialog, IDC_DLLCOMBO, WM_SETTEXT, 1, (LPARAM) "");
221 disable(IDC_DLLS_ADDDLL);
224 static void on_add_combo_change(HWND dialog)
228 SendDlgItemMessage(dialog, IDC_DLLCOMBO, WM_GETTEXT, sizeof(buffer), (LPARAM) buffer);
231 enable(IDC_DLLS_ADDDLL)
233 disable(IDC_DLLS_ADDDLL);
236 static void set_dllmode(HWND dialog, DWORD id)
243 mode = id_to_mode(id);
245 sel = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0);
246 if (sel == -1) return;
248 dll = (struct dll *) SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETITEMDATA, sel, 0);
250 str = mode_to_string(mode);
251 WINE_TRACE("Setting %s to %s\n", dll->name, str);
253 SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
254 set_reg_key(config_key, keypath("DllOverrides"), dll->name, str);
256 load_library_settings(dialog); /* ... and refresh */
259 static void on_add_click(HWND dialog)
261 static const char dotDll[] = ".dll";
262 char buffer[1024], *ptr;
264 ZeroMemory(buffer, sizeof(buffer));
266 SendDlgItemMessage(dialog, IDC_DLLCOMBO, WM_GETTEXT, sizeof(buffer), (LPARAM) buffer);
267 if (lstrlenA(buffer) >= sizeof(dotDll))
269 ptr = buffer + lstrlenA(buffer) - sizeof(dotDll) + 1;
270 if (!lstrcmpiA(ptr, dotDll))
272 WINE_TRACE("Stripping dll extension\n");
276 SendDlgItemMessage(dialog, IDC_DLLCOMBO, WM_SETTEXT, 0, (LPARAM) "");
277 disable(IDC_DLLS_ADDDLL);
279 WINE_TRACE("Adding %s as native, builtin", buffer);
281 SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
282 set_reg_key(config_key, keypath("DllOverrides"), buffer, "native,builtin");
284 load_library_settings(dialog);
286 SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_SELECTSTRING, (WPARAM) 0, (LPARAM) buffer);
288 set_controls_from_selection(dialog);
291 static INT_PTR CALLBACK loadorder_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
298 CheckRadioButton(hwndDlg, IDC_RAD_BUILTIN, IDC_RAD_DISABLE, lParam);
303 if(HIWORD(wParam) != BN_CLICKED) break;
304 switch (LOWORD(wParam))
306 case IDC_RAD_BUILTIN:
308 case IDC_RAD_BUILTIN_NATIVE:
309 case IDC_RAD_NATIVE_BUILTIN:
310 case IDC_RAD_DISABLE:
311 sel = LOWORD(wParam);
314 EndDialog(hwndDlg, sel);
317 EndDialog(hwndDlg, wParam);
324 static void on_edit_click(HWND hwnd)
327 int index = SendDlgItemMessage(hwnd, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0);
331 /* if no override is selected the edit button should be disabled... */
334 dll = (struct dll *) SendDlgItemMessage(hwnd, IDC_DLLS_LIST, LB_GETITEMDATA, index, 0);
335 id = mode_to_id(dll->mode);
337 ret = DialogBoxParam(0, MAKEINTRESOURCE(IDD_LOADORDER), hwnd, loadorder_dlgproc, id);
340 set_dllmode(hwnd, ret);
343 static void on_remove_click(HWND dialog)
345 int sel = SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0);
348 if (sel == LB_ERR) return;
350 dll = (struct dll *) SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETITEMDATA, sel, 0);
352 SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_DELETESTRING, sel, 0);
354 SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
355 set_reg_key(config_key, keypath("DllOverrides"), dll->name, NULL);
357 HeapFree(GetProcessHeap(), 0, dll->name);
358 HeapFree(GetProcessHeap(), 0, dll);
360 if (SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_GETCOUNT, 0, 0) > 0)
361 SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_SETCURSEL, max(sel - 1, 0), 0);
364 disable(IDC_DLLS_EDITDLL);
365 disable(IDC_DLLS_REMOVEDLL);
368 set_controls_from_selection(dialog);
372 LibrariesDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
380 set_window_title(hDlg);
383 switch (((LPNMHDR)lParam)->code) {
385 load_library_settings(hDlg);
390 switch(HIWORD(wParam)) {
392 /* FIXME: when the user hits enter in the DLL combo box we should invoke the add
393 * add button, rather than the propsheet OK button. But I don't know how to do that!
397 if(LOWORD(wParam) == IDC_DLLCOMBO)
399 on_add_combo_change(hDlg);
404 switch(LOWORD(wParam)) {
405 case IDC_DLLS_ADDDLL:
408 case IDC_DLLS_EDITDLL:
411 case IDC_DLLS_REMOVEDLL:
412 on_remove_click(hDlg);
417 set_controls_from_selection(hDlg);