1 #ifndef EL__BFU_INPFIELD_H 2 #define EL__BFU_INPFIELD_H 3 4 #include "bfu/common.h" 5 #include "util/memlist.h" 6 #include "util/lists.h" 7 #include "util/align.h" 8 9 10 struct dialog; 11 struct dialog_data; 12 struct input_history; 13 struct session; 14 struct terminal; 15 struct widget_data; 16 17 enum inpfield_flags { 18 INPFIELD_NONE = 0, /* Field label on first line, value on next one. */ 19 INPFIELD_FLOAT = 1, /* Field label followed by ':' and value on the same line. */ 20 INPFIELD_FLOAT2 = 2, /* Field label followed by value on the same line. */ 21 }; 22 23 struct widget_info_field { 24 int min; 25 int max; 26 struct input_history *history; 27 enum inpfield_flags flags; 28 }; 29 30 struct widget_data_info_field { 31 int vpos; 32 int cpos; 33 struct list_head history; 34 struct input_history_entry *cur_hist; 35 }; 36 37 void 38 add_dlg_field_do(struct dialog *dlg, enum widget_type type, unsigned char *label, 39 int min, int max, widget_handler_T *handler, 40 int data_len, void *data, 41 struct input_history *history, enum inpfield_flags flags); 42 43 #define add_dlg_field(dlg, label, min, max, handler, len, field, history) \ 44 add_dlg_field_do(dlg, WIDGET_FIELD, label, min, max, handler, len, field, history, INPFIELD_NONE) 45 46 #define add_dlg_field_float(dlg, label, min, max, handler, len, field, history) \ 47 add_dlg_field_do(dlg, WIDGET_FIELD, label, min, max, handler, len, field, history, INPFIELD_FLOAT) 48 49 #define add_dlg_field_float2(dlg, label, min, max, handler, len, field, history) \ 50 add_dlg_field_do(dlg, WIDGET_FIELD, label, min, max, handler, len, field, history, INPFIELD_FLOAT2) 51 52 #define add_dlg_field_pass(dlg, label, min, max, handler, len, field) \ 53 add_dlg_field_do(dlg, WIDGET_FIELD_PASS, label, min, max, handler, len, field, NULL, INPFIELD_NONE) 54 55 #define add_dlg_field_float_pass(dlg, label, min, max, handler, len, field) \ 56 add_dlg_field_do(dlg, WIDGET_FIELD_PASS, label, min, max, handler, len, field, NULL, INPFIELD_FLOAT) 57 58 59 extern struct widget_ops field_ops; 60 extern struct widget_ops field_pass_ops; 61 62 widget_handler_status_T check_number(struct dialog_data *, struct widget_data *); 63 widget_handler_status_T check_nonempty(struct dialog_data *, struct widget_data *); 64 65 void dlg_format_field(struct terminal *, struct widget_data *, int, int *, int, int *, enum format_align); 66 67 void input_field(struct terminal *, struct memory_list *, int, unsigned char *, 68 unsigned char *, unsigned char *, unsigned char *, void *, 69 struct input_history *, int, unsigned char *, int, int, 70 widget_handler_T *check, 71 void (*)(void *, unsigned char *), 72 void (*)(void *)); 73 74 void 75 input_dialog(struct terminal *term, struct memory_list *ml, 76 unsigned char *title, 77 unsigned char *text, 78 void *data, struct input_history *history, int l, 79 unsigned char *def, int min, int max, 80 widget_handler_T *check, 81 void (*fn)(void *, unsigned char *), 82 void (*cancelfn)(void *)); 83 84 85 /* Input lines */ 86 87 #define INPUT_LINE_BUFFER_SIZE 256 88 #define INPUT_LINE_WIDGETS 1 89 90 enum input_line_code { 91 INPUT_LINE_CANCEL, 92 INPUT_LINE_PROCEED, 93 INPUT_LINE_REWIND, 94 }; 95 96 struct input_line; 97 98 /* If the handler returns non zero value it means to cancel the input line */ 99 typedef enum input_line_code (*input_line_handler_T)(struct input_line *line, int action_id); 100 101 struct input_line { 102 struct session *ses; 103 input_line_handler_T handler; 104 void *data; 105 unsigned char buffer[INPUT_LINE_BUFFER_SIZE]; 106 }; 107 108 void 109 input_field_line(struct session *ses, unsigned char *prompt, void *data, 110 struct input_history *history, input_line_handler_T handler); 111 112 #define widget_has_history(widget_data) ((widget_data)->widget->type == WIDGET_FIELD \ 113 && (widget_data)->widget->info.field.history) 114 115 #define widget_is_textfield(widget_data) ((widget_data)->widget->type == WIDGET_FIELD \ 116 || (widget_data)->widget->type == WIDGET_FIELD_PASS) 117 118 #endif 119