void selectiface(char *ifname, int withall, int *aborted) { int ch; struct iflist *list; struct iflist *ptmp; struct scroll_list scrolllist; initiflist(&list); if (list == NULL) { no_ifaces_error(); *aborted = 1; return; } if ((withall) && (list != NULL)) { ptmp = xmalloc(sizeof(struct iflist)); strncpy(ptmp->ifname, "All interfaces", sizeof(ptmp->ifname)); ptmp->ifindex = 0; rate_init(&ptmp->rate, 5); /* FIXME: need iflist_entry_init() */ ptmp->prev_entry = NULL; list->prev_entry = ptmp; ptmp->next_entry = list; list = ptmp; } tx_listkeyhelp(STDATTR, HIGHATTR); ptmp = list; tx_init_listbox(&scrolllist, 24, 14, (COLS - 24) / 2 - 9, (LINES - 14) / 2, STDATTR, BOXATTR, BARSTDATTR, HIGHATTR); tx_set_listbox_title(&scrolllist, "Select Interface", 1); while (ptmp != NULL) { tx_add_list_entry(&scrolllist, (char *) ptmp, ptmp->ifname); ptmp = ptmp->next_entry; } tx_show_listbox(&scrolllist); tx_operate_listbox(&scrolllist, &ch, aborted); tx_close_listbox(&scrolllist); if (!(*aborted) && (list != NULL)) { ptmp = (struct iflist *) scrolllist.textptr->nodeptr; if ((withall) && (ptmp->prev_entry == NULL)) /* All Interfaces */ strcpy(ifname, ""); else strcpy(ifname, ptmp->ifname); } tx_destroy_list(&scrolllist); destroyiflist(list); update_panels(); doupdate(); }
void tx_operate_listbox(struct scroll_list *list, int *keystroke, int *aborted) { int ch; int exitloop = 0; int row = 0; char padding[MAX_TEXT_LENGTH]; char sp_buf[10]; if (list->textlist == NULL) { tx_errbox("No list entries", ANYKEY_MSG, &ch); *aborted = 1; return; } list->textptr = list->textlist; tx_listkeyhelp(list->mainattr, list->keyattr); update_panels(); doupdate(); while (!exitloop) { snprintf(sp_buf, 9, "%%%dc", list->width - strlen(list->textptr->text) - 3); snprintf(padding, MAX_TEXT_LENGTH - 1, sp_buf, ' '); wattrset(list->win, list->selectattr); mvwprintw(list->win, row, 0, " %s%s", list->textptr->text, padding); ch = wgetch(list->win); wattrset(list->win, list->mainattr); mvwprintw(list->win, row, 0, " %s%s", list->textptr->text, padding); switch(ch) { case KEY_UP: if (list->textptr == NULL) continue; if (list->textptr->prev_entry != NULL) { if (row == 0) { scrollok(list->win, 1); wscrl(list->win, -1); scrollok(list->win, 0); } else row--; list->textptr = list->textptr->prev_entry; } break; case KEY_DOWN: if (list->textptr == NULL) continue; if (list->textptr->next_entry != NULL) { if (row == list->height - 3) { scrollok(list->win, 1); wscrl(list->win, 1); scrollok(list->win, 0); } else row++; list->textptr = list->textptr->next_entry; } break; case 13: *aborted = 0; exitloop = 1; break; case 27: case 'x': case 'X': case 24: *aborted = 1; exitloop = 1; case 12: case 'l': case 'L': tx_refresh_screen(); break; } } *keystroke = ch; }