xref: /OK3568_Linux_fs/buildroot/support/kconfig/lxdialog/menubox.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  menubox.c -- implements the menu box
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5*4882a593Smuzhiyun  *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com)
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  *  This program is free software; you can redistribute it and/or
8*4882a593Smuzhiyun  *  modify it under the terms of the GNU General Public License
9*4882a593Smuzhiyun  *  as published by the Free Software Foundation; either version 2
10*4882a593Smuzhiyun  *  of the License, or (at your option) any later version.
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *  This program is distributed in the hope that it will be useful,
13*4882a593Smuzhiyun  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14*4882a593Smuzhiyun  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*4882a593Smuzhiyun  *  GNU General Public License for more details.
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  *  You should have received a copy of the GNU General Public License
18*4882a593Smuzhiyun  *  along with this program; if not, write to the Free Software
19*4882a593Smuzhiyun  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*4882a593Smuzhiyun  */
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun  *  Changes by Clifford Wolf (god@clifford.at)
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  *  [ 1998-06-13 ]
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  *    *)  A bugfix for the Page-Down problem
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  *    *)  Formerly when I used Page Down and Page Up, the cursor would be set
30*4882a593Smuzhiyun  *        to the first position in the menu box.  Now lxdialog is a bit
31*4882a593Smuzhiyun  *        smarter and works more like other menu systems (just have a look at
32*4882a593Smuzhiyun  *        it).
33*4882a593Smuzhiyun  *
34*4882a593Smuzhiyun  *    *)  Formerly if I selected something my scrolling would be broken because
35*4882a593Smuzhiyun  *        lxdialog is re-invoked by the Menuconfig shell script, can't
36*4882a593Smuzhiyun  *        remember the last scrolling position, and just sets it so that the
37*4882a593Smuzhiyun  *        cursor is at the bottom of the box.  Now it writes the temporary file
38*4882a593Smuzhiyun  *        lxdialog.scrltmp which contains this information. The file is
39*4882a593Smuzhiyun  *        deleted by lxdialog if the user leaves a submenu or enters a new
40*4882a593Smuzhiyun  *        one, but it would be nice if Menuconfig could make another "rm -f"
41*4882a593Smuzhiyun  *        just to be sure.  Just try it out - you will recognise a difference!
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  *  [ 1998-06-14 ]
44*4882a593Smuzhiyun  *
45*4882a593Smuzhiyun  *    *)  Now lxdialog is crash-safe against broken "lxdialog.scrltmp" files
46*4882a593Smuzhiyun  *        and menus change their size on the fly.
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  *    *)  If for some reason the last scrolling position is not saved by
49*4882a593Smuzhiyun  *        lxdialog, it sets the scrolling so that the selected item is in the
50*4882a593Smuzhiyun  *        middle of the menu box, not at the bottom.
51*4882a593Smuzhiyun  *
52*4882a593Smuzhiyun  * 02 January 1999, Michael Elizabeth Chastain (mec@shout.net)
53*4882a593Smuzhiyun  * Reset 'scroll' to 0 if the value from lxdialog.scrltmp is bogus.
54*4882a593Smuzhiyun  * This fixes a bug in Menuconfig where using ' ' to descend into menus
55*4882a593Smuzhiyun  * would leave mis-synchronized lxdialog.scrltmp files lying around,
56*4882a593Smuzhiyun  * fscanf would read in 'scroll', and eventually that value would get used.
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun #include "dialog.h"
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun static int menu_width, item_x;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /*
64*4882a593Smuzhiyun  * Print menu item
65*4882a593Smuzhiyun  */
do_print_item(WINDOW * win,const char * item,int line_y,int selected,int hotkey)66*4882a593Smuzhiyun static void do_print_item(WINDOW * win, const char *item, int line_y,
67*4882a593Smuzhiyun 			  int selected, int hotkey)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun 	int j;
70*4882a593Smuzhiyun 	char *menu_item = malloc(menu_width + 1);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	strncpy(menu_item, item, menu_width - item_x);
73*4882a593Smuzhiyun 	menu_item[menu_width - item_x] = '\0';
74*4882a593Smuzhiyun 	j = first_alpha(menu_item, "YyNnMmHh");
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	/* Clear 'residue' of last item */
77*4882a593Smuzhiyun 	wattrset(win, dlg.menubox.atr);
78*4882a593Smuzhiyun 	wmove(win, line_y, 0);
79*4882a593Smuzhiyun #if OLD_NCURSES
80*4882a593Smuzhiyun 	{
81*4882a593Smuzhiyun 		int i;
82*4882a593Smuzhiyun 		for (i = 0; i < menu_width; i++)
83*4882a593Smuzhiyun 			waddch(win, ' ');
84*4882a593Smuzhiyun 	}
85*4882a593Smuzhiyun #else
86*4882a593Smuzhiyun 	wclrtoeol(win);
87*4882a593Smuzhiyun #endif
88*4882a593Smuzhiyun 	wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
89*4882a593Smuzhiyun 	mvwaddstr(win, line_y, item_x, menu_item);
90*4882a593Smuzhiyun 	if (hotkey) {
91*4882a593Smuzhiyun 		wattrset(win, selected ? dlg.tag_key_selected.atr
92*4882a593Smuzhiyun 			 : dlg.tag_key.atr);
93*4882a593Smuzhiyun 		mvwaddch(win, line_y, item_x + j, menu_item[j]);
94*4882a593Smuzhiyun 	}
95*4882a593Smuzhiyun 	if (selected) {
96*4882a593Smuzhiyun 		wmove(win, line_y, item_x + 1);
97*4882a593Smuzhiyun 	}
98*4882a593Smuzhiyun 	free(menu_item);
99*4882a593Smuzhiyun 	wrefresh(win);
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #define print_item(index, choice, selected)				\
103*4882a593Smuzhiyun do {									\
104*4882a593Smuzhiyun 	item_set(index);						\
105*4882a593Smuzhiyun 	do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \
106*4882a593Smuzhiyun } while (0)
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun /*
109*4882a593Smuzhiyun  * Print the scroll indicators.
110*4882a593Smuzhiyun  */
print_arrows(WINDOW * win,int item_no,int scroll,int y,int x,int height)111*4882a593Smuzhiyun static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
112*4882a593Smuzhiyun 			 int height)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun 	int cur_y, cur_x;
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	getyx(win, cur_y, cur_x);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	wmove(win, y, x);
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 	if (scroll > 0) {
121*4882a593Smuzhiyun 		wattrset(win, dlg.uarrow.atr);
122*4882a593Smuzhiyun 		waddch(win, ACS_UARROW);
123*4882a593Smuzhiyun 		waddstr(win, "(-)");
124*4882a593Smuzhiyun 	} else {
125*4882a593Smuzhiyun 		wattrset(win, dlg.menubox.atr);
126*4882a593Smuzhiyun 		waddch(win, ACS_HLINE);
127*4882a593Smuzhiyun 		waddch(win, ACS_HLINE);
128*4882a593Smuzhiyun 		waddch(win, ACS_HLINE);
129*4882a593Smuzhiyun 		waddch(win, ACS_HLINE);
130*4882a593Smuzhiyun 	}
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	y = y + height + 1;
133*4882a593Smuzhiyun 	wmove(win, y, x);
134*4882a593Smuzhiyun 	wrefresh(win);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	if ((height < item_no) && (scroll + height < item_no)) {
137*4882a593Smuzhiyun 		wattrset(win, dlg.darrow.atr);
138*4882a593Smuzhiyun 		waddch(win, ACS_DARROW);
139*4882a593Smuzhiyun 		waddstr(win, "(+)");
140*4882a593Smuzhiyun 	} else {
141*4882a593Smuzhiyun 		wattrset(win, dlg.menubox_border.atr);
142*4882a593Smuzhiyun 		waddch(win, ACS_HLINE);
143*4882a593Smuzhiyun 		waddch(win, ACS_HLINE);
144*4882a593Smuzhiyun 		waddch(win, ACS_HLINE);
145*4882a593Smuzhiyun 		waddch(win, ACS_HLINE);
146*4882a593Smuzhiyun 	}
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	wmove(win, cur_y, cur_x);
149*4882a593Smuzhiyun 	wrefresh(win);
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun /*
153*4882a593Smuzhiyun  * Display the termination buttons.
154*4882a593Smuzhiyun  */
print_buttons(WINDOW * win,int height,int width,int selected)155*4882a593Smuzhiyun static void print_buttons(WINDOW * win, int height, int width, int selected)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun 	int x = width / 2 - 28;
158*4882a593Smuzhiyun 	int y = height - 2;
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 	print_button(win, gettext("Select"), y, x, selected == 0);
161*4882a593Smuzhiyun 	print_button(win, gettext(" Exit "), y, x + 12, selected == 1);
162*4882a593Smuzhiyun 	print_button(win, gettext(" Help "), y, x + 24, selected == 2);
163*4882a593Smuzhiyun 	print_button(win, gettext(" Save "), y, x + 36, selected == 3);
164*4882a593Smuzhiyun 	print_button(win, gettext(" Load "), y, x + 48, selected == 4);
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	wmove(win, y, x + 1 + 12 * selected);
167*4882a593Smuzhiyun 	wrefresh(win);
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun /* scroll up n lines (n may be negative) */
do_scroll(WINDOW * win,int * scroll,int n)171*4882a593Smuzhiyun static void do_scroll(WINDOW *win, int *scroll, int n)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun 	/* Scroll menu up */
174*4882a593Smuzhiyun 	scrollok(win, TRUE);
175*4882a593Smuzhiyun 	wscrl(win, n);
176*4882a593Smuzhiyun 	scrollok(win, FALSE);
177*4882a593Smuzhiyun 	*scroll = *scroll + n;
178*4882a593Smuzhiyun 	wrefresh(win);
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun /*
182*4882a593Smuzhiyun  * Display a menu for choosing among a number of options
183*4882a593Smuzhiyun  */
dialog_menu(const char * title,const char * prompt,const void * selected,int * s_scroll)184*4882a593Smuzhiyun int dialog_menu(const char *title, const char *prompt,
185*4882a593Smuzhiyun 		const void *selected, int *s_scroll)
186*4882a593Smuzhiyun {
187*4882a593Smuzhiyun 	int i, j, x, y, box_x, box_y;
188*4882a593Smuzhiyun 	int height, width, menu_height;
189*4882a593Smuzhiyun 	int key = 0, button = 0, scroll = 0, choice = 0;
190*4882a593Smuzhiyun 	int first_item =  0, max_choice;
191*4882a593Smuzhiyun 	WINDOW *dialog, *menu;
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun do_resize:
194*4882a593Smuzhiyun 	height = getmaxy(stdscr);
195*4882a593Smuzhiyun 	width = getmaxx(stdscr);
196*4882a593Smuzhiyun 	if (height < MENUBOX_HEIGTH_MIN || width < MENUBOX_WIDTH_MIN)
197*4882a593Smuzhiyun 		return -ERRDISPLAYTOOSMALL;
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	height -= 4;
200*4882a593Smuzhiyun 	width  -= 5;
201*4882a593Smuzhiyun 	menu_height = height - 10;
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	max_choice = MIN(menu_height, item_count());
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	/* center dialog box on screen */
206*4882a593Smuzhiyun 	x = (getmaxx(stdscr) - width) / 2;
207*4882a593Smuzhiyun 	y = (getmaxy(stdscr) - height) / 2;
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	draw_shadow(stdscr, y, x, height, width);
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun 	dialog = newwin(height, width, y, x);
212*4882a593Smuzhiyun 	keypad(dialog, TRUE);
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun 	draw_box(dialog, 0, 0, height, width,
215*4882a593Smuzhiyun 		 dlg.dialog.atr, dlg.border.atr);
216*4882a593Smuzhiyun 	wattrset(dialog, dlg.border.atr);
217*4882a593Smuzhiyun 	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
218*4882a593Smuzhiyun 	for (i = 0; i < width - 2; i++)
219*4882a593Smuzhiyun 		waddch(dialog, ACS_HLINE);
220*4882a593Smuzhiyun 	wattrset(dialog, dlg.dialog.atr);
221*4882a593Smuzhiyun 	wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
222*4882a593Smuzhiyun 	waddch(dialog, ACS_RTEE);
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 	print_title(dialog, title, width);
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun 	wattrset(dialog, dlg.dialog.atr);
227*4882a593Smuzhiyun 	print_autowrap(dialog, prompt, width - 2, 1, 3);
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun 	menu_width = width - 6;
230*4882a593Smuzhiyun 	box_y = height - menu_height - 5;
231*4882a593Smuzhiyun 	box_x = (width - menu_width) / 2 - 1;
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun 	/* create new window for the menu */
234*4882a593Smuzhiyun 	menu = subwin(dialog, menu_height, menu_width,
235*4882a593Smuzhiyun 		      y + box_y + 1, x + box_x + 1);
236*4882a593Smuzhiyun 	keypad(menu, TRUE);
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun 	/* draw a box around the menu items */
239*4882a593Smuzhiyun 	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
240*4882a593Smuzhiyun 		 dlg.menubox_border.atr, dlg.menubox.atr);
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun 	if (menu_width >= 80)
243*4882a593Smuzhiyun 		item_x = (menu_width - 70) / 2;
244*4882a593Smuzhiyun 	else
245*4882a593Smuzhiyun 		item_x = 4;
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun 	/* Set choice to default item */
248*4882a593Smuzhiyun 	item_foreach()
249*4882a593Smuzhiyun 		if (selected && (selected == item_data()))
250*4882a593Smuzhiyun 			choice = item_n();
251*4882a593Smuzhiyun 	/* get the saved scroll info */
252*4882a593Smuzhiyun 	scroll = *s_scroll;
253*4882a593Smuzhiyun 	if ((scroll <= choice) && (scroll + max_choice > choice) &&
254*4882a593Smuzhiyun 	   (scroll >= 0) && (scroll + max_choice <= item_count())) {
255*4882a593Smuzhiyun 		first_item = scroll;
256*4882a593Smuzhiyun 		choice = choice - scroll;
257*4882a593Smuzhiyun 	} else {
258*4882a593Smuzhiyun 		scroll = 0;
259*4882a593Smuzhiyun 	}
260*4882a593Smuzhiyun 	if ((choice >= max_choice)) {
261*4882a593Smuzhiyun 		if (choice >= item_count() - max_choice / 2)
262*4882a593Smuzhiyun 			scroll = first_item = item_count() - max_choice;
263*4882a593Smuzhiyun 		else
264*4882a593Smuzhiyun 			scroll = first_item = choice - max_choice / 2;
265*4882a593Smuzhiyun 		choice = choice - scroll;
266*4882a593Smuzhiyun 	}
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 	/* Print the menu */
269*4882a593Smuzhiyun 	for (i = 0; i < max_choice; i++) {
270*4882a593Smuzhiyun 		print_item(first_item + i, i, i == choice);
271*4882a593Smuzhiyun 	}
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun 	wnoutrefresh(menu);
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun 	print_arrows(dialog, item_count(), scroll,
276*4882a593Smuzhiyun 		     box_y, box_x + item_x + 1, menu_height);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun 	print_buttons(dialog, height, width, 0);
279*4882a593Smuzhiyun 	wmove(menu, choice, item_x + 1);
280*4882a593Smuzhiyun 	wrefresh(menu);
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun 	while (key != KEY_ESC) {
283*4882a593Smuzhiyun 		key = wgetch(menu);
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun 		if (key < 256 && isalpha(key))
286*4882a593Smuzhiyun 			key = tolower(key);
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun 		if (strchr("ynmh ", key))
289*4882a593Smuzhiyun 			i = max_choice;
290*4882a593Smuzhiyun 		else {
291*4882a593Smuzhiyun 			for (i = choice + 1; i < max_choice; i++) {
292*4882a593Smuzhiyun 				item_set(scroll + i);
293*4882a593Smuzhiyun 				j = first_alpha(item_str(), "YyNnMmHh");
294*4882a593Smuzhiyun 				if (key == tolower(item_str()[j]))
295*4882a593Smuzhiyun 					break;
296*4882a593Smuzhiyun 			}
297*4882a593Smuzhiyun 			if (i == max_choice)
298*4882a593Smuzhiyun 				for (i = 0; i < max_choice; i++) {
299*4882a593Smuzhiyun 					item_set(scroll + i);
300*4882a593Smuzhiyun 					j = first_alpha(item_str(), "YyNnMmHh");
301*4882a593Smuzhiyun 					if (key == tolower(item_str()[j]))
302*4882a593Smuzhiyun 						break;
303*4882a593Smuzhiyun 				}
304*4882a593Smuzhiyun 		}
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun 		if (item_count() != 0 &&
307*4882a593Smuzhiyun 		    (i < max_choice ||
308*4882a593Smuzhiyun 		     key == KEY_UP || key == KEY_DOWN ||
309*4882a593Smuzhiyun 		     key == '-' || key == '+' ||
310*4882a593Smuzhiyun 		     key == KEY_PPAGE || key == KEY_NPAGE)) {
311*4882a593Smuzhiyun 			/* Remove highligt of current item */
312*4882a593Smuzhiyun 			print_item(scroll + choice, choice, FALSE);
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun 			if (key == KEY_UP || key == '-') {
315*4882a593Smuzhiyun 				if (choice < 2 && scroll) {
316*4882a593Smuzhiyun 					/* Scroll menu down */
317*4882a593Smuzhiyun 					do_scroll(menu, &scroll, -1);
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 					print_item(scroll, 0, FALSE);
320*4882a593Smuzhiyun 				} else
321*4882a593Smuzhiyun 					choice = MAX(choice - 1, 0);
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun 			} else if (key == KEY_DOWN || key == '+') {
324*4882a593Smuzhiyun 				print_item(scroll+choice, choice, FALSE);
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun 				if ((choice > max_choice - 3) &&
327*4882a593Smuzhiyun 				    (scroll + max_choice < item_count())) {
328*4882a593Smuzhiyun 					/* Scroll menu up */
329*4882a593Smuzhiyun 					do_scroll(menu, &scroll, 1);
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 					print_item(scroll+max_choice - 1,
332*4882a593Smuzhiyun 						   max_choice - 1, FALSE);
333*4882a593Smuzhiyun 				} else
334*4882a593Smuzhiyun 					choice = MIN(choice + 1, max_choice - 1);
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 			} else if (key == KEY_PPAGE) {
337*4882a593Smuzhiyun 				scrollok(menu, TRUE);
338*4882a593Smuzhiyun 				for (i = 0; (i < max_choice); i++) {
339*4882a593Smuzhiyun 					if (scroll > 0) {
340*4882a593Smuzhiyun 						do_scroll(menu, &scroll, -1);
341*4882a593Smuzhiyun 						print_item(scroll, 0, FALSE);
342*4882a593Smuzhiyun 					} else {
343*4882a593Smuzhiyun 						if (choice > 0)
344*4882a593Smuzhiyun 							choice--;
345*4882a593Smuzhiyun 					}
346*4882a593Smuzhiyun 				}
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun 			} else if (key == KEY_NPAGE) {
349*4882a593Smuzhiyun 				for (i = 0; (i < max_choice); i++) {
350*4882a593Smuzhiyun 					if (scroll + max_choice < item_count()) {
351*4882a593Smuzhiyun 						do_scroll(menu, &scroll, 1);
352*4882a593Smuzhiyun 						print_item(scroll+max_choice-1,
353*4882a593Smuzhiyun 							   max_choice - 1, FALSE);
354*4882a593Smuzhiyun 					} else {
355*4882a593Smuzhiyun 						if (choice + 1 < max_choice)
356*4882a593Smuzhiyun 							choice++;
357*4882a593Smuzhiyun 					}
358*4882a593Smuzhiyun 				}
359*4882a593Smuzhiyun 			} else
360*4882a593Smuzhiyun 				choice = i;
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun 			print_item(scroll + choice, choice, TRUE);
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun 			print_arrows(dialog, item_count(), scroll,
365*4882a593Smuzhiyun 				     box_y, box_x + item_x + 1, menu_height);
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun 			wnoutrefresh(dialog);
368*4882a593Smuzhiyun 			wrefresh(menu);
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun 			continue;	/* wait for another key press */
371*4882a593Smuzhiyun 		}
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun 		switch (key) {
374*4882a593Smuzhiyun 		case KEY_LEFT:
375*4882a593Smuzhiyun 		case TAB:
376*4882a593Smuzhiyun 		case KEY_RIGHT:
377*4882a593Smuzhiyun 			button = ((key == KEY_LEFT ? --button : ++button) < 0)
378*4882a593Smuzhiyun 			    ? 4 : (button > 4 ? 0 : button);
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun 			print_buttons(dialog, height, width, button);
381*4882a593Smuzhiyun 			wrefresh(menu);
382*4882a593Smuzhiyun 			break;
383*4882a593Smuzhiyun 		case ' ':
384*4882a593Smuzhiyun 		case 's':
385*4882a593Smuzhiyun 		case 'y':
386*4882a593Smuzhiyun 		case 'n':
387*4882a593Smuzhiyun 		case 'm':
388*4882a593Smuzhiyun 		case '/':
389*4882a593Smuzhiyun 		case 'h':
390*4882a593Smuzhiyun 		case '?':
391*4882a593Smuzhiyun 		case 'z':
392*4882a593Smuzhiyun 		case '\n':
393*4882a593Smuzhiyun 			/* save scroll info */
394*4882a593Smuzhiyun 			*s_scroll = scroll;
395*4882a593Smuzhiyun 			delwin(menu);
396*4882a593Smuzhiyun 			delwin(dialog);
397*4882a593Smuzhiyun 			item_set(scroll + choice);
398*4882a593Smuzhiyun 			item_set_selected(1);
399*4882a593Smuzhiyun 			switch (key) {
400*4882a593Smuzhiyun 			case 'h':
401*4882a593Smuzhiyun 			case '?':
402*4882a593Smuzhiyun 				return 2;
403*4882a593Smuzhiyun 			case 's':
404*4882a593Smuzhiyun 			case 'y':
405*4882a593Smuzhiyun 				return 5;
406*4882a593Smuzhiyun 			case 'n':
407*4882a593Smuzhiyun 				return 6;
408*4882a593Smuzhiyun 			case 'm':
409*4882a593Smuzhiyun 				return 7;
410*4882a593Smuzhiyun 			case ' ':
411*4882a593Smuzhiyun 				return 8;
412*4882a593Smuzhiyun 			case '/':
413*4882a593Smuzhiyun 				return 9;
414*4882a593Smuzhiyun 			case 'z':
415*4882a593Smuzhiyun 				return 10;
416*4882a593Smuzhiyun 			case '\n':
417*4882a593Smuzhiyun 				return button;
418*4882a593Smuzhiyun 			}
419*4882a593Smuzhiyun 			return 0;
420*4882a593Smuzhiyun 		case 'e':
421*4882a593Smuzhiyun 		case 'x':
422*4882a593Smuzhiyun 			key = KEY_ESC;
423*4882a593Smuzhiyun 			break;
424*4882a593Smuzhiyun 		case KEY_ESC:
425*4882a593Smuzhiyun 			key = on_key_esc(menu);
426*4882a593Smuzhiyun 			break;
427*4882a593Smuzhiyun 		case KEY_RESIZE:
428*4882a593Smuzhiyun 			on_key_resize();
429*4882a593Smuzhiyun 			delwin(menu);
430*4882a593Smuzhiyun 			delwin(dialog);
431*4882a593Smuzhiyun 			goto do_resize;
432*4882a593Smuzhiyun 		}
433*4882a593Smuzhiyun 	}
434*4882a593Smuzhiyun 	delwin(menu);
435*4882a593Smuzhiyun 	delwin(dialog);
436*4882a593Smuzhiyun 	return key;		/* ESC pressed */
437*4882a593Smuzhiyun }
438