2003-10-25 04:35:49 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
|
|
|
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-10-25 04:35:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Form handling functions (interface).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NETSURF_RENDER_FORM_H_
|
|
|
|
#define _NETSURF_RENDER_FORM_H_
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "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
|