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.
20 * $FreeBSD: src/gnu/lib/libdialog/yesno.c,v 1.11.8.3 2001/07/31 20:34:00 eric Exp $
21 * $DragonFly: src/gnu/lib/libdialog/yesno.c,v 1.2 2003/06/17 04:25:43 dillon Exp $
25 #include "dialog.priv.h"
27 /* Actual work function */
28 static int dialog_yesno_proc(unsigned char *title
, unsigned char *prompt
,
29 int height
, int width
, int yesdefault
);
32 * Display a dialog box with two buttons - Yes and No
35 dialog_yesno(unsigned char *title
, unsigned char *prompt
, int height
, int width
)
37 return dialog_yesno_proc(title
, prompt
, height
, width
, TRUE
);
41 * Display a dialog box with two buttons - No and Yes
44 dialog_noyes(unsigned char *title
, unsigned char *prompt
, int height
, int width
)
46 return dialog_yesno_proc(title
, prompt
, height
, width
, FALSE
);
50 dialog_yesno_proc(unsigned char *title
, unsigned char *prompt
, int height
, int width
, int yesdefault
)
52 int i
, j
, x
, y
, key
, button
;
56 /* disable helpline */
57 tmphlp
= get_helpline();
61 height
= strheight(prompt
)+4;
64 j
= ((title
!= NULL
) ? strwidth(title
) : 0);
67 width
= MAX(width
,23);
73 /* center dialog box on screen */
74 x
= DialogX
? DialogX
: (COLS
- width
)/2;
75 y
= DialogY
? DialogY
: (LINES
- height
)/2;
79 draw_shadow(stdscr
, y
, x
, height
, width
);
81 dialog
= newwin(height
, width
, y
, x
);
84 fprintf(stderr
, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height
,width
,y
,x
);
89 draw_box(dialog
, 0, 0, height
, width
, dialog_attr
, border_attr
);
90 wattrset(dialog
, border_attr
);
91 wmove(dialog
, height
-3, 0);
92 waddch(dialog
, ACS_LTEE
);
93 for (i
= 0; i
< width
-2; i
++)
94 waddch(dialog
, ACS_HLINE
);
95 wattrset(dialog
, dialog_attr
);
96 waddch(dialog
, ACS_RTEE
);
97 wmove(dialog
, height
-2, 1);
98 for (i
= 0; i
< width
-2; i
++)
102 wattrset(dialog
, title_attr
);
103 wmove(dialog
, 0, (width
- strlen(title
))/2 - 1);
105 waddstr(dialog
, title
);
108 wattrset(dialog
, dialog_attr
);
110 print_autowrap(dialog
, prompt
, height
-1, width
-2, width
, 1, 2, TRUE
, FALSE
);
112 display_helpline(dialog
, height
-1, width
);
117 /* preset button 0 or 1 for YES or NO as the default */
119 button
= !yesdefault
;
121 print_button(dialog
, " No ", y
, x
+13, button
);
122 print_button(dialog
, " Yes " , y
, x
, !button
);
124 wmove(dialog
, y
, x
+16);
126 wmove(dialog
, y
, x
+2);
129 key
= wgetch(dialog
);
134 restore_helpline(tmphlp
);
139 restore_helpline(tmphlp
);
148 /* redrawn at the loop's entry */
154 restore_helpline(tmphlp
);
166 restore_helpline(tmphlp
);
167 return -1; /* ESC pressed */
169 /* End of dialog_yesno() */