2 * dialog.h -- common declarations for all dialog modules
4 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
6 * SPDX-License-Identifier: GPL-2.0+
20 # define gettext(Msgid) ((const char *) (Msgid))
29 * Colors in ncurses 1.9.9e do not work properly since foreground and
30 * background colors are OR'd rather than separately masked. This version
31 * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
32 * with standard curses. The simplest fix (to make this work with standard
33 * curses) uses the wbkgdset() function, not used in the original hack.
34 * Turn it off if we're building with 1.9.9e, since it just confuses things.
36 #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
39 #define wbkgdset(w,p) /*nothing */
44 #define TR(params) _tracef params
49 #define BUF_SIZE (10*1024)
50 #define MIN(x,y) (x < y ? x : y)
51 #define MAX(x,y) (x > y ? x : y)
54 #define ACS_ULCORNER '+'
57 #define ACS_LLCORNER '+'
60 #define ACS_URCORNER '+'
63 #define ACS_LRCORNER '+'
78 #define ACS_UARROW '^'
81 #define ACS_DARROW 'v'
84 /* error return codes */
85 #define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
91 chtype atr; /* Color attribute */
92 int fg; /* foreground */
93 int bg; /* background */
94 int hl; /* highlight this item */
97 struct subtitle_list {
98 struct subtitle_list *next;
103 const char *backtitle;
104 struct subtitle_list *subtitles;
105 struct dialog_color screen;
106 struct dialog_color shadow;
107 struct dialog_color dialog;
108 struct dialog_color title;
109 struct dialog_color border;
110 struct dialog_color button_active;
111 struct dialog_color button_inactive;
112 struct dialog_color button_key_active;
113 struct dialog_color button_key_inactive;
114 struct dialog_color button_label_active;
115 struct dialog_color button_label_inactive;
116 struct dialog_color inputbox;
117 struct dialog_color inputbox_border;
118 struct dialog_color searchbox;
119 struct dialog_color searchbox_title;
120 struct dialog_color searchbox_border;
121 struct dialog_color position_indicator;
122 struct dialog_color menubox;
123 struct dialog_color menubox_border;
124 struct dialog_color item;
125 struct dialog_color item_selected;
126 struct dialog_color tag;
127 struct dialog_color tag_selected;
128 struct dialog_color tag_key;
129 struct dialog_color tag_key_selected;
130 struct dialog_color check;
131 struct dialog_color check_selected;
132 struct dialog_color uarrow;
133 struct dialog_color darrow;
139 extern struct dialog_info dlg;
140 extern char dialog_input_result[];
141 extern int saved_x, saved_y; /* Needed in signal handler in mconf.c */
144 * Function prototypes
147 /* item list as used by checklist and menubox */
148 void item_reset(void);
149 void item_make(const char *fmt, ...);
150 void item_add_str(const char *fmt, ...);
151 void item_set_tag(char tag);
152 void item_set_data(void *p);
153 void item_set_selected(int val);
154 int item_activate_selected(void);
155 void *item_data(void);
158 /* item list manipulation for lxdialog use */
159 #define MAXITEMSTR 200
161 char str[MAXITEMSTR]; /* prompt displayed */
163 void *data; /* pointer to menu item - used by menubox+checklist */
164 int selected; /* Set to 1 by dialog_*() function if selected. */
167 /* list of lialog_items */
169 struct dialog_item node;
170 struct dialog_list *next;
173 extern struct dialog_list *item_cur;
174 extern struct dialog_list item_nil;
175 extern struct dialog_list *item_head;
177 int item_count(void);
178 void item_set(int n);
180 const char *item_str(void);
181 int item_is_selected(void);
182 int item_is_tag(char tag);
183 #define item_foreach() \
184 for (item_cur = item_head ? item_head: item_cur; \
185 item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
187 /* generic key handlers */
188 int on_key_esc(WINDOW *win);
189 int on_key_resize(void);
191 /* minimum (re)size values */
192 #define CHECKLIST_HEIGTH_MIN 6 /* For dialog_checklist() */
193 #define CHECKLIST_WIDTH_MIN 6
194 #define INPUTBOX_HEIGTH_MIN 2 /* For dialog_inputbox() */
195 #define INPUTBOX_WIDTH_MIN 2
196 #define MENUBOX_HEIGTH_MIN 15 /* For dialog_menu() */
197 #define MENUBOX_WIDTH_MIN 65
198 #define TEXTBOX_HEIGTH_MIN 8 /* For dialog_textbox() */
199 #define TEXTBOX_WIDTH_MIN 8
200 #define YESNO_HEIGTH_MIN 4 /* For dialog_yesno() */
201 #define YESNO_WIDTH_MIN 4
202 #define WINDOW_HEIGTH_MIN 19 /* For init_dialog() */
203 #define WINDOW_WIDTH_MIN 80
205 int init_dialog(const char *backtitle);
206 void set_dialog_backtitle(const char *backtitle);
207 void set_dialog_subtitles(struct subtitle_list *subtitles);
208 void end_dialog(int x, int y);
209 void attr_clear(WINDOW * win, int height, int width, chtype attr);
210 void dialog_clear(void);
211 void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
212 void print_button(WINDOW * win, const char *label, int y, int x, int selected);
213 void print_title(WINDOW *dialog, const char *title, int width);
214 void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
216 void draw_shadow(WINDOW * win, int y, int x, int height, int width);
218 int first_alpha(const char *string, const char *exempt);
219 int dialog_yesno(const char *title, const char *prompt, int height, int width);
220 int dialog_msgbox(const char *title, const char *prompt, int height,
221 int width, int pause);
224 typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void
226 int dialog_textbox(const char *title, char *tbuf, int initial_height,
227 int initial_width, int *keys, int *_vscroll, int *_hscroll,
228 update_text_fn update_text, void *data);
229 int dialog_menu(const char *title, const char *prompt,
230 const void *selected, int *s_scroll);
231 int dialog_checklist(const char *title, const char *prompt, int height,
232 int width, int list_height);
233 int dialog_inputbox(const char *title, const char *prompt, int height,
234 int width, const char *init);
237 * This is the base for fictitious keys, which activate
240 * Mouse-generated keys are the following:
241 * -- the first 32 are used as numbers, in addition to '0'-'9'
242 * -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
243 * -- uppercase chars are used to invoke the button (M_EVENT + 'O')
245 #define M_EVENT (KEY_MAX+1)