199 lines
6.8 KiB
Text
199 lines
6.8 KiB
Text
$NetBSD: patch-af,v 1.3 2000/07/28 20:30:11 jlam Exp $
|
|
|
|
--- menubox.c.orig Thu Aug 17 22:21:00 1995
|
|
+++ menubox.c Fri Jul 28 15:30:22 2000
|
|
@@ -53,12 +53,32 @@
|
|
dialog_menu (const char *title, const char *prompt, int height, int width,
|
|
int menu_height, int item_no, const char * const * items)
|
|
{
|
|
- int i, x, y, cur_x, cur_y, box_x, box_y;
|
|
- int key = 0, button = 0, choice = 0, scroll = 0, max_choice;
|
|
+ int i, j, x, y, cur_x, cur_y, box_x, box_y;
|
|
+ int key = 0, button = 0, choice = 0, d_scroll = 0, max_choice;
|
|
WINDOW *dialog, *menu;
|
|
|
|
max_choice = MIN (menu_height, item_no);
|
|
|
|
+ /* Find length of longest item in order to center menu */
|
|
+ tag_x = 0;
|
|
+ item_x = 0;
|
|
+ for (i = 0; i < item_no; i++) {
|
|
+ tag_x = MAX (tag_x,
|
|
+ strlen (items[i * 2]) + strlen (items[i * 2 + 1]) + 2);
|
|
+ item_x = MAX (item_x, strlen (items[i * 2]));
|
|
+ }
|
|
+
|
|
+ /* Choose useful default height and width if they are negative */
|
|
+ if (height < 0)
|
|
+ height = strheight(prompt) + menu_height + 4 + 2;
|
|
+ if (width < 0) {
|
|
+ i = strwidth(prompt);
|
|
+ j = ((title != NULL) ? strwidth(title) : 0);
|
|
+ width = MAX (i, j);
|
|
+ width = MAX (width, tag_x + 4) + 4;
|
|
+ }
|
|
+ width = MAX (width, MIN_DIALOG_WIDTH);
|
|
+
|
|
/* center dialog box on screen */
|
|
x = (COLS - width) / 2;
|
|
y = (LINES - height) / 2;
|
|
@@ -107,14 +127,6 @@
|
|
draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2,
|
|
menubox_border_attr, menubox_attr);
|
|
|
|
- tag_x = 0;
|
|
- item_x = 0;
|
|
- /* Find length of longest item in order to center menu */
|
|
- for (i = 0; i < item_no; i++) {
|
|
- tag_x = MAX (tag_x,
|
|
- strlen (items[i * 2]) + strlen (items[i * 2 + 1]) + 2);
|
|
- item_x = MAX (item_x, strlen (items[i * 2]));
|
|
- }
|
|
tag_x = (menu_width - tag_x) / 2;
|
|
item_x = tag_x + item_x + 2;
|
|
|
|
@@ -146,7 +158,7 @@
|
|
/* Check if key pressed matches first character of any
|
|
item tag in menu */
|
|
for (i = 0; i < max_choice; i++)
|
|
- if (toupper (key) == toupper (items[(scroll + i) * 2][0]))
|
|
+ if (toupper (key) == toupper (items[(d_scroll + i) * 2][0]))
|
|
break;
|
|
|
|
if (i < max_choice ||
|
|
@@ -159,33 +171,33 @@
|
|
i = key - M_EVENT;
|
|
else if (key == KEY_UP || key == '-') {
|
|
if (!choice) {
|
|
- if (scroll) {
|
|
+ if (d_scroll) {
|
|
|
|
/* Scroll menu down */
|
|
getyx (dialog, cur_y, cur_x);
|
|
if (menu_height > 1) {
|
|
/* De-highlight current first item */
|
|
- print_item (menu, items[scroll * 2],
|
|
- items[scroll * 2 + 1], 0, FALSE);
|
|
+ print_item (menu, items[d_scroll * 2],
|
|
+ items[d_scroll * 2 + 1], 0, FALSE);
|
|
scrollok (menu, TRUE);
|
|
wscrl (menu, -1);
|
|
scrollok (menu, FALSE);
|
|
}
|
|
- scroll--;
|
|
- print_item (menu, items[scroll * 2],
|
|
- items[scroll * 2 + 1], 0, TRUE);
|
|
+ d_scroll--;
|
|
+ print_item (menu, items[d_scroll * 2],
|
|
+ items[d_scroll * 2 + 1], 0, TRUE);
|
|
wnoutrefresh (menu);
|
|
|
|
/* print the up/down arrows */
|
|
wmove (dialog, box_y, box_x + tag_x + 1);
|
|
- wattrset (dialog, scroll ? uarrow_attr : menubox_attr);
|
|
- waddch (dialog, scroll ? ACS_UARROW : ACS_HLINE);
|
|
+ wattrset (dialog, d_scroll ? uarrow_attr : menubox_attr);
|
|
+ waddch (dialog, d_scroll ? ACS_UARROW : ACS_HLINE);
|
|
wmove (dialog, box_y, box_x + tag_x + 2);
|
|
- waddch (dialog, scroll ? '(' : ACS_HLINE);
|
|
+ waddch (dialog, d_scroll ? '(' : ACS_HLINE);
|
|
wmove (dialog, box_y, box_x + tag_x + 3);
|
|
- waddch (dialog, scroll ? '-' : ACS_HLINE);
|
|
+ waddch (dialog, d_scroll ? '-' : ACS_HLINE);
|
|
wmove (dialog, box_y, box_x + tag_x + 4);
|
|
- waddch (dialog, scroll ? ')' : ACS_HLINE);
|
|
+ waddch (dialog, d_scroll ? ')' : ACS_HLINE);
|
|
wattrset (dialog, darrow_attr);
|
|
wmove (dialog, box_y + menu_height + 1,
|
|
box_x + tag_x + 1);
|
|
@@ -201,21 +213,21 @@
|
|
i = choice - 1;
|
|
} else if (key == KEY_DOWN || key == '+')
|
|
if (choice == max_choice - 1) {
|
|
- if (scroll + choice < item_no - 1) {
|
|
+ if (d_scroll + choice < item_no - 1) {
|
|
/* Scroll menu up */
|
|
getyx (dialog, cur_y, cur_x);
|
|
if (menu_height > 1) {
|
|
/* De-highlight current last item */
|
|
- print_item (menu, items[(scroll + max_choice - 1)
|
|
- * 2], items[(scroll + max_choice - 1)
|
|
+ print_item (menu, items[(d_scroll + max_choice - 1)
|
|
+ * 2], items[(d_scroll + max_choice - 1)
|
|
* 2 + 1], max_choice - 1, FALSE);
|
|
scrollok (menu, TRUE);
|
|
scroll (menu);
|
|
scrollok (menu, FALSE);
|
|
}
|
|
- scroll++;
|
|
- print_item (menu, items[(scroll + max_choice - 1) * 2],
|
|
- items[(scroll + max_choice - 1) * 2 + 1],
|
|
+ d_scroll++;
|
|
+ print_item (menu, items[(d_scroll + max_choice - 1) * 2],
|
|
+ items[(d_scroll + max_choice - 1) * 2 + 1],
|
|
max_choice - 1, TRUE);
|
|
wnoutrefresh (menu);
|
|
|
|
@@ -227,21 +239,21 @@
|
|
waddstr (dialog, "(-)");
|
|
wmove (dialog, box_y + menu_height + 1,
|
|
box_x + tag_x + 1);
|
|
- wattrset (dialog, scroll + choice < item_no - 1 ?
|
|
+ wattrset (dialog, d_scroll + choice < item_no - 1 ?
|
|
darrow_attr : menubox_border_attr);
|
|
- waddch (dialog, scroll + choice < item_no - 1 ?
|
|
+ waddch (dialog, d_scroll + choice < item_no - 1 ?
|
|
ACS_DARROW : ACS_HLINE);
|
|
wmove (dialog, box_y + menu_height + 1,
|
|
box_x + tag_x + 2);
|
|
- waddch (dialog, scroll + choice < item_no - 1 ?
|
|
+ waddch (dialog, d_scroll + choice < item_no - 1 ?
|
|
'(' : ACS_HLINE);
|
|
wmove (dialog, box_y + menu_height + 1,
|
|
box_x + tag_x + 3);
|
|
- waddch (dialog, scroll + choice < item_no - 1 ?
|
|
+ waddch (dialog, d_scroll + choice < item_no - 1 ?
|
|
'+' : ACS_HLINE);
|
|
wmove (dialog, box_y + menu_height + 1,
|
|
box_x + tag_x + 4);
|
|
- waddch (dialog, scroll + choice < item_no - 1 ?
|
|
+ waddch (dialog, d_scroll + choice < item_no - 1 ?
|
|
')' : ACS_HLINE);
|
|
wmove (dialog, cur_y, cur_x);
|
|
wrefresh (dialog);
|
|
@@ -253,13 +265,13 @@
|
|
if (i != choice) {
|
|
/* De-highlight current item */
|
|
getyx (dialog, cur_y, cur_x); /* Save cursor position */
|
|
- print_item (menu, items[(scroll + choice) * 2],
|
|
- items[(scroll + choice) * 2 + 1], choice, FALSE);
|
|
+ print_item (menu, items[(d_scroll + choice) * 2],
|
|
+ items[(d_scroll + choice) * 2 + 1], choice, FALSE);
|
|
|
|
/* Highlight new item */
|
|
choice = i;
|
|
- print_item (menu, items[(scroll + choice) * 2],
|
|
- items[(scroll + choice) * 2 + 1], choice, TRUE);
|
|
+ print_item (menu, items[(d_scroll + choice) * 2],
|
|
+ items[(d_scroll + choice) * 2 + 1], choice, TRUE);
|
|
wnoutrefresh (menu);
|
|
wmove (dialog, cur_y, cur_x);
|
|
wrefresh (dialog);
|
|
@@ -271,7 +283,7 @@
|
|
case 'o':
|
|
case M_EVENT + 'O':
|
|
delwin (dialog);
|
|
- return scroll + choice;
|
|
+ return d_scroll + choice;
|
|
case 'C':
|
|
case 'c':
|
|
case M_EVENT + 'C':
|
|
@@ -297,7 +309,7 @@
|
|
break;
|
|
case '\n':
|
|
delwin (dialog);
|
|
- return (button? -2 : (scroll + choice));
|
|
+ return (button? -2 : (d_scroll + choice));
|
|
case ESC:
|
|
break;
|
|
}
|