xref: /OK3568_Linux_fs/buildroot/support/kconfig/lxdialog/dialog.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  dialog.h -- common declarations for all dialog modules
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *  This program is free software; you can redistribute it and/or
7*4882a593Smuzhiyun  *  modify it under the terms of the GNU General Public License
8*4882a593Smuzhiyun  *  as published by the Free Software Foundation; either version 2
9*4882a593Smuzhiyun  *  of the License, or (at your option) any later version.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *  This program is distributed in the hope that it will be useful,
12*4882a593Smuzhiyun  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13*4882a593Smuzhiyun  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*4882a593Smuzhiyun  *  GNU General Public License for more details.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  *  You should have received a copy of the GNU General Public License
17*4882a593Smuzhiyun  *  along with this program; if not, write to the Free Software
18*4882a593Smuzhiyun  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*4882a593Smuzhiyun  */
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #include <sys/types.h>
22*4882a593Smuzhiyun #include <fcntl.h>
23*4882a593Smuzhiyun #include <unistd.h>
24*4882a593Smuzhiyun #include <ctype.h>
25*4882a593Smuzhiyun #include <stdlib.h>
26*4882a593Smuzhiyun #include <string.h>
27*4882a593Smuzhiyun #include <stdbool.h>
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #ifndef KBUILD_NO_NLS
30*4882a593Smuzhiyun # include <libintl.h>
31*4882a593Smuzhiyun #else
32*4882a593Smuzhiyun # define gettext(Msgid) ((const char *) (Msgid))
33*4882a593Smuzhiyun #endif
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #ifdef __sun__
36*4882a593Smuzhiyun #define CURS_MACROS
37*4882a593Smuzhiyun #endif
38*4882a593Smuzhiyun #include CURSES_LOC
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /*
41*4882a593Smuzhiyun  * Colors in ncurses 1.9.9e do not work properly since foreground and
42*4882a593Smuzhiyun  * background colors are OR'd rather than separately masked.  This version
43*4882a593Smuzhiyun  * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
44*4882a593Smuzhiyun  * with standard curses.  The simplest fix (to make this work with standard
45*4882a593Smuzhiyun  * curses) uses the wbkgdset() function, not used in the original hack.
46*4882a593Smuzhiyun  * Turn it off if we're building with 1.9.9e, since it just confuses things.
47*4882a593Smuzhiyun  */
48*4882a593Smuzhiyun #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
49*4882a593Smuzhiyun #define OLD_NCURSES 1
50*4882a593Smuzhiyun #undef  wbkgdset
51*4882a593Smuzhiyun #define wbkgdset(w,p)		/*nothing */
52*4882a593Smuzhiyun #else
53*4882a593Smuzhiyun #define OLD_NCURSES 0
54*4882a593Smuzhiyun #endif
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #define TR(params) _tracef params
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #define KEY_ESC 27
59*4882a593Smuzhiyun #define TAB 9
60*4882a593Smuzhiyun #define MAX_LEN 2048
61*4882a593Smuzhiyun #define BUF_SIZE (10*1024)
62*4882a593Smuzhiyun #define MIN(x,y) (x < y ? x : y)
63*4882a593Smuzhiyun #define MAX(x,y) (x > y ? x : y)
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun #ifndef ACS_ULCORNER
66*4882a593Smuzhiyun #define ACS_ULCORNER '+'
67*4882a593Smuzhiyun #endif
68*4882a593Smuzhiyun #ifndef ACS_LLCORNER
69*4882a593Smuzhiyun #define ACS_LLCORNER '+'
70*4882a593Smuzhiyun #endif
71*4882a593Smuzhiyun #ifndef ACS_URCORNER
72*4882a593Smuzhiyun #define ACS_URCORNER '+'
73*4882a593Smuzhiyun #endif
74*4882a593Smuzhiyun #ifndef ACS_LRCORNER
75*4882a593Smuzhiyun #define ACS_LRCORNER '+'
76*4882a593Smuzhiyun #endif
77*4882a593Smuzhiyun #ifndef ACS_HLINE
78*4882a593Smuzhiyun #define ACS_HLINE '-'
79*4882a593Smuzhiyun #endif
80*4882a593Smuzhiyun #ifndef ACS_VLINE
81*4882a593Smuzhiyun #define ACS_VLINE '|'
82*4882a593Smuzhiyun #endif
83*4882a593Smuzhiyun #ifndef ACS_LTEE
84*4882a593Smuzhiyun #define ACS_LTEE '+'
85*4882a593Smuzhiyun #endif
86*4882a593Smuzhiyun #ifndef ACS_RTEE
87*4882a593Smuzhiyun #define ACS_RTEE '+'
88*4882a593Smuzhiyun #endif
89*4882a593Smuzhiyun #ifndef ACS_UARROW
90*4882a593Smuzhiyun #define ACS_UARROW '^'
91*4882a593Smuzhiyun #endif
92*4882a593Smuzhiyun #ifndef ACS_DARROW
93*4882a593Smuzhiyun #define ACS_DARROW 'v'
94*4882a593Smuzhiyun #endif
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /* error return codes */
97*4882a593Smuzhiyun #define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun  *   Color definitions
101*4882a593Smuzhiyun  */
102*4882a593Smuzhiyun struct dialog_color {
103*4882a593Smuzhiyun 	chtype atr;	/* Color attribute */
104*4882a593Smuzhiyun 	int fg;		/* foreground */
105*4882a593Smuzhiyun 	int bg;		/* background */
106*4882a593Smuzhiyun 	int hl;		/* highlight this item */
107*4882a593Smuzhiyun };
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun struct subtitle_list {
110*4882a593Smuzhiyun 	struct subtitle_list *next;
111*4882a593Smuzhiyun 	const char *text;
112*4882a593Smuzhiyun };
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun struct dialog_info {
115*4882a593Smuzhiyun 	const char *backtitle;
116*4882a593Smuzhiyun 	struct subtitle_list *subtitles;
117*4882a593Smuzhiyun 	struct dialog_color screen;
118*4882a593Smuzhiyun 	struct dialog_color shadow;
119*4882a593Smuzhiyun 	struct dialog_color dialog;
120*4882a593Smuzhiyun 	struct dialog_color title;
121*4882a593Smuzhiyun 	struct dialog_color border;
122*4882a593Smuzhiyun 	struct dialog_color button_active;
123*4882a593Smuzhiyun 	struct dialog_color button_inactive;
124*4882a593Smuzhiyun 	struct dialog_color button_key_active;
125*4882a593Smuzhiyun 	struct dialog_color button_key_inactive;
126*4882a593Smuzhiyun 	struct dialog_color button_label_active;
127*4882a593Smuzhiyun 	struct dialog_color button_label_inactive;
128*4882a593Smuzhiyun 	struct dialog_color inputbox;
129*4882a593Smuzhiyun 	struct dialog_color inputbox_border;
130*4882a593Smuzhiyun 	struct dialog_color searchbox;
131*4882a593Smuzhiyun 	struct dialog_color searchbox_title;
132*4882a593Smuzhiyun 	struct dialog_color searchbox_border;
133*4882a593Smuzhiyun 	struct dialog_color position_indicator;
134*4882a593Smuzhiyun 	struct dialog_color menubox;
135*4882a593Smuzhiyun 	struct dialog_color menubox_border;
136*4882a593Smuzhiyun 	struct dialog_color item;
137*4882a593Smuzhiyun 	struct dialog_color item_selected;
138*4882a593Smuzhiyun 	struct dialog_color tag;
139*4882a593Smuzhiyun 	struct dialog_color tag_selected;
140*4882a593Smuzhiyun 	struct dialog_color tag_key;
141*4882a593Smuzhiyun 	struct dialog_color tag_key_selected;
142*4882a593Smuzhiyun 	struct dialog_color check;
143*4882a593Smuzhiyun 	struct dialog_color check_selected;
144*4882a593Smuzhiyun 	struct dialog_color uarrow;
145*4882a593Smuzhiyun 	struct dialog_color darrow;
146*4882a593Smuzhiyun };
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun /*
149*4882a593Smuzhiyun  * Global variables
150*4882a593Smuzhiyun  */
151*4882a593Smuzhiyun extern struct dialog_info dlg;
152*4882a593Smuzhiyun extern char dialog_input_result[];
153*4882a593Smuzhiyun extern int saved_x, saved_y;		/* Needed in signal handler in mconf.c */
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun /*
156*4882a593Smuzhiyun  * Function prototypes
157*4882a593Smuzhiyun  */
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /* item list as used by checklist and menubox */
160*4882a593Smuzhiyun void item_reset(void);
161*4882a593Smuzhiyun void item_make(const char *fmt, ...);
162*4882a593Smuzhiyun void item_add_str(const char *fmt, ...);
163*4882a593Smuzhiyun void item_set_tag(char tag);
164*4882a593Smuzhiyun void item_set_data(void *p);
165*4882a593Smuzhiyun void item_set_selected(int val);
166*4882a593Smuzhiyun int item_activate_selected(void);
167*4882a593Smuzhiyun void *item_data(void);
168*4882a593Smuzhiyun char item_tag(void);
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun /* item list manipulation for lxdialog use */
171*4882a593Smuzhiyun #define MAXITEMSTR 200
172*4882a593Smuzhiyun struct dialog_item {
173*4882a593Smuzhiyun 	char str[MAXITEMSTR];	/* prompt displayed */
174*4882a593Smuzhiyun 	char tag;
175*4882a593Smuzhiyun 	void *data;	/* pointer to menu item - used by menubox+checklist */
176*4882a593Smuzhiyun 	int selected;	/* Set to 1 by dialog_*() function if selected. */
177*4882a593Smuzhiyun };
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun /* list of lialog_items */
180*4882a593Smuzhiyun struct dialog_list {
181*4882a593Smuzhiyun 	struct dialog_item node;
182*4882a593Smuzhiyun 	struct dialog_list *next;
183*4882a593Smuzhiyun };
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun extern struct dialog_list *item_cur;
186*4882a593Smuzhiyun extern struct dialog_list item_nil;
187*4882a593Smuzhiyun extern struct dialog_list *item_head;
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun int item_count(void);
190*4882a593Smuzhiyun void item_set(int n);
191*4882a593Smuzhiyun int item_n(void);
192*4882a593Smuzhiyun const char *item_str(void);
193*4882a593Smuzhiyun int item_is_selected(void);
194*4882a593Smuzhiyun int item_is_tag(char tag);
195*4882a593Smuzhiyun #define item_foreach() \
196*4882a593Smuzhiyun 	for (item_cur = item_head ? item_head: item_cur; \
197*4882a593Smuzhiyun 	     item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun /* generic key handlers */
200*4882a593Smuzhiyun int on_key_esc(WINDOW *win);
201*4882a593Smuzhiyun int on_key_resize(void);
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun /* minimum (re)size values */
204*4882a593Smuzhiyun #define CHECKLIST_HEIGTH_MIN 6	/* For dialog_checklist() */
205*4882a593Smuzhiyun #define CHECKLIST_WIDTH_MIN 6
206*4882a593Smuzhiyun #define INPUTBOX_HEIGTH_MIN 2	/* For dialog_inputbox() */
207*4882a593Smuzhiyun #define INPUTBOX_WIDTH_MIN 2
208*4882a593Smuzhiyun #define MENUBOX_HEIGTH_MIN 15	/* For dialog_menu() */
209*4882a593Smuzhiyun #define MENUBOX_WIDTH_MIN 65
210*4882a593Smuzhiyun #define TEXTBOX_HEIGTH_MIN 8	/* For dialog_textbox() */
211*4882a593Smuzhiyun #define TEXTBOX_WIDTH_MIN 8
212*4882a593Smuzhiyun #define YESNO_HEIGTH_MIN 4	/* For dialog_yesno() */
213*4882a593Smuzhiyun #define YESNO_WIDTH_MIN 4
214*4882a593Smuzhiyun #define WINDOW_HEIGTH_MIN 19	/* For init_dialog() */
215*4882a593Smuzhiyun #define WINDOW_WIDTH_MIN 80
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun int init_dialog(const char *backtitle);
218*4882a593Smuzhiyun void set_dialog_backtitle(const char *backtitle);
219*4882a593Smuzhiyun void set_dialog_subtitles(struct subtitle_list *subtitles);
220*4882a593Smuzhiyun void end_dialog(int x, int y);
221*4882a593Smuzhiyun void attr_clear(WINDOW * win, int height, int width, chtype attr);
222*4882a593Smuzhiyun void dialog_clear(void);
223*4882a593Smuzhiyun void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
224*4882a593Smuzhiyun void print_button(WINDOW * win, const char *label, int y, int x, int selected);
225*4882a593Smuzhiyun void print_title(WINDOW *dialog, const char *title, int width);
226*4882a593Smuzhiyun void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
227*4882a593Smuzhiyun 	      chtype border);
228*4882a593Smuzhiyun void draw_shadow(WINDOW * win, int y, int x, int height, int width);
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun int first_alpha(const char *string, const char *exempt);
231*4882a593Smuzhiyun int dialog_yesno(const char *title, const char *prompt, int height, int width);
232*4882a593Smuzhiyun int dialog_msgbox(const char *title, const char *prompt, int height,
233*4882a593Smuzhiyun 		  int width, int pause);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void
237*4882a593Smuzhiyun 			       *_data);
238*4882a593Smuzhiyun int dialog_textbox(const char *title, char *tbuf, int initial_height,
239*4882a593Smuzhiyun 		   int initial_width, int *keys, int *_vscroll, int *_hscroll,
240*4882a593Smuzhiyun 		   update_text_fn update_text, void *data);
241*4882a593Smuzhiyun int dialog_menu(const char *title, const char *prompt,
242*4882a593Smuzhiyun 		const void *selected, int *s_scroll);
243*4882a593Smuzhiyun int dialog_checklist(const char *title, const char *prompt, int height,
244*4882a593Smuzhiyun 		     int width, int list_height);
245*4882a593Smuzhiyun int dialog_inputbox(const char *title, const char *prompt, int height,
246*4882a593Smuzhiyun 		    int width, const char *init);
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun /*
249*4882a593Smuzhiyun  * This is the base for fictitious keys, which activate
250*4882a593Smuzhiyun  * the buttons.
251*4882a593Smuzhiyun  *
252*4882a593Smuzhiyun  * Mouse-generated keys are the following:
253*4882a593Smuzhiyun  *   -- the first 32 are used as numbers, in addition to '0'-'9'
254*4882a593Smuzhiyun  *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
255*4882a593Smuzhiyun  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
256*4882a593Smuzhiyun  */
257*4882a593Smuzhiyun #define M_EVENT (KEY_MAX+1)
258