2 * yesno.c -- implements the yes/no box
4 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
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.
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.
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.
22 static const char rcsid[] =
23 "$FreeBSD: src/gnu/lib/libdialog/yesno.c,v 1.11.8.3 2001/07/31 20:34:00 eric Exp $";
27 #include "dialog.priv.h"
29 /* Actual work function */
30 static int dialog_yesno_proc(unsigned char *title, unsigned char *prompt,
31 int height, int width, int yesdefault);
34 * Display a dialog box with two buttons - Yes and No
37 dialog_yesno(unsigned char *title, unsigned char *prompt, int height, int width)
39 return dialog_yesno_proc(title, prompt, height, width, TRUE);
43 * Display a dialog box with two buttons - No and Yes
46 dialog_noyes(unsigned char *title, unsigned char *prompt, int height, int width)
48 return dialog_yesno_proc(title, prompt, height, width, FALSE);
52 dialog_yesno_proc(unsigned char *title, unsigned char *prompt, int height, int width, int yesdefault)
54 int i, j, x, y, key, button;
58 /* disable helpline */
59 tmphlp = get_helpline();
63 height = strheight(prompt)+4;
66 j = ((title != NULL) ? strwidth(title) : 0);
69 width = MAX(width,23);
75 /* center dialog box on screen */
76 x = DialogX ? DialogX : (COLS - width)/2;
77 y = DialogY ? DialogY : (LINES - height)/2;
81 draw_shadow(stdscr, y, x, height, width);
83 dialog = newwin(height, width, y, x);
86 fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height,width,y,x);
91 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
92 wattrset(dialog, border_attr);
93 wmove(dialog, height-3, 0);
94 waddch(dialog, ACS_LTEE);
95 for (i = 0; i < width-2; i++)
96 waddch(dialog, ACS_HLINE);
97 wattrset(dialog, dialog_attr);
98 waddch(dialog, ACS_RTEE);
99 wmove(dialog, height-2, 1);
100 for (i = 0; i < width-2; i++)
104 wattrset(dialog, title_attr);
105 wmove(dialog, 0, (width - strlen(title))/2 - 1);
107 waddstr(dialog, title);
110 wattrset(dialog, dialog_attr);
112 print_autowrap(dialog, prompt, height-1, width-2, width, 1, 2, TRUE, FALSE);
114 display_helpline(dialog, height-1, width);
119 /* preset button 0 or 1 for YES or NO as the default */
121 button = !yesdefault;
123 print_button(dialog, " No ", y, x+13, button);
124 print_button(dialog, " Yes " , y, x, !button);
126 wmove(dialog, y, x+16);
128 wmove(dialog, y, x+2);
131 key = wgetch(dialog);
136 restore_helpline(tmphlp);
141 restore_helpline(tmphlp);
150 /* redrawn at the loop's entry */
156 restore_helpline(tmphlp);
168 restore_helpline(tmphlp);
169 return -1; /* ESC pressed */
171 /* End of dialog_yesno() */