Fix compilation using --enable-html-highlight.
[elinks.git] / src / document / forms.h
blobba1a0112b9a1c0b80b5f55746a70821d17bdf8ba
1 #ifndef EL__DOCUMENT_FORMS_H
2 #define EL__DOCUMENT_FORMS_H
4 #include "util/lists.h"
6 struct document;
7 struct menu_item;
11 enum form_method {
12 FORM_METHOD_GET,
13 FORM_METHOD_POST,
14 FORM_METHOD_POST_MP,
15 FORM_METHOD_POST_TEXT_PLAIN,
18 struct form {
19 LIST_HEAD(struct form);
21 /** The value of @c form_num serves both as a unique ID of the form.
22 * However @c form_num and #form_end also stores information about where
23 * in the source the form is positioned. Combined they are used to
24 * figured which form items belong to which forms after rendering
25 * tables.
27 * Initially the range between @c form_num and #form_end will
28 * stretch from 0 to INT_MAX. When a new form is added the
29 * range is partitioned so the forms each has unique source
30 * ranges. */
31 int form_num;
32 int form_end; /**< @see #form_num */
34 unsigned char *action;
35 unsigned char *name;
36 unsigned char *onsubmit;
37 unsigned char *target;
38 enum form_method method;
40 LIST_OF(struct form_control) items;
45 enum form_type {
46 FC_TEXT,
47 FC_PASSWORD,
48 FC_FILE,
49 FC_TEXTAREA,
50 FC_CHECKBOX,
51 FC_RADIO,
52 FC_SELECT,
53 FC_SUBMIT,
54 FC_IMAGE,
55 FC_RESET,
56 FC_BUTTON,
57 FC_HIDDEN,
60 enum form_mode {
61 FORM_MODE_NORMAL,
62 FORM_MODE_READONLY,
63 FORM_MODE_DISABLED,
66 #define form_field_is_readonly(field) ((field)->mode != FORM_MODE_NORMAL)
68 enum form_wrap {
69 FORM_WRAP_NONE,
70 FORM_WRAP_SOFT,
71 FORM_WRAP_HARD,
74 struct form_control {
75 LIST_HEAD(struct form_control);
77 struct form *form;
78 int g_ctrl_num;
80 /** The value of @c position is relative to the place of the
81 * form item in the source. */
82 int position;
84 enum form_type type;
85 enum form_mode mode;
87 unsigned char *id; /**< used by scripts */
88 unsigned char *name;
89 unsigned char *alt;
90 /** Default value, cannot be changed by document scripts.
91 * - For ::FC_TEXT, ::FC_PASSWORD, and ::FC_TEXTAREA:
92 * @c default_value is in the charset of the document.
93 * - For ::FC_FILE: The parser does not set @c default_value. */
94 unsigned char *default_value;
95 int default_state;
96 int size;
97 int cols, rows;
98 enum form_wrap wrap;
99 int maxlength;
100 int nvalues;
101 unsigned char **values;
102 /** Labels in a selection menu.
103 * - For ::FC_SELECT: @c labels are in the charset of the terminal.
104 * (That charset can be UTF-8 only if CONFIG_UTF8 is defined,
105 * and is assumed to be unibyte otherwise.) The charset of
106 * the document and the UTF-8 I/O option have no effect here. */
107 unsigned char **labels;
108 struct menu_item *menu;
111 /* Numerical form type <-> form type name */
112 int str2form_type(unsigned char *s);
113 unsigned char *form_type2str(enum form_type num);
115 struct form *init_form(void);
116 void done_form(struct form *form);
117 int has_form_submit(struct form *form);
119 int get_form_control_link(struct document *document, struct form_control *fc);
120 void done_form_control(struct form_control *fc);
122 #endif