From 73f7db2a75a7cee2add50973e8861b767f5bb650 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sun, 28 Sep 2003 23:41:07 +0000 Subject: [project @ 2003-09-28 23:41:06 by bursa] Rewrite text and password inputs to stop using wimp icons. svn path=/import/netsurf/; revision=330 --- render/box.c | 119 +++++++++++++++++++++++++++-------------------------------- render/box.h | 24 ++++-------- 2 files changed, 62 insertions(+), 81 deletions(-) (limited to 'render') diff --git a/render/box.c b/render/box.c index b681b9637..4f76072f0 100644 --- a/render/box.c +++ b/render/box.c @@ -67,6 +67,8 @@ static struct result box_select(xmlNode *n, struct status *status, struct css_style *style); static struct result box_input(xmlNode *n, struct status *status, struct css_style *style); +static struct box *box_input_text(xmlNode *n, struct status *status, + struct css_style *style, bool password); static struct result box_button(xmlNode *n, struct status *status, struct css_style *style); static void add_option(xmlNode* n, struct gui_gadget* current_select, char *text); @@ -812,61 +814,13 @@ struct result box_input(xmlNode *n, struct status *status, /* the default type is "text" */ if (type == 0 || stricmp(type, "text") == 0) { - box = box_create(style, NULL, 0); - box->font = font_open(status->content->data.html.fonts, style); - box->gadget = gadget = xcalloc(1, sizeof(struct gui_gadget)); - gadget->type = GADGET_TEXTBOX; - - gadget->data.textbox.maxlength = 32; - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "maxlength"))) { - gadget->data.textbox.maxlength = atoi(s); - xmlFree(s); - } - - gadget->data.textbox.size = box->gadget->data.textbox.maxlength; - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "size"))) { - gadget->data.textbox.size = atoi(s); - xmlFree(s); - } - - gadget->data.textbox.text = xcalloc( - gadget->data.textbox.maxlength + 2, sizeof(char)); - - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) { - strncpy(gadget->data.textbox.text, s, - gadget->data.textbox.maxlength); - xmlFree(s); - } - + box = box_input_text(n, status, style, false); + gadget = box->gadget; } else if (stricmp(type, "password") == 0) { - box = box_create(style, NULL, 0); - box->font = font_open(status->content->data.html.fonts, style); - box->gadget = gadget = xcalloc(1, sizeof(struct gui_gadget)); - gadget->type = GADGET_PASSWORD; - - gadget->data.password.maxlength = 32; - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "maxlength"))) { - gadget->data.password.maxlength = atoi(s); - xmlFree(s); - } - - gadget->data.password.size = box->gadget->data.password.maxlength; - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "size"))) { - gadget->data.password.size = atoi(s); - xmlFree(s); - } - - gadget->data.password.text = xcalloc( - gadget->data.password.maxlength + 2, sizeof(char)); - - if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) { - strncpy(gadget->data.password.text, s, - gadget->data.password.maxlength); - xmlFree(s); - } - + box = box_input_text(n, status, style, true); + gadget = box->gadget; } else if (stricmp(type, "hidden") == 0) { @@ -958,6 +912,55 @@ struct result box_input(xmlNode *n, struct status *status, return (struct result) {box, 0}; } +struct box *box_input_text(xmlNode *n, struct status *status, + struct css_style *style, bool password) +{ + char *s; + unsigned int i; + struct box *box = box_create(style, 0, 0); + struct box *inline_container, *inline_box; + style->display = CSS_DISPLAY_INLINE_BLOCK; + + box->gadget = xcalloc(1, sizeof(struct gui_gadget)); + + box->gadget->maxlength = 100; + if ((s = (char *) xmlGetProp(n, (const xmlChar *) "maxlength"))) { + box->gadget->maxlength = atoi(s); + xmlFree(s); + } + + s = (char *) xmlGetProp(n, (const xmlChar *) "value"); + box->gadget->value = s ? tolat1(s) : xstrdup(""); + box->gadget->initial_value = xstrdup(box->gadget->value); + if (s) + xmlFree(s); + + inline_container = box_create(0, 0, 0); + inline_container->type = BOX_INLINE_CONTAINER; + inline_box = box_create(style, 0, 0); + inline_box->type = BOX_INLINE; + inline_box->style_clone = 1; + inline_box->length = strlen(box->gadget->value); + if (password) { + box->gadget->type = GADGET_PASSWORD; + inline_box->text = xcalloc(inline_box->length + 1, 1); + for (i = 0; i != inline_box->length; i++) + inline_box->text[i] = '*'; + } else { + box->gadget->type = GADGET_TEXTBOX; + inline_box->text = xstrdup(box->gadget->value); + /* replace spaces with hard spaces to prevent line wrapping */ + for (i = 0; i != inline_box->length; i++) + if (inline_box->text[i] == ' ') + inline_box->text[i] = 160; + } + inline_box->font = font_open(status->content->data.html.fonts, style); + box_add_child(inline_container, inline_box); + box_add_child(box, inline_container); + + return box; +} + struct result box_button(xmlNode *n, struct status *status, struct css_style *style) { @@ -1459,18 +1462,6 @@ void gadget_free(struct gui_gadget* g) if (g->data.checkbox.value != 0) xmlFree(g->data.checkbox.value); break; - case GADGET_TEXTAREA: - break; - case GADGET_TEXTBOX: - gui_remove_gadget(g); - if (g->data.textbox.text != 0) - xmlFree(g->data.textbox.text); - break; - case GADGET_PASSWORD: - gui_remove_gadget(g); - if (g->data.password.text != 0) - xmlFree(g->data.password.text); - break; case GADGET_IMAGE: if (g->data.image.n != 0) xmlFree(g->data.image.n); diff --git a/render/box.h b/render/box.h index 0dad5400d..279463346 100644 --- a/render/box.h +++ b/render/box.h @@ -49,20 +49,14 @@ struct gui_gadget { char *value; char *initial_value; struct form* form; - union { + struct box *caret_inline_container; + struct box *caret_text_box; + int caret_char_offset; + unsigned int maxlength; + union { struct { char* value; } hidden; - struct { - unsigned int maxlength; - char* text; - int size; - } textbox; - struct { - unsigned int maxlength; - char* text; - int size; - } password; struct { char* name; char* value; @@ -84,11 +78,6 @@ struct gui_gadget { int selected; char* value; } radio; - struct { - struct box *caret_inline_container; - struct box *caret_text_box; - int caret_char_offset; - } textarea; } data; }; @@ -122,7 +111,8 @@ struct plugin_params { struct box { box_type type; struct css_style * style; - unsigned long x, y, width, height; + long x, y; + unsigned long width, height; unsigned long min_width, max_width; char * text; unsigned int space : 1; /* 1 <=> followed by a space */ -- cgit v1.2.3