1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/kconfig/lxdialog/yesno.c Thu Jul 12 19:20:36 2007 +0000
1.3 @@ -0,0 +1,114 @@
1.4 +/*
1.5 + * yesno.c -- implements the yes/no box
1.6 + *
1.7 + * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
1.8 + * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
1.9 + *
1.10 + * This program is free software; you can redistribute it and/or
1.11 + * modify it under the terms of the GNU General Public License
1.12 + * as published by the Free Software Foundation; either version 2
1.13 + * of the License, or (at your option) any later version.
1.14 + *
1.15 + * This program is distributed in the hope that it will be useful,
1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.18 + * GNU General Public License for more details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License
1.21 + * along with this program; if not, write to the Free Software
1.22 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1.23 + */
1.24 +
1.25 +#include "dialog.h"
1.26 +
1.27 +/*
1.28 + * Display termination buttons
1.29 + */
1.30 +static void print_buttons(WINDOW * dialog, int height, int width, int selected)
1.31 +{
1.32 + int x = width / 2 - 10;
1.33 + int y = height - 2;
1.34 +
1.35 + print_button(dialog, " Yes ", y, x, selected == 0);
1.36 + print_button(dialog, " No ", y, x + 13, selected == 1);
1.37 +
1.38 + wmove(dialog, y, x + 1 + 13 * selected);
1.39 + wrefresh(dialog);
1.40 +}
1.41 +
1.42 +/*
1.43 + * Display a dialog box with two buttons - Yes and No
1.44 + */
1.45 +int dialog_yesno(const char *title, const char *prompt, int height, int width)
1.46 +{
1.47 + int i, x, y, key = 0, button = 0;
1.48 + WINDOW *dialog;
1.49 +
1.50 +do_resize:
1.51 + if (getmaxy(stdscr) < (height + 4))
1.52 + return -ERRDISPLAYTOOSMALL;
1.53 + if (getmaxx(stdscr) < (width + 4))
1.54 + return -ERRDISPLAYTOOSMALL;
1.55 +
1.56 + /* center dialog box on screen */
1.57 + x = (COLS - width) / 2;
1.58 + y = (LINES - height) / 2;
1.59 +
1.60 + draw_shadow(stdscr, y, x, height, width);
1.61 +
1.62 + dialog = newwin(height, width, y, x);
1.63 + keypad(dialog, TRUE);
1.64 +
1.65 + draw_box(dialog, 0, 0, height, width,
1.66 + dlg.dialog.atr, dlg.border.atr);
1.67 + wattrset(dialog, dlg.border.atr);
1.68 + mvwaddch(dialog, height - 3, 0, ACS_LTEE);
1.69 + for (i = 0; i < width - 2; i++)
1.70 + waddch(dialog, ACS_HLINE);
1.71 + wattrset(dialog, dlg.dialog.atr);
1.72 + waddch(dialog, ACS_RTEE);
1.73 +
1.74 + print_title(dialog, title, width);
1.75 +
1.76 + wattrset(dialog, dlg.dialog.atr);
1.77 + print_autowrap(dialog, prompt, width - 2, 1, 3);
1.78 +
1.79 + print_buttons(dialog, height, width, 0);
1.80 +
1.81 + while (key != KEY_ESC) {
1.82 + key = wgetch(dialog);
1.83 + switch (key) {
1.84 + case 'Y':
1.85 + case 'y':
1.86 + delwin(dialog);
1.87 + return 0;
1.88 + case 'N':
1.89 + case 'n':
1.90 + delwin(dialog);
1.91 + return 1;
1.92 +
1.93 + case TAB:
1.94 + case KEY_LEFT:
1.95 + case KEY_RIGHT:
1.96 + button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
1.97 +
1.98 + print_buttons(dialog, height, width, button);
1.99 + wrefresh(dialog);
1.100 + break;
1.101 + case ' ':
1.102 + case '\n':
1.103 + delwin(dialog);
1.104 + return button;
1.105 + case KEY_ESC:
1.106 + key = on_key_esc(dialog);
1.107 + break;
1.108 + case KEY_RESIZE:
1.109 + delwin(dialog);
1.110 + on_key_resize();
1.111 + goto do_resize;
1.112 + }
1.113 + }
1.114 +
1.115 + delwin(dialog);
1.116 + return key; /* ESC pressed */
1.117 +}