Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  *  dialog.h -- common declarations for all dialog modules
0004  *
0005  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
0006  */
0007 
0008 #include <sys/types.h>
0009 #include <fcntl.h>
0010 #include <unistd.h>
0011 #include <ctype.h>
0012 #include <stdlib.h>
0013 #include <string.h>
0014 #include <stdbool.h>
0015 
0016 #ifdef __sun__
0017 #define CURS_MACROS
0018 #endif
0019 #include <ncurses.h>
0020 
0021 /*
0022  * Colors in ncurses 1.9.9e do not work properly since foreground and
0023  * background colors are OR'd rather than separately masked.  This version
0024  * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
0025  * with standard curses.  The simplest fix (to make this work with standard
0026  * curses) uses the wbkgdset() function, not used in the original hack.
0027  * Turn it off if we're building with 1.9.9e, since it just confuses things.
0028  */
0029 #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
0030 #define OLD_NCURSES 1
0031 #undef  wbkgdset
0032 #define wbkgdset(w,p)       /*nothing */
0033 #else
0034 #define OLD_NCURSES 0
0035 #endif
0036 
0037 #define TR(params) _tracef params
0038 
0039 #define KEY_ESC 27
0040 #define TAB 9
0041 #define MAX_LEN 2048
0042 #define BUF_SIZE (10*1024)
0043 #define MIN(x,y) (x < y ? x : y)
0044 #define MAX(x,y) (x > y ? x : y)
0045 
0046 #ifndef ACS_ULCORNER
0047 #define ACS_ULCORNER '+'
0048 #endif
0049 #ifndef ACS_LLCORNER
0050 #define ACS_LLCORNER '+'
0051 #endif
0052 #ifndef ACS_URCORNER
0053 #define ACS_URCORNER '+'
0054 #endif
0055 #ifndef ACS_LRCORNER
0056 #define ACS_LRCORNER '+'
0057 #endif
0058 #ifndef ACS_HLINE
0059 #define ACS_HLINE '-'
0060 #endif
0061 #ifndef ACS_VLINE
0062 #define ACS_VLINE '|'
0063 #endif
0064 #ifndef ACS_LTEE
0065 #define ACS_LTEE '+'
0066 #endif
0067 #ifndef ACS_RTEE
0068 #define ACS_RTEE '+'
0069 #endif
0070 #ifndef ACS_UARROW
0071 #define ACS_UARROW '^'
0072 #endif
0073 #ifndef ACS_DARROW
0074 #define ACS_DARROW 'v'
0075 #endif
0076 
0077 /* error return codes */
0078 #define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
0079 
0080 /*
0081  *   Color definitions
0082  */
0083 struct dialog_color {
0084     chtype atr; /* Color attribute */
0085     int fg;     /* foreground */
0086     int bg;     /* background */
0087     int hl;     /* highlight this item */
0088 };
0089 
0090 struct subtitle_list {
0091     struct subtitle_list *next;
0092     const char *text;
0093 };
0094 
0095 struct dialog_info {
0096     const char *backtitle;
0097     struct subtitle_list *subtitles;
0098     struct dialog_color screen;
0099     struct dialog_color shadow;
0100     struct dialog_color dialog;
0101     struct dialog_color title;
0102     struct dialog_color border;
0103     struct dialog_color button_active;
0104     struct dialog_color button_inactive;
0105     struct dialog_color button_key_active;
0106     struct dialog_color button_key_inactive;
0107     struct dialog_color button_label_active;
0108     struct dialog_color button_label_inactive;
0109     struct dialog_color inputbox;
0110     struct dialog_color inputbox_border;
0111     struct dialog_color searchbox;
0112     struct dialog_color searchbox_title;
0113     struct dialog_color searchbox_border;
0114     struct dialog_color position_indicator;
0115     struct dialog_color menubox;
0116     struct dialog_color menubox_border;
0117     struct dialog_color item;
0118     struct dialog_color item_selected;
0119     struct dialog_color tag;
0120     struct dialog_color tag_selected;
0121     struct dialog_color tag_key;
0122     struct dialog_color tag_key_selected;
0123     struct dialog_color check;
0124     struct dialog_color check_selected;
0125     struct dialog_color uarrow;
0126     struct dialog_color darrow;
0127 };
0128 
0129 /*
0130  * Global variables
0131  */
0132 extern struct dialog_info dlg;
0133 extern char dialog_input_result[];
0134 extern int saved_x, saved_y;        /* Needed in signal handler in mconf.c */
0135 
0136 /*
0137  * Function prototypes
0138  */
0139 
0140 /* item list as used by checklist and menubox */
0141 void item_reset(void);
0142 void item_make(const char *fmt, ...);
0143 void item_add_str(const char *fmt, ...);
0144 void item_set_tag(char tag);
0145 void item_set_data(void *p);
0146 void item_set_selected(int val);
0147 int item_activate_selected(void);
0148 void *item_data(void);
0149 char item_tag(void);
0150 
0151 /* item list manipulation for lxdialog use */
0152 #define MAXITEMSTR 200
0153 struct dialog_item {
0154     char str[MAXITEMSTR];   /* prompt displayed */
0155     char tag;
0156     void *data; /* pointer to menu item - used by menubox+checklist */
0157     int selected;   /* Set to 1 by dialog_*() function if selected. */
0158 };
0159 
0160 /* list of lialog_items */
0161 struct dialog_list {
0162     struct dialog_item node;
0163     struct dialog_list *next;
0164 };
0165 
0166 extern struct dialog_list *item_cur;
0167 extern struct dialog_list item_nil;
0168 extern struct dialog_list *item_head;
0169 
0170 int item_count(void);
0171 void item_set(int n);
0172 int item_n(void);
0173 const char *item_str(void);
0174 int item_is_selected(void);
0175 int item_is_tag(char tag);
0176 #define item_foreach() \
0177     for (item_cur = item_head ? item_head: item_cur; \
0178          item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
0179 
0180 /* generic key handlers */
0181 int on_key_esc(WINDOW *win);
0182 int on_key_resize(void);
0183 
0184 /* minimum (re)size values */
0185 #define CHECKLIST_HEIGTH_MIN 6  /* For dialog_checklist() */
0186 #define CHECKLIST_WIDTH_MIN 6
0187 #define INPUTBOX_HEIGTH_MIN 2   /* For dialog_inputbox() */
0188 #define INPUTBOX_WIDTH_MIN 2
0189 #define MENUBOX_HEIGTH_MIN 15   /* For dialog_menu() */
0190 #define MENUBOX_WIDTH_MIN 65
0191 #define TEXTBOX_HEIGTH_MIN 8    /* For dialog_textbox() */
0192 #define TEXTBOX_WIDTH_MIN 8
0193 #define YESNO_HEIGTH_MIN 4  /* For dialog_yesno() */
0194 #define YESNO_WIDTH_MIN 4
0195 #define WINDOW_HEIGTH_MIN 19    /* For init_dialog() */
0196 #define WINDOW_WIDTH_MIN 80
0197 
0198 int init_dialog(const char *backtitle);
0199 void set_dialog_backtitle(const char *backtitle);
0200 void set_dialog_subtitles(struct subtitle_list *subtitles);
0201 void end_dialog(int x, int y);
0202 void attr_clear(WINDOW * win, int height, int width, chtype attr);
0203 void dialog_clear(void);
0204 void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
0205 void print_button(WINDOW * win, const char *label, int y, int x, int selected);
0206 void print_title(WINDOW *dialog, const char *title, int width);
0207 void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
0208           chtype border);
0209 void draw_shadow(WINDOW * win, int y, int x, int height, int width);
0210 
0211 int first_alpha(const char *string, const char *exempt);
0212 int dialog_yesno(const char *title, const char *prompt, int height, int width);
0213 int dialog_msgbox(const char *title, const char *prompt, int height,
0214           int width, int pause);
0215 
0216 
0217 typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void
0218                    *_data);
0219 int dialog_textbox(const char *title, char *tbuf, int initial_height,
0220            int initial_width, int *keys, int *_vscroll, int *_hscroll,
0221            update_text_fn update_text, void *data);
0222 int dialog_menu(const char *title, const char *prompt,
0223         const void *selected, int *s_scroll);
0224 int dialog_checklist(const char *title, const char *prompt, int height,
0225              int width, int list_height);
0226 int dialog_inputbox(const char *title, const char *prompt, int height,
0227             int width, const char *init);
0228 
0229 /*
0230  * This is the base for fictitious keys, which activate
0231  * the buttons.
0232  *
0233  * Mouse-generated keys are the following:
0234  *   -- the first 32 are used as numbers, in addition to '0'-'9'
0235  *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
0236  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
0237  */
0238 #define M_EVENT (KEY_MAX+1)