dialog.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * dialog.h -- common declarations for all dialog modules
  4. *
  5. * AUTHOR: Savio Lam ([email protected])
  6. */
  7. #include <sys/types.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
  10. #include <ctype.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <stdbool.h>
  14. #ifdef __sun__
  15. #define CURS_MACROS
  16. #endif
  17. #include <ncurses.h>
  18. #define TR(params) _tracef params
  19. #define KEY_ESC 27
  20. #define TAB 9
  21. #define MAX_LEN 2048
  22. #define BUF_SIZE (10*1024)
  23. #define MIN(x,y) (x < y ? x : y)
  24. #define MAX(x,y) (x > y ? x : y)
  25. #ifndef ACS_ULCORNER
  26. #define ACS_ULCORNER '+'
  27. #endif
  28. #ifndef ACS_LLCORNER
  29. #define ACS_LLCORNER '+'
  30. #endif
  31. #ifndef ACS_URCORNER
  32. #define ACS_URCORNER '+'
  33. #endif
  34. #ifndef ACS_LRCORNER
  35. #define ACS_LRCORNER '+'
  36. #endif
  37. #ifndef ACS_HLINE
  38. #define ACS_HLINE '-'
  39. #endif
  40. #ifndef ACS_VLINE
  41. #define ACS_VLINE '|'
  42. #endif
  43. #ifndef ACS_LTEE
  44. #define ACS_LTEE '+'
  45. #endif
  46. #ifndef ACS_RTEE
  47. #define ACS_RTEE '+'
  48. #endif
  49. #ifndef ACS_UARROW
  50. #define ACS_UARROW '^'
  51. #endif
  52. #ifndef ACS_DARROW
  53. #define ACS_DARROW 'v'
  54. #endif
  55. /* error return codes */
  56. #define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
  57. /*
  58. * Color definitions
  59. */
  60. struct dialog_color {
  61. chtype atr; /* Color attribute */
  62. int fg; /* foreground */
  63. int bg; /* background */
  64. int hl; /* highlight this item */
  65. };
  66. struct subtitle_list {
  67. struct subtitle_list *next;
  68. const char *text;
  69. };
  70. struct dialog_info {
  71. const char *backtitle;
  72. struct subtitle_list *subtitles;
  73. struct dialog_color screen;
  74. struct dialog_color shadow;
  75. struct dialog_color dialog;
  76. struct dialog_color title;
  77. struct dialog_color border;
  78. struct dialog_color button_active;
  79. struct dialog_color button_inactive;
  80. struct dialog_color button_key_active;
  81. struct dialog_color button_key_inactive;
  82. struct dialog_color button_label_active;
  83. struct dialog_color button_label_inactive;
  84. struct dialog_color inputbox;
  85. struct dialog_color inputbox_border;
  86. struct dialog_color searchbox;
  87. struct dialog_color searchbox_title;
  88. struct dialog_color searchbox_border;
  89. struct dialog_color position_indicator;
  90. struct dialog_color menubox;
  91. struct dialog_color menubox_border;
  92. struct dialog_color item;
  93. struct dialog_color item_selected;
  94. struct dialog_color tag;
  95. struct dialog_color tag_selected;
  96. struct dialog_color tag_key;
  97. struct dialog_color tag_key_selected;
  98. struct dialog_color check;
  99. struct dialog_color check_selected;
  100. struct dialog_color uarrow;
  101. struct dialog_color darrow;
  102. };
  103. /*
  104. * Global variables
  105. */
  106. extern struct dialog_info dlg;
  107. extern char dialog_input_result[];
  108. extern int saved_x, saved_y; /* Needed in signal handler in mconf.c */
  109. /*
  110. * Function prototypes
  111. */
  112. /* item list as used by checklist and menubox */
  113. void item_reset(void);
  114. void item_make(const char *fmt, ...);
  115. void item_add_str(const char *fmt, ...);
  116. void item_set_tag(char tag);
  117. void item_set_data(void *p);
  118. void item_set_selected(int val);
  119. int item_activate_selected(void);
  120. void *item_data(void);
  121. char item_tag(void);
  122. /* item list manipulation for lxdialog use */
  123. #define MAXITEMSTR 200
  124. struct dialog_item {
  125. char str[MAXITEMSTR]; /* prompt displayed */
  126. char tag;
  127. void *data; /* pointer to menu item - used by menubox+checklist */
  128. int selected; /* Set to 1 by dialog_*() function if selected. */
  129. };
  130. /* list of lialog_items */
  131. struct dialog_list {
  132. struct dialog_item node;
  133. struct dialog_list *next;
  134. };
  135. extern struct dialog_list *item_cur;
  136. extern struct dialog_list item_nil;
  137. extern struct dialog_list *item_head;
  138. int item_count(void);
  139. void item_set(int n);
  140. int item_n(void);
  141. const char *item_str(void);
  142. int item_is_selected(void);
  143. int item_is_tag(char tag);
  144. #define item_foreach() \
  145. for (item_cur = item_head ? item_head: item_cur; \
  146. item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
  147. /* generic key handlers */
  148. int on_key_esc(WINDOW *win);
  149. int on_key_resize(void);
  150. /* minimum (re)size values */
  151. #define CHECKLIST_HEIGTH_MIN 6 /* For dialog_checklist() */
  152. #define CHECKLIST_WIDTH_MIN 6
  153. #define INPUTBOX_HEIGTH_MIN 2 /* For dialog_inputbox() */
  154. #define INPUTBOX_WIDTH_MIN 2
  155. #define MENUBOX_HEIGTH_MIN 15 /* For dialog_menu() */
  156. #define MENUBOX_WIDTH_MIN 65
  157. #define TEXTBOX_HEIGTH_MIN 8 /* For dialog_textbox() */
  158. #define TEXTBOX_WIDTH_MIN 8
  159. #define YESNO_HEIGTH_MIN 4 /* For dialog_yesno() */
  160. #define YESNO_WIDTH_MIN 4
  161. #define WINDOW_HEIGTH_MIN 19 /* For init_dialog() */
  162. #define WINDOW_WIDTH_MIN 80
  163. int init_dialog(const char *backtitle);
  164. void set_dialog_backtitle(const char *backtitle);
  165. void set_dialog_subtitles(struct subtitle_list *subtitles);
  166. void end_dialog(int x, int y);
  167. void attr_clear(WINDOW * win, int height, int width, chtype attr);
  168. void dialog_clear(void);
  169. void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
  170. void print_button(WINDOW * win, const char *label, int y, int x, int selected);
  171. void print_title(WINDOW *dialog, const char *title, int width);
  172. void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
  173. chtype border);
  174. void draw_shadow(WINDOW * win, int y, int x, int height, int width);
  175. int first_alpha(const char *string, const char *exempt);
  176. int dialog_yesno(const char *title, const char *prompt, int height, int width);
  177. int dialog_msgbox(const char *title, const char *prompt, int height,
  178. int width, int pause);
  179. int dialog_textbox(const char *title, const char *tbuf, int initial_height,
  180. int initial_width, int *_vscroll, int *_hscroll,
  181. int (*extra_key_cb)(int, size_t, size_t, void *), void *data);
  182. int dialog_menu(const char *title, const char *prompt,
  183. const void *selected, int *s_scroll);
  184. int dialog_checklist(const char *title, const char *prompt, int height,
  185. int width, int list_height);
  186. int dialog_inputbox(const char *title, const char *prompt, int height,
  187. int width, const char *init);