1
0

msgbox.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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
  27. dialog_msgbox (const char *title, const char *prompt, int height, int width,
  28. int pause)
  29. {
  30. int i, x, y, key = 0;
  31. WINDOW *dialog;
  32. /* center dialog box on screen */
  33. x = (COLS - width) / 2;
  34. y = (LINES - height) / 2;
  35. draw_shadow (stdscr, y, x, height, width);
  36. dialog = newwin (height, width, y, x);
  37. keypad (dialog, TRUE);
  38. draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
  39. if (title != NULL && strlen(title) >= width-2 ) {
  40. /* truncate long title -- mec */
  41. char * title2 = malloc(width-2+1);
  42. memcpy( title2, title, width-2 );
  43. title2[width-2] = '\0';
  44. title = title2;
  45. }
  46. if (title != NULL) {
  47. wattrset (dialog, title_attr);
  48. mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
  49. waddstr (dialog, (char *)title);
  50. waddch (dialog, ' ');
  51. }
  52. wattrset (dialog, dialog_attr);
  53. print_autowrap (dialog, prompt, width - 2, 1, 2);
  54. if (pause) {
  55. wattrset (dialog, border_attr);
  56. mvwaddch (dialog, height - 3, 0, ACS_LTEE);
  57. for (i = 0; i < width - 2; i++)
  58. waddch (dialog, ACS_HLINE);
  59. wattrset (dialog, dialog_attr);
  60. waddch (dialog, ACS_RTEE);
  61. print_button (dialog, " Ok ",
  62. height - 2, width / 2 - 4, TRUE);
  63. wrefresh (dialog);
  64. while (key != ESC && key != '\n' && key != ' ' &&
  65. key != 'O' && key != 'o' && key != 'X' && key != 'x')
  66. key = wgetch (dialog);
  67. } else {
  68. key = '\n';
  69. wrefresh (dialog);
  70. }
  71. delwin (dialog);
  72. return key == ESC ? -1 : 0;
  73. }