mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.5 KiB

  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. * MODIFIED FOR ROCK LINUX CONFIG BY: Clifford Wolf (clifford@clifford.at)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include "dialog.h"
  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. /* center dialog box on screen */
  34. x = (COLS - width) / 2;
  35. y = (LINES - height) / 2;
  36. draw_shadow (stdscr, y, x, height, width);
  37. dialog = newwin (height, width, y, x);
  38. keypad (dialog, TRUE);
  39. draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
  40. if (title != NULL && strlen(title) >= width-2 ) {
  41. /* truncate long title -- mec */
  42. char * title2 = malloc(width-2+1);
  43. memcpy( title2, title, width-2 );
  44. title2[width-2] = '\0';
  45. title = title2;
  46. }
  47. if (title != NULL) {
  48. wattrset (dialog, title_attr);
  49. mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
  50. waddstr (dialog, (char *)title);
  51. waddch (dialog, ' ');
  52. }
  53. wattrset (dialog, dialog_attr);
  54. print_autowrap (dialog, prompt, width - 2, 1, 2);
  55. if (pause) {
  56. wattrset (dialog, border_attr);
  57. mvwaddch (dialog, height - 3, 0, ACS_LTEE);
  58. for (i = 0; i < width - 2; i++)
  59. waddch (dialog, ACS_HLINE);
  60. wattrset (dialog, dialog_attr);
  61. waddch (dialog, ACS_RTEE);
  62. print_button (dialog, " Ok ",
  63. height - 2, width / 2 - 4, TRUE);
  64. wrefresh (dialog);
  65. while (key != ESC && key != '\n' && key != ' ' &&
  66. key != 'O' && key != 'o' && key != 'X' && key != 'x')
  67. key = wgetch (dialog);
  68. } else {
  69. key = '\n';
  70. wrefresh (dialog);
  71. }
  72. delwin (dialog);
  73. return key == ESC ? -1 : 0;
  74. }