00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "dialog.h"
00023
00024
00025
00026
00027
00028 int
00029 dialog_msgbox (const char *title, const char *prompt, int height, int width,
00030 int pause)
00031 {
00032 int i, x, y, key = 0;
00033 WINDOW *dialog;
00034
00035
00036 x = (COLS - width) / 2;
00037 y = (LINES - height) / 2;
00038
00039 draw_shadow (stdscr, y, x, height, width);
00040
00041 dialog = newwin (height, width, y, x);
00042 keypad (dialog, TRUE);
00043
00044 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
00045
00046 if (title != NULL && strlen(title) >= width-2 ) {
00047
00048 char * title2 = malloc(width-2+1);
00049 memcpy( title2, title, width-2 );
00050 title2[width-2] = '\0';
00051 title = title2;
00052 }
00053
00054 if (title != NULL) {
00055 wattrset (dialog, title_attr);
00056 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
00057 waddstr (dialog, (char *)title);
00058 waddch (dialog, ' ');
00059 }
00060 wattrset (dialog, dialog_attr);
00061 print_autowrap (dialog, prompt, width - 2, 1, 2);
00062
00063 if (pause) {
00064 wattrset (dialog, border_attr);
00065 mvwaddch (dialog, height - 3, 0, ACS_LTEE);
00066 for (i = 0; i < width - 2; i++)
00067 waddch (dialog, ACS_HLINE);
00068 wattrset (dialog, dialog_attr);
00069 waddch (dialog, ACS_RTEE);
00070
00071 print_button (dialog, " Ok ",
00072 height - 2, width / 2 - 4, TRUE);
00073
00074 wrefresh (dialog);
00075 while (key != ESC && key != '\n' && key != ' ' &&
00076 key != 'O' && key != 'o' && key != 'X' && key != 'x')
00077 key = wgetch (dialog);
00078 } else {
00079 key = '\n';
00080 wrefresh (dialog);
00081 }
00082
00083 delwin (dialog);
00084 return key == ESC ? -1 : 0;
00085 }