dialog.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * dialog.h -- common declarations for all dialog modules
  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. #include <sys/types.h>
  21. #include <fcntl.h>
  22. #include <unistd.h>
  23. #include <ctype.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #ifdef __sun__
  27. #define CURS_MACROS
  28. #endif
  29. #include CURSES_LOC
  30. /*
  31. * Colors in ncurses 1.9.9e do not work properly since foreground and
  32. * background colors are OR'd rather than separately masked. This version
  33. * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
  34. * with standard curses. The simplest fix (to make this work with standard
  35. * curses) uses the wbkgdset() function, not used in the original hack.
  36. * Turn it off if we're building with 1.9.9e, since it just confuses things.
  37. */
  38. #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
  39. #define OLD_NCURSES 1
  40. #undef wbkgdset
  41. #define wbkgdset(w,p) /*nothing */
  42. #else
  43. #define OLD_NCURSES 0
  44. #endif
  45. #define TR(params) _tracef params
  46. #define ESC 27
  47. #define TAB 9
  48. #define MAX_LEN 2048
  49. #define BUF_SIZE (10*1024)
  50. #define MIN(x,y) (x < y ? x : y)
  51. #define MAX(x,y) (x > y ? x : y)
  52. #ifndef ACS_ULCORNER
  53. #define ACS_ULCORNER '+'
  54. #endif
  55. #ifndef ACS_LLCORNER
  56. #define ACS_LLCORNER '+'
  57. #endif
  58. #ifndef ACS_URCORNER
  59. #define ACS_URCORNER '+'
  60. #endif
  61. #ifndef ACS_LRCORNER
  62. #define ACS_LRCORNER '+'
  63. #endif
  64. #ifndef ACS_HLINE
  65. #define ACS_HLINE '-'
  66. #endif
  67. #ifndef ACS_VLINE
  68. #define ACS_VLINE '|'
  69. #endif
  70. #ifndef ACS_LTEE
  71. #define ACS_LTEE '+'
  72. #endif
  73. #ifndef ACS_RTEE
  74. #define ACS_RTEE '+'
  75. #endif
  76. #ifndef ACS_UARROW
  77. #define ACS_UARROW '^'
  78. #endif
  79. #ifndef ACS_DARROW
  80. #define ACS_DARROW 'v'
  81. #endif
  82. /*
  83. * Color definitions
  84. */
  85. struct dialog_color {
  86. chtype atr; /* Color attribute */
  87. int fg; /* foreground */
  88. int bg; /* background */
  89. int hl; /* highlight this item */
  90. };
  91. struct dialog_info {
  92. const char *backtitle;
  93. struct dialog_color screen;
  94. struct dialog_color shadow;
  95. struct dialog_color dialog;
  96. struct dialog_color title;
  97. struct dialog_color border;
  98. struct dialog_color button_active;
  99. struct dialog_color button_inactive;
  100. struct dialog_color button_key_active;
  101. struct dialog_color button_key_inactive;
  102. struct dialog_color button_label_active;
  103. struct dialog_color button_label_inactive;
  104. struct dialog_color inputbox;
  105. struct dialog_color inputbox_border;
  106. struct dialog_color searchbox;
  107. struct dialog_color searchbox_title;
  108. struct dialog_color searchbox_border;
  109. struct dialog_color position_indicator;
  110. struct dialog_color menubox;
  111. struct dialog_color menubox_border;
  112. struct dialog_color item;
  113. struct dialog_color item_selected;
  114. struct dialog_color tag;
  115. struct dialog_color tag_selected;
  116. struct dialog_color tag_key;
  117. struct dialog_color tag_key_selected;
  118. struct dialog_color check;
  119. struct dialog_color check_selected;
  120. struct dialog_color uarrow;
  121. struct dialog_color darrow;
  122. };
  123. /*
  124. * Global variables
  125. */
  126. extern struct dialog_info dlg;
  127. /*
  128. * Function prototypes
  129. */
  130. void init_dialog(void);
  131. void end_dialog(void);
  132. void attr_clear(WINDOW * win, int height, int width, chtype attr);
  133. void dialog_clear(void);
  134. void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
  135. void print_button(WINDOW * win, const char *label, int y, int x, int selected);
  136. void print_title(WINDOW *dialog, const char *title, int width);
  137. void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
  138. chtype border);
  139. void draw_shadow(WINDOW * win, int y, int x, int height, int width);
  140. int first_alpha(const char *string, const char *exempt);
  141. int dialog_yesno(const char *title, const char *prompt, int height, int width);
  142. int dialog_msgbox(const char *title, const char *prompt, int height,
  143. int width, int pause);
  144. int dialog_textbox(const char *title, const char *file, int height, int width);
  145. int dialog_menu(const char *title, const char *prompt, int height, int width,
  146. int menu_height, const char *choice, int item_no,
  147. const char *const *items);
  148. int dialog_checklist(const char *title, const char *prompt, int height,
  149. int width, int list_height, int item_no,
  150. const char *const *items);
  151. extern char dialog_input_result[];
  152. int dialog_inputbox(const char *title, const char *prompt, int height,
  153. int width, const char *init);
  154. /*
  155. * This is the base for fictitious keys, which activate
  156. * the buttons.
  157. *
  158. * Mouse-generated keys are the following:
  159. * -- the first 32 are used as numbers, in addition to '0'-'9'
  160. * -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
  161. * -- uppercase chars are used to invoke the button (M_EVENT + 'O')
  162. */
  163. #define M_EVENT (KEY_MAX+1)