yann@1: /* yann@1: * dialog.h -- common declarations for all dialog modules yann@1: * yann@1: * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) yann@1: * yann@1: * This program is free software; you can redistribute it and/or yann@1: * modify it under the terms of the GNU General Public License yann@1: * as published by the Free Software Foundation; either version 2 yann@1: * of the License, or (at your option) any later version. yann@1: * yann@1: * This program is distributed in the hope that it will be useful, yann@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of yann@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the yann@1: * GNU General Public License for more details. yann@1: * yann@1: * You should have received a copy of the GNU General Public License yann@1: * along with this program; if not, write to the Free Software yann@1: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. yann@1: */ yann@1: yann@1: #include yann@1: #include yann@1: #include yann@1: #include yann@1: #include yann@1: #include yann@1: #include yann@1: yann@943: #ifndef KBUILD_NO_NLS yann@943: # include yann@943: #else yann@943: # define gettext(Msgid) ((const char *) (Msgid)) yann@943: #endif yann@943: yann@1: #ifdef __sun__ yann@1: #define CURS_MACROS yann@1: #endif yann@1: #include CURSES_LOC yann@1: yann@1: /* yann@1: * Colors in ncurses 1.9.9e do not work properly since foreground and yann@1: * background colors are OR'd rather than separately masked. This version yann@1: * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible yann@1: * with standard curses. The simplest fix (to make this work with standard yann@1: * curses) uses the wbkgdset() function, not used in the original hack. yann@1: * Turn it off if we're building with 1.9.9e, since it just confuses things. yann@1: */ yann@1: #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE) yann@1: #define OLD_NCURSES 1 yann@1: #undef wbkgdset yann@1: #define wbkgdset(w,p) /*nothing */ yann@1: #else yann@1: #define OLD_NCURSES 0 yann@1: #endif yann@1: yann@1: #define TR(params) _tracef params yann@1: yann@1: #define KEY_ESC 27 yann@1: #define TAB 9 yann@1: #define MAX_LEN 2048 yann@1: #define BUF_SIZE (10*1024) yann@1: #define MIN(x,y) (x < y ? x : y) yann@1: #define MAX(x,y) (x > y ? x : y) yann@1: yann@1: #ifndef ACS_ULCORNER yann@1: #define ACS_ULCORNER '+' yann@1: #endif yann@1: #ifndef ACS_LLCORNER yann@1: #define ACS_LLCORNER '+' yann@1: #endif yann@1: #ifndef ACS_URCORNER yann@1: #define ACS_URCORNER '+' yann@1: #endif yann@1: #ifndef ACS_LRCORNER yann@1: #define ACS_LRCORNER '+' yann@1: #endif yann@1: #ifndef ACS_HLINE yann@1: #define ACS_HLINE '-' yann@1: #endif yann@1: #ifndef ACS_VLINE yann@1: #define ACS_VLINE '|' yann@1: #endif yann@1: #ifndef ACS_LTEE yann@1: #define ACS_LTEE '+' yann@1: #endif yann@1: #ifndef ACS_RTEE yann@1: #define ACS_RTEE '+' yann@1: #endif yann@1: #ifndef ACS_UARROW yann@1: #define ACS_UARROW '^' yann@1: #endif yann@1: #ifndef ACS_DARROW yann@1: #define ACS_DARROW 'v' yann@1: #endif yann@1: yann@1: /* error return codes */ yann@1: #define ERRDISPLAYTOOSMALL (KEY_MAX + 1) yann@1: yann@1: /* yann@1: * Color definitions yann@1: */ yann@1: struct dialog_color { yann@1: chtype atr; /* Color attribute */ yann@1: int fg; /* foreground */ yann@1: int bg; /* background */ yann@1: int hl; /* highlight this item */ yann@1: }; yann@1: yann@1: struct dialog_info { yann@1: const char *backtitle; yann@1: struct dialog_color screen; yann@1: struct dialog_color shadow; yann@1: struct dialog_color dialog; yann@1: struct dialog_color title; yann@1: struct dialog_color border; yann@1: struct dialog_color button_active; yann@1: struct dialog_color button_inactive; yann@1: struct dialog_color button_key_active; yann@1: struct dialog_color button_key_inactive; yann@1: struct dialog_color button_label_active; yann@1: struct dialog_color button_label_inactive; yann@1: struct dialog_color inputbox; yann@1: struct dialog_color inputbox_border; yann@1: struct dialog_color searchbox; yann@1: struct dialog_color searchbox_title; yann@1: struct dialog_color searchbox_border; yann@1: struct dialog_color position_indicator; yann@1: struct dialog_color menubox; yann@1: struct dialog_color menubox_border; yann@1: struct dialog_color item; yann@1: struct dialog_color item_selected; yann@1: struct dialog_color tag; yann@1: struct dialog_color tag_selected; yann@1: struct dialog_color tag_key; yann@1: struct dialog_color tag_key_selected; yann@1: struct dialog_color check; yann@1: struct dialog_color check_selected; yann@1: struct dialog_color uarrow; yann@1: struct dialog_color darrow; yann@1: }; yann@1: yann@1: /* yann@1: * Global variables yann@1: */ yann@1: extern struct dialog_info dlg; yann@1: extern char dialog_input_result[]; yann@1: yann@1: /* yann@1: * Function prototypes yann@1: */ yann@1: yann@1: /* item list as used by checklist and menubox */ yann@1: void item_reset(void); yann@1: void item_make(const char *fmt, ...); yann@1: void item_add_str(const char *fmt, ...); yann@1: void item_set_tag(char tag); yann@1: void item_set_data(void *p); yann@1: void item_set_selected(int val); yann@1: int item_activate_selected(void); yann@1: void *item_data(void); yann@1: char item_tag(void); yann@1: yann@1: /* item list manipulation for lxdialog use */ yann@1: #define MAXITEMSTR 200 yann@1: struct dialog_item { yann@1: char str[MAXITEMSTR]; /* promtp displayed */ yann@1: char tag; yann@1: void *data; /* pointer to menu item - used by menubox+checklist */ yann@1: int selected; /* Set to 1 by dialog_*() function if selected. */ yann@1: }; yann@1: yann@1: /* list of lialog_items */ yann@1: struct dialog_list { yann@1: struct dialog_item node; yann@1: struct dialog_list *next; yann@1: }; yann@1: yann@1: extern struct dialog_list *item_cur; yann@1: extern struct dialog_list item_nil; yann@1: extern struct dialog_list *item_head; yann@1: yann@1: int item_count(void); yann@1: void item_set(int n); yann@1: int item_n(void); yann@1: const char *item_str(void); yann@1: int item_is_selected(void); yann@1: int item_is_tag(char tag); yann@1: #define item_foreach() \ yann@1: for (item_cur = item_head ? item_head: item_cur; \ yann@1: item_cur && (item_cur != &item_nil); item_cur = item_cur->next) yann@1: yann@1: /* generic key handlers */ yann@1: int on_key_esc(WINDOW *win); yann@1: int on_key_resize(void); yann@1: yann@943: int init_dialog(const char *backtitle); yann@943: void set_dialog_backtitle(const char *backtitle); yann@943: void end_dialog(int x, int y); yann@1: void attr_clear(WINDOW * win, int height, int width, chtype attr); yann@1: void dialog_clear(void); yann@1: void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x); yann@1: void print_button(WINDOW * win, const char *label, int y, int x, int selected); yann@1: void print_title(WINDOW *dialog, const char *title, int width); yann@1: void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box, yann@1: chtype border); yann@1: void draw_shadow(WINDOW * win, int y, int x, int height, int width); yann@1: yann@1: int first_alpha(const char *string, const char *exempt); yann@1: int dialog_yesno(const char *title, const char *prompt, int height, int width); yann@1: int dialog_msgbox(const char *title, const char *prompt, int height, yann@1: int width, int pause); yann@1: int dialog_textbox(const char *title, const char *file, int height, int width); yann@1: int dialog_menu(const char *title, const char *prompt, yann@1: const void *selected, int *s_scroll); yann@1: int dialog_checklist(const char *title, const char *prompt, int height, yann@1: int width, int list_height); yann@1: extern char dialog_input_result[]; yann@1: int dialog_inputbox(const char *title, const char *prompt, int height, yann@1: int width, const char *init); yann@1: yann@1: /* yann@1: * This is the base for fictitious keys, which activate yann@1: * the buttons. yann@1: * yann@1: * Mouse-generated keys are the following: yann@1: * -- the first 32 are used as numbers, in addition to '0'-'9' yann@1: * -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o') yann@1: * -- uppercase chars are used to invoke the button (M_EVENT + 'O') yann@1: */ yann@1: #define M_EVENT (KEY_MAX+1)