Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Ravnborg | dec69da | 2005-11-19 21:56:20 +0100 | [diff] [blame^] | 28 | int dialog_msgbox(const char *title, const char *prompt, int height, int width, |
| 29 | int pause) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 31 | int i, x, y, key = 0; |
| 32 | WINDOW *dialog; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 34 | /* center dialog box on screen */ |
| 35 | x = (COLS - width) / 2; |
| 36 | y = (LINES - height) / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 38 | draw_shadow(stdscr, y, x, height, width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 40 | dialog = newwin(height, width, y, x); |
| 41 | keypad(dialog, TRUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 43 | draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 45 | if (title != NULL && strlen(title) >= width - 2) { |
| 46 | /* truncate long title -- mec */ |
| 47 | char *title2 = malloc(width - 2 + 1); |
| 48 | memcpy(title2, title, width - 2); |
| 49 | title2[width - 2] = '\0'; |
| 50 | title = title2; |
| 51 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 53 | if (title != NULL) { |
| 54 | wattrset(dialog, title_attr); |
| 55 | mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' '); |
| 56 | waddstr(dialog, (char *)title); |
| 57 | waddch(dialog, ' '); |
| 58 | } |
| 59 | wattrset(dialog, dialog_attr); |
| 60 | print_autowrap(dialog, prompt, width - 2, 1, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 62 | if (pause) { |
| 63 | wattrset(dialog, border_attr); |
| 64 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
| 65 | for (i = 0; i < width - 2; i++) |
| 66 | waddch(dialog, ACS_HLINE); |
| 67 | wattrset(dialog, dialog_attr); |
| 68 | waddch(dialog, ACS_RTEE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 70 | print_button(dialog, " Ok ", height - 2, width / 2 - 4, TRUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 72 | wrefresh(dialog); |
| 73 | while (key != ESC && key != '\n' && key != ' ' && |
| 74 | key != 'O' && key != 'o' && key != 'X' && key != 'x') |
| 75 | key = wgetch(dialog); |
| 76 | } else { |
| 77 | key = '\n'; |
| 78 | wrefresh(dialog); |
| 79 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 81 | delwin(dialog); |
| 82 | return key == ESC ? -1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |