dialog.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <sys/types.h>
  20. #include <fcntl.h>
  21. #include <unistd.h>
  22. #include <ctype.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdbool.h>
  26. #ifndef KBUILD_NO_NLS
  27. # include <libintl.h>
  28. #else
  29. # define gettext(Msgid) ((const char *) (Msgid))
  30. #endif
  31. #ifdef __sun__
  32. #define CURS_MACROS
  33. #endif
  34. #include CURSES_LOC
  35. /*
  36. * Colors in ncurses 1.9.9e do not work properly since foreground and
  37. * background colors are OR'd rather than separately masked. This version
  38. * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
  39. * with standard curses. The simplest fix (to make this work with standard
  40. * curses) uses the wbkgdset() function, not used in the original hack.
  41. * Turn it off if we're building with 1.9.9e, since it just confuses things.
  42. */
  43. #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
  44. #define OLD_NCURSES 1
  45. #undef wbkgdset
  46. #define wbkgdset(w,p) /*nothing */
  47. #else
  48. #define OLD_NCURSES 0
  49. #endif
  50. #define TR(params) _tracef params
  51. #define KEY_ESC 27
  52. #define TAB 9
  53. #define MAX_LEN 2048
  54. #define BUF_SIZE (10*1024)
  55. #define MIN(x,y) (x < y ? x : y)
  56. #define MAX(x,y) (x > y ? x : y)
  57. #ifndef ACS_ULCORNER
  58. #define ACS_ULCORNER '+'
  59. #endif
  60. #ifndef ACS_LLCORNER
  61. #define ACS_LLCORNER '+'
  62. #endif
  63. #ifndef ACS_URCORNER
  64. #define ACS_URCORNER '+'
  65. #endif
  66. #ifndef ACS_LRCORNER
  67. #define ACS_LRCORNER '+'
  68. #endif
  69. #ifndef ACS_HLINE
  70. #define ACS_HLINE '-'
  71. #endif
  72. #ifndef ACS_VLINE
  73. #define ACS_VLINE '|'
  74. #endif
  75. #ifndef ACS_LTEE
  76. #define ACS_LTEE '+'
  77. #endif
  78. #ifndef ACS_RTEE
  79. #define ACS_RTEE '+'
  80. #endif
  81. #ifndef ACS_UARROW
  82. #define ACS_UARROW '^'
  83. #endif
  84. #ifndef ACS_DARROW
  85. #define ACS_DARROW 'v'
  86. #endif
  87. /* error return codes */
  88. #define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
  89. /*
  90. * Color definitions
  91. */
  92. struct dialog_color {
  93. chtype atr; /* Color attribute */
  94. int fg; /* foreground */
  95. int bg; /* background */
  96. int hl; /* highlight this item */
  97. };
  98. struct dialog_info {
  99. const char *backtitle;
  100. struct dialog_color screen;
  101. struct dialog_color shadow;
  102. struct dialog_color dialog;
  103. struct dialog_color title;
  104. struct dialog_color border;
  105. struct dialog_color button_active;
  106. struct dialog_color button_inactive;
  107. struct dialog_color button_key_active;
  108. struct dialog_color button_key_inactive;
  109. struct dialog_color button_label_active;
  110. struct dialog_color button_label_inactive;
  111. struct dialog_color inputbox;
  112. struct dialog_color inputbox_border;
  113. struct dialog_color searchbox;
  114. struct dialog_color searchbox_title;
  115. struct dialog_color searchbox_border;
  116. struct dialog_color position_indicator;
  117. struct dialog_color menubox;
  118. struct dialog_color menubox_border;
  119. struct dialog_color item;
  120. struct dialog_color item_selected;
  121. struct dialog_color tag;
  122. struct dialog_color tag_selected;
  123. struct dialog_color tag_key;
  124. struct dialog_color tag_key_selected;
  125. struct dialog_color check;
  126. struct dialog_color check_selected;
  127. struct dialog_color uarrow;
  128. struct dialog_color darrow;
  129. };
  130. /*
  131. * Global variables
  132. */
  133. extern struct dialog_info dlg;
  134. extern char dialog_input_result[];
  135. /*
  136. * Function prototypes
  137. */
  138. /* item list as used by checklist and menubox */
  139. void item_reset(void);
  140. void item_make(const char *fmt, ...);
  141. void item_add_str(const char *fmt, ...);
  142. void item_set_tag(char tag);
  143. void item_set_data(void *p);
  144. void item_set_selected(int val);
  145. int item_activate_selected(void);
  146. void *item_data(void);
  147. char item_tag(void);
  148. /* item list manipulation for lxdialog use */
  149. #define MAXITEMSTR 200
  150. struct dialog_item {
  151. char str[MAXITEMSTR]; /* promtp displayed */
  152. char tag;
  153. void *data; /* pointer to menu item - used by menubox+checklist */
  154. int selected; /* Set to 1 by dialog_*() function if selected. */
  155. };
  156. /* list of lialog_items */
  157. struct dialog_list {
  158. struct dialog_item node;
  159. struct dialog_list *next;
  160. };
  161. extern struct dialog_list *item_cur;
  162. extern struct dialog_list item_nil;
  163. extern struct dialog_list *item_head;
  164. int item_count(void);
  165. void item_set(int n);
  166. int item_n(void);
  167. const char *item_str(void);
  168. int item_is_selected(void);
  169. int item_is_tag(char tag);
  170. #define item_foreach() \
  171. for (item_cur = item_head ? item_head: item_cur; \
  172. item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
  173. /* generic key handlers */
  174. int on_key_esc(WINDOW *win);
  175. int on_key_resize(void);
  176. int init_dialog(const char *backtitle);
  177. void set_dialog_backtitle(const char *backtitle);
  178. void end_dialog(int x, int y);
  179. void attr_clear(WINDOW * win, int height, int width, chtype attr);
  180. void dialog_clear(void);
  181. void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
  182. void print_button(WINDOW * win, const char *label, int y, int x, int selected);
  183. void print_title(WINDOW *dialog, const char *title, int width);
  184. void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
  185. chtype border);
  186. void draw_shadow(WINDOW * win, int y, int x, int height, int width);
  187. int first_alpha(const char *string, const char *exempt);
  188. int dialog_yesno(const char *title, const char *prompt, int height, int width);
  189. int dialog_msgbox(const char *title, const char *prompt, int height,
  190. int width, int pause);
  191. int dialog_textbox(const char *title, const char *file, int height, int width);
  192. int dialog_menu(const char *title, const char *prompt,
  193. const void *selected, int *s_scroll);
  194. int dialog_checklist(const char *title, const char *prompt, int height,
  195. int width, int list_height);
  196. extern char dialog_input_result[];
  197. int dialog_inputbox(const char *title, const char *prompt, int height,
  198. int width, const char *init);
  199. /*
  200. * This is the base for fictitious keys, which activate
  201. * the buttons.
  202. *
  203. * Mouse-generated keys are the following:
  204. * -- the first 32 are used as numbers, in addition to '0'-'9'
  205. * -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
  206. * -- uppercase chars are used to invoke the button (M_EVENT + 'O')
  207. */
  208. #define M_EVENT (KEY_MAX+1)