ELinks 0.12pre5.GIT
[elinks.git] / src / bfu / inpfield.h
blobd45a902052f8b7130ce58e7afd622883ea1b594d
1 #ifndef EL__BFU_INPFIELD_H
2 #define EL__BFU_INPFIELD_H
4 #include "bfu/common.h"
5 #include "util/memlist.h"
6 #include "util/lists.h"
7 #include "util/align.h"
10 struct dialog;
11 struct dialog_data;
12 struct input_history;
13 struct session;
14 struct terminal;
15 struct widget_data;
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. */
23 struct widget_info_field {
24 int min;
25 int max;
26 struct input_history *history;
27 enum inpfield_flags flags;
30 struct widget_data_info_field {
31 int vpos;
32 int cpos;
33 LIST_OF(struct input_history_entry) history;
34 struct input_history_entry *cur_hist;
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);
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)
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)
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)
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)
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)
59 extern const struct widget_ops field_ops;
60 extern const struct widget_ops field_pass_ops;
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 *);
65 void dlg_format_field(struct terminal *, struct widget_data *, int, int *, int, int *, enum format_align, int format_only);
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 *));
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 *));
85 /* Input lines */
87 #define INPUT_LINE_BUFFER_SIZE 256
88 #define INPUT_LINE_WIDGETS 1
90 enum input_line_code {
91 INPUT_LINE_CANCEL,
92 INPUT_LINE_PROCEED,
93 INPUT_LINE_REWIND,
96 struct input_line;
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);
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];
108 void
109 input_field_line(struct session *ses, unsigned char *prompt, void *data,
110 struct input_history *history, input_line_handler_T handler);
112 #define widget_has_history(widget_data) ((widget_data)->widget->type == WIDGET_FIELD \
113 && (widget_data)->widget->info.field.history)
115 #define widget_is_textfield(widget_data) ((widget_data)->widget->type == WIDGET_FIELD \
116 || (widget_data)->widget->type == WIDGET_FIELD_PASS)
118 #endif