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