base/config/kconfig/lxdialog/yesno.c

Go to the documentation of this file.
00001 /*
00002  *  yesno.c -- implements the yes/no box
00003  *
00004  *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
00005  *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
00006  *
00007  *  This program is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU General Public License
00009  *  as published by the Free Software Foundation; either version 2
00010  *  of the License, or (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020  */
00021 
00022 #include "dialog.h"
00023 
00024 /*
00025  * Display termination buttons
00026  */
00027 static void
00028 print_buttons(WINDOW *dialog, int height, int width, int selected)
00029 {
00030     int x = width / 2 - 10;
00031     int y = height - 2;
00032 
00033     print_button (dialog, " Yes ", y, x, selected == 0);
00034     print_button (dialog, "  No  ", y, x + 13, selected == 1);
00035 
00036     wmove(dialog, y, x+1 + 13*selected );
00037     wrefresh (dialog);
00038 }
00039 
00040 /*
00041  * Display a dialog box with two buttons - Yes and No
00042  */
00043 int
00044 dialog_yesno (const char *title, const char *prompt, int height, int width)
00045 {
00046     int i, x, y, key = 0, button = 0;
00047     WINDOW *dialog;
00048 
00049     /* center dialog box on screen */
00050     x = (COLS - width) / 2;
00051     y = (LINES - height) / 2;
00052 
00053     draw_shadow (stdscr, y, x, height, width);
00054 
00055     dialog = newwin (height, width, y, x);
00056     keypad (dialog, TRUE);
00057 
00058     draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
00059     wattrset (dialog, border_attr);
00060     mvwaddch (dialog, height-3, 0, ACS_LTEE);
00061     for (i = 0; i < width - 2; i++)
00062     waddch (dialog, ACS_HLINE);
00063     wattrset (dialog, dialog_attr);
00064     waddch (dialog, ACS_RTEE);
00065 
00066     if (title != NULL && strlen(title) >= width-2 ) {
00067     /* truncate long title -- mec */
00068     char * title2 = malloc(width-2+1);
00069     memcpy( title2, title, width-2 );
00070     title2[width-2] = '\0';
00071     title = title2;
00072     }
00073 
00074     if (title != NULL) {
00075     wattrset (dialog, title_attr);
00076     mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
00077     waddstr (dialog, (char *)title);
00078     waddch (dialog, ' ');
00079     }
00080 
00081     wattrset (dialog, dialog_attr);
00082     print_autowrap (dialog, prompt, width - 2, 1, 3);
00083 
00084     print_buttons(dialog, height, width, 0);
00085 
00086     while (key != ESC) {
00087     key = wgetch (dialog);
00088     switch (key) {
00089     case 'Y':
00090     case 'y':
00091         delwin (dialog);
00092         return 0;
00093     case 'N':
00094     case 'n':
00095         delwin (dialog);
00096         return 1;
00097 
00098     case TAB:
00099     case KEY_LEFT:
00100     case KEY_RIGHT:
00101         button = ((key == KEY_LEFT ? --button : ++button) < 0)
00102             ? 1 : (button > 1 ? 0 : button);
00103 
00104         print_buttons(dialog, height, width, button);
00105         wrefresh (dialog);
00106         break;
00107     case ' ':
00108     case '\n':
00109         delwin (dialog);
00110         return button;
00111     case ESC:
00112         break;
00113     }
00114     }
00115 
00116     delwin (dialog);
00117     return -1;          /* ESC pressed */
00118 }

Generated on Tue Feb 2 17:46:04 2010 for RTAI API by  doxygen 1.4.7