msgbox.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "dialog.h"
  22. /*
  23. * Display a message box. Program will pause and display an "OK" button
  24. * if the parameter 'pause' is non-zero.
  25. */
  26. int dialog_msgbox(const char *title, const char *prompt, int height, int width,
  27. int pause)
  28. {
  29. int i, x, y, key = 0;
  30. WINDOW *dialog;
  31. /* center dialog box on screen */
  32. x = (COLS - width) / 2;
  33. y = (LINES - height) / 2;
  34. draw_shadow(stdscr, y, x, height, width);
  35. dialog = newwin(height, width, y, x);
  36. keypad(dialog, TRUE);
  37. draw_box(dialog, 0, 0, height, width,
  38. dlg.dialog.atr, dlg.border.atr);
  39. print_title(dialog, title, width);
  40. wattrset(dialog, dlg.dialog.atr);
  41. print_autowrap(dialog, prompt, width - 2, 1, 2);
  42. if (pause) {
  43. wattrset(dialog, dlg.border.atr);
  44. mvwaddch(dialog, height - 3, 0, ACS_LTEE);
  45. for (i = 0; i < width - 2; i++)
  46. waddch(dialog, ACS_HLINE);
  47. wattrset(dialog, dlg.dialog.atr);
  48. waddch(dialog, ACS_RTEE);
  49. print_button(dialog, " Ok ", height - 2, width / 2 - 4, TRUE);
  50. wrefresh(dialog);
  51. while (key != ESC && key != '\n' && key != ' ' &&
  52. key != 'O' && key != 'o' && key != 'X' && key != 'x')
  53. key = wgetch(dialog);
  54. } else {
  55. key = '\n';
  56. wrefresh(dialog);
  57. }
  58. delwin(dialog);
  59. return key == ESC ? -1 : 0;
  60. }