summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
Diffstat (limited to 'render')
-rw-r--r--render/box.c85
-rw-r--r--render/box.h18
-rw-r--r--render/layout.c74
3 files changed, 167 insertions, 10 deletions
diff --git a/render/box.c b/render/box.c
index 59a32016f..5fc1aa355 100644
--- a/render/box.c
+++ b/render/box.c
@@ -1,5 +1,5 @@
/**
- * $Id: box.c,v 1.22 2002/12/27 20:35:32 bursa Exp $
+ * $Id: box.c,v 1.23 2002/12/29 22:27:35 monkeyson Exp $
*/
#include <assert.h>
@@ -19,6 +19,8 @@
* internal functions
*/
+struct box* box_gui_gadget(xmlNode * n, struct css_style* style);
+
void box_add_child(struct box * parent, struct box * child);
struct box * box_create(xmlNode * node, box_type type, struct css_style * style,
const char *href);
@@ -77,6 +79,7 @@ struct box * box_create(xmlNode * node, box_type type, struct css_style * style,
box->next_float = 0;
box->col = 0;
box->font = 0;
+ box->gadget = 0;
return box;
}
@@ -173,6 +176,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
}
if (n->type == XML_TEXT_NODE ||
+ (n->type == XML_ELEMENT_NODE && (strcmp((const char *) n->name, "input") == 0)) ||
(n->type == XML_ELEMENT_NODE && (style->float_ == CSS_FLOAT_LEFT ||
style->float_ == CSS_FLOAT_RIGHT))) {
/* text nodes are converted to inline boxes, wrapped in an inline container block */
@@ -194,6 +198,11 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
}
box->font = font_open(fonts, box->style);
box_add_child(inline_container, box);
+ } else if (strcmp((const char *) n->name, "input") == 0) {
+ LOG(("input"));
+ box = box_gui_gadget(n, parent_style);
+ if (box != NULL)
+ box_add_child(inline_container, box);
} else {
LOG(("float"));
box = box_create(0, BOX_FLOAT_LEFT, 0, href);
@@ -406,6 +415,7 @@ void box_normalise_block(struct box *block)
assert(block->type == BOX_BLOCK || block->type == BOX_TABLE_CELL);
for (child = block->children; child != 0; prev_child = child, child = child->next) {
+ fprintf(stderr, "child->type = %d\n", child->type);
switch (child->type) {
case BOX_BLOCK:
/* ok */
@@ -702,6 +712,12 @@ void box_free(struct box *box)
/* last this box */
// if (box->style != 0)
// free(box->style);
+ if (box->gadget != 0)
+ {
+ /* gadget_free(box->gadget); */
+ free((void*)box->gadget);
+ }
+
if (box->text != 0)
free((void*)box->text);
/* only free href if we're the top most user */
@@ -713,3 +729,70 @@ void box_free(struct box *box)
free((void*)box->href);
}
}
+
+struct box* box_gui_gadget(xmlNode * n, struct css_style* style)
+{
+ struct box* box = 0;
+ char* s;
+ char* type;
+
+ if ((type = (char *) xmlGetProp(n, (xmlChar *) "type")))
+ {
+ 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;
+
+ box->text = 0;
+ box->length = 0;
+ box->font = 0;
+
+ if ((s = (char *) xmlGetProp(n, (xmlChar *) "value"))) {
+ box->gadget->data.actionbutt.label = s;
+ }
+ else
+ {
+ box->gadget->data.actionbutt.label = strdup(type);
+ box->gadget->data.actionbutt.label[0] = toupper(type[0]);
+ }
+ }
+ 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;
+
+ box->text = 0;
+ box->length = 0;
+ box->font = 0;
+
+ box->gadget->data.textbox.maxlength = 255;
+ 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"))) {
+ strncpy(box->gadget->data.textbox.text, s,
+ box->gadget->data.textbox.maxlength);
+ free(s);
+ }
+
+ }
+ free(type);
+ }
+ return box;
+}
diff --git a/render/box.h b/render/box.h
index ad5290d34..05f7ffeb8 100644
--- a/render/box.h
+++ b/render/box.h
@@ -1,5 +1,5 @@
/**
- * $Id: box.h,v 1.12 2002/12/27 17:28:19 bursa Exp $
+ * $Id: box.h,v 1.13 2002/12/29 22:27:35 monkeyson Exp $
*/
#ifndef _NETSURF_RENDER_BOX_H_
@@ -27,6 +27,21 @@ struct column {
unsigned long min, max, width;
};
+struct gui_gadget {
+ enum { GADGET_HIDDEN = 0, GADGET_TEXTBOX, GADGET_RADIO, GADGET_OPTION,
+ GADGET_COMBO, GADGET_LIST, GADGET_TEXTAREA, GADGET_ACTIONBUTTON } type;
+ union {
+ struct {
+ int maxlength;
+ char* text;
+ int size;
+ } textbox;
+ struct {
+ char* label;
+ } actionbutt;
+ } data;
+};
+
struct box {
box_type type;
xmlNode * node;
@@ -46,6 +61,7 @@ struct box {
struct box * next_float;
struct column *col;
struct font_data *font;
+ struct gui_gadget* gadget;
};
#define UNKNOWN_WIDTH ULONG_MAX
diff --git a/render/layout.c b/render/layout.c
index e136a009a..62cb25f0e 100644
--- a/render/layout.c
+++ b/render/layout.c
@@ -1,5 +1,5 @@
/**
- * $Id: layout.c,v 1.27 2002/12/27 22:29:45 bursa Exp $
+ * $Id: layout.c,v 1.28 2002/12/29 22:27:35 monkeyson Exp $
*/
#include <assert.h>
@@ -107,6 +107,35 @@ void layout_node(struct box * box, unsigned long width, struct box * cont,
}
}
+
+
+int gadget_width(struct gui_gadget* gadget)
+{
+ switch (gadget->type)
+ {
+ case GADGET_TEXTBOX:
+ return gadget->data.textbox.size * 8;
+ case GADGET_ACTIONBUTTON:
+ return strlen(gadget->data.actionbutt.label) * 8 + 16;
+ default:
+ assert(0);
+ }
+ return 0;
+}
+
+int gadget_height(struct gui_gadget* gadget)
+{
+ switch (gadget->type)
+ {
+ case GADGET_TEXTBOX:
+ return 28;
+ case GADGET_ACTIONBUTTON:
+ return 28;
+ default:
+ assert(0);
+ }
+ return 0;
+}
/**
* layout_block -- position block and recursively layout children
*
@@ -300,18 +329,31 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
find_sides(cont->float_children, cy, cy, &x0, &x1, &left, &right);
/* get minimum line height from containing block */
- height = line_height(first->parent->parent->style);
+ if (first->text != 0)
+ height = line_height(first->parent->parent->style);
+ else if (first->gadget != 0)
+ height = gadget_height(first->gadget);
/* pass 1: find height of line assuming sides at top of line */
for (x = 0, b = first; x < x1 - x0 && b != 0; b = b->next) {
assert(b->type == BOX_INLINE || b->type == BOX_FLOAT_LEFT || b->type == BOX_FLOAT_RIGHT);
if (b->type == BOX_INLINE) {
- h = line_height(b->style ? b->style : b->parent->parent->style);
+ if (b->text != 0)
+ h = line_height(b->style ? b->style : b->parent->parent->style);
+ else if (b->gadget != 0)
+ h = gadget_height(b->gadget);
+
b->height = h;
if (h > height) height = h;
- if (b->width == UNKNOWN_WIDTH)
+ if (b->width == UNKNOWN_WIDTH && b->font != 0)
b->width = font_width(b->font, b->text, b->length);
- x += b->width + b->space ? b->font->space_width : 0;
+ else if (b->width == UNKNOWN_WIDTH && b->gadget != 0)
+ b->width = gadget_width(b->gadget);
+
+ if (b->font != 0)
+ x += b->width + b->space ? b->font->space_width : 0;
+ else if (b->gadget != 0)
+ x += b->width;
}
}
@@ -328,7 +370,10 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
b->x = x;
x += b->width;
space_before = space_after;
- space_after = b->space ? b->font->space_width : 0;
+ if (b->font != 0)
+ space_after = b->space ? b->font->space_width : 0;
+ else
+ space_after = 0;
c = b;
move_y = 1;
/* fprintf(stderr, "layout_line: '%.*s' %li %li\n", b->length, b->text, xp, x); */
@@ -378,8 +423,10 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
if (space == 0)
w = c->width;
- else
+ else if (c->font != 0)
w = font_width(c->font, c->text, space - c->text);
+ else if (c->gadget != 0)
+ w = gadget_width(c->gadget);
if (x1 - x0 < x + space_before + w && left == 0 && right == 0 && c == first) {
/* first word doesn't fit, but no floats and first on line so force in */
@@ -405,7 +452,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
/* first word doesn't fit, but full width not available so leave for later */
b = c;
/* fprintf(stderr, "layout_line: overflow, leaving\n"); */
- } else {
+ } else if (c->text != 0) {
/* fit as many words as possible */
assert(space != 0);
space = font_split(c->font, c->text, c->length,
@@ -669,8 +716,11 @@ void calculate_inline_container_widths(struct box *box)
switch (child->type) {
case BOX_INLINE:
/* max = all one line */
+ if (child->font != 0)
+ {
child->width = font_width(child->font,
child->text, child->length);
+
max += child->width;
/* min = widest word */
@@ -682,6 +732,14 @@ void calculate_inline_container_widths(struct box *box)
}
width = font_width(child->font, word, strlen(word));
if (min < width) min = width;
+ }
+ else if (child->gadget != 0)
+ {
+ child->width = gadget_width(child->gadget);
+ max += child->width;
+ if (min < child->width)
+ min = child->width;
+ }
break;
case BOX_FLOAT_LEFT: