Sort the list of supported platforms that we show to the user.

This commit is contained in:
uwe 2004-03-28 15:32:35 +00:00
parent 0b6352e327
commit d4129e7685
2 changed files with 76 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* -*-C++-*- $NetBSD: menu.cpp,v 1.8 2003/12/23 15:24:26 uwe Exp $ */
/* -*-C++-*- $NetBSD: menu.cpp,v 1.9 2004/03/28 15:32:35 uwe Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -109,10 +109,7 @@ MainTabWindow::init(HWND w)
SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETCURSEL, menu.dir_default(),
0);
// platform
for (i = 0; entry = menu.platform_get(i); i++)
_insert_item(w, entry, IDC_MAIN_PLATFORM);
SendDlgItemMessage(w, IDC_MAIN_PLATFORM, CB_SETCURSEL,
menu.platform_default(), 0);
_sort_platids(w);
// kernel file name.
Edit_SetText(GetDlgItem(w, IDC_MAIN_KERNEL), pref.kernel_user ?
pref.kernel_user_file : TEXT("netbsd.gz"));
@ -149,6 +146,68 @@ MainTabWindow::init(HWND w)
EnableWindow(_combobox_serial_speed, pref.boot_serial);
}
int
MainTabWindow::_platcmp(const void *a, const void *b)
{
const MainTabWindow::PlatMap *pa =
reinterpret_cast <const MainTabWindow::PlatMap *>(a);
const MainTabWindow::PlatMap *pb =
reinterpret_cast <const MainTabWindow::PlatMap *>(b);
return wcscmp(pa->name, pb->name);
}
void
MainTabWindow::_sort_platids(HWND w)
{
HpcMenuInterface &menu = HPC_MENU;
MainTabWindow::PlatMap *p;
TCHAR *entry;
int nids;
int i;
for (nids = 0; menu.platform_get(nids); ++nids)
continue;
_platmap = reinterpret_cast <MainTabWindow::PlatMap *>
(malloc(nids * sizeof(MainTabWindow::PlatMap)));
if (_platmap == NULL) {
// can't sort, present in the order of definition
for (i = 0; entry = menu.platform_get(i); i++)
_insert_item(w, entry, IDC_MAIN_PLATFORM);
SendDlgItemMessage(w, IDC_MAIN_PLATFORM, CB_SETCURSEL,
menu.platform_default(), 0);
return;
}
for (i = 0, p = _platmap; i < nids; ++i, ++p) {
p->id = i;
p->name = menu.platform_get(i);
}
qsort(_platmap, nids, sizeof(MainTabWindow::PlatMap),
MainTabWindow::_platcmp);
int defid = menu.platform_default();
int defitem = 0;
for (i = 0; i < nids; ++i) {
if (_platmap[i].id == defid)
defitem = i;
_insert_item(w, _platmap[i].name, IDC_MAIN_PLATFORM);
}
SendDlgItemMessage(w, IDC_MAIN_PLATFORM, CB_SETCURSEL, defitem, 0);
}
int
MainTabWindow::_item_to_platid(int idx)
{
if (_platmap == NULL)
return idx;
else
return _platmap[idx].id;
}
void
MainTabWindow::layout()
{
@ -197,7 +256,7 @@ MainTabWindow::get()
pref.kernel_user = TRUE;
int i = ComboBox_GetCurSel(GetDlgItem(_window, IDC_MAIN_PLATFORM));
menu.platform_set(i);
menu.platform_set(_item_to_platid(i));
if (_is_checked(IDC_MAIN_ROOT_WD))
pref.rootfs = 0;

View File

@ -1,4 +1,4 @@
/* -*-C++-*- $NetBSD: menu.h,v 1.2 2001/05/21 15:55:04 uch Exp $ */
/* -*-C++-*- $NetBSD: menu.h,v 1.3 2004/03/28 15:32:35 uwe Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -42,6 +42,16 @@ private:
HWND _edit_md_root;
HWND _combobox_serial_speed;
struct PlatMap {
int id; // index in platid_name_table
TCHAR *name; // platform name
};
struct PlatMap *_platmap;
void _sort_platids(HWND w);
int _item_to_platid(int idx);
static int _platcmp(const void *, const void *);
int _item_idx;
void _insert_item(HWND w, TCHAR *name, int id);
public: