2002-05-04 23:57:18 +04:00
|
|
|
/**
|
2003-01-02 16:26:43 +03:00
|
|
|
* $Id: box.c,v 1.26 2003/01/02 13:26:43 bursa Exp $
|
2002-05-04 23:57:18 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "libxml/HTMLparser.h"
|
2002-10-15 14:41:12 +04:00
|
|
|
#include "libutf-8/utf-8.h"
|
2002-08-18 20:46:45 +04:00
|
|
|
#include "netsurf/render/css.h"
|
2002-09-27 01:38:33 +04:00
|
|
|
#include "netsurf/riscos/font.h"
|
2002-08-18 20:46:45 +04:00
|
|
|
#include "netsurf/render/box.h"
|
|
|
|
#include "netsurf/render/utils.h"
|
2002-10-08 13:38:29 +04:00
|
|
|
#include "netsurf/utils/log.h"
|
2002-05-04 23:57:18 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* internal functions
|
|
|
|
*/
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
struct box* input(xmlNode * n, struct css_style* style, struct form* current_form);
|
2002-12-30 01:27:35 +03:00
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
void box_add_child(struct box * parent, struct box * child);
|
2002-08-12 03:01:02 +04:00
|
|
|
struct box * box_create(xmlNode * node, box_type type, struct css_style * style,
|
|
|
|
const char *href);
|
2002-10-08 15:15:29 +04:00
|
|
|
char * tolat1(const xmlChar * s);
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
|
|
|
|
struct css_stylesheet * stylesheet,
|
|
|
|
struct css_selector ** selector, unsigned int depth,
|
|
|
|
struct box * parent, struct box * inline_container,
|
2002-12-30 05:06:03 +03:00
|
|
|
const char *href, struct font_set *fonts,
|
2002-12-31 01:56:30 +03:00
|
|
|
struct gui_gadget* current_select, struct formoption* current_option,
|
|
|
|
struct gui_gadget* current_textarea, struct form* current_form,
|
|
|
|
struct page_elements* elements);
|
2002-05-22 01:32:35 +04:00
|
|
|
struct css_style * box_get_style(struct css_stylesheet * stylesheet, struct css_style * parent_style,
|
|
|
|
xmlNode * n, struct css_selector * selector, unsigned int depth);
|
2002-08-18 20:46:45 +04:00
|
|
|
void box_normalise_block(struct box *block);
|
|
|
|
void box_normalise_table(struct box *table);
|
|
|
|
void box_normalise_table_row_group(struct box *row_group);
|
|
|
|
void box_normalise_table_row(struct box *row);
|
|
|
|
void box_normalise_inline_container(struct box *cont);
|
2002-05-04 23:57:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add a child to a box tree node
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_add_child(struct box * parent, struct box * child)
|
|
|
|
{
|
2003-01-02 16:26:43 +03:00
|
|
|
if (parent->children != 0) { /* has children already */
|
2002-05-04 23:57:18 +04:00
|
|
|
parent->last->next = child;
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev = parent->last;
|
|
|
|
} else { /* this is the first child */
|
2002-05-04 23:57:18 +04:00
|
|
|
parent->children = child;
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev = 0;
|
|
|
|
}
|
2002-05-04 23:57:18 +04:00
|
|
|
|
|
|
|
parent->last = child;
|
|
|
|
child->parent = parent;
|
|
|
|
}
|
|
|
|
|
2002-06-27 03:27:30 +04:00
|
|
|
/**
|
|
|
|
* create a box tree node
|
|
|
|
*/
|
|
|
|
|
2002-08-12 03:01:02 +04:00
|
|
|
struct box * box_create(xmlNode * node, box_type type, struct css_style * style,
|
|
|
|
const char *href)
|
2002-06-27 03:27:30 +04:00
|
|
|
{
|
|
|
|
struct box * box = xcalloc(1, sizeof(struct box));
|
|
|
|
box->type = type;
|
2002-08-18 20:46:45 +04:00
|
|
|
box->node = node;
|
2002-06-27 03:27:30 +04:00
|
|
|
box->style = style;
|
2002-09-19 23:54:43 +04:00
|
|
|
box->width = UNKNOWN_WIDTH;
|
2002-09-18 23:36:28 +04:00
|
|
|
box->max_width = UNKNOWN_MAX_WIDTH;
|
2002-08-12 03:01:02 +04:00
|
|
|
box->text = 0;
|
|
|
|
box->href = href;
|
2002-08-18 20:46:45 +04:00
|
|
|
box->length = 0;
|
2002-09-18 23:36:28 +04:00
|
|
|
box->columns = 1;
|
2002-08-18 20:46:45 +04:00
|
|
|
box->next = 0;
|
2003-01-02 16:26:43 +03:00
|
|
|
box->prev = 0;
|
2002-08-18 20:46:45 +04:00
|
|
|
box->children = 0;
|
|
|
|
box->last = 0;
|
|
|
|
box->parent = 0;
|
|
|
|
box->float_children = 0;
|
|
|
|
box->next_float = 0;
|
2002-09-18 23:36:28 +04:00
|
|
|
box->col = 0;
|
2002-09-27 01:38:33 +04:00
|
|
|
box->font = 0;
|
2002-12-30 01:27:35 +03:00
|
|
|
box->gadget = 0;
|
2002-12-30 05:06:03 +03:00
|
|
|
box->img = 0;
|
2002-06-27 03:27:30 +04:00
|
|
|
return box;
|
|
|
|
}
|
2002-05-04 23:57:18 +04:00
|
|
|
|
2002-09-12 01:19:24 +04:00
|
|
|
|
|
|
|
char * tolat1(const xmlChar * s)
|
|
|
|
{
|
2002-10-15 14:41:12 +04:00
|
|
|
char *d = xcalloc(strlen((char*)s) + 1, sizeof(char));
|
2002-09-12 01:19:24 +04:00
|
|
|
char *d0 = d;
|
|
|
|
unsigned int u, chars;
|
|
|
|
|
|
|
|
while (*s != 0) {
|
2002-10-15 14:41:12 +04:00
|
|
|
u = sgetu8((unsigned char*)s, (int*) &chars);
|
2002-09-12 01:19:24 +04:00
|
|
|
s += chars;
|
2002-09-18 23:36:28 +04:00
|
|
|
if (u == 0x09 || u == 0x0a || u == 0x0d)
|
|
|
|
*d = ' ';
|
|
|
|
else if ((0x20 <= u && u <= 0x7f) || (0xa0 <= u && u <= 0xff))
|
|
|
|
*d = u;
|
|
|
|
else
|
|
|
|
*d = '?';
|
2002-09-12 01:19:24 +04:00
|
|
|
d++;
|
|
|
|
}
|
|
|
|
*d = 0;
|
|
|
|
|
|
|
|
return d0;
|
|
|
|
}
|
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
/**
|
|
|
|
* make a box tree with style data from an xml tree
|
|
|
|
*
|
|
|
|
* arguments:
|
|
|
|
* n xml tree
|
|
|
|
* parent_style style at this point in xml tree
|
|
|
|
* stylesheet stylesheet to use
|
|
|
|
* selector element selector hierachy to this point
|
|
|
|
* depth depth in xml tree
|
|
|
|
* parent parent in box tree
|
|
|
|
* inline_container current inline container box, or 0
|
|
|
|
*
|
|
|
|
* returns:
|
|
|
|
* updated current inline container
|
|
|
|
*/
|
|
|
|
|
2002-08-18 20:46:45 +04:00
|
|
|
void xml_to_box(xmlNode * n, struct css_style * parent_style,
|
|
|
|
struct css_stylesheet * stylesheet,
|
|
|
|
struct css_selector ** selector, unsigned int depth,
|
|
|
|
struct box * parent, struct box * inline_container,
|
2002-12-30 05:06:03 +03:00
|
|
|
const char *href, struct font_set *fonts,
|
2002-12-31 01:56:30 +03:00
|
|
|
struct gui_gadget* current_select, struct formoption* current_option,
|
|
|
|
struct gui_gadget* current_textarea, struct form* current_form,
|
|
|
|
struct page_elements* elements)
|
2002-08-18 20:46:45 +04:00
|
|
|
{
|
2002-10-08 13:38:29 +04:00
|
|
|
LOG(("node %p", n));
|
2002-08-18 20:46:45 +04:00
|
|
|
convert_xml_to_box(n, parent_style, stylesheet,
|
2002-12-31 01:56:30 +03:00
|
|
|
selector, depth, parent, inline_container, href, fonts, current_select, current_option,
|
|
|
|
current_textarea, current_form, elements);
|
2002-10-08 13:38:29 +04:00
|
|
|
LOG(("normalising"));
|
2002-08-18 20:46:45 +04:00
|
|
|
box_normalise_block(parent->children);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-30 05:06:03 +03:00
|
|
|
void LOG2(char* log)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", log);
|
|
|
|
}
|
|
|
|
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
|
|
|
|
struct css_stylesheet * stylesheet,
|
2002-05-04 23:57:18 +04:00
|
|
|
struct css_selector ** selector, unsigned int depth,
|
2002-08-12 03:01:02 +04:00
|
|
|
struct box * parent, struct box * inline_container,
|
2002-12-30 05:06:03 +03:00
|
|
|
const char *href, struct font_set *fonts,
|
2002-12-31 01:56:30 +03:00
|
|
|
struct gui_gadget* current_select, struct formoption* current_option,
|
|
|
|
struct gui_gadget* current_textarea, struct form* current_form,
|
|
|
|
struct page_elements* elements)
|
2002-05-04 23:57:18 +04:00
|
|
|
{
|
|
|
|
struct box * box;
|
|
|
|
struct box * inline_container_c;
|
2002-10-08 15:15:29 +04:00
|
|
|
struct css_style * style;
|
2002-05-04 23:57:18 +04:00
|
|
|
xmlNode * c;
|
2002-06-27 03:27:30 +04:00
|
|
|
char * s;
|
2002-05-04 23:57:18 +04:00
|
|
|
|
2002-10-08 13:38:29 +04:00
|
|
|
assert(n != 0 && parent_style != 0 && stylesheet != 0 && selector != 0 &&
|
|
|
|
parent != 0 && fonts != 0);
|
|
|
|
LOG(("depth %i, node %p, node type %i", depth, n, n->type));
|
2002-09-11 18:24:02 +04:00
|
|
|
gui_multitask();
|
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
if (n->type == XML_ELEMENT_NODE) {
|
|
|
|
/* work out the style for this element */
|
|
|
|
*selector = xrealloc(*selector, (depth + 1) * sizeof(struct css_selector));
|
2002-06-26 16:19:24 +04:00
|
|
|
(*selector)[depth].element = (const char *) n->name;
|
2002-05-04 23:57:18 +04:00
|
|
|
(*selector)[depth].class = (*selector)[depth].id = 0;
|
2002-08-12 03:01:02 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "class"))) {
|
2002-06-27 03:27:30 +04:00
|
|
|
(*selector)[depth].class = s;
|
2002-08-12 03:01:02 +04:00
|
|
|
free(s);
|
|
|
|
}
|
2002-05-22 01:32:35 +04:00
|
|
|
style = box_get_style(stylesheet, parent_style, n, *selector, depth + 1);
|
2002-10-08 13:38:29 +04:00
|
|
|
LOG(("display: %s", css_display_name[style->display]));
|
2002-06-29 00:14:04 +04:00
|
|
|
if (style->display == CSS_DISPLAY_NONE)
|
|
|
|
return inline_container;
|
2002-08-12 03:01:02 +04:00
|
|
|
|
|
|
|
if (strcmp((const char *) n->name, "a") == 0) {
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "href"))) {
|
|
|
|
href = strdup(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
2002-05-22 01:32:35 +04:00
|
|
|
}
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
if (n->type == XML_ELEMENT_NODE && (strcmp((const char *) n->name, "form") == 0))
|
|
|
|
{
|
|
|
|
struct form* form = box_form(n);
|
|
|
|
if (form != NULL)
|
|
|
|
{
|
|
|
|
current_form = form;
|
|
|
|
add_form_element(elements, form);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (n->type == XML_TEXT_NODE ||
|
2002-12-30 01:27:35 +03:00
|
|
|
(n->type == XML_ELEMENT_NODE && (strcmp((const char *) n->name, "input") == 0)) ||
|
2002-12-30 05:06:03 +03:00
|
|
|
(n->type == XML_ELEMENT_NODE && (strcmp((const char *) n->name, "select") == 0)) ||
|
|
|
|
(n->type == XML_ELEMENT_NODE && (strcmp((const char *) n->name, "option") == 0)) ||
|
2002-12-31 01:56:30 +03:00
|
|
|
(n->type == XML_ELEMENT_NODE && (strcmp((const char *) n->name, "textarea") == 0)) ||
|
2002-12-30 05:06:03 +03:00
|
|
|
(n->type == XML_ELEMENT_NODE && (strcmp((const char *) n->name, "img") == 0)) ||
|
2002-05-22 01:32:35 +04:00
|
|
|
(n->type == XML_ELEMENT_NODE && (style->float_ == CSS_FLOAT_LEFT ||
|
|
|
|
style->float_ == CSS_FLOAT_RIGHT))) {
|
2003-01-02 16:26:43 +03:00
|
|
|
char * text = 0;
|
|
|
|
int ignore;
|
|
|
|
|
|
|
|
if (n->type == XML_TEXT_NODE)
|
|
|
|
text = squash_whitespace(tolat1(n->content));
|
|
|
|
ignore = n->type == XML_TEXT_NODE && text[0] == ' ' && text[1] == 0;
|
|
|
|
|
2002-05-22 01:32:35 +04:00
|
|
|
/* text nodes are converted to inline boxes, wrapped in an inline container block */
|
2003-01-02 16:26:43 +03:00
|
|
|
if (inline_container == 0 && !ignore) {
|
|
|
|
/* this is the first inline node: make a container */
|
2002-05-22 01:32:35 +04:00
|
|
|
inline_container = xcalloc(1, sizeof(struct box));
|
|
|
|
inline_container->type = BOX_INLINE_CONTAINER;
|
|
|
|
box_add_child(parent, inline_container);
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
if (ignore) {
|
|
|
|
xfree(text);
|
|
|
|
} else if (n->type == XML_TEXT_NODE) {
|
2002-12-30 05:06:03 +03:00
|
|
|
LOG2("TEXT NODE");
|
2002-12-31 01:56:30 +03:00
|
|
|
if (current_textarea != 0)
|
2002-12-30 05:06:03 +03:00
|
|
|
{
|
|
|
|
char* thistext = squash_whitespace(tolat1(n->content));
|
2002-12-31 01:56:30 +03:00
|
|
|
textarea_addtext(current_textarea, thistext);
|
|
|
|
}
|
|
|
|
else if (current_option != 0)
|
|
|
|
{
|
|
|
|
char* thistext = (tolat1(n->content));
|
2002-12-30 05:06:03 +03:00
|
|
|
LOG2("adding to option");
|
|
|
|
option_addtext(current_option, thistext);
|
|
|
|
LOG2("freeing thistext");
|
|
|
|
LOG2("arse");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG2(("text node"));
|
2002-08-12 03:01:02 +04:00
|
|
|
box = box_create(n, BOX_INLINE, parent_style, href);
|
2003-01-02 16:26:43 +03:00
|
|
|
box->text = text;
|
2002-06-19 01:24:21 +04:00
|
|
|
box->length = strlen(box->text);
|
2002-12-27 20:28:19 +03:00
|
|
|
if (box->text[box->length - 1] == ' ') {
|
|
|
|
box->space = 1;
|
|
|
|
box->length--;
|
|
|
|
} else {
|
|
|
|
box->space = 0;
|
|
|
|
}
|
2002-09-27 01:38:33 +04:00
|
|
|
box->font = font_open(fonts, box->style);
|
2002-06-29 00:14:04 +04:00
|
|
|
box_add_child(inline_container, box);
|
2002-12-30 05:06:03 +03:00
|
|
|
}
|
|
|
|
} else if (strcmp((const char *) n->name, "img") == 0) {
|
|
|
|
LOG2(("image"));
|
2002-12-31 01:56:30 +03:00
|
|
|
box = box_image(n, parent_style, href);
|
|
|
|
if (box != NULL)
|
|
|
|
{
|
|
|
|
box_add_child(inline_container, box);
|
|
|
|
add_img_element(elements, box->img);
|
|
|
|
}
|
|
|
|
} else if (strcmp((const char *) n->name, "textarea") == 0) {
|
|
|
|
LOG2(("textarea"));
|
|
|
|
box = box_textarea(n, parent_style, current_form);
|
2002-12-30 05:06:03 +03:00
|
|
|
if (box != NULL)
|
2002-12-31 01:56:30 +03:00
|
|
|
{
|
2002-12-30 05:06:03 +03:00
|
|
|
box_add_child(inline_container, box);
|
2002-12-31 01:56:30 +03:00
|
|
|
current_textarea = box->gadget;
|
|
|
|
add_gadget_element(elements, box->gadget);
|
|
|
|
}
|
2002-12-30 05:06:03 +03:00
|
|
|
} else if (strcmp((const char *) n->name, "select") == 0) {
|
|
|
|
LOG2(("select"));
|
2002-12-31 01:56:30 +03:00
|
|
|
box = box_select(n, parent_style, current_form);
|
2002-12-30 05:06:03 +03:00
|
|
|
if (box != NULL)
|
|
|
|
{
|
|
|
|
box_add_child(inline_container, box);
|
|
|
|
current_select = box->gadget;
|
2002-12-31 01:56:30 +03:00
|
|
|
add_gadget_element(elements, box->gadget);
|
2002-12-30 05:06:03 +03:00
|
|
|
}
|
|
|
|
} else if (strcmp((const char *) n->name, "option") == 0) {
|
|
|
|
LOG2(("option"));
|
|
|
|
current_option = box_option(n, parent_style, current_select);
|
2002-12-30 01:27:35 +03:00
|
|
|
} else if (strcmp((const char *) n->name, "input") == 0) {
|
2002-12-30 05:06:03 +03:00
|
|
|
LOG2(("input"));
|
2002-12-31 01:56:30 +03:00
|
|
|
box = box_input(n, parent_style, current_form, elements);
|
2002-12-30 01:27:35 +03:00
|
|
|
if (box != NULL)
|
2002-12-31 01:56:30 +03:00
|
|
|
{
|
2002-12-30 01:27:35 +03:00
|
|
|
box_add_child(inline_container, box);
|
2002-12-31 01:56:30 +03:00
|
|
|
add_gadget_element(elements, box->gadget);
|
|
|
|
}
|
2002-05-22 01:32:35 +04:00
|
|
|
} else {
|
2002-12-30 05:06:03 +03:00
|
|
|
LOG2(("float"));
|
2002-08-12 03:01:02 +04:00
|
|
|
box = box_create(0, BOX_FLOAT_LEFT, 0, href);
|
2002-06-29 00:14:04 +04:00
|
|
|
if (style->float_ == CSS_FLOAT_RIGHT) box->type = BOX_FLOAT_RIGHT;
|
|
|
|
box_add_child(inline_container, box);
|
|
|
|
style->float_ = CSS_FLOAT_NONE;
|
|
|
|
parent = box;
|
|
|
|
if (style->display == CSS_DISPLAY_INLINE)
|
|
|
|
style->display = CSS_DISPLAY_BLOCK;
|
2002-05-05 01:17:06 +04:00
|
|
|
}
|
2002-06-29 00:14:04 +04:00
|
|
|
}
|
2002-05-05 01:17:06 +04:00
|
|
|
|
2002-06-29 00:14:04 +04:00
|
|
|
if (n->type == XML_ELEMENT_NODE) {
|
2002-05-04 23:57:18 +04:00
|
|
|
switch (style->display) {
|
|
|
|
case CSS_DISPLAY_BLOCK: /* blocks get a node in the box tree */
|
2002-08-12 03:01:02 +04:00
|
|
|
box = box_create(n, BOX_BLOCK, style, href);
|
2002-05-04 23:57:18 +04:00
|
|
|
box_add_child(parent, box);
|
|
|
|
inline_container_c = 0;
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
2002-08-18 20:46:45 +04:00
|
|
|
inline_container_c = convert_xml_to_box(c, style, stylesheet,
|
2002-08-12 03:01:02 +04:00
|
|
|
selector, depth + 1, box, inline_container_c,
|
2002-12-31 01:56:30 +03:00
|
|
|
href, fonts, current_select, current_option,
|
|
|
|
current_textarea, current_form, elements);
|
2002-05-04 23:57:18 +04:00
|
|
|
inline_container = 0;
|
|
|
|
break;
|
|
|
|
case CSS_DISPLAY_INLINE: /* inline elements get no box, but their children do */
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
2002-08-18 20:46:45 +04:00
|
|
|
inline_container = convert_xml_to_box(c, style, stylesheet,
|
2002-08-12 03:01:02 +04:00
|
|
|
selector, depth + 1, parent, inline_container,
|
2002-12-31 01:56:30 +03:00
|
|
|
href, fonts, current_select, current_option,
|
|
|
|
current_textarea, current_form, elements);
|
2002-05-04 23:57:18 +04:00
|
|
|
break;
|
|
|
|
case CSS_DISPLAY_TABLE:
|
2002-08-12 03:01:02 +04:00
|
|
|
box = box_create(n, BOX_TABLE, style, href);
|
2002-05-04 23:57:18 +04:00
|
|
|
box_add_child(parent, box);
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
2002-08-18 20:46:45 +04:00
|
|
|
convert_xml_to_box(c, style, stylesheet,
|
2002-08-12 03:01:02 +04:00
|
|
|
selector, depth + 1, box, 0,
|
2002-12-31 01:56:30 +03:00
|
|
|
href, fonts, current_select, current_option,
|
|
|
|
current_textarea, current_form, elements);
|
2002-05-04 23:57:18 +04:00
|
|
|
inline_container = 0;
|
|
|
|
break;
|
2002-08-18 20:46:45 +04:00
|
|
|
case CSS_DISPLAY_TABLE_ROW_GROUP:
|
|
|
|
case CSS_DISPLAY_TABLE_HEADER_GROUP:
|
|
|
|
case CSS_DISPLAY_TABLE_FOOTER_GROUP:
|
|
|
|
box = box_create(n, BOX_TABLE_ROW_GROUP, style, href);
|
|
|
|
box_add_child(parent, box);
|
|
|
|
inline_container_c = 0;
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
|
|
|
inline_container_c = convert_xml_to_box(c, style, stylesheet,
|
|
|
|
selector, depth + 1, box, inline_container_c,
|
2002-12-31 01:56:30 +03:00
|
|
|
href, fonts, current_select, current_option,
|
|
|
|
current_textarea, current_form, elements);
|
2002-08-18 20:46:45 +04:00
|
|
|
inline_container = 0;
|
|
|
|
break;
|
2002-05-04 23:57:18 +04:00
|
|
|
case CSS_DISPLAY_TABLE_ROW:
|
2002-08-12 03:01:02 +04:00
|
|
|
box = box_create(n, BOX_TABLE_ROW, style, href);
|
2002-05-04 23:57:18 +04:00
|
|
|
box_add_child(parent, box);
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
2002-08-18 20:46:45 +04:00
|
|
|
convert_xml_to_box(c, style, stylesheet,
|
2002-08-12 03:01:02 +04:00
|
|
|
selector, depth + 1, box, 0,
|
2002-12-31 01:56:30 +03:00
|
|
|
href, fonts, current_select, current_option,
|
|
|
|
current_textarea, current_form, elements);
|
2002-05-04 23:57:18 +04:00
|
|
|
inline_container = 0;
|
|
|
|
break;
|
|
|
|
case CSS_DISPLAY_TABLE_CELL:
|
2002-08-12 03:01:02 +04:00
|
|
|
box = box_create(n, BOX_TABLE_CELL, style, href);
|
2002-06-27 03:27:30 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "colspan"))) {
|
2002-09-18 23:36:28 +04:00
|
|
|
if ((box->columns = strtol(s, 0, 10)) == 0)
|
|
|
|
box->columns = 1;
|
2002-06-27 03:27:30 +04:00
|
|
|
} else
|
2002-09-18 23:36:28 +04:00
|
|
|
box->columns = 1;
|
2002-05-04 23:57:18 +04:00
|
|
|
box_add_child(parent, box);
|
|
|
|
inline_container_c = 0;
|
|
|
|
for (c = n->children; c != 0; c = c->next)
|
2002-08-18 20:46:45 +04:00
|
|
|
inline_container_c = convert_xml_to_box(c, style, stylesheet,
|
2002-08-12 03:01:02 +04:00
|
|
|
selector, depth + 1, box, inline_container_c,
|
2002-12-31 01:56:30 +03:00
|
|
|
href, fonts, current_select, current_option,
|
|
|
|
current_textarea, current_form, elements);
|
2002-05-04 23:57:18 +04:00
|
|
|
inline_container = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2002-06-26 16:19:24 +04:00
|
|
|
break;
|
2002-05-04 23:57:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-08 13:38:29 +04:00
|
|
|
LOG(("depth %i, node %p, node type %i END", depth, n, n->type));
|
2002-05-04 23:57:18 +04:00
|
|
|
return inline_container;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
/**
|
2002-05-22 01:32:35 +04:00
|
|
|
* get the style for an element
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct css_style * box_get_style(struct css_stylesheet * stylesheet, struct css_style * parent_style,
|
|
|
|
xmlNode * n, struct css_selector * selector, unsigned int depth)
|
|
|
|
{
|
|
|
|
struct css_style * style = xcalloc(1, sizeof(struct css_style));
|
2002-06-26 16:19:24 +04:00
|
|
|
char * s;
|
2002-05-22 01:32:35 +04:00
|
|
|
|
|
|
|
memcpy(style, parent_style, sizeof(struct css_style));
|
|
|
|
css_get_style(stylesheet, selector, depth, style);
|
|
|
|
|
2002-06-29 00:14:04 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "align"))) {
|
|
|
|
if (strcmp((const char *) n->name, "table") == 0 ||
|
|
|
|
strcmp((const char *) n->name, "img") == 0) {
|
|
|
|
if (strcmp(s, "left") == 0) style->float_ = CSS_FLOAT_LEFT;
|
|
|
|
else if (strcmp(s, "right") == 0) style->float_ = CSS_FLOAT_RIGHT;
|
|
|
|
} else {
|
|
|
|
if (strcmp(s, "left") == 0) style->text_align = CSS_TEXT_ALIGN_LEFT;
|
|
|
|
else if (strcmp(s, "center") == 0) style->text_align = CSS_TEXT_ALIGN_CENTER;
|
|
|
|
else if (strcmp(s, "right") == 0) style->text_align = CSS_TEXT_ALIGN_RIGHT;
|
|
|
|
}
|
2002-08-12 03:01:02 +04:00
|
|
|
free(s);
|
2002-06-29 00:14:04 +04:00
|
|
|
}
|
|
|
|
|
2002-12-27 23:35:32 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "bgcolor"))) {
|
|
|
|
unsigned int r, g, b;
|
|
|
|
if (s[0] == '#' && sscanf(s + 1, "%2x%2x%2x", &r, &g, &b) == 3)
|
|
|
|
style->background_color = (b << 16) | (g << 8) | r;
|
|
|
|
}
|
|
|
|
|
2002-06-26 16:19:24 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "clear"))) {
|
2002-06-21 22:16:24 +04:00
|
|
|
if (strcmp(s, "all") == 0) style->clear = CSS_CLEAR_BOTH;
|
|
|
|
else if (strcmp(s, "left") == 0) style->clear = CSS_CLEAR_LEFT;
|
|
|
|
else if (strcmp(s, "right") == 0) style->clear = CSS_CLEAR_RIGHT;
|
|
|
|
}
|
|
|
|
|
2002-12-27 23:35:32 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "color"))) {
|
|
|
|
unsigned int r, g, b;
|
|
|
|
if (s[0] == '#' && sscanf(s + 1, "%2x%2x%2x", &r, &g, &b) == 3)
|
|
|
|
style->color = (b << 16) | (g << 8) | r;
|
|
|
|
}
|
|
|
|
|
2002-06-26 16:19:24 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "width"))) {
|
2002-08-12 03:01:02 +04:00
|
|
|
if (strrchr(s, '%')) {
|
|
|
|
style->width.width = CSS_WIDTH_PERCENT;
|
2002-05-22 01:32:35 +04:00
|
|
|
style->width.value.percent = atof(s);
|
2002-08-12 03:01:02 +04:00
|
|
|
} else {
|
|
|
|
style->width.width = CSS_WIDTH_LENGTH;
|
|
|
|
style->width.value.length.unit = CSS_UNIT_PX;
|
2002-05-22 01:32:35 +04:00
|
|
|
style->width.value.length.value = atof(s);
|
2002-08-12 03:01:02 +04:00
|
|
|
}
|
|
|
|
free(s);
|
2002-05-22 01:32:35 +04:00
|
|
|
}
|
|
|
|
|
2002-06-26 16:19:24 +04:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "style"))) {
|
2002-05-22 01:32:35 +04:00
|
|
|
struct css_style * astyle = xcalloc(1, sizeof(struct css_style));
|
|
|
|
memcpy(astyle, &css_empty_style, sizeof(struct css_style));
|
|
|
|
css_parse_property_list(astyle, s);
|
|
|
|
css_cascade(style, astyle);
|
|
|
|
free(astyle);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
/**
|
2002-05-04 23:57:18 +04:00
|
|
|
* print a box tree to standard output
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_dump(struct box * box, unsigned int depth)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct box * c;
|
2002-06-19 01:24:21 +04:00
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
for (i = 0; i < depth; i++)
|
2002-06-19 01:24:21 +04:00
|
|
|
fprintf(stderr, " ");
|
2002-05-04 23:57:18 +04:00
|
|
|
|
2002-06-19 01:24:21 +04:00
|
|
|
fprintf(stderr, "x%li y%li w%li h%li ", box->x, box->y, box->width, box->height);
|
2002-09-18 23:36:28 +04:00
|
|
|
if (box->max_width != UNKNOWN_MAX_WIDTH)
|
|
|
|
fprintf(stderr, "min%lu max%lu ", box->min_width, box->max_width);
|
2002-05-04 23:57:18 +04:00
|
|
|
|
|
|
|
switch (box->type) {
|
2002-06-27 03:27:30 +04:00
|
|
|
case BOX_BLOCK: fprintf(stderr, "BOX_BLOCK "); break;
|
2002-06-19 01:24:21 +04:00
|
|
|
case BOX_INLINE_CONTAINER: fprintf(stderr, "BOX_INLINE_CONTAINER "); break;
|
2002-06-21 22:16:24 +04:00
|
|
|
case BOX_INLINE: fprintf(stderr, "BOX_INLINE '%.*s' ",
|
|
|
|
(int) box->length, box->text); break;
|
2002-06-27 03:27:30 +04:00
|
|
|
case BOX_TABLE: fprintf(stderr, "BOX_TABLE "); break;
|
|
|
|
case BOX_TABLE_ROW: fprintf(stderr, "BOX_TABLE_ROW "); break;
|
2002-09-18 23:36:28 +04:00
|
|
|
case BOX_TABLE_CELL: fprintf(stderr, "BOX_TABLE_CELL [columns %i] ",
|
|
|
|
box->columns); break;
|
2002-08-18 20:46:45 +04:00
|
|
|
case BOX_TABLE_ROW_GROUP: fprintf(stderr, "BOX_TABLE_ROW_GROUP "); break;
|
2002-06-29 00:14:04 +04:00
|
|
|
case BOX_FLOAT_LEFT: fprintf(stderr, "BOX_FLOAT_LEFT "); break;
|
|
|
|
case BOX_FLOAT_RIGHT: fprintf(stderr, "BOX_FLOAT_RIGHT "); break;
|
2002-06-19 01:24:21 +04:00
|
|
|
default: fprintf(stderr, "Unknown box type ");
|
2002-05-04 23:57:18 +04:00
|
|
|
}
|
2002-06-27 03:27:30 +04:00
|
|
|
if (box->node)
|
|
|
|
fprintf(stderr, "<%s> ", box->node->name);
|
2002-06-19 01:24:21 +04:00
|
|
|
if (box->style)
|
|
|
|
css_dump_style(box->style);
|
2002-08-12 03:01:02 +04:00
|
|
|
if (box->href != 0)
|
|
|
|
fprintf(stderr, " -> '%s'", box->href);
|
2002-06-19 01:24:21 +04:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
for (c = box->children; c != 0; c = c->next)
|
|
|
|
box_dump(c, depth + 1);
|
|
|
|
}
|
|
|
|
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
/**
|
|
|
|
* ensure the box tree is correctly nested
|
2003-01-02 16:26:43 +03:00
|
|
|
*
|
|
|
|
* parent permitted child nodes
|
|
|
|
* BLOCK BLOCK, INLINE_CONTAINER, TABLE
|
|
|
|
* INLINE_CONTAINER INLINE, FLOAT_LEFT, FLOAT_RIGHT
|
|
|
|
* INLINE none
|
|
|
|
* TABLE at least 1 TABLE_ROW_GROUP
|
|
|
|
* TABLE_ROW_GROUP at least 1 TABLE_ROW
|
|
|
|
* TABLE_ROW at least 1 TABLE_CELL
|
|
|
|
* TABLE_CELL BLOCK, INLINE_CONTAINER, TABLE (same as BLOCK)
|
|
|
|
* FLOAT_(LEFT|RIGHT) exactly 1 BLOCK or TABLE
|
2002-08-18 20:46:45 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void box_normalise_block(struct box *block)
|
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box *table;
|
|
|
|
struct css_style *style;
|
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(block != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(block->type == BOX_BLOCK || block->type == BOX_TABLE_CELL);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("block %p, block->type", block, block->type));
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = block->children; child != 0; child = next_child) {
|
|
|
|
LOG(("child %p, child->type = %d", child, child->type));
|
|
|
|
next_child = child->next; /* child may be destroyed */
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_BLOCK:
|
|
|
|
/* ok */
|
|
|
|
box_normalise_block(child);
|
|
|
|
break;
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
box_normalise_inline_container(child);
|
|
|
|
break;
|
|
|
|
case BOX_TABLE:
|
|
|
|
box_normalise_table(child);
|
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* insert implied table */
|
|
|
|
style = xcalloc(1, sizeof(struct css_style));
|
|
|
|
memcpy(style, block->style, sizeof(struct css_style));
|
|
|
|
css_cascade(style, &css_blank_style);
|
|
|
|
table = box_create(0, BOX_TABLE, style, block->href);
|
2003-01-02 16:26:43 +03:00
|
|
|
if (child->prev == 0)
|
2002-08-18 20:46:45 +04:00
|
|
|
block->children = table;
|
|
|
|
else
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev->next = table;
|
|
|
|
table->prev = child->prev;
|
2002-08-18 20:46:45 +04:00
|
|
|
while (child != 0 && (
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
|
|
|
child->type == BOX_TABLE_ROW ||
|
|
|
|
child->type == BOX_TABLE_CELL)) {
|
|
|
|
box_add_child(table, child);
|
|
|
|
child = child->next;
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
table->last->next = 0;
|
|
|
|
table->next = next_child = child;
|
2002-09-18 23:36:28 +04:00
|
|
|
table->parent = block;
|
2002-08-18 20:46:45 +04:00
|
|
|
box_normalise_table(table);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("block %p done", block));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void box_normalise_table(struct box *table)
|
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box *row_group;
|
|
|
|
struct css_style *style;
|
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(table != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(table->type == BOX_TABLE);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("table %p", table));
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = table->children; child != 0; child = next_child) {
|
|
|
|
next_child = child->next;
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
/* ok */
|
|
|
|
box_normalise_table_row_group(child);
|
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* insert implied table row group */
|
2002-09-27 01:38:33 +04:00
|
|
|
/* fprintf(stderr, "inserting implied table row group\n"); */
|
2002-08-18 20:46:45 +04:00
|
|
|
style = xcalloc(1, sizeof(struct css_style));
|
|
|
|
memcpy(style, table->style, sizeof(struct css_style));
|
|
|
|
css_cascade(style, &css_blank_style);
|
|
|
|
row_group = box_create(0, BOX_TABLE_ROW_GROUP, style, table->href);
|
2003-01-02 16:26:43 +03:00
|
|
|
if (child->prev == 0)
|
2002-08-18 20:46:45 +04:00
|
|
|
table->children = row_group;
|
|
|
|
else
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev->next = row_group;
|
|
|
|
row_group->prev = child->prev;
|
2002-08-18 20:46:45 +04:00
|
|
|
while (child != 0 && (
|
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW ||
|
|
|
|
child->type == BOX_TABLE_CELL)) {
|
|
|
|
box_add_child(row_group, child);
|
|
|
|
child = child->next;
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
row_group->last->next = 0;
|
|
|
|
row_group->next = next_child = child;
|
2002-09-18 23:36:28 +04:00
|
|
|
row_group->parent = table;
|
2002-08-18 20:46:45 +04:00
|
|
|
box_normalise_table_row_group(row_group);
|
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%i\n", child->type);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
|
|
|
|
if (table->children == 0) {
|
|
|
|
LOG(("table->children == 0, removing"));
|
|
|
|
if (table->prev == 0)
|
|
|
|
table->parent->children = table->next;
|
|
|
|
else
|
|
|
|
table->prev->next = table->next;
|
|
|
|
if (table->next != 0)
|
|
|
|
table->next->prev = table->prev;
|
|
|
|
box_free_box(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("table %p done", table));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void box_normalise_table_row_group(struct box *row_group)
|
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box *row;
|
|
|
|
struct css_style *style;
|
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(row_group != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(row_group->type == BOX_TABLE_ROW_GROUP);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("row_group %p", row_group));
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = row_group->children; child != 0; child = next_child) {
|
|
|
|
next_child = child->next;
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
/* ok */
|
|
|
|
box_normalise_table_row(child);
|
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* insert implied table row */
|
|
|
|
style = xcalloc(1, sizeof(struct css_style));
|
|
|
|
memcpy(style, row_group->style, sizeof(struct css_style));
|
|
|
|
css_cascade(style, &css_blank_style);
|
|
|
|
row = box_create(0, BOX_TABLE_ROW, style, row_group->href);
|
2003-01-02 16:26:43 +03:00
|
|
|
if (child->prev == 0)
|
2002-08-18 20:46:45 +04:00
|
|
|
row_group->children = row;
|
|
|
|
else
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev->next = row;
|
|
|
|
row->prev = child->prev;
|
2002-08-18 20:46:45 +04:00
|
|
|
while (child != 0 && (
|
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
|
|
|
child->type == BOX_TABLE_CELL)) {
|
|
|
|
box_add_child(row, child);
|
|
|
|
child = child->next;
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
row->last->next = 0;
|
|
|
|
row->next = next_child = child;
|
2002-09-18 23:36:28 +04:00
|
|
|
row->parent = row_group;
|
2002-08-18 20:46:45 +04:00
|
|
|
box_normalise_table_row(row);
|
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
|
|
|
|
if (row_group->children == 0) {
|
|
|
|
LOG(("row_group->children == 0, removing"));
|
|
|
|
if (row_group->prev == 0)
|
|
|
|
row_group->parent->children = row_group->next;
|
|
|
|
else
|
|
|
|
row_group->prev->next = row_group->next;
|
|
|
|
if (row_group->next != 0)
|
|
|
|
row_group->next->prev = row_group->prev;
|
|
|
|
box_free_box(row_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("row_group %p done", row_group));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void box_normalise_table_row(struct box *row)
|
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
struct box *cell;
|
|
|
|
struct css_style *style;
|
2002-09-18 23:36:28 +04:00
|
|
|
unsigned int columns = 0;
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(row != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(row->type == BOX_TABLE_ROW);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("row %p", row));
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = row->children; child != 0; child = next_child) {
|
|
|
|
next_child = child->next;
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
/* ok */
|
|
|
|
box_normalise_block(child);
|
2002-09-18 23:36:28 +04:00
|
|
|
columns += child->columns;
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
/* insert implied table cell */
|
|
|
|
style = xcalloc(1, sizeof(struct css_style));
|
|
|
|
memcpy(style, row->style, sizeof(struct css_style));
|
|
|
|
css_cascade(style, &css_blank_style);
|
|
|
|
cell = box_create(0, BOX_TABLE_CELL, style, row->href);
|
2003-01-02 16:26:43 +03:00
|
|
|
if (child->prev == 0)
|
2002-08-18 20:46:45 +04:00
|
|
|
row->children = cell;
|
|
|
|
else
|
2003-01-02 16:26:43 +03:00
|
|
|
child->prev->next = cell;
|
|
|
|
cell->prev = child->prev;
|
2002-08-18 20:46:45 +04:00
|
|
|
while (child != 0 && (
|
|
|
|
child->type == BOX_BLOCK ||
|
|
|
|
child->type == BOX_INLINE_CONTAINER ||
|
|
|
|
child->type == BOX_TABLE ||
|
|
|
|
child->type == BOX_TABLE_ROW_GROUP ||
|
|
|
|
child->type == BOX_TABLE_ROW)) {
|
|
|
|
box_add_child(cell, child);
|
|
|
|
child = child->next;
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
cell->last->next = 0;
|
|
|
|
cell->next = next_child = child;
|
2002-09-18 23:36:28 +04:00
|
|
|
cell->parent = row;
|
2002-08-18 20:46:45 +04:00
|
|
|
box_normalise_block(cell);
|
2002-09-18 23:36:28 +04:00
|
|
|
columns++;
|
2002-08-18 20:46:45 +04:00
|
|
|
break;
|
|
|
|
case BOX_INLINE:
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
/* should have been wrapped in inline
|
|
|
|
container by convert_xml_to_box() */
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2002-09-18 23:36:28 +04:00
|
|
|
if (row->parent->parent->columns < columns)
|
|
|
|
row->parent->parent->columns = columns;
|
2003-01-02 16:26:43 +03:00
|
|
|
|
|
|
|
if (row->children == 0) {
|
|
|
|
LOG(("row->children == 0, removing"));
|
|
|
|
if (row->prev == 0)
|
|
|
|
row->parent->children = row->next;
|
|
|
|
else
|
|
|
|
row->prev->next = row->next;
|
|
|
|
if (row->next != 0)
|
|
|
|
row->next->prev = row->prev;
|
|
|
|
box_free_box(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("row %p done", row));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void box_normalise_inline_container(struct box *cont)
|
|
|
|
{
|
|
|
|
struct box *child;
|
2003-01-02 16:26:43 +03:00
|
|
|
struct box *next_child;
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
assert(cont != 0);
|
2002-08-18 20:46:45 +04:00
|
|
|
assert(cont->type == BOX_INLINE_CONTAINER);
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("cont %p", cont));
|
2002-08-18 20:46:45 +04:00
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
for (child = cont->children; child != 0; child = next_child) {
|
|
|
|
next_child = child->next;
|
2002-08-18 20:46:45 +04:00
|
|
|
switch (child->type) {
|
|
|
|
case BOX_INLINE:
|
|
|
|
/* ok */
|
|
|
|
break;
|
|
|
|
case BOX_FLOAT_LEFT:
|
|
|
|
case BOX_FLOAT_RIGHT:
|
|
|
|
/* ok */
|
|
|
|
assert(child->children != 0);
|
|
|
|
switch (child->children->type) {
|
|
|
|
case BOX_BLOCK:
|
|
|
|
box_normalise_block(child->children);
|
|
|
|
break;
|
|
|
|
case BOX_TABLE:
|
|
|
|
box_normalise_table(child->children);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BOX_BLOCK:
|
|
|
|
case BOX_INLINE_CONTAINER:
|
|
|
|
case BOX_TABLE:
|
|
|
|
case BOX_TABLE_ROW_GROUP:
|
|
|
|
case BOX_TABLE_ROW:
|
|
|
|
case BOX_TABLE_CELL:
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
LOG(("cont %p done", cont));
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
2002-09-08 22:11:56 +04:00
|
|
|
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
void gadget_free(struct gui_gadget* g)
|
|
|
|
{
|
|
|
|
struct formoption* o;
|
|
|
|
|
|
|
|
if (g->name != 0)
|
|
|
|
xfree(g->name);
|
2003-01-02 16:26:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
switch (g->type)
|
|
|
|
{
|
|
|
|
case GADGET_HIDDEN:
|
|
|
|
if (g->data.hidden.value != 0)
|
|
|
|
xfree(g->data.hidden.value);
|
|
|
|
break;
|
|
|
|
case GADGET_RADIO:
|
|
|
|
if (g->data.checkbox.value != 0)
|
|
|
|
xfree(g->data.radio.value);
|
|
|
|
break;
|
|
|
|
case GADGET_CHECKBOX:
|
|
|
|
if (g->data.checkbox.value != 0)
|
|
|
|
xfree(g->data.checkbox.value);
|
|
|
|
break;
|
|
|
|
case GADGET_TEXTAREA:
|
|
|
|
if (g->data.textarea.text != 0)
|
|
|
|
xfree(g->data.textarea.text);
|
|
|
|
break;
|
|
|
|
case GADGET_TEXTBOX:
|
|
|
|
gui_remove_gadget(g);
|
|
|
|
if (g->data.textbox.text != 0)
|
|
|
|
xfree(g->data.textbox.text);
|
|
|
|
break;
|
|
|
|
case GADGET_ACTIONBUTTON:
|
|
|
|
if (g->data.actionbutt.label != 0)
|
|
|
|
xfree(g->data.actionbutt.label);
|
|
|
|
break;
|
|
|
|
case GADGET_SELECT:
|
|
|
|
o = g->data.select.items;
|
|
|
|
while (o != NULL)
|
|
|
|
{
|
|
|
|
if (o->text != 0)
|
|
|
|
xfree(o->text);
|
|
|
|
if (o->value != 0)
|
|
|
|
xfree(o->value);
|
|
|
|
xfree(o);
|
|
|
|
o = o->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
/**
|
|
|
|
* free a box tree recursively
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_free(struct box *box)
|
|
|
|
{
|
|
|
|
/* free children first */
|
|
|
|
if (box->children != 0)
|
|
|
|
box_free(box->children);
|
|
|
|
|
|
|
|
/* then siblings */
|
|
|
|
if (box->next != 0)
|
|
|
|
box_free(box->next);
|
|
|
|
|
|
|
|
/* last this box */
|
2003-01-02 16:26:43 +03:00
|
|
|
box_free_box(box);
|
|
|
|
}
|
|
|
|
|
|
|
|
void box_free_box(struct box *box)
|
|
|
|
{
|
2002-10-15 14:41:12 +04:00
|
|
|
// if (box->style != 0)
|
|
|
|
// free(box->style);
|
2002-12-30 01:27:35 +03:00
|
|
|
if (box->gadget != 0)
|
|
|
|
{
|
2002-12-31 01:56:30 +03:00
|
|
|
gadget_free(box->gadget);
|
2002-12-30 01:27:35 +03:00
|
|
|
free((void*)box->gadget);
|
|
|
|
}
|
2002-12-30 05:06:03 +03:00
|
|
|
|
|
|
|
if (box->img != 0)
|
|
|
|
{
|
|
|
|
free((void*)box->img);
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
if (box->text != 0)
|
2002-10-15 14:41:12 +04:00
|
|
|
free((void*)box->text);
|
2002-09-08 22:11:56 +04:00
|
|
|
/* only free href if we're the top most user */
|
2002-10-15 14:41:12 +04:00
|
|
|
if (box->href != 0)
|
|
|
|
{
|
|
|
|
if (box->parent == 0)
|
|
|
|
free((void*)box->href);
|
|
|
|
else if (box->parent->href != box->href)
|
|
|
|
free((void*)box->href);
|
|
|
|
}
|
2002-09-08 22:11:56 +04:00
|
|
|
}
|
2002-12-30 01:27:35 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
struct box* box_image(xmlNode * n, struct css_style* style, char* href)
|
2002-12-30 05:06:03 +03:00
|
|
|
{
|
|
|
|
struct box* box = 0;
|
|
|
|
char* s;
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
box = box_create(n, BOX_INLINE, style, href);
|
2002-12-30 05:06:03 +03:00
|
|
|
box->img = xcalloc(1, sizeof(struct img));
|
|
|
|
|
|
|
|
box->text = 0;
|
|
|
|
box->length = 0;
|
|
|
|
box->font = 0;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "width")))
|
|
|
|
{
|
|
|
|
box->img->width = atoi(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
box->img->width = 24;
|
2003-01-02 16:26:43 +03:00
|
|
|
|
2002-12-30 05:06:03 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "height")))
|
|
|
|
{
|
|
|
|
box->img->height = atoi(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
box->img->height = 24;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "alt")))
|
|
|
|
{
|
|
|
|
box->img->alt = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
struct box* box_textarea(xmlNode* n, struct css_style* style, struct form* current_form)
|
|
|
|
{
|
|
|
|
struct box* box = 0;
|
|
|
|
char* s;
|
|
|
|
|
|
|
|
LOG2("creating box");
|
|
|
|
box = box_create(n, BOX_INLINE, style, NULL);
|
|
|
|
LOG2("creating gadget");
|
|
|
|
box->gadget = xcalloc(1, sizeof(struct gui_gadget));
|
|
|
|
box->gadget->type = GADGET_TEXTAREA;
|
|
|
|
box->gadget->form = current_form;
|
|
|
|
|
|
|
|
box->text = 0;
|
|
|
|
box->length = 0;
|
|
|
|
box->font = 0;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "cols")))
|
|
|
|
{
|
|
|
|
box->gadget->data.textarea.cols = atoi(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
box->gadget->data.textarea.cols = 40;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "rows")))
|
|
|
|
{
|
|
|
|
box->gadget->data.textarea.rows = atoi(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
box->gadget->data.textarea.rows = 16;
|
2003-01-02 16:26:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "name")))
|
|
|
|
{
|
|
|
|
box->gadget->name = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct box* box_select(xmlNode * n, struct css_style* style, struct form* current_form)
|
2002-12-30 05:06:03 +03:00
|
|
|
{
|
|
|
|
struct box* box = 0;
|
|
|
|
char* s;
|
|
|
|
|
|
|
|
LOG2("creating box");
|
|
|
|
box = box_create(n, BOX_INLINE, style, NULL);
|
|
|
|
LOG2("creating gadget");
|
|
|
|
box->gadget = xcalloc(1, sizeof(struct gui_gadget));
|
|
|
|
box->gadget->type = GADGET_SELECT;
|
2002-12-31 01:56:30 +03:00
|
|
|
box->gadget->form = current_form;
|
2002-12-30 05:06:03 +03:00
|
|
|
|
|
|
|
box->text = 0;
|
|
|
|
box->length = 0;
|
|
|
|
box->font = 0;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "size")))
|
|
|
|
{
|
|
|
|
box->gadget->data.select.size = atoi(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
box->gadget->data.select.size = 1;
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "multiple"))) {
|
|
|
|
box->gadget->data.select.multiple = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "name"))) {
|
|
|
|
box->gadget->name = s;
|
|
|
|
}
|
|
|
|
|
2002-12-30 05:06:03 +03:00
|
|
|
box->gadget->data.select.items = NULL;
|
|
|
|
box->gadget->data.select.numitems = 0;
|
|
|
|
/* to do: multiple, name */
|
|
|
|
LOG2("returning from select");
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct formoption* box_option(xmlNode* n, struct css_style* style, struct gui_gadget* current_select)
|
|
|
|
{
|
|
|
|
struct formoption* option;
|
2002-12-31 01:56:30 +03:00
|
|
|
char* s;
|
2002-12-30 05:06:03 +03:00
|
|
|
assert(current_select != 0);
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2002-12-30 05:06:03 +03:00
|
|
|
LOG2("realloc option");
|
|
|
|
if (current_select->data.select.items == 0)
|
|
|
|
{
|
|
|
|
option = xcalloc(1, sizeof(struct formoption));
|
|
|
|
current_select->data.select.items = option;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct formoption* current;
|
|
|
|
option = xcalloc(1, sizeof(struct formoption));
|
|
|
|
current = current_select->data.select.items;
|
|
|
|
while (current->next != 0)
|
|
|
|
current = current->next;
|
|
|
|
current->next = option;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TO DO: set selected / value here */
|
2002-12-31 01:56:30 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "selected"))) {
|
|
|
|
option->selected = -1;
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "value"))) {
|
|
|
|
option->value = s;
|
|
|
|
}
|
2002-12-30 05:06:03 +03:00
|
|
|
|
|
|
|
LOG2("returning");
|
|
|
|
return option;
|
|
|
|
}
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
void textarea_addtext(struct gui_gadget* textarea, char* text)
|
|
|
|
{
|
|
|
|
assert (textarea != 0);
|
|
|
|
assert (text != 0);
|
|
|
|
|
|
|
|
if (textarea->data.textarea.text == 0)
|
|
|
|
{
|
|
|
|
textarea->data.textarea.text = strdup(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textarea->data.textarea.text = xrealloc(textarea->data.textarea.text, strlen(textarea->data.textarea.text) + strlen(text) + 1);
|
|
|
|
strcat(textarea->data.textarea.text, text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-30 05:06:03 +03:00
|
|
|
void option_addtext(struct formoption* option, char* text)
|
|
|
|
{
|
|
|
|
assert(option != 0);
|
|
|
|
assert(text != 0);
|
|
|
|
|
|
|
|
if (option->text == 0)
|
|
|
|
{
|
|
|
|
LOG2("option->text is 0");
|
|
|
|
option->text = strdup(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG2("option->text is realloced");
|
|
|
|
option->text = xrealloc(option->text, strlen(option->text) + strlen(text) + 1);
|
|
|
|
strcat(option->text, text);
|
|
|
|
}
|
|
|
|
LOG2("returning");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
struct box* box_input(xmlNode * n, struct css_style* style, struct form* current_form, struct page_elements* elements)
|
2002-12-30 01:27:35 +03:00
|
|
|
{
|
|
|
|
struct box* box = 0;
|
|
|
|
char* s;
|
|
|
|
char* type;
|
|
|
|
|
|
|
|
if ((type = (char *) xmlGetProp(n, (xmlChar *) "type")))
|
|
|
|
{
|
2002-12-31 01:56:30 +03:00
|
|
|
if (strcmp(type, "hidden") == 0)
|
|
|
|
{
|
|
|
|
struct gui_gadget* g = xcalloc(1, sizeof(struct gui_gadget));
|
|
|
|
g->type = GADGET_HIDDEN;
|
|
|
|
g->form = current_form;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "value"))) {
|
|
|
|
g->data.hidden.value = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "name"))) {
|
|
|
|
g->name = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strcmp(type, "checkbox") == 0 || strcmp(type, "radio") == 0)
|
|
|
|
{
|
|
|
|
box = box_create(n, BOX_INLINE, style, NULL);
|
|
|
|
box->gadget = xcalloc(1, sizeof(struct gui_gadget));
|
|
|
|
if (type[0] == 'c')
|
|
|
|
box->gadget->type = GADGET_CHECKBOX;
|
|
|
|
else
|
|
|
|
box->gadget->type = GADGET_RADIO;
|
|
|
|
box->gadget->form = current_form;
|
|
|
|
|
|
|
|
box->text = 0;
|
|
|
|
box->length = 0;
|
|
|
|
box->font = 0;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "checked"))) {
|
|
|
|
if (type[0] == 'c')
|
|
|
|
box->gadget->data.checkbox.selected = -1;
|
|
|
|
else
|
|
|
|
box->gadget->data.radio.selected = -1;
|
|
|
|
free(s);
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "value"))) {
|
|
|
|
if (type[0] == 'c')
|
|
|
|
box->gadget->data.checkbox.value = s;
|
|
|
|
else
|
|
|
|
box->gadget->data.radio.value = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "name"))) {
|
|
|
|
box->gadget->name = s;
|
|
|
|
}
|
|
|
|
}
|
2002-12-30 01:27:35 +03:00
|
|
|
if (strcmp(type, "submit") == 0 || strcmp(type, "reset") == 0)
|
|
|
|
{
|
|
|
|
//style->display = CSS_DISPLAY_BLOCK;
|
|
|
|
|
|
|
|
box = box_create(n, BOX_INLINE, style, NULL);
|
|
|
|
box->gadget = xcalloc(1, sizeof(struct gui_gadget));
|
|
|
|
box->gadget->type = GADGET_ACTIONBUTTON;
|
2002-12-31 01:56:30 +03:00
|
|
|
box->gadget->form = current_form;
|
2002-12-30 01:27:35 +03:00
|
|
|
|
|
|
|
box->text = 0;
|
|
|
|
box->length = 0;
|
|
|
|
box->font = 0;
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "value"))) {
|
|
|
|
box->gadget->data.actionbutt.label = s;
|
|
|
|
}
|
2003-01-02 16:26:43 +03:00
|
|
|
else
|
2002-12-30 01:27:35 +03:00
|
|
|
{
|
|
|
|
box->gadget->data.actionbutt.label = strdup(type);
|
|
|
|
box->gadget->data.actionbutt.label[0] = toupper(type[0]);
|
|
|
|
}
|
2002-12-31 01:56:30 +03:00
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "name"))) {
|
|
|
|
box->gadget->name = s;
|
|
|
|
}
|
2002-12-30 01:27:35 +03:00
|
|
|
}
|
|
|
|
if (strcmp(type, "text") == 0 || strcmp(type, "password") == 0)
|
|
|
|
{
|
|
|
|
//style->display = CSS_DISPLAY_BLOCK;
|
|
|
|
|
|
|
|
box = box_create(n, BOX_INLINE, style, NULL);
|
|
|
|
box->gadget = xcalloc(1, sizeof(struct gui_gadget));
|
|
|
|
box->gadget->type = GADGET_TEXTBOX;
|
2002-12-31 01:56:30 +03:00
|
|
|
box->gadget->form = current_form;
|
2002-12-30 01:27:35 +03:00
|
|
|
|
|
|
|
box->text = 0;
|
|
|
|
box->length = 0;
|
|
|
|
box->font = 0;
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
box->gadget->data.textbox.maxlength = 32;
|
2002-12-30 01:27:35 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "maxlength"))) {
|
|
|
|
box->gadget->data.textbox.maxlength = atoi(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
box->gadget->data.textbox.size = box->gadget->data.textbox.maxlength;
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "size"))) {
|
|
|
|
box->gadget->data.textbox.size = atoi(s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
box->gadget->data.textbox.text = xcalloc(box->gadget->data.textbox.maxlength + 1, sizeof(char));
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "value"))) {
|
2003-01-02 16:26:43 +03:00
|
|
|
strncpy(box->gadget->data.textbox.text, s,
|
2002-12-30 01:27:35 +03:00
|
|
|
box->gadget->data.textbox.maxlength);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "name"))) {
|
|
|
|
box->gadget->name = s;
|
|
|
|
}
|
2002-12-30 01:27:35 +03:00
|
|
|
}
|
|
|
|
free(type);
|
|
|
|
}
|
|
|
|
return box;
|
|
|
|
}
|
2002-12-31 01:56:30 +03:00
|
|
|
|
|
|
|
struct form* box_form(xmlNode* n)
|
|
|
|
{
|
|
|
|
struct form* form;
|
|
|
|
char* s;
|
|
|
|
|
|
|
|
form = xcalloc(1, sizeof(struct form*));
|
2003-01-02 16:26:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "action"))) {
|
|
|
|
form->action = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s = (char *) xmlGetProp(n, (xmlChar *) "method"))) {
|
|
|
|
if (strcmp(s, "get") == 0)
|
|
|
|
form->action = method_GET;
|
|
|
|
else if (strcmp(s, "post") == 0)
|
|
|
|
form->action = method_POST;
|
|
|
|
xfree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return form;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_form_element(struct page_elements* pe, struct form* f)
|
|
|
|
{
|
|
|
|
pe->forms = xrealloc(pe->forms, (pe->numForms + 1) * sizeof(struct form*));
|
|
|
|
pe->forms[pe->numForms] = f;
|
|
|
|
pe->numForms++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_gadget_element(struct page_elements* pe, struct gadget* g)
|
|
|
|
{
|
|
|
|
pe->gadgets = xrealloc(pe->gadgets, (pe->numGadgets + 1) * sizeof(struct gui_gadget*));
|
|
|
|
pe->gadgets[pe->numGadgets] = g;
|
|
|
|
pe->numGadgets++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_img_element(struct page_elements* pe, struct img* i)
|
|
|
|
{
|
|
|
|
pe->images = xrealloc(pe->images, (pe->numImages + 1) * sizeof(struct img*));
|
|
|
|
pe->images[pe->numImages] = i;
|
|
|
|
pe->numImages++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|