home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / shell / dialog-0.000 / dialog-0 / dialog-0.6c / msgbox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-11  |  2.4 KB  |  85 lines

  1. /*
  2.  *  msgbox.c -- implements the message box and info box
  3.  *
  4.  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
  5.  *
  6.  *  This program is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU General Public License
  8.  *  as published by the Free Software Foundation; either version 2
  9.  *  of the License, or (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include "dialog.h"
  22.  
  23. /*
  24.  * Display a message box. Program will pause and display an "OK" button
  25.  * if the parameter 'pause' is non-zero.
  26.  */
  27. int
  28. dialog_msgbox (const char *title, const char *prompt, int height, int width,
  29.         int pause)
  30. {
  31.     int i, x, y, key = 0;
  32.     WINDOW *dialog;
  33.  
  34.     /* center dialog box on screen */
  35.     x = (COLS - width) / 2;
  36.     y = (LINES - height) / 2;
  37.  
  38. #ifdef HAVE_NCURSES
  39.     if (use_shadow)
  40.     draw_shadow (stdscr, y, x, height, width);
  41. #endif
  42.     dialog = newwin (height, width, y, x);
  43.     mouse_setbase (x, y);
  44.     keypad (dialog, TRUE);
  45.  
  46.     draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
  47.  
  48.     if (title != NULL) {
  49.     wattrset (dialog, title_attr);
  50.     wmove (dialog, 0, (width - strlen (title)) / 2 - 1);
  51.     waddch (dialog, ' ');
  52.     waddstr (dialog, title);
  53.     waddch (dialog, ' ');
  54.     }
  55.     wattrset (dialog, dialog_attr);
  56.     print_autowrap (dialog, prompt, width - 2, 1, 2);
  57.  
  58.     if (pause) {
  59.     wattrset (dialog, border_attr);
  60.     wmove (dialog, height - 3, 0);
  61.     waddch (dialog, ACS_LTEE);
  62.     for (i = 0; i < width - 2; i++)
  63.         waddch (dialog, ACS_HLINE);
  64.     wattrset (dialog, dialog_attr);
  65.     waddch (dialog, ACS_RTEE);
  66.     wmove (dialog, height - 2, 1);
  67.     for (i = 0; i < width - 2; i++)
  68.         waddch (dialog, ' ');
  69.  
  70.     mouse_mkbutton (height - 2, width / 2 - 4, 6, '\n');
  71.     print_button (dialog, "  OK  ",
  72.               height - 2, width / 2 - 4, TRUE);
  73.  
  74.     wrefresh (dialog);
  75.     while (key != ESC && key != '\n' && key != ' ')
  76.         key = mouse_wgetch (dialog);
  77.     } else {
  78.     key = '\n';
  79.     wrefresh (dialog);
  80.     }
  81.  
  82.     delwin (dialog);
  83.     return key == ESC ? -1 : 0;
  84. }
  85.