0001
0002
0003
0004
0005
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
0023
0024
0025
0026
0027
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)
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
0078 #define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
0079
0080
0081
0082
0083 struct dialog_color {
0084 chtype atr;
0085 int fg;
0086 int bg;
0087 int hl;
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
0131
0132 extern struct dialog_info dlg;
0133 extern char dialog_input_result[];
0134 extern int saved_x, saved_y;
0135
0136
0137
0138
0139
0140
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
0152 #define MAXITEMSTR 200
0153 struct dialog_item {
0154 char str[MAXITEMSTR];
0155 char tag;
0156 void *data;
0157 int selected;
0158 };
0159
0160
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
0181 int on_key_esc(WINDOW *win);
0182 int on_key_resize(void);
0183
0184
0185 #define CHECKLIST_HEIGTH_MIN 6
0186 #define CHECKLIST_WIDTH_MIN 6
0187 #define INPUTBOX_HEIGTH_MIN 2
0188 #define INPUTBOX_WIDTH_MIN 2
0189 #define MENUBOX_HEIGTH_MIN 15
0190 #define MENUBOX_WIDTH_MIN 65
0191 #define TEXTBOX_HEIGTH_MIN 8
0192 #define TEXTBOX_WIDTH_MIN 8
0193 #define YESNO_HEIGTH_MIN 4
0194 #define YESNO_WIDTH_MIN 4
0195 #define WINDOW_HEIGTH_MIN 19
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
0231
0232
0233
0234
0235
0236
0237
0238 #define M_EVENT (KEY_MAX+1)