blob: 236759ff3f4ebc5a0aeef6f1330471ce8de48d60 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * msgbox.c -- implements the message box and info box
3 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include "dialog.h"
23
24/*
25 * Display a message box. Program will pause and display an "OK" button
26 * if the parameter 'pause' is non-zero.
27 */
Sam Ravnborgdec69da2005-11-19 21:56:20 +010028int dialog_msgbox(const char *title, const char *prompt, int height, int width,
29 int pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010031 int i, x, y, key = 0;
32 WINDOW *dialog;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010034 /* center dialog box on screen */
35 x = (COLS - width) / 2;
36 y = (LINES - height) / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010038 draw_shadow(stdscr, y, x, height, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010040 dialog = newwin(height, width, y, x);
41 keypad(dialog, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Sam Ravnborg98e5a152006-07-24 21:40:46 +020043 draw_box(dialog, 0, 0, height, width,
44 dlg.dialog.atr, dlg.border.atr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Sam Ravnborgfa7009d2005-11-19 23:38:06 +010046 print_title(dialog, title, width);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Sam Ravnborg98e5a152006-07-24 21:40:46 +020048 wattrset(dialog, dlg.dialog.atr);
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010049 print_autowrap(dialog, prompt, width - 2, 1, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010051 if (pause) {
Sam Ravnborg98e5a152006-07-24 21:40:46 +020052 wattrset(dialog, dlg.border.atr);
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010053 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
54 for (i = 0; i < width - 2; i++)
55 waddch(dialog, ACS_HLINE);
Sam Ravnborg98e5a152006-07-24 21:40:46 +020056 wattrset(dialog, dlg.dialog.atr);
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010057 waddch(dialog, ACS_RTEE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010059 print_button(dialog, " Ok ", height - 2, width / 2 - 4, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010061 wrefresh(dialog);
62 while (key != ESC && key != '\n' && key != ' ' &&
63 key != 'O' && key != 'o' && key != 'X' && key != 'x')
64 key = wgetch(dialog);
65 } else {
66 key = '\n';
67 wrefresh(dialog);
68 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Sam Ravnborgb1c5f1c2005-11-19 19:13:34 +010070 delwin(dialog);
71 return key == ESC ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}