Dash:
[t2-trunk.git] / misc / confdialog / msgbox.c
blob1a4fff7cca041d59aac01a3d5b1d59f0d05a9795
1 /*
2 * --- T2-COPYRIGHT-NOTE-BEGIN ---
3 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 *
5 * T2 SDE: misc/confdialog/msgbox.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 * msgbox.c -- implements the message box and info box
20 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
21 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@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 a message box. Program will pause and display an "OK" button
43 * if the parameter 'pause' is non-zero.
45 int
46 dialog_msgbox (const char *title, const char *prompt, int height, int width,
47 int pause)
49 int i, x, y, key = 0;
50 WINDOW *dialog;
52 /* center dialog box on screen */
53 x = (COLS - width) / 2;
54 y = (LINES - height) / 2;
56 draw_shadow (stdscr, y, x, height, width);
58 dialog = newwin (height, width, y, x);
59 keypad (dialog, TRUE);
61 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
63 if (title != NULL && strlen(title) >= width-2 ) {
64 /* truncate long title -- mec */
65 char * title2 = malloc(width-2+1);
66 memcpy( title2, title, width-2 );
67 title2[width-2] = '\0';
68 title = title2;
71 if (title != NULL) {
72 wattrset (dialog, title_attr);
73 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
74 waddstr (dialog, (char *)title);
75 waddch (dialog, ' ');
77 wattrset (dialog, dialog_attr);
78 print_autowrap (dialog, prompt, width - 2, 1, 2);
80 if (pause) {
81 wattrset (dialog, border_attr);
82 mvwaddch (dialog, height - 3, 0, ACS_LTEE);
83 for (i = 0; i < width - 2; i++)
84 waddch (dialog, ACS_HLINE);
85 wattrset (dialog, dialog_attr);
86 waddch (dialog, ACS_RTEE);
88 print_button (dialog, " Ok ",
89 height - 2, width / 2 - 4, TRUE);
91 wrefresh (dialog);
92 while (key != ESC && key != '\n' && key != ' ' &&
93 key != 'O' && key != 'o' && key != 'X' && key != 'x')
94 key = wgetch (dialog);
95 } else {
96 key = '\n';
97 wrefresh (dialog);
100 delwin (dialog);
101 return key == ESC ? -1 : 0;