Dash:
[t2-trunk.git] / misc / confdialog / yesno.c
blob38799154d39a124eb48e21309110ed5e9957b9b4
1 /*
2 * --- T2-COPYRIGHT-NOTE-BEGIN ---
3 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 *
5 * T2 SDE: misc/confdialog/yesno.c
6 * Copyright (C) 2004 - 2005 The T2 SDE Project
7 * Copyright (C) 1998 - 2003 ROCK Linux Project
8 *
9 * More information can be found in the files COPYING and README.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License. A copy of the
14 * GNU General Public License can be found in the file COPYING.
15 * --- T2-COPYRIGHT-NOTE-END ---
18 * yesno.c -- implements the yes/no box
20 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
21 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
22 * MODIFIED FOR ROCK LINUX CONFIG BY: Clifford Wolf (clifford@clifford.at)
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * as published by the Free Software Foundation; either version 2
27 * of the License, or (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39 #include "dialog.h"
42 * Display termination buttons
44 static void
45 print_buttons(WINDOW *dialog, int height, int width, int selected)
47 int x = width / 2 - 10;
48 int y = height - 2;
50 print_button (dialog, " Yes ", y, x, selected == 0);
51 print_button (dialog, " No ", y, x + 13, selected == 1);
53 wmove(dialog, y, x+1 + 13*selected );
54 wrefresh (dialog);
58 * Display a dialog box with two buttons - Yes and No
60 int
61 dialog_yesno (const char *title, const char *prompt, int height, int width)
63 int i, x, y, key = 0, button = 0;
64 WINDOW *dialog;
66 /* center dialog box on screen */
67 x = (COLS - width) / 2;
68 y = (LINES - height) / 2;
70 draw_shadow (stdscr, y, x, height, width);
72 dialog = newwin (height, width, y, x);
73 keypad (dialog, TRUE);
75 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
76 wattrset (dialog, border_attr);
77 mvwaddch (dialog, height-3, 0, ACS_LTEE);
78 for (i = 0; i < width - 2; i++)
79 waddch (dialog, ACS_HLINE);
80 wattrset (dialog, dialog_attr);
81 waddch (dialog, ACS_RTEE);
83 if (title != NULL && strlen(title) >= width-2 ) {
84 /* truncate long title -- mec */
85 char * title2 = malloc(width-2+1);
86 memcpy( title2, title, width-2 );
87 title2[width-2] = '\0';
88 title = title2;
91 if (title != NULL) {
92 wattrset (dialog, title_attr);
93 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
94 waddstr (dialog, (char *)title);
95 waddch (dialog, ' ');
98 wattrset (dialog, dialog_attr);
99 print_autowrap (dialog, prompt, width - 2, 1, 3);
101 print_buttons(dialog, height, width, 0);
103 while (key != ESC) {
104 key = wgetch (dialog);
105 switch (key) {
106 case 'Y':
107 case 'y':
108 delwin (dialog);
109 return 0;
110 case 'N':
111 case 'n':
112 delwin (dialog);
113 return 1;
115 case TAB:
116 case KEY_LEFT:
117 case KEY_RIGHT:
118 button = ((key == KEY_LEFT ? --button : ++button) < 0)
119 ? 1 : (button > 1 ? 0 : button);
121 print_buttons(dialog, height, width, button);
122 wrefresh (dialog);
123 break;
124 case ' ':
125 case '\n':
126 delwin (dialog);
127 return button;
128 case ESC:
129 break;
133 delwin (dialog);
134 return -1; /* ESC pressed */