| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  menubox.c -- implements the menu box | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) | 
					
						
							|  |  |  |  *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  *  modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  *  as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  *  of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  *  GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  *  along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  *  Changes by Clifford Wolf (god@clifford.at) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  [ 1998-06-13 ] | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *    *)  A bugfix for the Page-Down problem | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  |  *    *)  Formerly when I used Page Down and Page Up, the cursor would be set | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  *        to the first position in the menu box.  Now lxdialog is a bit | 
					
						
							|  |  |  |  *        smarter and works more like other menu systems (just have a look at | 
					
						
							|  |  |  |  *        it). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *    *)  Formerly if I selected something my scrolling would be broken because | 
					
						
							|  |  |  |  *        lxdialog is re-invoked by the Menuconfig shell script, can't | 
					
						
							|  |  |  |  *        remember the last scrolling position, and just sets it so that the | 
					
						
							|  |  |  |  *        cursor is at the bottom of the box.  Now it writes the temporary file | 
					
						
							|  |  |  |  *        lxdialog.scrltmp which contains this information. The file is | 
					
						
							|  |  |  |  *        deleted by lxdialog if the user leaves a submenu or enters a new | 
					
						
							|  |  |  |  *        one, but it would be nice if Menuconfig could make another "rm -f" | 
					
						
							|  |  |  |  *        just to be sure.  Just try it out - you will recognise a difference! | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  [ 1998-06-14 ] | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *    *)  Now lxdialog is crash-safe against broken "lxdialog.scrltmp" files | 
					
						
							|  |  |  |  *        and menus change their size on the fly. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *    *)  If for some reason the last scrolling position is not saved by | 
					
						
							|  |  |  |  *        lxdialog, it sets the scrolling so that the selected item is in the | 
					
						
							|  |  |  |  *        middle of the menu box, not at the bottom. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 02 January 1999, Michael Elizabeth Chastain (mec@shout.net) | 
					
						
							|  |  |  |  * Reset 'scroll' to 0 if the value from lxdialog.scrltmp is bogus. | 
					
						
							|  |  |  |  * This fixes a bug in Menuconfig where using ' ' to descend into menus | 
					
						
							|  |  |  |  * would leave mis-synchronized lxdialog.scrltmp files lying around, | 
					
						
							|  |  |  |  * fscanf would read in 'scroll', and eventually that value would get used. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "dialog.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-09 17:27:14 +02:00
										 |  |  | static int menu_width, item_x; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Print menu item | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-09-02 22:01:42 +02:00
										 |  |  | static void do_print_item(WINDOW * win, const char *item, int line_y, | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  |                           int selected, int hotkey) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	int j; | 
					
						
							| 
									
										
										
										
											2005-11-19 22:17:55 +01:00
										 |  |  | 	char *menu_item = malloc(menu_width + 1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-09 17:27:14 +02:00
										 |  |  | 	strncpy(menu_item, item, menu_width - item_x); | 
					
						
							| 
									
										
										
										
											2006-09-02 22:01:42 +02:00
										 |  |  | 	menu_item[menu_width - item_x] = '\0'; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	j = first_alpha(menu_item, "YyNnMmHh"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	/* Clear 'residue' of last item */ | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 	wattrset(win, dlg.menubox.atr); | 
					
						
							| 
									
										
										
										
											2006-09-02 22:01:42 +02:00
										 |  |  | 	wmove(win, line_y, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #if OLD_NCURSES
 | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		int i; | 
					
						
							|  |  |  | 		for (i = 0; i < menu_width; i++) | 
					
						
							|  |  |  | 			waddch(win, ' '); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	wclrtoeol(win); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 	wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); | 
					
						
							| 
									
										
										
										
											2006-09-02 22:01:42 +02:00
										 |  |  | 	mvwaddstr(win, line_y, item_x, menu_item); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	if (hotkey) { | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 		wattrset(win, selected ? dlg.tag_key_selected.atr | 
					
						
							|  |  |  | 			 : dlg.tag_key.atr); | 
					
						
							| 
									
										
										
										
											2006-09-02 22:01:42 +02:00
										 |  |  | 		mvwaddch(win, line_y, item_x + j, menu_item[j]); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (selected) { | 
					
						
							| 
									
										
										
										
											2006-09-02 22:01:42 +02:00
										 |  |  | 		wmove(win, line_y, item_x + 1); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-11-19 22:17:55 +01:00
										 |  |  | 	free(menu_item); | 
					
						
							| 
									
										
										
										
											2005-11-20 23:03:49 +01:00
										 |  |  | 	wrefresh(win); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | #define print_item(index, choice, selected)				\
 | 
					
						
							|  |  |  | do {									\ | 
					
						
							|  |  |  | 	item_set(index);						\ | 
					
						
							|  |  |  | 	do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \ | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Print the scroll indicators. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-11-19 21:56:20 +01:00
										 |  |  | static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, | 
					
						
							|  |  |  | 			 int height) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	int cur_y, cur_x; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	getyx(win, cur_y, cur_x); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wmove(win, y, x); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (scroll > 0) { | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 		wattrset(win, dlg.uarrow.atr); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 		waddch(win, ACS_UARROW); | 
					
						
							|  |  |  | 		waddstr(win, "(-)"); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 		wattrset(win, dlg.menubox.atr); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 		waddch(win, ACS_HLINE); | 
					
						
							|  |  |  | 		waddch(win, ACS_HLINE); | 
					
						
							|  |  |  | 		waddch(win, ACS_HLINE); | 
					
						
							|  |  |  | 		waddch(win, ACS_HLINE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	y = y + height + 1; | 
					
						
							|  |  |  | 	wmove(win, y, x); | 
					
						
							| 
									
										
										
										
											2005-11-20 23:03:49 +01:00
										 |  |  | 	wrefresh(win); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((height < item_no) && (scroll + height < item_no)) { | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 		wattrset(win, dlg.darrow.atr); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 		waddch(win, ACS_DARROW); | 
					
						
							|  |  |  | 		waddstr(win, "(+)"); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 		wattrset(win, dlg.menubox_border.atr); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 		waddch(win, ACS_HLINE); | 
					
						
							|  |  |  | 		waddch(win, ACS_HLINE); | 
					
						
							|  |  |  | 		waddch(win, ACS_HLINE); | 
					
						
							|  |  |  | 		waddch(win, ACS_HLINE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wmove(win, cur_y, cur_x); | 
					
						
							| 
									
										
										
										
											2005-11-20 23:03:49 +01:00
										 |  |  | 	wrefresh(win); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Display the termination buttons. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | static void print_buttons(WINDOW * win, int height, int width, int selected) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 	int x = width / 2 - 28; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	int y = height - 2; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-11 23:42:54 +01:00
										 |  |  | 	print_button(win, gettext("Select"), y, x, selected == 0); | 
					
						
							|  |  |  | 	print_button(win, gettext(" Exit "), y, x + 12, selected == 1); | 
					
						
							|  |  |  | 	print_button(win, gettext(" Help "), y, x + 24, selected == 2); | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 	print_button(win, gettext(" Save "), y, x + 36, selected == 3); | 
					
						
							|  |  |  | 	print_button(win, gettext(" Load "), y, x + 48, selected == 4); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	wmove(win, y, x + 1 + 12 * selected); | 
					
						
							|  |  |  | 	wrefresh(win); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-20 23:03:49 +01:00
										 |  |  | /* scroll up n lines (n may be negative) */ | 
					
						
							|  |  |  | static void do_scroll(WINDOW *win, int *scroll, int n) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* Scroll menu up */ | 
					
						
							|  |  |  | 	scrollok(win, TRUE); | 
					
						
							|  |  |  | 	wscrl(win, n); | 
					
						
							|  |  |  | 	scrollok(win, FALSE); | 
					
						
							|  |  |  | 	*scroll = *scroll + n; | 
					
						
							|  |  |  | 	wrefresh(win); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Display a menu for choosing among a number of options | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-07-29 22:48:57 +02:00
										 |  |  | int dialog_menu(const char *title, const char *prompt, | 
					
						
							|  |  |  |                 const void *selected, int *s_scroll) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	int i, j, x, y, box_x, box_y; | 
					
						
							| 
									
										
										
										
											2006-07-29 22:48:57 +02:00
										 |  |  | 	int height, width, menu_height; | 
					
						
							| 
									
										
										
										
											2005-11-21 22:59:32 +01:00
										 |  |  | 	int key = 0, button = 0, scroll = 0, choice = 0; | 
					
						
							|  |  |  | 	int first_item =  0, max_choice; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	WINDOW *dialog, *menu; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-29 22:48:57 +02:00
										 |  |  | do_resize: | 
					
						
							|  |  |  | 	height = getmaxy(stdscr); | 
					
						
							|  |  |  | 	width = getmaxx(stdscr); | 
					
						
							| 
									
										
										
										
											2013-06-15 11:07:35 +02:00
										 |  |  | 	if (height < MENUBOX_HEIGTH_MIN || width < MENUBOX_WIDTH_MIN) | 
					
						
							| 
									
										
										
										
											2006-07-29 22:48:57 +02:00
										 |  |  | 		return -ERRDISPLAYTOOSMALL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	height -= 4; | 
					
						
							|  |  |  | 	width  -= 5; | 
					
						
							|  |  |  | 	menu_height = height - 10; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 	max_choice = MIN(menu_height, item_count()); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* center dialog box on screen */ | 
					
						
							| 
									
										
										
										
											2013-05-12 12:30:49 +02:00
										 |  |  | 	x = (getmaxx(stdscr) - width) / 2; | 
					
						
							|  |  |  | 	y = (getmaxy(stdscr) - height) / 2; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	draw_shadow(stdscr, y, x, height, width); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dialog = newwin(height, width, y, x); | 
					
						
							|  |  |  | 	keypad(dialog, TRUE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 	draw_box(dialog, 0, 0, height, width, | 
					
						
							|  |  |  | 		 dlg.dialog.atr, dlg.border.atr); | 
					
						
							|  |  |  | 	wattrset(dialog, dlg.border.atr); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	mvwaddch(dialog, height - 3, 0, ACS_LTEE); | 
					
						
							|  |  |  | 	for (i = 0; i < width - 2; i++) | 
					
						
							|  |  |  | 		waddch(dialog, ACS_HLINE); | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 	wattrset(dialog, dlg.dialog.atr); | 
					
						
							|  |  |  | 	wbkgdset(dialog, dlg.dialog.atr & A_COLOR); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	waddch(dialog, ACS_RTEE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-19 23:38:06 +01:00
										 |  |  | 	print_title(dialog, title, width); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 	wattrset(dialog, dlg.dialog.atr); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	print_autowrap(dialog, prompt, width - 2, 1, 3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	menu_width = width - 6; | 
					
						
							|  |  |  | 	box_y = height - menu_height - 5; | 
					
						
							|  |  |  | 	box_x = (width - menu_width) / 2 - 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* create new window for the menu */ | 
					
						
							|  |  |  | 	menu = subwin(dialog, menu_height, menu_width, | 
					
						
							|  |  |  | 		      y + box_y + 1, x + box_x + 1); | 
					
						
							|  |  |  | 	keypad(menu, TRUE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* draw a box around the menu items */ | 
					
						
							|  |  |  | 	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, | 
					
						
							| 
									
										
										
										
											2006-07-24 21:40:46 +02:00
										 |  |  | 		 dlg.menubox_border.atr, dlg.menubox.atr); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-29 22:48:57 +02:00
										 |  |  | 	if (menu_width >= 80) | 
					
						
							|  |  |  | 		item_x = (menu_width - 70) / 2; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		item_x = 4; | 
					
						
							| 
									
										
										
										
											2006-04-09 17:27:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-20 22:41:21 +01:00
										 |  |  | 	/* Set choice to default item */ | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 	item_foreach() | 
					
						
							|  |  |  | 		if (selected && (selected == item_data())) | 
					
						
							|  |  |  | 			choice = item_n(); | 
					
						
							|  |  |  | 	/* get the saved scroll info */ | 
					
						
							|  |  |  | 	scroll = *s_scroll; | 
					
						
							|  |  |  | 	if ((scroll <= choice) && (scroll + max_choice > choice) && | 
					
						
							|  |  |  | 	   (scroll >= 0) && (scroll + max_choice <= item_count())) { | 
					
						
							|  |  |  | 		first_item = scroll; | 
					
						
							|  |  |  | 		choice = choice - scroll; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		scroll = 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 	if ((choice >= max_choice)) { | 
					
						
							|  |  |  | 		if (choice >= item_count() - max_choice / 2) | 
					
						
							|  |  |  | 			scroll = first_item = item_count() - max_choice; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			scroll = first_item = choice - max_choice / 2; | 
					
						
							|  |  |  | 		choice = choice - scroll; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	/* Print the menu */ | 
					
						
							|  |  |  | 	for (i = 0; i < max_choice; i++) { | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | 		print_item(first_item + i, i, i == choice); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wnoutrefresh(menu); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 	print_arrows(dialog, item_count(), scroll, | 
					
						
							| 
									
										
										
										
											2006-04-09 17:27:14 +02:00
										 |  |  | 		     box_y, box_x + item_x + 1, menu_height); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	print_buttons(dialog, height, width, 0); | 
					
						
							| 
									
										
										
										
											2006-04-09 17:27:14 +02:00
										 |  |  | 	wmove(menu, choice, item_x + 1); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	wrefresh(menu); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-28 23:57:48 +02:00
										 |  |  | 	while (key != KEY_ESC) { | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 		key = wgetch(menu); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (key < 256 && isalpha(key)) | 
					
						
							|  |  |  | 			key = tolower(key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (strchr("ynmh", key)) | 
					
						
							|  |  |  | 			i = max_choice; | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			for (i = choice + 1; i < max_choice; i++) { | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 				item_set(scroll + i); | 
					
						
							|  |  |  | 				j = first_alpha(item_str(), "YyNnMmHh"); | 
					
						
							|  |  |  | 				if (key == tolower(item_str()[j])) | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (i == max_choice) | 
					
						
							|  |  |  | 				for (i = 0; i < max_choice; i++) { | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 					item_set(scroll + i); | 
					
						
							|  |  |  | 					j = first_alpha(item_str(), "YyNnMmHh"); | 
					
						
							|  |  |  | 					if (key == tolower(item_str()[j])) | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-19 21:48:44 +02:00
										 |  |  | 		if (item_count() != 0 && | 
					
						
							|  |  |  | 		    (i < max_choice || | 
					
						
							|  |  |  | 		     key == KEY_UP || key == KEY_DOWN || | 
					
						
							|  |  |  | 		     key == '-' || key == '+' || | 
					
						
							|  |  |  | 		     key == KEY_PPAGE || key == KEY_NPAGE)) { | 
					
						
							| 
									
										
										
										
											2005-11-20 22:41:21 +01:00
										 |  |  | 			/* Remove highligt of current item */ | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | 			print_item(scroll + choice, choice, FALSE); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (key == KEY_UP || key == '-') { | 
					
						
							|  |  |  | 				if (choice < 2 && scroll) { | 
					
						
							|  |  |  | 					/* Scroll menu down */ | 
					
						
							| 
									
										
										
										
											2005-11-20 23:03:49 +01:00
										 |  |  | 					do_scroll(menu, &scroll, -1); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | 					print_item(scroll, 0, FALSE); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 				} else | 
					
						
							|  |  |  | 					choice = MAX(choice - 1, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} else if (key == KEY_DOWN || key == '+') { | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | 				print_item(scroll+choice, choice, FALSE); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if ((choice > max_choice - 3) && | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 				    (scroll + max_choice < item_count())) { | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 					/* Scroll menu up */ | 
					
						
							| 
									
										
										
										
											2005-11-20 23:03:49 +01:00
										 |  |  | 					do_scroll(menu, &scroll, 1); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | 					print_item(scroll+max_choice - 1, | 
					
						
							|  |  |  | 						   max_choice - 1, FALSE); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 				} else | 
					
						
							| 
									
										
										
										
											2005-11-19 21:56:20 +01:00
										 |  |  | 					choice = MIN(choice + 1, max_choice - 1); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			} else if (key == KEY_PPAGE) { | 
					
						
							|  |  |  | 				scrollok(menu, TRUE); | 
					
						
							|  |  |  | 				for (i = 0; (i < max_choice); i++) { | 
					
						
							|  |  |  | 					if (scroll > 0) { | 
					
						
							| 
									
										
										
										
											2005-11-20 23:03:49 +01:00
										 |  |  | 						do_scroll(menu, &scroll, -1); | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | 						print_item(scroll, 0, FALSE); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						if (choice > 0) | 
					
						
							|  |  |  | 							choice--; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} else if (key == KEY_NPAGE) { | 
					
						
							|  |  |  | 				for (i = 0; (i < max_choice); i++) { | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 					if (scroll + max_choice < item_count()) { | 
					
						
							| 
									
										
										
										
											2005-11-20 23:03:49 +01:00
										 |  |  | 						do_scroll(menu, &scroll, 1); | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | 						print_item(scroll+max_choice-1, | 
					
						
							|  |  |  | 							   max_choice - 1, FALSE); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						if (choice + 1 < max_choice) | 
					
						
							|  |  |  | 							choice++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				choice = i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-20 23:34:35 +01:00
										 |  |  | 			print_item(scroll + choice, choice, TRUE); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 			print_arrows(dialog, item_count(), scroll, | 
					
						
							| 
									
										
										
										
											2006-04-09 17:27:14 +02:00
										 |  |  | 				     box_y, box_x + item_x + 1, menu_height); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			wnoutrefresh(dialog); | 
					
						
							|  |  |  | 			wrefresh(menu); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			continue;	/* wait for another key press */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		switch (key) { | 
					
						
							|  |  |  | 		case KEY_LEFT: | 
					
						
							|  |  |  | 		case TAB: | 
					
						
							|  |  |  | 		case KEY_RIGHT: | 
					
						
							|  |  |  | 			button = ((key == KEY_LEFT ? --button : ++button) < 0) | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 			    ? 4 : (button > 4 ? 0 : button); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			print_buttons(dialog, height, width, button); | 
					
						
							|  |  |  | 			wrefresh(menu); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case ' ': | 
					
						
							|  |  |  | 		case 's': | 
					
						
							|  |  |  | 		case 'y': | 
					
						
							|  |  |  | 		case 'n': | 
					
						
							|  |  |  | 		case 'm': | 
					
						
							|  |  |  | 		case '/': | 
					
						
							| 
									
										
											  
											
												menuconfig: add support to show hidden options which have prompts
Usage:
  Press <Z> to show all config symbols which have prompts.
Quote Tim Bird:
| I've been bitten by this numerous times.  I most often
| use ftrace on ARM, but when I go back to x86, I almost
| always go through a sequence of searching for the
| function graph tracer in the menus, then realizing it's
| completely missing until I disable CC_OPTIMIZE_FOR_SIZE.
|
| Is there any way to have the menu item appear, but be
| unsettable unless the SIZE option is disabled?  I'm
| not a Kconfig guru...
I myself found this useful too. For example, I need to test
ftrace/tracing and want to be sure all the tracing features are
enabled, so I  enter the "Tracers" menu, and press <Z> to
see if there is any config hidden.
I also noticed gconfig and xconfig have a button "Show all options",
but that's a bit too much, and I think normally what we are not
interested in those configs which have no prompt thus can't be
changed by users.
Exmaple:
      --- Tracers
      -*-   Kernel Function Tracer
      - -     Kernel Function Graph Tracer
      [*]   Interrupts-off Latency Tracer
      - -   Preemption-off Latency Tracer
      [*]   Sysprof Tracer
Here you can see 2 tracers are not selectable, and then can find
out how to make them selectable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
											
										 
											2010-04-14 11:46:02 +08:00
										 |  |  | 		case 'h': | 
					
						
							|  |  |  | 		case '?': | 
					
						
							|  |  |  | 		case 'z': | 
					
						
							|  |  |  | 		case '\n': | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			/* save scroll info */ | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 			*s_scroll = scroll; | 
					
						
							|  |  |  | 			delwin(menu); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			delwin(dialog); | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 			item_set(scroll + choice); | 
					
						
							|  |  |  | 			item_set_selected(1); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			switch (key) { | 
					
						
							| 
									
										
											  
											
												menuconfig: add support to show hidden options which have prompts
Usage:
  Press <Z> to show all config symbols which have prompts.
Quote Tim Bird:
| I've been bitten by this numerous times.  I most often
| use ftrace on ARM, but when I go back to x86, I almost
| always go through a sequence of searching for the
| function graph tracer in the menus, then realizing it's
| completely missing until I disable CC_OPTIMIZE_FOR_SIZE.
|
| Is there any way to have the menu item appear, but be
| unsettable unless the SIZE option is disabled?  I'm
| not a Kconfig guru...
I myself found this useful too. For example, I need to test
ftrace/tracing and want to be sure all the tracing features are
enabled, so I  enter the "Tracers" menu, and press <Z> to
see if there is any config hidden.
I also noticed gconfig and xconfig have a button "Show all options",
but that's a bit too much, and I think normally what we are not
interested in those configs which have no prompt thus can't be
changed by users.
Exmaple:
      --- Tracers
      -*-   Kernel Function Tracer
      - -     Kernel Function Graph Tracer
      [*]   Interrupts-off Latency Tracer
      - -   Preemption-off Latency Tracer
      [*]   Sysprof Tracer
Here you can see 2 tracers are not selectable, and then can find
out how to make them selectable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
											
										 
											2010-04-14 11:46:02 +08:00
										 |  |  | 			case 'h': | 
					
						
							|  |  |  | 			case '?': | 
					
						
							|  |  |  | 				return 2; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			case 's': | 
					
						
							|  |  |  | 			case 'y': | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 				return 5; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			case 'n': | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 				return 6; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			case 'm': | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 				return 7; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			case ' ': | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 				return 8; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			case '/': | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 				return 9; | 
					
						
							| 
									
										
											  
											
												menuconfig: add support to show hidden options which have prompts
Usage:
  Press <Z> to show all config symbols which have prompts.
Quote Tim Bird:
| I've been bitten by this numerous times.  I most often
| use ftrace on ARM, but when I go back to x86, I almost
| always go through a sequence of searching for the
| function graph tracer in the menus, then realizing it's
| completely missing until I disable CC_OPTIMIZE_FOR_SIZE.
|
| Is there any way to have the menu item appear, but be
| unsettable unless the SIZE option is disabled?  I'm
| not a Kconfig guru...
I myself found this useful too. For example, I need to test
ftrace/tracing and want to be sure all the tracing features are
enabled, so I  enter the "Tracers" menu, and press <Z> to
see if there is any config hidden.
I also noticed gconfig and xconfig have a button "Show all options",
but that's a bit too much, and I think normally what we are not
interested in those configs which have no prompt thus can't be
changed by users.
Exmaple:
      --- Tracers
      -*-   Kernel Function Tracer
      - -     Kernel Function Graph Tracer
      [*]   Interrupts-off Latency Tracer
      - -   Preemption-off Latency Tracer
      [*]   Sysprof Tracer
Here you can see 2 tracers are not selectable, and then can find
out how to make them selectable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
											
										 
											2010-04-14 11:46:02 +08:00
										 |  |  | 			case 'z': | 
					
						
							| 
									
										
										
										
											2012-12-19 09:50:58 +08:00
										 |  |  | 				return 10; | 
					
						
							| 
									
										
											  
											
												menuconfig: add support to show hidden options which have prompts
Usage:
  Press <Z> to show all config symbols which have prompts.
Quote Tim Bird:
| I've been bitten by this numerous times.  I most often
| use ftrace on ARM, but when I go back to x86, I almost
| always go through a sequence of searching for the
| function graph tracer in the menus, then realizing it's
| completely missing until I disable CC_OPTIMIZE_FOR_SIZE.
|
| Is there any way to have the menu item appear, but be
| unsettable unless the SIZE option is disabled?  I'm
| not a Kconfig guru...
I myself found this useful too. For example, I need to test
ftrace/tracing and want to be sure all the tracing features are
enabled, so I  enter the "Tracers" menu, and press <Z> to
see if there is any config hidden.
I also noticed gconfig and xconfig have a button "Show all options",
but that's a bit too much, and I think normally what we are not
interested in those configs which have no prompt thus can't be
changed by users.
Exmaple:
      --- Tracers
      -*-   Kernel Function Tracer
      - -     Kernel Function Graph Tracer
      [*]   Interrupts-off Latency Tracer
      - -   Preemption-off Latency Tracer
      [*]   Sysprof Tracer
Here you can see 2 tracers are not selectable, and then can find
out how to make them selectable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
											
										 
											2010-04-14 11:46:02 +08:00
										 |  |  | 			case '\n': | 
					
						
							|  |  |  | 				return button; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		case 'e': | 
					
						
							|  |  |  | 		case 'x': | 
					
						
							| 
									
										
										
										
											2006-07-28 23:57:48 +02:00
										 |  |  | 			key = KEY_ESC; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case KEY_ESC: | 
					
						
							|  |  |  | 			key = on_key_esc(menu); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2006-07-29 22:48:57 +02:00
										 |  |  | 		case KEY_RESIZE: | 
					
						
							|  |  |  | 			on_key_resize(); | 
					
						
							|  |  |  | 			delwin(menu); | 
					
						
							|  |  |  | 			delwin(dialog); | 
					
						
							|  |  |  | 			goto do_resize; | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-07-27 22:10:27 +02:00
										 |  |  | 	delwin(menu); | 
					
						
							| 
									
										
										
										
											2005-11-19 19:13:34 +01:00
										 |  |  | 	delwin(dialog); | 
					
						
							| 
									
										
										
										
											2006-07-28 23:57:48 +02:00
										 |  |  | 	return key;		/* ESC pressed */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } |