kconfig/lxdialog/dialog.h
changeset 723 bea5656eb1d1
child 943 1cca90ce0481
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/kconfig/lxdialog/dialog.h	Fri Jul 25 15:54:52 2008 +0000
     1.3 @@ -0,0 +1,224 @@
     1.4 +/*
     1.5 + *  dialog.h -- common declarations for all dialog modules
     1.6 + *
     1.7 + *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
     1.8 + *
     1.9 + *  This program is free software; you can redistribute it and/or
    1.10 + *  modify it under the terms of the GNU General Public License
    1.11 + *  as published by the Free Software Foundation; either version 2
    1.12 + *  of the License, or (at your option) any later version.
    1.13 + *
    1.14 + *  This program is distributed in the hope that it will be useful,
    1.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 + *  GNU General Public License for more details.
    1.18 + *
    1.19 + *  You should have received a copy of the GNU General Public License
    1.20 + *  along with this program; if not, write to the Free Software
    1.21 + *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    1.22 + */
    1.23 +
    1.24 +#include <sys/types.h>
    1.25 +#include <fcntl.h>
    1.26 +#include <unistd.h>
    1.27 +#include <ctype.h>
    1.28 +#include <stdlib.h>
    1.29 +#include <string.h>
    1.30 +#include <stdbool.h>
    1.31 +
    1.32 +#ifdef __sun__
    1.33 +#define CURS_MACROS
    1.34 +#endif
    1.35 +#include CURSES_LOC
    1.36 +
    1.37 +/*
    1.38 + * Colors in ncurses 1.9.9e do not work properly since foreground and
    1.39 + * background colors are OR'd rather than separately masked.  This version
    1.40 + * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
    1.41 + * with standard curses.  The simplest fix (to make this work with standard
    1.42 + * curses) uses the wbkgdset() function, not used in the original hack.
    1.43 + * Turn it off if we're building with 1.9.9e, since it just confuses things.
    1.44 + */
    1.45 +#if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
    1.46 +#define OLD_NCURSES 1
    1.47 +#undef  wbkgdset
    1.48 +#define wbkgdset(w,p)		/*nothing */
    1.49 +#else
    1.50 +#define OLD_NCURSES 0
    1.51 +#endif
    1.52 +
    1.53 +#define TR(params) _tracef params
    1.54 +
    1.55 +#define KEY_ESC 27
    1.56 +#define TAB 9
    1.57 +#define MAX_LEN 2048
    1.58 +#define BUF_SIZE (10*1024)
    1.59 +#define MIN(x,y) (x < y ? x : y)
    1.60 +#define MAX(x,y) (x > y ? x : y)
    1.61 +
    1.62 +#ifndef ACS_ULCORNER
    1.63 +#define ACS_ULCORNER '+'
    1.64 +#endif
    1.65 +#ifndef ACS_LLCORNER
    1.66 +#define ACS_LLCORNER '+'
    1.67 +#endif
    1.68 +#ifndef ACS_URCORNER
    1.69 +#define ACS_URCORNER '+'
    1.70 +#endif
    1.71 +#ifndef ACS_LRCORNER
    1.72 +#define ACS_LRCORNER '+'
    1.73 +#endif
    1.74 +#ifndef ACS_HLINE
    1.75 +#define ACS_HLINE '-'
    1.76 +#endif
    1.77 +#ifndef ACS_VLINE
    1.78 +#define ACS_VLINE '|'
    1.79 +#endif
    1.80 +#ifndef ACS_LTEE
    1.81 +#define ACS_LTEE '+'
    1.82 +#endif
    1.83 +#ifndef ACS_RTEE
    1.84 +#define ACS_RTEE '+'
    1.85 +#endif
    1.86 +#ifndef ACS_UARROW
    1.87 +#define ACS_UARROW '^'
    1.88 +#endif
    1.89 +#ifndef ACS_DARROW
    1.90 +#define ACS_DARROW 'v'
    1.91 +#endif
    1.92 +
    1.93 +/* error return codes */
    1.94 +#define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
    1.95 +
    1.96 +/*
    1.97 + *   Color definitions
    1.98 + */
    1.99 +struct dialog_color {
   1.100 +	chtype atr;	/* Color attribute */
   1.101 +	int fg;		/* foreground */
   1.102 +	int bg;		/* background */
   1.103 +	int hl;		/* highlight this item */
   1.104 +};
   1.105 +
   1.106 +struct dialog_info {
   1.107 +	const char *backtitle;
   1.108 +	struct dialog_color screen;
   1.109 +	struct dialog_color shadow;
   1.110 +	struct dialog_color dialog;
   1.111 +	struct dialog_color title;
   1.112 +	struct dialog_color border;
   1.113 +	struct dialog_color button_active;
   1.114 +	struct dialog_color button_inactive;
   1.115 +	struct dialog_color button_key_active;
   1.116 +	struct dialog_color button_key_inactive;
   1.117 +	struct dialog_color button_label_active;
   1.118 +	struct dialog_color button_label_inactive;
   1.119 +	struct dialog_color inputbox;
   1.120 +	struct dialog_color inputbox_border;
   1.121 +	struct dialog_color searchbox;
   1.122 +	struct dialog_color searchbox_title;
   1.123 +	struct dialog_color searchbox_border;
   1.124 +	struct dialog_color position_indicator;
   1.125 +	struct dialog_color menubox;
   1.126 +	struct dialog_color menubox_border;
   1.127 +	struct dialog_color item;
   1.128 +	struct dialog_color item_selected;
   1.129 +	struct dialog_color tag;
   1.130 +	struct dialog_color tag_selected;
   1.131 +	struct dialog_color tag_key;
   1.132 +	struct dialog_color tag_key_selected;
   1.133 +	struct dialog_color check;
   1.134 +	struct dialog_color check_selected;
   1.135 +	struct dialog_color uarrow;
   1.136 +	struct dialog_color darrow;
   1.137 +};
   1.138 +
   1.139 +/*
   1.140 + * Global variables
   1.141 + */
   1.142 +extern struct dialog_info dlg;
   1.143 +extern char dialog_input_result[];
   1.144 +
   1.145 +/*
   1.146 + * Function prototypes
   1.147 + */
   1.148 +
   1.149 +/* item list as used by checklist and menubox */
   1.150 +void item_reset(void);
   1.151 +void item_make(const char *fmt, ...);
   1.152 +void item_add_str(const char *fmt, ...);
   1.153 +void item_set_tag(char tag);
   1.154 +void item_set_data(void *p);
   1.155 +void item_set_selected(int val);
   1.156 +int item_activate_selected(void);
   1.157 +void *item_data(void);
   1.158 +char item_tag(void);
   1.159 +
   1.160 +/* item list manipulation for lxdialog use */
   1.161 +#define MAXITEMSTR 200
   1.162 +struct dialog_item {
   1.163 +	char str[MAXITEMSTR];	/* promtp displayed */
   1.164 +	char tag;
   1.165 +	void *data;	/* pointer to menu item - used by menubox+checklist */
   1.166 +	int selected;	/* Set to 1 by dialog_*() function if selected. */
   1.167 +};
   1.168 +
   1.169 +/* list of lialog_items */
   1.170 +struct dialog_list {
   1.171 +	struct dialog_item node;
   1.172 +	struct dialog_list *next;
   1.173 +};
   1.174 +
   1.175 +extern struct dialog_list *item_cur;
   1.176 +extern struct dialog_list item_nil;
   1.177 +extern struct dialog_list *item_head;
   1.178 +
   1.179 +int item_count(void);
   1.180 +void item_set(int n);
   1.181 +int item_n(void);
   1.182 +const char *item_str(void);
   1.183 +int item_is_selected(void);
   1.184 +int item_is_tag(char tag);
   1.185 +#define item_foreach() \
   1.186 +	for (item_cur = item_head ? item_head: item_cur; \
   1.187 +	     item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
   1.188 +
   1.189 +/* generic key handlers */
   1.190 +int on_key_esc(WINDOW *win);
   1.191 +int on_key_resize(void);
   1.192 +
   1.193 +void init_dialog(const char *backtitle);
   1.194 +void reset_dialog(void);
   1.195 +void end_dialog(void);
   1.196 +void attr_clear(WINDOW * win, int height, int width, chtype attr);
   1.197 +void dialog_clear(void);
   1.198 +void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
   1.199 +void print_button(WINDOW * win, const char *label, int y, int x, int selected);
   1.200 +void print_title(WINDOW *dialog, const char *title, int width);
   1.201 +void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
   1.202 +	      chtype border);
   1.203 +void draw_shadow(WINDOW * win, int y, int x, int height, int width);
   1.204 +
   1.205 +int first_alpha(const char *string, const char *exempt);
   1.206 +int dialog_yesno(const char *title, const char *prompt, int height, int width);
   1.207 +int dialog_msgbox(const char *title, const char *prompt, int height,
   1.208 +		  int width, int pause);
   1.209 +int dialog_textbox(const char *title, const char *file, int height, int width);
   1.210 +int dialog_menu(const char *title, const char *prompt,
   1.211 +		const void *selected, int *s_scroll);
   1.212 +int dialog_checklist(const char *title, const char *prompt, int height,
   1.213 +		     int width, int list_height);
   1.214 +extern char dialog_input_result[];
   1.215 +int dialog_inputbox(const char *title, const char *prompt, int height,
   1.216 +		    int width, const char *init);
   1.217 +
   1.218 +/*
   1.219 + * This is the base for fictitious keys, which activate
   1.220 + * the buttons.
   1.221 + *
   1.222 + * Mouse-generated keys are the following:
   1.223 + *   -- the first 32 are used as numbers, in addition to '0'-'9'
   1.224 + *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
   1.225 + *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
   1.226 + */
   1.227 +#define M_EVENT (KEY_MAX+1)