yesno.c revision 3515
1/* 2 * yesno.c -- implements the yes/no box 3 * 4 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 22#include "dialog.priv.h" 23#include <dialog.h> 24 25 26/* 27 * Display a dialog box with two buttons - Yes and No 28 */ 29int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int width) 30{ 31 int i, x, y, key = 0, button = 0; 32 WINDOW *dialog; 33 34 /* center dialog box on screen */ 35 x = (COLS - width)/2; 36 y = (LINES - height)/2; 37 38#ifdef HAVE_NCURSES 39 if (use_shadow) 40 draw_shadow(stdscr, y, x, height, width); 41#endif 42 dialog = newwin(height, width, y, x); 43 keypad(dialog, TRUE); 44 45 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 46 wattrset(dialog, border_attr); 47 wmove(dialog, height-3, 0); 48 waddch(dialog, ACS_LTEE); 49 for (i = 0; i < width-2; i++) 50 waddch(dialog, ACS_HLINE); 51 wattrset(dialog, dialog_attr); 52 waddch(dialog, ACS_RTEE); 53 wmove(dialog, height-2, 1); 54 for (i = 0; i < width-2; i++) 55 waddch(dialog, ' '); 56 57 if (title != NULL) { 58 wattrset(dialog, title_attr); 59 wmove(dialog, 0, (width - strlen(title))/2 - 1); 60 waddch(dialog, ' '); 61 waddstr(dialog, title); 62 waddch(dialog, ' '); 63 } 64 wattrset(dialog, dialog_attr); 65 print_autowrap(dialog, prompt, width, 1, 3); 66 67 x = width/2-10; 68 y = height-2; 69 print_button(dialog, " No ", y, x+13, FALSE); 70 print_button(dialog, " Yes ", y, x, TRUE); 71 wrefresh(dialog); 72 73 while (key != ESC) { 74 key = wgetch(dialog); 75 switch (key) { 76 case 'Y': 77 case 'y': 78 delwin(dialog); 79 return 0; 80 case 'N': 81 case 'n': 82 delwin(dialog); 83 return 1; 84 case KEY_BTAB: 85 case TAB: 86 case KEY_UP: 87 case KEY_DOWN: 88 case KEY_LEFT: 89 case KEY_RIGHT: 90 if (!button) { 91 button = 1; /* Indicates "No" button is selected */ 92 print_button(dialog, " Yes ", y, x, FALSE); 93 print_button(dialog, " No ", y, x+13, TRUE); 94 } 95 else { 96 button = 0; /* Indicates "Yes" button is selected */ 97 print_button(dialog, " No ", y, x+13, FALSE); 98 print_button(dialog, " Yes ", y, x, TRUE); 99 } 100 wrefresh(dialog); 101 break; 102 case ' ': 103 case '\n': 104 delwin(dialog); 105 return button; 106 case ESC: 107 break; 108 } 109 } 110 111 delwin(dialog); 112 return -1; /* ESC pressed */ 113} 114/* End of dialog_yesno() */ 115