Improve the interface provided by libdialog. Move a cursor around over

the components and trigger actions based on its position. This reduces
the need to remember the functions of various keys, and makes the
interface more consistant across library.
~
This commit is contained in:
eric 2001-07-18 05:21:37 +00:00
parent acbb5d8140
commit c344255922
6 changed files with 283 additions and 108 deletions

View File

@ -22,7 +22,8 @@
*/ */
#ifndef lint #ifndef lint
static const char rcsid[] = "$FreeBSD$"; static const char rcsid[] =
"$FreeBSD$";
#endif #endif
#include <dialog.h> #include <dialog.h>
@ -40,10 +41,10 @@ int
dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width, dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width,
int list_height, int cnt, void *it, unsigned char *result) int list_height, int cnt, void *it, unsigned char *result)
{ {
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button, choice, int i, j, x, y, cur_x, cur_y, old_x, old_y, box_x, box_y, key = 0, button,
l, k, scroll, max_choice, item_no = 0, *status; choice, l, k, scroll, max_choice, item_no = 0, *status;
int redraw_menu = FALSE; int redraw_menu = FALSE;
int rval = 0; int rval = 0, onlist = 1, ok_space, cancel_space;
char okButton, cancelButton; char okButton, cancelButton;
WINDOW *dialog, *list; WINDOW *dialog, *list;
unsigned char **items = NULL; unsigned char **items = NULL;
@ -186,11 +187,9 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
*/ */
if (ditems && result) { if (ditems && result) {
cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]); cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]);
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : FALSE);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : FALSE);
okButton = toupper(ditems[OK_BUTTON].prompt[0]); okButton = toupper(ditems[OK_BUTTON].prompt[0]);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x, print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : TRUE);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : TRUE);
} }
else { else {
cancelButton = 'C'; cancelButton = 'C';
@ -198,7 +197,9 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
okButton = 'O'; okButton = 'O';
print_button(dialog, " OK ", y, x, TRUE); print_button(dialog, " OK ", y, x, TRUE);
} }
wrefresh(dialog); wnoutrefresh(dialog);
wmove(list, choice, check_x+1);
wrefresh(list);
while (key != ESC) { while (key != ESC) {
key = wgetch(dialog); key = wgetch(dialog);
@ -259,7 +260,26 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
break; break;
if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) || if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) ||
KEY_IS_UP(key) || KEY_IS_DOWN(key) || key == ' ') { KEY_IS_UP(key) || KEY_IS_DOWN(key) || ((key == ' ' || key == '\n' ||
key == '\r') && onlist)) {
/* if moving from buttons to the list, reset and redraw buttons */
if (!onlist) {
onlist = 1;
button = 0;
if (ditems && result) {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
}
else {
print_button(dialog, "Cancel", y, x + 14, button);
print_button(dialog, " OK ", y, x, !button);
}
wmove(list, choice, check_x+1);
wnoutrefresh(dialog);
wrefresh(list);
}
if (key >= '1' && key <= MIN('9', '0'+max_choice)) if (key >= '1' && key <= MIN('9', '0'+max_choice))
i = key - '1'; i = key - '1';
@ -318,8 +338,10 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
else else
i = choice + 1; i = choice + 1;
} }
else if (key == ' ') { /* Toggle item status */ else if ((key == ' ' || key == '\n' || key == '\r') && onlist) { /* Toggle item status */
char lbra = 0, rbra = 0, mark = 0; char lbra = 0, rbra = 0, mark = 0;
getyx(list, old_y, old_x); /* Save cursor position */
if (ditems) { if (ditems) {
if (ditems[scroll + choice].fire) { if (ditems[scroll + choice].fire) {
@ -367,7 +389,6 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
} }
else else
status[scroll + choice] = !status[scroll + choice]; status[scroll + choice] = !status[scroll + choice];
getyx(dialog, cur_y, cur_x); /* Save cursor position */
wmove(list, choice, check_x); wmove(list, choice, check_x);
wattrset(list, check_selected_attr); wattrset(list, check_selected_attr);
if (!lbra) if (!lbra)
@ -377,9 +398,8 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
if (!mark) if (!mark)
mark = 'X'; mark = 'X';
wprintw(list, "%c%c%c", lbra, status[scroll + choice] ? mark : ' ', rbra); wprintw(list, "%c%c%c", lbra, status[scroll + choice] ? mark : ' ', rbra);
wnoutrefresh(list); wmove(list, old_y, old_x); /* Restore cursor to previous position */
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */ wrefresh(list);
wrefresh(dialog);
continue; /* wait for another key press */ continue; /* wait for another key press */
} }
@ -392,9 +412,8 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
/* Highlight new item */ /* Highlight new item */
choice = i; choice = i;
print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, TRUE, DREF(ditems, scroll + choice), list_width, item_x, check_x); print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1], status[scroll + choice], choice, TRUE, DREF(ditems, scroll + choice), list_width, item_x, check_x);
wnoutrefresh(list); wmove(list, choice, check_x+1); /* Restore cursor to previous position */
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */ wrefresh(list);
wrefresh(dialog);
} }
continue; /* wait for another key press */ continue; /* wait for another key press */
} }
@ -406,6 +425,10 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
else else
scroll = 0; scroll = 0;
redraw_menu = TRUE; redraw_menu = TRUE;
if (!onlist) {
onlist = 1;
button = 0;
}
break; break;
case KEY_NPAGE: /* can we go down a full page? */ case KEY_NPAGE: /* can we go down a full page? */
@ -417,12 +440,17 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
else else
scroll += list_height; scroll += list_height;
redraw_menu = TRUE; redraw_menu = TRUE;
if (!onlist) {
onlist = 1;
button = 0;
}
break; break;
case KEY_HOME: /* go to the top */ case KEY_HOME: /* go to the top */
scroll = 0; scroll = 0;
choice = 0; choice = 0;
redraw_menu = TRUE; redraw_menu = TRUE;
onlist = 1;
break; break;
case KEY_END: /* Go to the bottom */ case KEY_END: /* Go to the bottom */
@ -431,57 +459,96 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
scroll = 0; scroll = 0;
choice = max_choice - 1; choice = max_choice - 1;
redraw_menu = TRUE; redraw_menu = TRUE;
onlist = 1;
break; break;
/* swap the selection of OK/Cancel buttons */
case TAB: case TAB:
case KEY_BTAB: case KEY_BTAB:
/* move to next component */
if (onlist) { /* on list, next is ok button */
onlist = 0;
if (ditems && result) {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
ok_space = 1;
cancel_space = strlen(ditems[OK_BUTTON].prompt) + 6;
}
else {
print_button(dialog, "Cancel", y, x + 14, button);
print_button(dialog, " OK ", y, x, !button);
ok_space = 3;
cancel_space = 15;
}
if (button)
wmove(dialog, y, x + cancel_space);
else
wmove(dialog, y, x + ok_space);
wrefresh(dialog);
break;
}
else if (button) { /* on cancel button, next is list */
button = 0;
onlist = 1;
redraw_menu = TRUE;
break;
}
/* on ok button, next is cancel button, same as left/right case */
case KEY_LEFT: case KEY_LEFT:
case KEY_RIGHT: case KEY_RIGHT:
onlist = 0;
button = !button; button = !button;
if (ditems && result) { if (ditems && result) {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button); print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ok_space = 1;
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button); cancel_space = strlen(ditems[OK_BUTTON].prompt) + 6;
} }
else { else {
print_button(dialog, "Cancel", y, x + 14, button); print_button(dialog, "Cancel", y, x + 14, button);
print_button(dialog, " OK ", y, x, !button); print_button(dialog, " OK ", y, x, !button);
ok_space = 3;
cancel_space = 15;
} }
if (button)
wmove(dialog, y, x + cancel_space);
else
wmove(dialog, y, x + ok_space);
wrefresh(dialog); wrefresh(dialog);
break; break;
/* Select either the OK or Cancel button */ case ' ':
case '\n': case '\n':
case '\r': case '\r':
if (ditems) { if (!onlist) {
if (result && ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire) { if (ditems) {
int st; if (result && ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire) {
WINDOW *save = dupwin(newscr); int st;
WINDOW *save = dupwin(newscr);
st = ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]); st = ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]);
if (st & DITEM_RESTORE) { if (st & DITEM_RESTORE) {
touchwin(save); touchwin(save);
wrefresh(save); wrefresh(save);
} }
delwin(save); delwin(save);
if (st == DITEM_FAILURE) if (st == DITEM_FAILURE)
continue; continue;
}
}
else if (result) {
*result = '\0';
for (i = 0; i < item_no; i++) {
if (status[i]) {
strcat(result, items[i*3]);
strcat(result, "\n");
} }
} }
else if (result) {
*result = '\0';
for (i = 0; i < item_no; i++) {
if (status[i]) {
strcat(result, items[i*3]);
strcat(result, "\n");
}
}
}
rval = button;
key = ESC; /* Bail out! */
break;
} }
rval = button;
key = ESC; /* Bail out! */
break;
/* Let me outta here! */ /* Let me outta here! */
case ESC: case ESC:
@ -496,13 +563,24 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
} }
if (redraw_menu) { if (redraw_menu) {
getyx(list, old_y, old_x);
wclear(list); wclear(list);
for (i = 0; i < max_choice; i++) for (i = 0; i < max_choice; i++)
print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice, DREF(ditems, scroll + i), list_width, item_x, check_x);
i, i == choice, DREF(ditems, scroll + i), list_width, item_x, check_x);
wnoutrefresh(list);
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
wrefresh(dialog);
/* redraw buttons to fix highlighting */
if (ditems && result) {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
}
else {
print_button(dialog, "Cancel", y, x + 14, button);
print_button(dialog, " OK ", y, x, !button);
}
wnoutrefresh(dialog);
wmove(list, old_y, old_x);
wrefresh(list);
redraw_menu = FALSE; redraw_menu = FALSE;
} }
} }

View File

@ -21,7 +21,8 @@
*/ */
#ifndef lint #ifndef lint
static const char rcsid[] = "$FreeBSD$"; static const char rcsid[] =
"$FreeBSD$";
#endif #endif
#include <dialog.h> #include <dialog.h>
@ -41,7 +42,7 @@ dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width,
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button, choice, int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button, choice,
l, k, scroll, max_choice, item_no, redraw_menu = FALSE; l, k, scroll, max_choice, item_no, redraw_menu = FALSE;
char okButton, cancelButton; char okButton, cancelButton;
int rval = 0; int rval = 0, ok_space, cancel_space;
WINDOW *dialog, *menu; WINDOW *dialog, *menu;
unsigned char **items = NULL; unsigned char **items = NULL;
dialogMenuItem *ditems; dialogMenuItem *ditems;
@ -172,11 +173,9 @@ dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width,
if (ditems && result) { if (ditems && result) {
cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]); cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]);
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : FALSE);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : FALSE);
okButton = toupper(ditems[OK_BUTTON].prompt[0]); okButton = toupper(ditems[OK_BUTTON].prompt[0]);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x, print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : TRUE);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : TRUE);
} }
else { else {
cancelButton = 'C'; cancelButton = 'C';
@ -346,15 +345,21 @@ dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width,
case KEY_RIGHT: case KEY_RIGHT:
button = !button; button = !button;
if (ditems && result) { if (ditems && result) {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button); print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x, ok_space = 1;
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button); cancel_space = strlen(ditems[OK_BUTTON].prompt) + 6;
} }
else { else {
print_button(dialog, "Cancel", y, x + 14, button); print_button(dialog, "Cancel", y, x + 14, button);
print_button(dialog, " OK ", y, x, !button); print_button(dialog, " OK ", y, x, !button);
ok_space = 3;
cancel_space = 15;
} }
if (button)
wmove(dialog, y, x+cancel_space);
else
wmove(dialog, y, x+ok_space);
wrefresh(dialog); wrefresh(dialog);
break; break;

View File

@ -22,7 +22,8 @@
*/ */
#ifndef lint #ifndef lint
static const char rcsid[] = "$FreeBSD$"; static const char rcsid[] =
"$FreeBSD$";
#endif #endif
#include <dialog.h> #include <dialog.h>
@ -43,10 +44,10 @@ int
dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height,
int cnt, void *it, unsigned char *result) int cnt, void *it, unsigned char *result)
{ {
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button, choice, int i, j, x, y, cur_x, cur_y, old_x, old_y, box_x, box_y, key = 0, button,
l, k, scroll, max_choice, *status, item_no = 0, was_on = 0; choice, l, k, scroll, max_choice, *status, item_no = 0, was_on = 0;
int redraw_menu = FALSE; int redraw_menu = FALSE;
int rval = 0; int rval = 0, onlist = 1, ok_space, cancel_space;
char okButton, cancelButton; char okButton, cancelButton;
WINDOW *dialog, *list; WINDOW *dialog, *list;
unsigned char **items = NULL; unsigned char **items = NULL;
@ -209,8 +210,10 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
okButton = 'O'; okButton = 'O';
print_button(dialog, " OK ", y, x, TRUE); print_button(dialog, " OK ", y, x, TRUE);
} }
wnoutrefresh(dialog);
wmove(list, choice, check_x+1);
wrefresh(list);
wrefresh(dialog);
while (key != ESC) { while (key != ESC) {
key = wgetch(dialog); key = wgetch(dialog);
@ -267,8 +270,30 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
for (i = 0; i < max_choice; i++) for (i = 0; i < max_choice; i++)
if (key != ' ' && toupper(key) == toupper(items[(scroll + i) * 3][0])) if (key != ' ' && toupper(key) == toupper(items[(scroll + i) * 3][0]))
break; break;
if (i < max_choice || (key >= '1' && key <= MIN('9', '0' + max_choice)) || if (i < max_choice || (key >= '1' && key <= MIN('9', '0' + max_choice)) ||
KEY_IS_UP(key) || KEY_IS_DOWN(key) || key == ' ') { KEY_IS_UP(key) || KEY_IS_DOWN(key) || ((key == ' ' || key == '\r' || key == '\n') && onlist == 1)) {
/* if moving from buttons to the list, reset and redraw buttons */
if (!onlist) {
onlist = 1;
button = 0;
if (ditems && result ) {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
}
else {
print_button(dialog, "Cancel", y, x + 14, button);
print_button(dialog, " OK ", y, x, !button);
}
}
wmove(list, choice, check_x+1);
wnoutrefresh(dialog);
wrefresh(list);
if (key >= '1' && key <= MIN('9', '0' + max_choice)) if (key >= '1' && key <= MIN('9', '0' + max_choice))
i = key - '1'; i = key - '1';
else if (KEY_IS_UP(key)) { else if (KEY_IS_UP(key)) {
@ -325,7 +350,8 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
else else
i = choice + 1; i = choice + 1;
} }
else if (key == ' ') { /* Toggle item status */ else if ((key == ' ' || key == '\r' || key == '\n') && onlist) { /* Toggle item status */
getyx(list, old_y, old_x); /* Save cursor position */
if (status[scroll + choice]) if (status[scroll + choice])
continue; continue;
else if (ditems) { else if (ditems) {
@ -350,9 +376,8 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
status[scroll + i], i, i == choice, status[scroll + i], i, i == choice,
DREF(ditems, scroll + i)); DREF(ditems, scroll + i));
} }
wnoutrefresh(list); /* wmove(list, old_y, old_x);*/ /* Restore cursor to previous position */
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */ /* wrefresh(list); */
wrefresh(dialog);
} }
if (st & DITEM_LEAVE_MENU) { if (st & DITEM_LEAVE_MENU) {
/* Allow a fire action to take us out of the menu */ /* Allow a fire action to take us out of the menu */
@ -374,28 +399,24 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
status[i] = 0; status[i] = 0;
status[scroll + choice] = TRUE; status[scroll + choice] = TRUE;
} }
getyx(dialog, cur_y, cur_x); /* Save cursor position */
for (i = 0; i < max_choice; i++) for (i = 0; i < max_choice; i++)
print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1],
status[scroll + i], i, i == choice, DREF(ditems, scroll + i)); status[scroll + i], i, i == choice, DREF(ditems, scroll + i));
wnoutrefresh(list); wmove(list, choice, check_x+1); /* Restore cursor position */
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */ wrefresh(list);
wrefresh(dialog);
continue; /* wait for another key press */ continue; /* wait for another key press */
} }
if (i != choice) { if (i != choice) {
/* De-highlight current item */ /* De-highlight current item */
getyx(dialog, cur_y, cur_x); /* Save cursor position */
print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 +1], print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 +1],
status[scroll + choice], choice, FALSE, DREF(ditems, scroll + choice)); status[scroll + choice], choice, FALSE, DREF(ditems, scroll + choice));
/* Highlight new item */ /* Highlight new item */
choice = i; choice = i;
print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1], print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1],
status[scroll + choice], choice, TRUE, DREF(ditems, scroll + choice)); status[scroll + choice], choice, TRUE, DREF(ditems, scroll + choice));
wnoutrefresh(list); wmove(list, choice, check_x+1); /* Restore cursor position */
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */ wrefresh(list);
wrefresh(dialog);
} }
continue; /* wait for another key press */ continue; /* wait for another key press */
} }
@ -407,6 +428,10 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
else else
scroll = 0; scroll = 0;
redraw_menu = TRUE; redraw_menu = TRUE;
if (!onlist) {
onlist = 1;
button = 0;
}
break; break;
case KEY_NPAGE: case KEY_NPAGE:
@ -418,12 +443,17 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
else else
scroll += list_height; scroll += list_height;
redraw_menu = TRUE; redraw_menu = TRUE;
if (!onlist) {
onlist = 1;
button = 0;
}
break; break;
case KEY_HOME: case KEY_HOME:
scroll = 0; scroll = 0;
choice = 0; choice = 0;
redraw_menu = TRUE; redraw_menu = TRUE;
onlist = 1;
break; break;
case KEY_END: case KEY_END:
@ -432,54 +462,86 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
scroll = 0; scroll = 0;
choice = max_choice - 1; choice = max_choice - 1;
redraw_menu = TRUE; redraw_menu = TRUE;
onlist = 1;
break; break;
case KEY_BTAB:
case TAB: case TAB:
case KEY_BTAB:
/* move to next component */
if (onlist) { /* on list, next is ok button */
onlist = 0;
if (ditems && result)
ok_space = 1;
else
ok_space = 3;
wmove(dialog, y, x + ok_space);
wrefresh(dialog);
break;
}
else if (button) { /* on cancel button, next is list */
button = 0;
onlist = 1;
redraw_menu = TRUE;
break;
}
/* on ok button, next is cancel button, same as left/right case */
case KEY_LEFT: case KEY_LEFT:
case KEY_RIGHT: case KEY_RIGHT:
onlist = 0;
button = !button; button = !button;
if (ditems && result) { if (ditems && result) {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5, print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button); ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x, print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button); ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
ok_space = 1;
cancel_space = strlen(ditems[OK_BUTTON].prompt) + 6;
} }
else { else {
print_button(dialog, "Cancel", y, x + 14, button); print_button(dialog, "Cancel", y, x + 14, button);
print_button(dialog, " OK ", y, x, !button); print_button(dialog, " OK ", y, x, !button);
ok_space = 3;
cancel_space = 15;
} }
if (button)
wmove(dialog, y, x + cancel_space);
else
wmove(dialog, y, x + ok_space);
wrefresh(dialog); wrefresh(dialog);
break; break;
case ' ':
case '\r': case '\r':
case '\n': case '\n':
if (ditems) { if (!onlist) {
if (result && ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire) { if (ditems) {
int st; if (result && ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire) {
WINDOW *save; int st;
WINDOW *save;
save = dupwin(newscr); save = dupwin(newscr);
st = ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]); st = ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]);
if (st & DITEM_RESTORE) { if (st & DITEM_RESTORE) {
touchwin(save); touchwin(save);
wrefresh(save); wrefresh(save);
} }
delwin(save); delwin(save);
}
}
else if (result) {
*result = '\0';
for (i = 0; i < item_no; i++) {
if (status[i]) {
strcpy(result, items[i*3]);
break;
} }
} }
else if (result) {
*result = '\0';
for (i = 0; i < item_no; i++) {
if (status[i]) {
strcpy(result, items[i*3]);
break;
}
}
}
rval = button;
key = ESC;
break;
} }
rval = button;
key = ESC;
break;
case ESC: case ESC:
rval = -1; rval = -1;
@ -492,12 +554,27 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
} }
if (redraw_menu) { if (redraw_menu) {
getyx(list, old_y, old_x);
wclear(list);
for (i = 0; i < max_choice; i++) for (i = 0; i < max_choice; i++)
print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i],
i, i == choice, DREF(ditems, scroll + i)); i, i == choice, DREF(ditems, scroll + i));
wnoutrefresh(list);
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y); print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
wrefresh(dialog);
/* redraw buttons to fix highlighting */
if (ditems && result) {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
}
else {
print_button(dialog, "Cancel", y, x + 14, button);
print_button(dialog, " OK ", y, x, !button);
}
wnoutrefresh(dialog);
wmove(list, old_y, old_x);
wrefresh(list);
redraw_menu = FALSE; redraw_menu = FALSE;
} }
} }

View File

@ -18,6 +18,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif
#include <dialog.h> #include <dialog.h>
#include "dialog.priv.h" #include "dialog.priv.h"
@ -147,7 +151,7 @@ int dialog_textbox(unsigned char *title, unsigned char *file, int height, int wi
wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wmove(dialog, cur_y, cur_x); /* Restore cursor position */
wrefresh(dialog); wrefresh(dialog);
while ((key != ESC) && (key != '\n') && (key != '\r')) { while ((key != ESC) && (key != '\n') && (key != '\r') && (key != ' ')) {
key = wgetch(dialog); key = wgetch(dialog);
switch (key) { switch (key) {
case 'E': /* Exit */ case 'E': /* Exit */

View File

@ -8,6 +8,11 @@
* *
*/ */
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <strings.h>
#include <stdio.h> #include <stdio.h>
@ -387,7 +392,7 @@ int dialog_treemenu(unsigned char *title, unsigned char *prompt,
redraw_menu = TRUE; redraw_menu = TRUE;
break; break;
case KEY_NPAGE: case KEY_NPAGE:
case ' ' : case 'f' :
if (scroll + menu_height >= item_no-1 - menu_height) { /* can we go down a full page? */ if (scroll + menu_height >= item_no-1 - menu_height) { /* can we go down a full page? */
scroll = item_no - menu_height; scroll = item_no - menu_height;
if (scroll < 0) scroll = 0; if (scroll < 0) scroll = 0;
@ -434,6 +439,7 @@ int dialog_treemenu(unsigned char *title, unsigned char *prompt,
} }
wrefresh(dialog); wrefresh(dialog);
break; break;
case ' ':
case '\r': case '\r':
case '\n': case '\n':
delwin(dialog); delwin(dialog);

View File

@ -19,7 +19,8 @@
*/ */
#ifndef lint #ifndef lint
static const char rcsid[] = "$FreeBSD$"; static const char rcsid[] =
"$FreeBSD$";
#endif #endif
#include <dialog.h> #include <dialog.h>
@ -121,6 +122,10 @@ dialog_yesno_proc(unsigned char *title, unsigned char *prompt, int height, int w
while (key != ESC) { while (key != ESC) {
print_button(dialog, " No ", y, x+13, button); print_button(dialog, " No ", y, x+13, button);
print_button(dialog, " Yes " , y, x, !button); print_button(dialog, " Yes " , y, x, !button);
if (button)
wmove(dialog, y, x+16);
else
wmove(dialog, y, x+2);
wrefresh(dialog); wrefresh(dialog);
key = wgetch(dialog); key = wgetch(dialog);