2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__DOCUMENT_FORMS_H
|
|
|
|
#define EL__DOCUMENT_FORMS_H
|
|
|
|
|
2021-11-02 15:49:03 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
#include <quickjs/quickjs.h>
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "util/lists.h"
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
struct document;
|
|
|
|
struct menu_item;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum form_method {
|
|
|
|
FORM_METHOD_GET,
|
|
|
|
FORM_METHOD_POST,
|
|
|
|
FORM_METHOD_POST_MP,
|
|
|
|
FORM_METHOD_POST_TEXT_PLAIN,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct form {
|
|
|
|
LIST_HEAD(struct form);
|
|
|
|
|
2007-07-27 12:45:02 -04:00
|
|
|
/** The value of @c form_num serves both as a unique ID of the form.
|
|
|
|
* However @c form_num and #form_end also stores information about where
|
2005-09-15 09:58:31 -04:00
|
|
|
* in the source the form is positioned. Combined they are used to
|
|
|
|
* figured which form items belong to which forms after rendering
|
|
|
|
* tables.
|
|
|
|
*
|
2007-07-27 12:45:02 -04:00
|
|
|
* Initially the range between @c form_num and #form_end will
|
|
|
|
* stretch from 0 to INT_MAX. When a new form is added the
|
|
|
|
* range is partitioned so the forms each has unique source
|
|
|
|
* ranges. */
|
2005-09-15 09:58:31 -04:00
|
|
|
int form_num;
|
2007-07-27 12:45:02 -04:00
|
|
|
int form_end; /**< @see #form_num */
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
char *action;
|
|
|
|
char *name;
|
|
|
|
char *onsubmit;
|
|
|
|
char *target;
|
2005-09-15 09:58:31 -04:00
|
|
|
enum form_method method;
|
|
|
|
|
2021-09-16 14:26:20 -04:00
|
|
|
#ifdef CONFIG_ECMASCRIPT
|
2021-11-02 15:49:03 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
JSValue ecmascript_obj;
|
|
|
|
#else
|
2021-09-16 14:26:20 -04:00
|
|
|
void *ecmascript_obj;
|
2021-11-02 15:49:03 -04:00
|
|
|
#endif
|
2021-09-16 14:26:20 -04:00
|
|
|
#endif
|
|
|
|
|
2018-09-09 13:18:53 -04:00
|
|
|
LIST_OF(struct el_form_control) items;
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum form_type {
|
|
|
|
FC_TEXT,
|
|
|
|
FC_PASSWORD,
|
|
|
|
FC_FILE,
|
|
|
|
FC_TEXTAREA,
|
|
|
|
FC_CHECKBOX,
|
|
|
|
FC_RADIO,
|
|
|
|
FC_SELECT,
|
|
|
|
FC_SUBMIT,
|
|
|
|
FC_IMAGE,
|
|
|
|
FC_RESET,
|
|
|
|
FC_BUTTON,
|
|
|
|
FC_HIDDEN,
|
2022-01-28 07:59:25 -05:00
|
|
|
FC_NONE = -1
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum form_mode {
|
|
|
|
FORM_MODE_NORMAL,
|
|
|
|
FORM_MODE_READONLY,
|
|
|
|
FORM_MODE_DISABLED,
|
|
|
|
};
|
|
|
|
|
2022-01-28 09:37:59 -05:00
|
|
|
typedef unsigned char form_mode_T;
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#define form_field_is_readonly(field) ((field)->mode != FORM_MODE_NORMAL)
|
|
|
|
|
|
|
|
enum form_wrap {
|
|
|
|
FORM_WRAP_NONE,
|
|
|
|
FORM_WRAP_SOFT,
|
|
|
|
FORM_WRAP_HARD,
|
|
|
|
};
|
|
|
|
|
2018-09-09 13:18:53 -04:00
|
|
|
struct el_form_control {
|
|
|
|
LIST_HEAD(struct el_form_control);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
struct form *form;
|
|
|
|
int g_ctrl_num;
|
|
|
|
|
2007-07-27 12:45:02 -04:00
|
|
|
/** The value of @c position is relative to the place of the
|
|
|
|
* form item in the source. */
|
2005-09-15 09:58:31 -04:00
|
|
|
int position;
|
|
|
|
|
|
|
|
enum form_type type;
|
2022-01-28 09:37:59 -05:00
|
|
|
form_mode_T mode;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
char *id; /**< used by scripts */
|
|
|
|
char *name;
|
|
|
|
char *alt;
|
2007-07-27 12:45:02 -04:00
|
|
|
/** Default value, cannot be changed by document scripts.
|
|
|
|
* - For ::FC_TEXT, ::FC_PASSWORD, and ::FC_TEXTAREA:
|
|
|
|
* @c default_value is in the charset of the document.
|
|
|
|
* - For ::FC_FILE: The parser does not set @c default_value. */
|
2021-01-02 10:20:27 -05:00
|
|
|
char *default_value;
|
2005-09-15 09:58:31 -04:00
|
|
|
int default_state;
|
|
|
|
int size;
|
|
|
|
int cols, rows;
|
|
|
|
enum form_wrap wrap;
|
|
|
|
int maxlength;
|
|
|
|
int nvalues;
|
2021-01-02 10:20:27 -05:00
|
|
|
char **values;
|
2007-07-27 12:45:02 -04:00
|
|
|
/** Labels in a selection menu.
|
|
|
|
* - For ::FC_SELECT: @c labels are in the charset of the terminal.
|
|
|
|
* (That charset can be UTF-8 only if CONFIG_UTF8 is defined,
|
|
|
|
* and is assumed to be unibyte otherwise.) The charset of
|
|
|
|
* the document and the UTF-8 I/O option have no effect here. */
|
2021-01-02 10:20:27 -05:00
|
|
|
char **labels;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct menu_item *menu;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Numerical form type <-> form type name */
|
2022-01-30 08:39:44 -05:00
|
|
|
enum form_type str2form_type(const char *s);
|
2022-02-15 11:28:44 -05:00
|
|
|
const char *form_type2str(enum form_type num);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
struct form *init_form(void);
|
|
|
|
void done_form(struct form *form);
|
|
|
|
int has_form_submit(struct form *form);
|
|
|
|
|
2018-09-09 13:18:53 -04:00
|
|
|
int get_form_control_link(struct document *document, struct el_form_control *fc);
|
|
|
|
void done_form_control(struct el_form_control *fc);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|