2003-10-25 04:35:49 +04:00
|
|
|
/*
|
2006-11-27 18:35:18 +03:00
|
|
|
* This file is part of NetSurf, http://netsurf-browser.org/
|
2003-10-25 04:35:49 +04:00
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
|
|
|
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Form handling functions (interface).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NETSURF_RENDER_FORM_H_
|
|
|
|
#define _NETSURF_RENDER_FORM_H_
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2004-01-20 22:08:34 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2003-10-25 04:35:49 +04:00
|
|
|
|
2003-10-25 18:13:49 +04:00
|
|
|
struct box;
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_control;
|
|
|
|
struct form_option;
|
|
|
|
|
2004-12-13 00:51:01 +03:00
|
|
|
/** Form submit method. */
|
|
|
|
typedef enum {
|
|
|
|
method_GET, /**< GET, always url encoded. */
|
|
|
|
method_POST_URLENC, /**< POST, url encoded. */
|
|
|
|
method_POST_MULTIPART /**< POST, multipart/form-data. */
|
|
|
|
} form_method;
|
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
/** HTML form. */
|
|
|
|
struct form {
|
2006-07-04 01:41:25 +04:00
|
|
|
char *action; /**< Absolute URL to submit to. */
|
2006-12-30 03:34:26 +03:00
|
|
|
char *target; /**< Target to submit to. */
|
2004-12-13 00:51:01 +03:00
|
|
|
form_method method; /**< Method and enctype. */
|
2005-06-26 05:55:20 +04:00
|
|
|
char *accept_charsets; /**< Charset to submit form in */
|
|
|
|
char *document_charset; /**< Charset of document containing form */
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_control *controls; /**< Linked list of controls. */
|
|
|
|
struct form_control *last_control; /**< Last control in list. */
|
2005-04-09 13:47:37 +04:00
|
|
|
struct form *prev; /**< Previous form in doc. */
|
2003-10-25 04:35:49 +04:00
|
|
|
};
|
|
|
|
|
2004-05-21 14:25:42 +04:00
|
|
|
/** Type of a struct form_control. */
|
|
|
|
typedef enum {
|
|
|
|
GADGET_HIDDEN,
|
|
|
|
GADGET_TEXTBOX,
|
|
|
|
GADGET_RADIO,
|
|
|
|
GADGET_CHECKBOX,
|
|
|
|
GADGET_SELECT,
|
|
|
|
GADGET_TEXTAREA,
|
|
|
|
GADGET_IMAGE,
|
|
|
|
GADGET_PASSWORD,
|
|
|
|
GADGET_SUBMIT,
|
|
|
|
GADGET_RESET,
|
|
|
|
GADGET_FILE
|
|
|
|
} form_control_type;
|
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
/** Form control. */
|
|
|
|
struct form_control {
|
2004-05-21 14:25:42 +04:00
|
|
|
form_control_type type;
|
2003-10-25 04:35:49 +04:00
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
char *initial_value;
|
|
|
|
bool disabled;
|
|
|
|
struct form *form;
|
|
|
|
struct box *box;
|
|
|
|
struct box *caret_inline_container;
|
|
|
|
struct box *caret_text_box;
|
2004-10-23 00:58:11 +04:00
|
|
|
size_t caret_box_offset, caret_form_offset;
|
2004-07-20 00:40:11 +04:00
|
|
|
unsigned int length;
|
2004-07-19 18:31:31 +04:00
|
|
|
int caret_pixel_offset;
|
2003-10-25 04:35:49 +04:00
|
|
|
unsigned int maxlength;
|
2004-05-22 03:42:26 +04:00
|
|
|
bool selected;
|
2003-10-25 04:35:49 +04:00
|
|
|
union {
|
|
|
|
struct {
|
2004-07-20 00:40:11 +04:00
|
|
|
int mx, my;
|
2003-10-25 04:35:49 +04:00
|
|
|
} image;
|
|
|
|
struct {
|
|
|
|
int num_items;
|
|
|
|
struct form_option *items, *last_item;
|
|
|
|
bool multiple;
|
|
|
|
int num_selected;
|
|
|
|
/** Currently selected item, if num_selected == 1. */
|
|
|
|
struct form_option *current;
|
|
|
|
} select;
|
|
|
|
} data;
|
2004-04-09 03:46:41 +04:00
|
|
|
struct form_control *prev; /**< Previous control in this form */
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_control *next; /**< Next control in this form. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Option in a select. */
|
|
|
|
struct form_option {
|
|
|
|
bool selected;
|
|
|
|
bool initial_selected;
|
2004-12-13 00:51:01 +03:00
|
|
|
char *value;
|
|
|
|
char *text; /**< NUL terminated. */
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_option* next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Successful control, as defined by HTML 4.01 17.13. */
|
|
|
|
struct form_successful_control {
|
2004-03-21 23:07:14 +03:00
|
|
|
bool file; /**< It's a file */
|
2003-10-25 04:35:49 +04:00
|
|
|
char *name; /**< Control name. */
|
|
|
|
char *value; /**< Current value. */
|
|
|
|
struct form_successful_control *next; /**< Next in linked list. */
|
|
|
|
};
|
|
|
|
|
2006-12-30 03:34:26 +03:00
|
|
|
struct form *form_new(char *action, char *target, form_method method, char *charset,
|
2005-06-26 05:55:20 +04:00
|
|
|
char *doc_charset);
|
2004-05-21 14:25:42 +04:00
|
|
|
struct form_control *form_new_control(form_control_type type);
|
2003-10-25 04:35:49 +04:00
|
|
|
void form_add_control(struct form *form, struct form_control *control);
|
2004-05-21 14:25:42 +04:00
|
|
|
void form_free_control(struct form_control *control);
|
2004-12-13 00:51:01 +03:00
|
|
|
bool form_add_option(struct form_control *control, char *value, char *text,
|
|
|
|
bool selected);
|
2004-08-08 23:13:40 +04:00
|
|
|
bool form_successful_controls(struct form *form,
|
|
|
|
struct form_control *submit_button,
|
|
|
|
struct form_successful_control **successful_controls);
|
2005-04-16 09:09:33 +04:00
|
|
|
char *form_url_encode(struct form *form,
|
|
|
|
struct form_successful_control *control);
|
2003-10-25 04:35:49 +04:00
|
|
|
void form_free_successful(struct form_successful_control *control);
|
|
|
|
|
|
|
|
#endif
|