Back to index

tetex-bin  3.0
msgbox.c
Go to the documentation of this file.
00001 /*
00002  *  msgbox.c -- implements the message box and info box
00003  *
00004  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 
00022 #include "dialog.h"
00023 
00024 
00025 /*
00026  * Display a message box. Program will pause and display an "OK" button
00027  * if the parameter 'pause' is non-zero.
00028  */
00029 int dialog_msgbox(char *title, char *prompt, int height, int width, int pause)
00030 {
00031   int i, x, y, key = 0;
00032   WINDOW *dialog;
00033 
00034   /* center dialog box on screen */
00035   x = (COLS - width)/2;
00036   y = (LINES - height)/2;
00037 
00038 #ifdef HAVE_NCURSES
00039   if (use_shadow)
00040     draw_shadow(stdscr, y, x, height, width);
00041 #endif
00042   dialog = newwin(height, width, y, x);
00043   keypad(dialog, TRUE);
00044 
00045   draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
00046 
00047   if (title != NULL) {
00048     wattrset(dialog, title_attr);
00049     wmove(dialog, 0, (width - strlen(title))/2 - 1);
00050     waddch(dialog, ' ');
00051     waddstr(dialog, title);
00052     waddch(dialog, ' ');
00053   }
00054   wattrset(dialog, dialog_attr);
00055   print_autowrap(dialog, prompt, width-2, 1, 2);
00056 
00057   if (pause) {
00058     wattrset(dialog, border_attr);
00059     wmove(dialog, height-3, 0);
00060     waddch(dialog, ACS_LTEE);
00061     for (i = 0; i < width-2; i++)
00062       waddch(dialog, ACS_HLINE);
00063     wattrset(dialog, dialog_attr);
00064     waddch(dialog, ACS_RTEE);
00065     wmove(dialog, height-2, 1);
00066     for (i = 0; i < width-2; i++)
00067     waddch(dialog, ' ');
00068     print_button(dialog, "  OK  ", height-2, width/2-4, TRUE);
00069     wrefresh(dialog);
00070     while (key != ESC && key != '\n' && key != ' ')
00071       key = wgetch(dialog);
00072   }
00073   else {
00074     key = '\n';
00075     wrefresh(dialog);
00076   }
00077 
00078   delwin(dialog);
00079   return (key == ESC ? -1 : 0);
00080 }
00081 /* End of dialog_msgbox() */