diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2010-08-20 23:24:19 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2010-08-20 23:24:19 +0200 |
commit | f5c598b518d1f906148534d015f50075d3e8242d (patch) | |
tree | 21dd70add5b366c3dd80641b77f6b18e0baa009e /src/form.cc | |
parent | e98d02a01ffeb18ede86af025e51ae1ec011c75a (diff) | |
parent | 5f0fc0e48b8cbee7e1795935da0abff6627fd498 (diff) |
merge
Diffstat (limited to 'src/form.cc')
-rw-r--r-- | src/form.cc | 977 |
1 files changed, 470 insertions, 507 deletions
diff --git a/src/form.cc b/src/form.cc index 78bc43e8..38afea8f 100644 --- a/src/form.cc +++ b/src/form.cc @@ -22,28 +22,28 @@ #include "misc.h" #include "msg.h" #include "prefs.h" -#include "nav.h" #include "uicmd.hh" +using namespace lout; using namespace dw; using namespace dw::core; using namespace dw::core::style; +using namespace dw::core::ui; /* - * Forward declarations + * Forward declarations */ class DilloHtmlReceiver; class DilloHtmlSelect; class DilloHtmlOption; -static dw::core::ui::Embed *Html_input_image(DilloHtml *html, - const char *tag, int tagsize); +static Embed *Html_input_image(DilloHtml *html, const char *tag, int tagsize); static void Html_option_finish(DilloHtml *html); /* - * Typedefs + * Typedefs */ typedef enum { @@ -67,7 +67,7 @@ typedef enum { } DilloHtmlInputType; /* - * Class declarations + * Class declarations */ class DilloHtmlForm { @@ -75,74 +75,74 @@ class DilloHtmlForm { friend class DilloHtmlInput; DilloHtml *html; - void eventHandler(dw::core::ui::Resource *resource); - void submit(DilloHtmlInput *input); - DilloUrl *buildQueryUrl(DilloHtmlInput *input); + bool showing_hiddens; + bool enabled; + void eventHandler(Resource *resource, EventButton *event); + DilloUrl *buildQueryUrl(DilloHtmlInput *active_input); Dstr *buildQueryData(DilloHtmlInput *active_submit); - char *makeMultipartBoundary(iconv_t encoder, DilloHtmlInput *active_submit); - Dstr *encodeText(iconv_t encoder, Dstr **input); - void urlencodeAppend(Dstr *str, const char *val); - void appendInputUrlencode(Dstr *data, + char *makeMultipartBoundary(iconv_t char_encoder, + DilloHtmlInput *active_submit); + Dstr *encodeText(iconv_t char_encoder, Dstr **input); + void strUrlencodeAppend(Dstr *dstr, const char *str); + void inputUrlencodeAppend(Dstr *data, const char *name, const char *value); + void inputMultipartAppend(Dstr *data, const char *boundary, const char *name, const char *value); - void appendInputMultipartFiles(Dstr* data, - const char *boundary, + void filesInputMultipartAppend(Dstr* data, const char *boundary, const char *name, Dstr *file, const char *filename); - void appendInputMultipart(Dstr *data, - const char *boundary, - const char *name, - const char *value); - void appendClickposUrlencode(Dstr *data, Dstr *name, Dstr *x, Dstr *y); - void appendClickposMultipart(Dstr *data, const char *boundary, Dstr *name, - Dstr *x, Dstr *y); + void imageInputUrlencodeAppend(Dstr *data, Dstr *name, Dstr *x, Dstr *y); + void imageInputMultipartAppend(Dstr *data, const char *boundary, Dstr *name, + Dstr *x, Dstr *y); public: //BUG: for now everything is public DilloHtmlMethod method; DilloUrl *action; - DilloHtmlEnc enc; + DilloHtmlEnc content_type; char *submit_charset; lout::misc::SimpleVector<DilloHtmlInput*> *inputs; int num_entry_fields; - int num_submit_buttons; DilloHtmlReceiver *form_receiver; public: - DilloHtmlForm (DilloHtml *html, + DilloHtmlForm (DilloHtml *html, DilloHtmlMethod method, const DilloUrl *action, - DilloHtmlEnc enc, const char *charset); + DilloHtmlEnc content_type, const char *charset, + bool enabled); ~DilloHtmlForm (); - DilloHtmlInput *getInput (dw::core::ui::Resource *resource); + DilloHtmlInput *getInput (Resource *resource); DilloHtmlInput *getRadioInput (const char *name); + void submit(DilloHtmlInput *active_input, EventButton *event); void reset (); + void display_hiddens(bool display); void addInput(DilloHtmlInput *input, DilloHtmlInputType type); + void setEnabled(bool enabled); }; class DilloHtmlReceiver: - public dw::core::ui::Resource::ActivateReceiver, - public dw::core::ui::ButtonResource::ClickedReceiver + public Resource::ActivateReceiver, + public Resource::ClickedReceiver { friend class DilloHtmlForm; DilloHtmlForm* form; DilloHtmlReceiver (DilloHtmlForm* form2) { form = form2; } ~DilloHtmlReceiver () { } - void activate (dw::core::ui::Resource *resource); - void enter (dw::core::ui::Resource *resource); - void leave (dw::core::ui::Resource *resource); - void clicked (dw::core::ui::ButtonResource *resource, - int buttonNo, int x, int y); + void activate (Resource *resource); + void enter (Resource *resource); + void leave (Resource *resource); + void clicked (Resource *resource, EventButton *event); }; class DilloHtmlInput { - // DilloHtmlForm::addInput() calls connectTo() + // DilloHtmlForm::addInput() calls connectTo() friend class DilloHtmlForm; public: //BUG: for now everything is public DilloHtmlInputType type; - dw::core::ui::Embed *embed; /* May be NULL (think: hidden input) */ + Embed *embed; /* May be NULL (think: hidden input) */ char *name; char *init_str; /* note: some overloading - for buttons, init_str is simply the value of the button; for text @@ -154,18 +154,16 @@ public: //BUG: for now everything is public private: void connectTo(DilloHtmlReceiver *form_receiver); - void activate(DilloHtmlForm *form, bool force_submit); + void activate(DilloHtmlForm *form, int num_entry_fields,EventButton *event); void readFile(BrowserWindow *bw); public: - DilloHtmlInput (DilloHtmlInputType type, - dw::core::ui::Embed *embed, - const char *name, - const char *init_str, - bool init_val); + DilloHtmlInput (DilloHtmlInputType type, Embed *embed, + const char *name, const char *init_str, bool init_val); ~DilloHtmlInput (); void appendValuesTo(Dlist *values, bool is_active_submit); void reset(); + void setEnabled(bool enabled) {if (embed) embed->setEnabled(enabled); }; }; class DilloHtmlSelect { @@ -178,9 +176,8 @@ public: DilloHtmlOption *getCurrentOption (); void addOption (char *value, bool selected, bool enabled); void ensureSelection (); - void addOptionsTo (dw::core::ui::SelectionResource *res); - void appendValuesTo (Dlist *values, - dw::core::ui::SelectionResource *res); + void addOptionsTo (SelectionResource *res); + void appendValuesTo (Dlist *values, SelectionResource *res); }; class DilloHtmlOption { @@ -190,20 +187,20 @@ public: bool selected, enabled; private: DilloHtmlOption (char *value, bool selected, bool enabled); - ~DilloHtmlOption (); + ~DilloHtmlOption (); }; /* - * Form API + * Form API */ -DilloHtmlForm *a_Html_form_new (DilloHtml *html, - DilloHtmlMethod method, +DilloHtmlForm *a_Html_form_new (DilloHtml *html, DilloHtmlMethod method, const DilloUrl *action, - DilloHtmlEnc enc, - const char *charset) + DilloHtmlEnc content_type, const char *charset, + bool enabled) { - return new DilloHtmlForm (html,method,action,enc,charset); + return new DilloHtmlForm (html, method, action, content_type, charset, + enabled); } void a_Html_form_delete (DilloHtmlForm *form) @@ -216,15 +213,30 @@ void a_Html_input_delete (DilloHtmlInput *input) delete input; } +void a_Html_form_submit2(void *vform) +{ + ((DilloHtmlForm *)vform)->submit(NULL, NULL); +} + +void a_Html_form_reset2(void *vform) +{ + ((DilloHtmlForm *)vform)->reset(); +} + +void a_Html_form_display_hiddens2(void *vform, bool display) +{ + ((DilloHtmlForm *)vform)->display_hiddens(display); +} + /* - * Form parsing functions + * Form parsing functions */ /* * Add an HTML control */ static void Html_add_input(DilloHtml *html, DilloHtmlInputType type, - dw::core::ui::Embed *embed, const char *name, + Embed *embed, const char *name, const char *init_str, bool init_val) { _MSG("name=[%s] init_str=[%s] init_val=[%d]\n", name, init_str, init_val); @@ -236,6 +248,8 @@ static void Html_add_input(DilloHtml *html, DilloHtmlInputType type, int ni = html->inputs_outside_form->size(); html->inputs_outside_form->increase(); html->inputs_outside_form->set(ni, input); + + input->setEnabled(false); } } @@ -244,18 +258,20 @@ static void Html_add_input(DilloHtml *html, DilloHtmlInputType type, */ static DilloHtmlInput *Html_get_radio_input(DilloHtml *html, const char *name) { - lout::misc::SimpleVector<DilloHtmlInput*>* inputs; + if (name) { + lout::misc::SimpleVector<DilloHtmlInput*>* inputs; - if (html->InFlags & IN_FORM) - inputs = html->getCurrentForm()->inputs; - else - inputs = html->inputs_outside_form; + if (html->InFlags & IN_FORM) + inputs = html->getCurrentForm()->inputs; + else + inputs = html->inputs_outside_form; - for (int idx = 0; idx < inputs->size(); idx++) { - DilloHtmlInput *input = inputs->get(idx); - if (input->type == DILLO_HTML_INPUT_RADIO && - input->name && !dStrcasecmp(input->name, name)) - return input; + for (int idx = 0; idx < inputs->size(); idx++) { + DilloHtmlInput *input = inputs->get(idx); + if (input->type == DILLO_HTML_INPUT_RADIO && + input->name && !dStrcasecmp(input->name, name)) + return input; + } } return NULL; } @@ -283,11 +299,11 @@ void Html_tag_open_form(DilloHtml *html, const char *tag, int tagsize) { DilloUrl *action; DilloHtmlMethod method; - DilloHtmlEnc enc; + DilloHtmlEnc content_type; char *charset, *first; const char *attrbuf; - DW2TB(html->dw)->addParbreak (9, S_TOP(html)->style); + HT2TB(html)->addParbreak (9, html->styleEngine->wordStyle ()); if (html->InFlags & IN_FORM) { BUG_MSG("nested forms\n"); @@ -308,13 +324,15 @@ void Html_tag_open_form(DilloHtml *html, const char *tag, int tagsize) } if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "action"))) action = a_Html_url_new(html, attrbuf, NULL, 0); - else + else { + BUG_MSG("action attribute required for <form>\n"); action = a_Url_dup(html->base_url); - enc = DILLO_HTML_ENC_URLENCODING; + } + content_type = DILLO_HTML_ENC_URLENCODED; if ((method == DILLO_HTML_METHOD_POST) && ((attrbuf = a_Html_get_attr(html, tag, tagsize, "enctype")))) { if (!dStrcasecmp(attrbuf, "multipart/form-data")) - enc = DILLO_HTML_ENC_MULTIPART; + content_type = DILLO_HTML_ENC_MULTIPART; } charset = NULL; first = NULL; @@ -335,32 +353,19 @@ void Html_tag_open_form(DilloHtml *html, const char *tag, int tagsize) } if (!charset) charset = html->charset; - html->formNew(method, action, enc, charset); + html->formNew(method, action, content_type, charset); dFree(first); a_Url_free(action); } void Html_tag_close_form(DilloHtml *html, int TagIdx) { - static const char *SubmitTag = - "<input type='submit' value='?Submit?' alt='dillo-generated-button'>"; - DilloHtmlForm *form; +// DilloHtmlForm *form; // int i; - - if (html->InFlags & IN_FORM) { - form = html->getCurrentForm (); - /* If we don't have a submit button and the user desires one, - let's add a custom one */ - if (form->num_submit_buttons == 0) { - if (prefs.show_extra_warnings || form->num_entry_fields != 1) - BUG_MSG("FORM lacks a Submit button\n"); - if (prefs.generate_submit) { - BUG_MSG(" (added a submit button internally)\n"); - Html_tag_open_input(html, SubmitTag, strlen(SubmitTag)); - form->num_submit_buttons = 0; - } - } - +// +// if (html->InFlags & IN_FORM) { +// form = html->getCurrentForm (); +// // /* Make buttons sensitive again */ // for (i = 0; i < form->inputs->size(); i++) { // input_i = form->inputs->get(i); @@ -376,14 +381,31 @@ void Html_tag_close_form(DilloHtml *html, int TagIdx) // a_Dw_button_set_sensitive(DW_BUTTON(input_i->widget), TRUE); // } // } - } +// } html->InFlags &= ~IN_FORM; html->InFlags &= ~IN_SELECT; html->InFlags &= ~IN_OPTION; html->InFlags &= ~IN_TEXTAREA; +} - a_Html_pop_tag(html, TagIdx); +/* + * get size, restrict it to reasonable value + */ +static int Html_input_get_size(DilloHtml *html, const char *attrbuf) +{ + const int MAX_SIZE = 1024; + int size = 20; + + if (attrbuf) { + size = strtol(attrbuf, NULL, 10); + if (size < 1 || size > MAX_SIZE) { + int badSize = size; + size = (size < 1 ? 20 : MAX_SIZE); + BUG_MSG("input size=%d, using size=%d instead\n", badSize, size); + } + } + return size; } /* @@ -392,11 +414,13 @@ void Html_tag_close_form(DilloHtml *html, int TagIdx) void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) { DilloHtmlInputType inp_type; - dw::core::ui::Embed *embed = NULL; + Resource *resource = NULL; + Embed *embed = NULL; char *value, *name, *type, *init_str; const char *attrbuf, *label; bool init_val = false; - + ResourceFactory *factory; + if (html->InFlags & IN_SELECT) { BUG_MSG("<input> element inside <select>\n"); return; @@ -405,59 +429,50 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) BUG_MSG("<input> element inside <button>\n"); return; } - + + factory = HT2LT(html)->getResourceFactory(); + /* Get 'value', 'name' and 'type' */ value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL); name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL); type = a_Html_get_attr_wdef(html, tag, tagsize, "type", ""); - + init_str = NULL; inp_type = DILLO_HTML_INPUT_UNKNOWN; if (!dStrcasecmp(type, "password")) { inp_type = DILLO_HTML_INPUT_PASSWORD; - dw::core::ui::EntryResource *entryResource = - HT2LT(html)->getResourceFactory()->createEntryResource (10, true); - embed = new dw::core::ui::Embed (entryResource); - init_str = (value) ? value : NULL; + attrbuf = a_Html_get_attr(html, tag, tagsize, "size"); + int size = Html_input_get_size(html, attrbuf); + resource = factory->createEntryResource (size, true, NULL); + init_str = value; } else if (!dStrcasecmp(type, "checkbox")) { inp_type = DILLO_HTML_INPUT_CHECKBOX; - dw::core::ui::CheckButtonResource *check_b_r = - HT2LT(html)->getResourceFactory()->createCheckButtonResource(false); - embed = new dw::core::ui::Embed (check_b_r); + resource = factory->createCheckButtonResource(false); init_val = (a_Html_get_attr(html, tag, tagsize, "checked") != NULL); init_str = (value) ? value : dStrdup("on"); } else if (!dStrcasecmp(type, "radio")) { inp_type = DILLO_HTML_INPUT_RADIO; - dw::core::ui::RadioButtonResource *rb_r = NULL; + RadioButtonResource *rb_r = NULL; DilloHtmlInput *input = Html_get_radio_input(html, name); if (input) - rb_r = - (dw::core::ui::RadioButtonResource*) - input->embed->getResource(); - rb_r = HT2LT(html)->getResourceFactory() - ->createRadioButtonResource(rb_r, false); - embed = new dw::core::ui::Embed (rb_r); + rb_r = (RadioButtonResource*) input->embed->getResource(); + resource = factory->createRadioButtonResource(rb_r, false); init_val = (a_Html_get_attr(html, tag, tagsize, "checked") != NULL); - init_str = (value) ? value : NULL; + init_str = value; } else if (!dStrcasecmp(type, "hidden")) { inp_type = DILLO_HTML_INPUT_HIDDEN; - if (value) - init_str = dStrdup(a_Html_get_attr(html, tag, tagsize, "value")); + init_str = value; + int size = Html_input_get_size(html, NULL); + resource = factory->createEntryResource(size, false, name); } else if (!dStrcasecmp(type, "submit")) { inp_type = DILLO_HTML_INPUT_SUBMIT; init_str = (value) ? value : dStrdup("submit"); - dw::core::ui::LabelButtonResource *label_b_r = - HT2LT(html)->getResourceFactory() - ->createLabelButtonResource(init_str); - embed = new dw::core::ui::Embed (label_b_r); + resource = factory->createLabelButtonResource(init_str); // gtk_widget_set_sensitive(widget, FALSE); /* Until end of FORM! */ } else if (!dStrcasecmp(type, "reset")) { inp_type = DILLO_HTML_INPUT_RESET; init_str = (value) ? value : dStrdup("Reset"); - dw::core::ui::LabelButtonResource *label_b_r = - HT2LT(html)->getResourceFactory() - ->createLabelButtonResource(init_str); - embed = new dw::core::ui::Embed (label_b_r); + resource = factory->createLabelButtonResource(init_str); // gtk_widget_set_sensitive(widget, FALSE); /* Until end of FORM! */ } else if (!dStrcasecmp(type, "image")) { if (URL_FLAGS(html->base_url) & URL_SpamSafe) { @@ -466,10 +481,7 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) attrbuf = a_Html_get_attr(html, tag, tagsize, "alt"); label = attrbuf ? attrbuf : value ? value : name ? name : "Submit"; init_str = dStrdup(label); - dw::core::ui::LabelButtonResource *label_b_r = - HT2LT(html)->getResourceFactory() - ->createLabelButtonResource(init_str); - embed = new dw::core::ui::Embed (label_b_r); + resource = factory->createLabelButtonResource(init_str); // gtk_widget_set_sensitive(widget, FALSE); /* Until end of FORM! */ } else { inp_type = DILLO_HTML_INPUT_IMAGE; @@ -485,7 +497,7 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) valid = false; BUG_MSG("Forms with file input MUST use HTTP POST method\n"); MSG("File input ignored in form not using HTTP POST method\n"); - } else if (form->enc != DILLO_HTML_ENC_MULTIPART) { + } else if (form->content_type != DILLO_HTML_ENC_MULTIPART) { valid = false; BUG_MSG("Forms with file input MUST use multipart/form-data" " encoding\n"); @@ -496,65 +508,60 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) if (valid) { inp_type = DILLO_HTML_INPUT_FILE; init_str = dStrdup("File selector"); - dw::core::ui::LabelButtonResource *lbr = - HT2LT(html)->getResourceFactory()-> - createLabelButtonResource(init_str); - embed = new dw::core::ui::Embed (lbr); + resource = factory->createLabelButtonResource(init_str); } } else if (!dStrcasecmp(type, "button")) { inp_type = DILLO_HTML_INPUT_BUTTON; if (value) { init_str = value; - dw::core::ui::LabelButtonResource *label_b_r = - HT2LT(html)->getResourceFactory() - ->createLabelButtonResource(init_str); - embed = new dw::core::ui::Embed (label_b_r); + resource = factory->createLabelButtonResource(init_str); } } else if (!dStrcasecmp(type, "text") || !*type) { /* Text input, which also is the default */ inp_type = DILLO_HTML_INPUT_TEXT; - dw::core::ui::EntryResource *entryResource = - HT2LT(html)->getResourceFactory()->createEntryResource (10, false); - embed = new dw::core::ui::Embed (entryResource); - init_str = (value) ? value : NULL; + attrbuf = a_Html_get_attr(html, tag, tagsize, "size"); + int size = Html_input_get_size(html, attrbuf); + resource = factory->createEntryResource(size, false, NULL); + init_str = value; } else { /* Unknown input type */ BUG_MSG("Unknown input type: \"%s\"\n", type); } + if (resource) + embed = new Embed (resource); + if (inp_type != DILLO_HTML_INPUT_UNKNOWN) { Html_add_input(html, inp_type, embed, name, (init_str) ? init_str : "", init_val); } - - if (embed != NULL && inp_type != DILLO_HTML_INPUT_IMAGE && + + if (embed != NULL && inp_type != DILLO_HTML_INPUT_IMAGE && inp_type != DILLO_HTML_INPUT_UNKNOWN) { + if (inp_type == DILLO_HTML_INPUT_HIDDEN) { + /* TODO Perhaps do this with access to current form setting */ + embed->setDisplayed(false); + } if (inp_type == DILLO_HTML_INPUT_TEXT || inp_type == DILLO_HTML_INPUT_PASSWORD) { - dw::core::ui::EntryResource *entryres = - (dw::core::ui::EntryResource*)embed->getResource(); - /* Readonly or not? */ if (a_Html_get_attr(html, tag, tagsize, "readonly")) - entryres->setEditable(false); + ((EntryResource *) resource)->setEditable(false); -// /* Set width of the entry */ -// if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "size"))) -// gtk_widget_set_usize(widget, (strtol(attrbuf, NULL, 10) + 1) * -// gdk_char_width(widget->style->font, '0'), 0); -// // /* Maximum length of the text in the entry */ // if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "maxlength"))) // gtk_entry_set_max_length(GTK_ENTRY(widget), // strtol(attrbuf, NULL, 10)); } - Color *bg; - if (prefs.standard_widget_colors) - bg = NULL; - else - bg = Color::createShaded(HT2LT(html), S_TOP(html)->current_bg_color); - HTML_SET_TOP_ATTR(html, backgroundColor, bg); - - DW2TB(html->dw)->addWidget (embed, S_TOP(html)->style); + if (prefs.show_tooltip && + (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { + CssPropertyList props; + char *tooltip_str = dStrdup(attrbuf); + + props.set (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, tooltip_str); + html->styleEngine->setNonCssHints (&props); + dFree(tooltip_str); + } + HT2TB(html)->addWidget (embed, html->styleEngine->backgroundStyle()); } dFree(type); dFree(name); @@ -570,7 +577,7 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) void Html_tag_open_isindex(DilloHtml *html, const char *tag, int tagsize) { DilloUrl *action; - dw::core::ui::Embed *embed; + Embed *embed; const char *attrbuf; if (html->InFlags & IN_FORM) { @@ -582,28 +589,22 @@ void Html_tag_open_isindex(DilloHtml *html, const char *tag, int tagsize) action = a_Html_url_new(html, attrbuf, NULL, 0); else action = a_Url_dup(html->base_url); - - html->formNew(DILLO_HTML_METHOD_GET, action, DILLO_HTML_ENC_URLENCODING, + + html->formNew(DILLO_HTML_METHOD_GET, action, DILLO_HTML_ENC_URLENCODED, html->charset); html->InFlags |= IN_FORM; - - DW2TB(html->dw)->addParbreak (9, S_TOP(html)->style); - + + HT2TB(html)->addParbreak (9, html->styleEngine->wordStyle ()); + if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "prompt"))) - DW2TB(html->dw)->addText(attrbuf, S_TOP(html)->style); - - dw::core::ui::EntryResource *entryResource = - HT2LT(html)->getResourceFactory()->createEntryResource (10, false); - embed = new dw::core::ui::Embed (entryResource); + HT2TB(html)->addText(attrbuf, html->styleEngine->wordStyle ()); + + ResourceFactory *factory = HT2LT(html)->getResourceFactory(); + EntryResource *entryResource = factory->createEntryResource (20,false,NULL); + embed = new Embed (entryResource); Html_add_input(html, DILLO_HTML_INPUT_INDEX, embed, NULL, NULL, FALSE); - Color *bg; - if (prefs.standard_widget_colors) - bg = NULL; - else - bg = Color::createShaded(HT2LT(html), S_TOP(html)->current_bg_color); - HTML_SET_TOP_ATTR(html, backgroundColor, bg); - DW2TB(html->dw)->addWidget (embed, S_TOP(html)->style); + HT2TB(html)->addWidget (embed, html->styleEngine->backgroundStyle ()); a_Url_free(action); html->InFlags &= ~IN_FORM; @@ -620,7 +621,7 @@ void Html_tag_open_textarea(DilloHtml *html, const char *tag, int tagsize) char *name; const char *attrbuf; int cols, rows; - + if (html->InFlags & IN_TEXTAREA) { BUG_MSG("nested <textarea>\n"); html->ReqTagClose = TRUE; @@ -630,22 +631,28 @@ void Html_tag_open_textarea(DilloHtml *html, const char *tag, int tagsize) BUG_MSG("<textarea> element inside <select>\n"); return; } - + html->InFlags |= IN_TEXTAREA; a_Html_stash_init(html); S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_VERBATIM; - - cols = 20; - if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "cols"))) + + if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "cols"))) { cols = strtol(attrbuf, NULL, 10); + } else { + BUG_MSG("cols attribute is required for <textarea>\n"); + cols = 20; + } if (cols < 1 || cols > MAX_COLS) { int badCols = cols; cols = (cols < 1 ? 20 : MAX_COLS); BUG_MSG("textarea cols=%d, using cols=%d instead\n", badCols, cols); } - rows = 10; - if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "rows"))) + if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "rows"))) { rows = strtol(attrbuf, NULL, 10); + } else { + BUG_MSG("rows attribute is required for <textarea>\n"); + rows = 10; + } if (rows < 1 || rows > MAX_ROWS) { int badRows = rows; rows = (rows < 1 ? 2 : MAX_ROWS); @@ -655,24 +662,17 @@ void Html_tag_open_textarea(DilloHtml *html, const char *tag, int tagsize) if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "name"))) name = dStrdup(attrbuf); - dw::core::ui::MultiLineTextResource *textres = - HT2LT(html)->getResourceFactory()->createMultiLineTextResource (cols, - rows); + ResourceFactory *factory = HT2LT(html)->getResourceFactory(); + MultiLineTextResource *textres = + factory->createMultiLineTextResource (cols, rows); - dw::core::ui::Embed *embed = new dw::core::ui::Embed(textres); + Embed *embed = new Embed(textres); /* Readonly or not? */ if (a_Html_get_attr(html, tag, tagsize, "readonly")) textres->setEditable(false); Html_add_input(html, DILLO_HTML_INPUT_TEXTAREA, embed, name, NULL, false); - Color *bg; - if (prefs.standard_widget_colors) - bg = NULL; - else - bg = Color::createShaded(HT2LT(html), S_TOP(html)->current_bg_color); - HTML_SET_TOP_ATTR(html, backgroundColor, bg); - - DW2TB(html->dw)->addWidget (embed, S_TOP(html)->style); + HT2TB(html)->addWidget (embed, html->styleEngine->backgroundStyle ()); dFree(name); } @@ -692,7 +692,7 @@ void Html_tag_close_textarea(DilloHtml *html, int TagIdx) dStr_erase(html->Stash, 0, 1); if (html->Stash->str[0] == '\n') dStr_erase(html->Stash, 0, 1); - + /* As the spec recommends to canonicalize line endings, it is safe * to replace '\r' with '\n'. It will be canonicalized anyway! */ for (i = 0; i < html->Stash->len; ++i) { @@ -703,17 +703,15 @@ void Html_tag_close_textarea(DilloHtml *html, int TagIdx) html->Stash->str[i] = '\n'; } } - + /* The HTML3.2 spec says it can have "text and character entities". */ str = a_Html_parse_entities(html, html->Stash->str, html->Stash->len); input = Html_get_current_input(html); input->init_str = str; - ((dw::core::ui::MultiLineTextResource *)input->embed->getResource ()) - ->setText(str); + ((MultiLineTextResource *)input->embed->getResource ())->setText(str); html->InFlags &= ~IN_TEXTAREA; } - a_Html_pop_tag(html, TagIdx); } /* @@ -722,8 +720,8 @@ void Html_tag_close_textarea(DilloHtml *html, int TagIdx) /* The select tag is quite tricky, because of gorpy html syntax. */ void Html_tag_open_select(DilloHtml *html, const char *tag, int tagsize) { -// const char *attrbuf; -// int size, type, multi; + const char *attrbuf; + int rows = 0; if (html->InFlags & IN_SELECT) { BUG_MSG("nested <select>\n"); @@ -733,51 +731,32 @@ void Html_tag_open_select(DilloHtml *html, const char *tag, int tagsize) html->InFlags &= ~IN_OPTION; char *name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL); - dw::core::ui::ResourceFactory *factory = - HT2LT(html)->getResourceFactory (); + ResourceFactory *factory = HT2LT(html)->getResourceFactory (); DilloHtmlInputType type; - dw::core::ui::SelectionResource *res; - if (a_Html_get_attr(html, tag, tagsize, "multiple")) { - type = DILLO_HTML_INPUT_SEL_LIST; - res = factory->createListResource ( - dw::core::ui::ListResource::SELECTION_MULTIPLE); - } else { - type = DILLO_HTML_INPUT_SELECT; - res = factory->createOptionMenuResource (); + SelectionResource *res; + bool multi = a_Html_get_attr(html, tag, tagsize, "multiple") != NULL; + + if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "size"))) { + rows = strtol(attrbuf, NULL, 10); + if (rows > 100) + rows = 100; } - dw::core::ui::Embed *embed = new dw::core::ui::Embed(res); + if (rows < 1) + rows = multi ? 10 : 1; - int bg; - if (prefs.standard_widget_colors) { - /* Valid colors required; SELECT can contain other elements (BUG) */ - HTML_SET_TOP_ATTR(html, color, Color::createSimple (HT2LT(html), 0)); - bg = 0xffffff; + if (rows == 1 && multi == false) { + type = DILLO_HTML_INPUT_SELECT; + res = factory->createOptionMenuResource (); } else { - bg = S_TOP(html)->current_bg_color; + type = DILLO_HTML_INPUT_SEL_LIST; + res = factory->createListResource (multi ? + ListResource::SELECTION_MULTIPLE : + ListResource::SELECTION_EXACTLY_ONE, + rows); } - HTML_SET_TOP_ATTR(html, backgroundColor, - Color::createShaded (HT2LT(html), bg)); - DW2TB(html->dw)->addWidget (embed, S_TOP(html)->style); + Embed *embed = new Embed(res); -// size = 0; -// if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "size"))) -// size = strtol(attrbuf, NULL, 10); -// -// multi = (a_Html_get_attr(html, tag, tagsize, "multiple")) ? 1 : 0; -// if (size < 1) -// size = multi ? 10 : 1; -// -// if (size == 1) { -// menu = gtk_menu_new(); -// widget = gtk_option_menu_new(); -// type = DILLO_HTML_INPUT_SELECT; -// } else { -// menu = gtk_list_new(); -// widget = menu; -// if (multi) -// gtk_list_set_selection_mode(GTK_LIST(menu), GTK_SELECTION_MULTIPLE); -// type = DILLO_HTML_INPUT_SEL_LIST; -// } + HT2TB(html)->addWidget (embed, html->styleEngine->backgroundStyle ()); Html_add_input(html, type, embed, name, NULL, false); a_Html_stash_init(html); @@ -798,15 +777,12 @@ void Html_tag_close_select(DilloHtml *html, int TagIdx) DilloHtmlInput *input = Html_get_current_input(html); DilloHtmlSelect *select = input->select; - // BUG(?): should not do this for MULTI selections + // BUG(?): should not do this for MULTI selections select->ensureSelection (); - dw::core::ui::SelectionResource *res = - (dw::core::ui::SelectionResource*)input->embed->getResource(); + SelectionResource *res = (SelectionResource*)input->embed->getResource(); select->addOptionsTo (res); } - - a_Html_pop_tag(html, TagIdx); } /* @@ -826,13 +802,10 @@ void Html_tag_open_option(DilloHtml *html, const char *tag, int tagsize) if (input->type == DILLO_HTML_INPUT_SELECT || input->type == DILLO_HTML_INPUT_SEL_LIST) { - char *value = - a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL); - bool selected = - (a_Html_get_attr(html, tag, tagsize, "selected") != NULL); - bool enabled = - (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL); - input->select->addOption(value,selected,enabled); + char *value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL); + bool selected = (a_Html_get_attr(html, tag, tagsize,"selected") != NULL); + bool enabled = (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL); + input->select->addOption(value, selected, enabled); } a_Html_stash_init(html); @@ -876,37 +849,23 @@ void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize) if (inp_type != DILLO_HTML_INPUT_UNKNOWN) { /* Render the button */ - dw::core::style::StyleAttrs style_attrs; - dw::core::style::Style *style; - dw::core::Widget *page; - dw::core::ui::Embed *embed; + Widget *page; + Embed *embed; char *name, *value; - style_attrs = *S_TOP(html)->style; - style_attrs.margin.setVal(0); - style_attrs.borderWidth.setVal(0); - style_attrs.padding.setVal(0); - style_attrs.backgroundColor = - Color::createShaded(HT2LT(html), S_TOP(html)->current_bg_color); - style = Style::create (HT2LT(html), &style_attrs); - page = new Textblock (prefs.limit_text_width); - page->setStyle (style); + page->setStyle (html->styleEngine->backgroundStyle ()); - dw::core::ui::ComplexButtonResource *complex_b_r = - HT2LT(html)->getResourceFactory() - ->createComplexButtonResource(page, true); - embed = new dw::core::ui::Embed(complex_b_r); + ResourceFactory *factory = HT2LT(html)->getResourceFactory(); + Resource *resource = factory->createComplexButtonResource(page, true); + embed = new Embed(resource); // a_Dw_button_set_sensitive (DW_BUTTON (button), FALSE); - DW2TB(html->dw)->addParbreak (5, style); - DW2TB(html->dw)->addWidget (embed, style); - DW2TB(html->dw)->addParbreak (5, style); - style->unref (); + HT2TB(html)->addParbreak (5, html->styleEngine->wordStyle ()); + HT2TB(html)->addWidget (embed, html->styleEngine->style ()); + HT2TB(html)->addParbreak (5, html->styleEngine->wordStyle ()); S_TOP(html)->textblock = html->dw = page; - /* right button press for menus for button contents */ - html->connectSignals(page); value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL); name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL); @@ -924,39 +883,39 @@ void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize) void Html_tag_close_button(DilloHtml *html, int TagIdx) { html->InFlags &= ~IN_BUTTON; - a_Html_pop_tag(html, TagIdx); } /* - * Class implementations + * Class implementations */ /* - * DilloHtmlForm + * DilloHtmlForm */ /* - * Constructor + * Constructor */ DilloHtmlForm::DilloHtmlForm (DilloHtml *html2, DilloHtmlMethod method2, const DilloUrl *action2, - DilloHtmlEnc enc2, - const char *charset) + DilloHtmlEnc content_type2, + const char *charset, bool enabled) { html = html2; method = method2; action = a_Url_dup(action2); - enc = enc2; + content_type = content_type2; submit_charset = dStrdup(charset); inputs = new misc::SimpleVector <DilloHtmlInput*> (4); num_entry_fields = 0; - num_submit_buttons = 0; + showing_hiddens = false; + this->enabled = enabled; form_receiver = new DilloHtmlReceiver (this); } /* - * Destructor + * Destructor */ DilloHtmlForm::~DilloHtmlForm () { @@ -969,17 +928,18 @@ DilloHtmlForm::~DilloHtmlForm () delete(form_receiver); } -void DilloHtmlForm::eventHandler(dw::core::ui::Resource *resource) +void DilloHtmlForm::eventHandler(Resource *resource, EventButton *event) { MSG("DilloHtmlForm::eventHandler\n"); - DilloHtmlInput *input = getInput(resource); - if (input) { - bool force_submit = - prefs.enterpress_forces_submit || - num_entry_fields == 1; - input->activate (this, force_submit); + if (event && (event->button == 3)) { + a_UIcmd_form_popup(html->bw, html->page_url, this, showing_hiddens); } else { - MSG("DilloHtmlForm::eventHandler: ERROR, input not found!\n"); + DilloHtmlInput *input = getInput(resource); + if (input) { + input->activate (this, num_entry_fields, event); + } else { + MSG("DilloHtmlForm::eventHandler: ERROR, input not found!\n"); + } } } @@ -987,11 +947,21 @@ void DilloHtmlForm::eventHandler(dw::core::ui::Resource *resource) * Submit. * (Called by eventHandler()) */ -void DilloHtmlForm::submit(DilloHtmlInput *input) +void DilloHtmlForm::submit(DilloHtmlInput *active_input, EventButton *event) { - DilloUrl *url = buildQueryUrl(input); + DilloUrl *url = buildQueryUrl(active_input); if (url) { - a_Nav_push(html->bw, url); + if (event && event->button == 2) { + if (prefs.middle_click_opens_new_tab) { + int focus = prefs.focus_new_tab ? 1 : 0; + if (event->state == SHIFT_MASK) focus = !focus; + a_UIcmd_open_url_nt(html->bw, url, focus); + } else { + a_UIcmd_open_url_nw(html->bw, url); + } + } else { + a_UIcmd_open_url(html->bw, url); + } a_Url_free(url); } // /* now, make the rendered area have its focus back */ @@ -1002,7 +972,7 @@ void DilloHtmlForm::submit(DilloHtmlInput *input) * Build a new query URL. * (Called by submit()) */ -DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *input) +DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) { DilloUrl *new_url = NULL; @@ -1013,11 +983,11 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *input) _MSG("DilloHtmlForm::buildQueryUrl: action=%s\n",URL_STR_(action)); - if (num_submit_buttons > 0) { - if ((input->type == DILLO_HTML_INPUT_SUBMIT) || - (input->type == DILLO_HTML_INPUT_IMAGE) || - (input->type == DILLO_HTML_INPUT_BUTTON_SUBMIT)) { - active_submit = input; + if (active_input) { + if ((active_input->type == DILLO_HTML_INPUT_SUBMIT) || + (active_input->type == DILLO_HTML_INPUT_IMAGE) || + (active_input->type == DILLO_HTML_INPUT_BUTTON_SUBMIT)) { + active_submit = active_input; } } @@ -1031,7 +1001,7 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *input) /* new_url keeps the dStr and sets DataStr to NULL */ a_Url_set_data(new_url, &DataStr); a_Url_set_flags(new_url, URL_FLAGS(new_url) | URL_Post); - if (enc == DILLO_HTML_ENC_MULTIPART) + if (content_type == DILLO_HTML_ENC_MULTIPART) a_Url_set_flags(new_url, URL_FLAGS(new_url) | URL_MultipartEnc); } else { /* remove <fragment> and <query> sections if present */ @@ -1063,11 +1033,11 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) { Dstr *DataStr = NULL; char *boundary = NULL; - iconv_t encoder = (iconv_t) -1; + iconv_t char_encoder = (iconv_t) -1; if (submit_charset && dStrcasecmp(submit_charset, "UTF-8")) { - encoder = iconv_open(submit_charset, "UTF-8"); - if (encoder == (iconv_t) -1) { + char_encoder = iconv_open(submit_charset, "UTF-8"); + if (char_encoder == (iconv_t) -1) { MSG_WARN("Cannot convert to character encoding '%s'\n", submit_charset); } else { @@ -1075,95 +1045,95 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) } } - if (enc == DILLO_HTML_ENC_MULTIPART) { - if (!(boundary = makeMultipartBoundary(encoder, active_submit))) + if (content_type == DILLO_HTML_ENC_MULTIPART) { + if (!(boundary = makeMultipartBoundary(char_encoder, active_submit))) MSG_ERR("Cannot generate multipart/form-data boundary.\n"); } - if ((enc == DILLO_HTML_ENC_URLENCODING) || (boundary != NULL)) { + if ((content_type == DILLO_HTML_ENC_URLENCODED) || (boundary != NULL)) { Dlist *values = dList_new(5); DataStr = dStr_sized_new(4096); - for (int input_idx = 0; input_idx < inputs->size(); input_idx++) { - DilloHtmlInput *input = inputs->get (input_idx); + for (int i = 0; i < inputs->size(); i++) { + DilloHtmlInput *input = inputs->get (i); Dstr *name = dStr_new(input->name); bool is_active_submit = (input == active_submit); + int valcount; - name = encodeText(encoder, &name); + name = encodeText(char_encoder, &name); input->appendValuesTo(values, is_active_submit); - if (input->type == DILLO_HTML_INPUT_FILE && dList_length(values) >0) { - if (dList_length(values) > 1) - MSG_WARN("multiple files per form control not supported\n"); - Dstr *file = (Dstr *) dList_nth_data(values, 0); - dList_remove(values, file); - - /* Get filename and encode it. Do not encode file contents. */ - dw::core::ui::LabelButtonResource *lbr = - (dw::core::ui::LabelButtonResource*) - input->embed->getResource(); - const char *filename = lbr->getLabel(); - if (filename[0] && strcmp(filename, input->init_str)) { - char *p = strrchr(filename, '/'); - if (p) - filename = p + 1; /* don't reveal path */ - Dstr *dfilename = dStr_new(filename); - dfilename = encodeText(encoder, &dfilename); - appendInputMultipartFiles(DataStr, boundary, name->str, - file, dfilename->str); - dStr_free(dfilename, 1); - } - dStr_free(file, 1); - } else if (input->type == DILLO_HTML_INPUT_INDEX) { - Dstr *val = (Dstr *) dList_nth_data(values, 0); - dList_remove(values, val); - val = encodeText(encoder, &val); - urlencodeAppend(DataStr, val->str); - dStr_free(val, 1); - } else if (input->type == DILLO_HTML_INPUT_IMAGE) { - if (dList_length(values) > 0) { + if ((valcount = dList_length(values)) > 0) { + if (input->type == DILLO_HTML_INPUT_FILE) { + if (valcount > 1) + MSG_WARN("multiple files per form control not supported\n"); + Dstr *file = (Dstr *) dList_nth_data(values, 0); + dList_remove(values, file); + + /* Get filename and encode it. Do not encode file contents. */ + LabelButtonResource *lbr = + (LabelButtonResource*) input->embed->getResource(); + const char *filename = lbr->getLabel(); + if (filename[0] && strcmp(filename, input->init_str)) { + const char *p = strrchr(filename, '/'); + if (p) + filename = p + 1; /* don't reveal path */ + Dstr *dfilename = dStr_new(filename); + dfilename = encodeText(char_encoder, &dfilename); + filesInputMultipartAppend(DataStr, boundary, name->str, + file, dfilename->str); + dStr_free(dfilename, 1); + } + dStr_free(file, 1); + } else if (input->type == DILLO_HTML_INPUT_INDEX) { + /* no name */ + Dstr *val = (Dstr *) dList_nth_data(values, 0); + dList_remove(values, val); + val = encodeText(char_encoder, &val); + strUrlencodeAppend(DataStr, val->str); + dStr_free(val, 1); + } else if (input->type == DILLO_HTML_INPUT_IMAGE) { Dstr *x, *y; x = (Dstr *) dList_nth_data(values, 0); dList_remove(values, x); y = (Dstr *) dList_nth_data(values, 0); dList_remove(values, y); - if (enc == DILLO_HTML_ENC_URLENCODING) - appendClickposUrlencode(DataStr, name, x, y); - else if (enc == DILLO_HTML_ENC_MULTIPART) - appendClickposMultipart(DataStr, boundary, name, x, y); + if (content_type == DILLO_HTML_ENC_URLENCODED) + imageInputUrlencodeAppend(DataStr, name, x, y); + else if (content_type == DILLO_HTML_ENC_MULTIPART) + imageInputMultipartAppend(DataStr, boundary, name, x, y); dStr_free(x, 1); dStr_free(y, 1); - } - } else { - int length = dList_length(values), i; - for (i = 0; i < length; i++) { - Dstr *val = (Dstr *) dList_nth_data(values, 0); - dList_remove(values, val); - val = encodeText(encoder, &val); - if (enc == DILLO_HTML_ENC_URLENCODING) - appendInputUrlencode(DataStr, name->str, val->str); - else if (enc == DILLO_HTML_ENC_MULTIPART) - appendInputMultipart(DataStr, boundary, - name->str, val->str); - dStr_free(val, 1); + } else { + for (int j = 0; j < valcount; j++) { + Dstr *val = (Dstr *) dList_nth_data(values, 0); + dList_remove(values, val); + val = encodeText(char_encoder, &val); + if (content_type == DILLO_HTML_ENC_URLENCODED) + inputUrlencodeAppend(DataStr, name->str, val->str); + else if (content_type == DILLO_HTML_ENC_MULTIPART) + inputMultipartAppend(DataStr, boundary, name->str, + val->str); + dStr_free(val, 1); + } } } dStr_free(name, 1); } if (DataStr->len > 0) { - if (enc == DILLO_HTML_ENC_URLENCODING) { + if (content_type == DILLO_HTML_ENC_URLENCODED) { if (DataStr->str[DataStr->len - 1] == '&') dStr_truncate(DataStr, DataStr->len - 1); - } else if (enc == DILLO_HTML_ENC_MULTIPART) { + } else if (content_type == DILLO_HTML_ENC_MULTIPART) { dStr_append(DataStr, "--"); } } dList_free(values); } dFree(boundary); - if (encoder != (iconv_t) -1) - (void)iconv_close(encoder); + if (char_encoder != (iconv_t) -1) + (void)iconv_close(char_encoder); return DataStr; } @@ -1171,7 +1141,7 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) * Generate a boundary string for use in separating the parts of a * multipart/form-data submission. */ -char *DilloHtmlForm::makeMultipartBoundary(iconv_t encoder, +char *DilloHtmlForm::makeMultipartBoundary(iconv_t char_encoder, DilloHtmlInput *active_submit) { const int max_tries = 10; @@ -1181,25 +1151,25 @@ char *DilloHtmlForm::makeMultipartBoundary(iconv_t encoder, char *ret = NULL; /* fill DataStr with names, filenames, and values */ - for (int input_idx = 0; input_idx < inputs->size(); input_idx++) { + for (int i = 0; i < inputs->size(); i++) { Dstr *dstr; - DilloHtmlInput *input = inputs->get (input_idx); + DilloHtmlInput *input = inputs->get (i); bool is_active_submit = (input == active_submit); input->appendValuesTo(values, is_active_submit); if (input->name) { dstr = dStr_new(input->name); - dstr = encodeText(encoder, &dstr); + dstr = encodeText(char_encoder, &dstr); dStr_append_l(DataStr, dstr->str, dstr->len); dStr_free(dstr, 1); } if (input->type == DILLO_HTML_INPUT_FILE) { - dw::core::ui::LabelButtonResource *lbr = - (dw::core::ui::LabelButtonResource*)input->embed->getResource(); + LabelButtonResource *lbr = + (LabelButtonResource*)input->embed->getResource(); const char *filename = lbr->getLabel(); if (filename[0] && strcmp(filename, input->init_str)) { dstr = dStr_new(filename); - dstr = encodeText(encoder, &dstr); + dstr = encodeText(char_encoder, &dstr); dStr_append_l(DataStr, dstr->str, dstr->len); dStr_free(dstr, 1); } @@ -1209,7 +1179,7 @@ char *DilloHtmlForm::makeMultipartBoundary(iconv_t encoder, dstr = (Dstr *) dList_nth_data(values, 0); dList_remove(values, dstr); if (input->type != DILLO_HTML_INPUT_FILE) - dstr = encodeText(encoder, &dstr); + dstr = encodeText(char_encoder, &dstr); dStr_append_l(DataStr, dstr->str, dstr->len); dStr_free(dstr, 1); } @@ -1233,9 +1203,9 @@ char *DilloHtmlForm::makeMultipartBoundary(iconv_t encoder, /* * Pass input text through character set encoder. * Return value: same input Dstr if no encoding is needed. - new Dstr when encoding (input Dstr is freed). + * new Dstr when encoding (input Dstr is freed). */ -Dstr *DilloHtmlForm::encodeText(iconv_t encoder, Dstr **input) +Dstr *DilloHtmlForm::encodeText(iconv_t char_encoder, Dstr **input) { int rc = 0; Dstr *output; @@ -1245,7 +1215,7 @@ Dstr *DilloHtmlForm::encodeText(iconv_t encoder, Dstr **input) size_t inLeft, outRoom; bool bad_chars = false; - if ((encoder == (iconv_t) -1) || *input == NULL || (*input)->len == 0) + if ((char_encoder == (iconv_t) -1) || *input == NULL || (*input)->len == 0) return *input; output = dStr_new(""); @@ -1258,7 +1228,7 @@ Dstr *DilloHtmlForm::encodeText(iconv_t encoder, Dstr **input) outPtr = buffer; outRoom = bufsize; - rc = iconv(encoder, &inPtr, &inLeft, &outPtr, &outRoom); + rc = iconv(char_encoder, &inPtr, &inLeft, &outPtr, &outRoom); // iconv() on success, number of bytes converted // -1, errno == EILSEQ illegal byte sequence found @@ -1298,28 +1268,27 @@ Dstr *DilloHtmlForm::encodeText(iconv_t encoder, Dstr **input) return output; } - + /* - * Urlencode 'val' and append it to 'str' + * Urlencode 'str' and append it to 'dstr' */ -void DilloHtmlForm::urlencodeAppend(Dstr *str, const char *val) +void DilloHtmlForm::strUrlencodeAppend(Dstr *dstr, const char *str) { - char *enc_val = a_Url_encode_hex_str(val); - dStr_append(str, enc_val); - dFree(enc_val); + char *encoded = a_Url_encode_hex_str(str); + dStr_append(dstr, encoded); + dFree(encoded); } /* * Append a name-value pair to url data using url encoding. */ -void DilloHtmlForm::appendInputUrlencode(Dstr *data, - const char *name, +void DilloHtmlForm::inputUrlencodeAppend(Dstr *data, const char *name, const char *value) { if (name && name[0]) { - urlencodeAppend(data, name); + strUrlencodeAppend(data, name); dStr_append_c(data, '='); - urlencodeAppend(data, value); + strUrlencodeAppend(data, value); dStr_append_c(data, '&'); } } @@ -1328,7 +1297,7 @@ void DilloHtmlForm::appendInputUrlencode(Dstr *data, * Append files to URL data using multipart encoding. * Currently only accepts one file. */ -void DilloHtmlForm::appendInputMultipartFiles(Dstr* data, +void DilloHtmlForm::filesInputMultipartAppend(Dstr* data, const char *boundary, const char *name, Dstr *file, @@ -1379,7 +1348,7 @@ void DilloHtmlForm::appendInputMultipartFiles(Dstr* data, /* * Append a name-value pair to url data using multipart encoding. */ -void DilloHtmlForm::appendInputMultipart(Dstr *data, +void DilloHtmlForm::inputMultipartAppend(Dstr *data, const char *boundary, const char *name, const char *value) @@ -1403,13 +1372,13 @@ void DilloHtmlForm::appendInputMultipart(Dstr *data, /* * Append an image button click position to url data using url encoding. */ -void DilloHtmlForm::appendClickposUrlencode(Dstr *data, Dstr *name, Dstr *x, - Dstr *y) +void DilloHtmlForm::imageInputUrlencodeAppend(Dstr *data, Dstr *name, Dstr *x, + Dstr *y) { if (name->len) { - urlencodeAppend(data, name->str); + strUrlencodeAppend(data, name->str); dStr_sprintfa(data, ".x=%s&", x->str); - urlencodeAppend(data, name->str); + strUrlencodeAppend(data, name->str); dStr_sprintfa(data, ".y=%s&", y->str); } else dStr_sprintfa(data, "x=%s&y=%s&", x->str, y->str); @@ -1418,8 +1387,8 @@ void DilloHtmlForm::appendClickposUrlencode(Dstr *data, Dstr *name, Dstr *x, /* * Append an image button click position to url data using multipart encoding. */ -void DilloHtmlForm::appendClickposMultipart(Dstr *data, const char *boundary, - Dstr *name, Dstr *x, Dstr *y) +void DilloHtmlForm::imageInputMultipartAppend(Dstr *data, const char *boundary, + Dstr *name, Dstr *x, Dstr *y) { int orig_len = name->len; @@ -1427,10 +1396,10 @@ void DilloHtmlForm::appendClickposMultipart(Dstr *data, const char *boundary, dStr_append_c(name, '.'); dStr_append_c(name, 'x'); - appendInputMultipart(data, boundary, name->str, x->str); + inputMultipartAppend(data, boundary, name->str, x->str); dStr_truncate(name, name->len - 1); dStr_append_c(name, 'y'); - appendInputMultipart(data, boundary, name->str, y->str); + inputMultipartAppend(data, boundary, name->str, y->str); dStr_truncate(name, orig_len); } @@ -1446,11 +1415,33 @@ void DilloHtmlForm::reset () } /* + * Show/hide "hidden" form controls + */ +void DilloHtmlForm::display_hiddens(bool display) +{ + int size = inputs->size(); + for (int i = 0; i < size; i++) { + DilloHtmlInput *input = inputs->get(i); + if (input->type == DILLO_HTML_INPUT_HIDDEN) { + input->embed->setDisplayed(display); + } + } + showing_hiddens = display; +} + +void DilloHtmlForm::setEnabled(bool enabled) +{ + for (int i = 0; i < inputs->size(); i++) + inputs->get(i)->setEnabled(enabled); +} + +/* * Add a new input. */ void DilloHtmlForm::addInput(DilloHtmlInput *input, DilloHtmlInputType type) { input->connectTo (form_receiver); + input->setEnabled (enabled); int ni = inputs->size (); inputs->increase (); inputs->set (ni,input); @@ -1459,17 +1450,13 @@ void DilloHtmlForm::addInput(DilloHtmlInput *input, DilloHtmlInputType type) if (type == DILLO_HTML_INPUT_PASSWORD || type == DILLO_HTML_INPUT_TEXT) { num_entry_fields++; - } else if (type == DILLO_HTML_INPUT_SUBMIT || - type == DILLO_HTML_INPUT_BUTTON_SUBMIT || - type == DILLO_HTML_INPUT_IMAGE) { - num_submit_buttons++; } } /* * Return the input with a given resource. */ -DilloHtmlInput *DilloHtmlForm::getInput (dw::core::ui::Resource *resource) +DilloHtmlInput *DilloHtmlForm::getInput (Resource *resource) { for (int idx = 0; idx < inputs->size(); idx++) { DilloHtmlInput *input = inputs->get(idx); @@ -1495,22 +1482,22 @@ DilloHtmlInput *DilloHtmlForm::getRadioInput (const char *name) } /* - * DilloHtmlReceiver + * DilloHtmlReceiver * * TODO: Currently there's "clicked" for buttons, we surely need "enter" for * textentries, and maybe the "mouseover, ...." set for Javascript. */ -void DilloHtmlReceiver::activate (dw::core::ui::Resource *resource) +void DilloHtmlReceiver::activate (Resource *resource) { - form->eventHandler(resource); + form->eventHandler(resource, NULL); } /* * Enter a form control, as in "onmouseover". * For _pressing_ enter in a text control, see activate(). */ -void DilloHtmlReceiver::enter (dw::core::ui::Resource *resource) +void DilloHtmlReceiver::enter (Resource *resource) { DilloHtml *html = form->html; DilloHtmlInput *input = form->getInput(resource); @@ -1532,29 +1519,27 @@ void DilloHtmlReceiver::enter (dw::core::ui::Resource *resource) /* * Leave a form control, or "onmouseout". */ -void DilloHtmlReceiver::leave (dw::core::ui::Resource *resource) +void DilloHtmlReceiver::leave (Resource *resource) { DilloHtml *html = form->html; a_UIcmd_set_msg(html->bw, ""); } -void DilloHtmlReceiver::clicked (dw::core::ui::ButtonResource *resource, - int buttonNo, int x, int y) +void DilloHtmlReceiver::clicked (Resource *resource, + EventButton *event) { -// form->eventHandler(resource, x, y); + form->eventHandler(resource, event); } /* - * DilloHtmlInput + * DilloHtmlInput */ /* - * Constructor + * Constructor */ -DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, - dw::core::ui::Embed *embed2, - const char *name2, - const char *init_str2, +DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, Embed *embed2, + const char *name2, const char *init_str2, bool init_val2) { type = type2; @@ -1576,7 +1561,7 @@ DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, } /* - * Destructor + * Destructor */ DilloHtmlInput::~DilloHtmlInput () { @@ -1592,61 +1577,57 @@ DilloHtmlInput::~DilloHtmlInput () */ void DilloHtmlInput::connectTo(DilloHtmlReceiver *form_receiver) { - dw::core::ui::Resource *resource = NULL; - if (embed) - resource = embed->getResource (); - switch (type) { - case DILLO_HTML_INPUT_UNKNOWN: - case DILLO_HTML_INPUT_HIDDEN: - case DILLO_HTML_INPUT_CHECKBOX: - case DILLO_HTML_INPUT_RADIO: - case DILLO_HTML_INPUT_BUTTON: - case DILLO_HTML_INPUT_TEXTAREA: - case DILLO_HTML_INPUT_SELECT: - case DILLO_HTML_INPUT_SEL_LIST: - // do nothing - break; - case DILLO_HTML_INPUT_TEXT: - case DILLO_HTML_INPUT_PASSWORD: - case DILLO_HTML_INPUT_INDEX: - case DILLO_HTML_INPUT_SUBMIT: - case DILLO_HTML_INPUT_RESET: - case DILLO_HTML_INPUT_BUTTON_SUBMIT: - case DILLO_HTML_INPUT_BUTTON_RESET: - case DILLO_HTML_INPUT_IMAGE: - case DILLO_HTML_INPUT_FILE: - if (resource) + Resource *resource; + if (embed && (resource = embed->getResource())) { + resource->connectClicked (form_receiver); + if (type == DILLO_HTML_INPUT_SUBMIT || + type == DILLO_HTML_INPUT_RESET || + type == DILLO_HTML_INPUT_BUTTON_SUBMIT || + type == DILLO_HTML_INPUT_BUTTON_RESET || + type == DILLO_HTML_INPUT_IMAGE || + type == DILLO_HTML_INPUT_FILE || + type == DILLO_HTML_INPUT_TEXT || + type == DILLO_HTML_INPUT_PASSWORD || + type == DILLO_HTML_INPUT_INDEX) { resource->connectActivate (form_receiver); - break; + } } } /* - * Activate a form + * Activate a form */ -void DilloHtmlInput::activate(DilloHtmlForm *form, bool force_submit) +void DilloHtmlInput::activate(DilloHtmlForm *form, int num_entry_fields, + EventButton *event) { switch (type) { - case DILLO_HTML_INPUT_TEXT: - case DILLO_HTML_INPUT_PASSWORD: - if (force_submit) - form->submit (this); - break; case DILLO_HTML_INPUT_FILE: readFile (form->html->bw); break; case DILLO_HTML_INPUT_RESET: case DILLO_HTML_INPUT_BUTTON_RESET: - form->reset (); + form->reset(); + break; + case DILLO_HTML_INPUT_TEXT: + case DILLO_HTML_INPUT_PASSWORD: + if (!(prefs.enterpress_forces_submit || num_entry_fields == 1)) { + break; + } else { + /* fall through */ + } + case DILLO_HTML_INPUT_SUBMIT: + case DILLO_HTML_INPUT_BUTTON_SUBMIT: + case DILLO_HTML_INPUT_IMAGE: + case DILLO_HTML_INPUT_INDEX: + form->submit(this, event); break; default: - form->submit (this); break; } } /* - * Read a file into cache + * Read a file into cache */ void DilloHtmlInput::readFile (BrowserWindow *bw) { @@ -1657,8 +1638,7 @@ void DilloHtmlInput::readFile (BrowserWindow *bw) file_data = a_Misc_file2dstr(filename); if (file_data) { a_UIcmd_set_msg(bw, "File loaded."); - dw::core::ui::LabelButtonResource *lbr = - (dw::core::ui::LabelButtonResource*)embed->getResource(); + LabelButtonResource *lbr = (LabelButtonResource*)embed->getResource(); lbr->setLabel(filename); } else { a_UIcmd_set_msg(bw, "ERROR: can't load: %s", filename); @@ -1675,24 +1655,24 @@ void DilloHtmlInput::appendValuesTo(Dlist *values, bool is_active_submit) case DILLO_HTML_INPUT_TEXT: case DILLO_HTML_INPUT_PASSWORD: case DILLO_HTML_INPUT_INDEX: + case DILLO_HTML_INPUT_HIDDEN: { - dw::core::ui::EntryResource *entryres = - (dw::core::ui::EntryResource*)embed->getResource(); + EntryResource *entryres = (EntryResource*)embed->getResource(); dList_append(values, dStr_new(entryres->getText())); } break; case DILLO_HTML_INPUT_TEXTAREA: { - dw::core::ui::MultiLineTextResource *textres = - (dw::core::ui::MultiLineTextResource*)embed->getResource(); + MultiLineTextResource *textres = + (MultiLineTextResource*)embed->getResource(); dList_append(values, dStr_new(textres->getText())); } break; case DILLO_HTML_INPUT_CHECKBOX: case DILLO_HTML_INPUT_RADIO: { - dw::core::ui::ToggleButtonResource *cb_r = - (dw::core::ui::ToggleButtonResource*)embed->getResource(); + ToggleButtonResource *cb_r = + (ToggleButtonResource*)embed->getResource(); if (name && init_str && cb_r->isActivated()) { dList_append(values, dStr_new(init_str)); } @@ -1703,21 +1683,16 @@ void DilloHtmlInput::appendValuesTo(Dlist *values, bool is_active_submit) if (is_active_submit) dList_append(values, dStr_new(init_str)); break; - case DILLO_HTML_INPUT_HIDDEN: - dList_append(values, dStr_new(init_str)); - break; case DILLO_HTML_INPUT_SELECT: case DILLO_HTML_INPUT_SEL_LIST: - { // brackets for compiler happiness. - dw::core::ui::SelectionResource *sel_res = - (dw::core::ui::SelectionResource*)embed->getResource(); + { + SelectionResource *sel_res = (SelectionResource*)embed->getResource(); select->appendValuesTo (values, sel_res); } break; case DILLO_HTML_INPUT_FILE: { - dw::core::ui::LabelButtonResource *lbr = - (dw::core::ui::LabelButtonResource*)embed->getResource(); + LabelButtonResource *lbr = (LabelButtonResource*)embed->getResource(); const char *filename = lbr->getLabel(); if (filename[0] && strcmp(filename, init_str)) { if (file_data) { @@ -1732,8 +1707,8 @@ void DilloHtmlInput::appendValuesTo(Dlist *values, bool is_active_submit) break; case DILLO_HTML_INPUT_IMAGE: if (is_active_submit) { - dw::core::ui::ComplexButtonResource *cbr = - (dw::core::ui::ComplexButtonResource*)embed->getResource(); + ComplexButtonResource *cbr = + (ComplexButtonResource*)embed->getResource(); Dstr *strX = dStr_new(""); Dstr *strY = dStr_new(""); dStr_sprintf(strX, "%d", cbr->getClickX()); @@ -1755,17 +1730,18 @@ void DilloHtmlInput::reset () switch (type) { case DILLO_HTML_INPUT_TEXT: case DILLO_HTML_INPUT_PASSWORD: + case DILLO_HTML_INPUT_INDEX: + case DILLO_HTML_INPUT_HIDDEN: { - dw::core::ui::EntryResource *entryres = - (dw::core::ui::EntryResource*)embed->getResource(); + EntryResource *entryres = (EntryResource*)embed->getResource(); entryres->setText(init_str ? init_str : ""); } break; case DILLO_HTML_INPUT_CHECKBOX: case DILLO_HTML_INPUT_RADIO: { - dw::core::ui::ToggleButtonResource *tb_r = - (dw::core::ui::ToggleButtonResource*)embed->getResource(); + ToggleButtonResource *tb_r = + (ToggleButtonResource*)embed->getResource(); tb_r->setActivated(init_val); } break; @@ -1801,15 +1777,14 @@ void DilloHtmlInput::reset () break; case DILLO_HTML_INPUT_TEXTAREA: if (init_str != NULL) { - dw::core::ui::MultiLineTextResource *textres = - (dw::core::ui::MultiLineTextResource*)embed->getResource(); + MultiLineTextResource *textres = + (MultiLineTextResource*)embed->getResource(); textres->setText(init_str ? init_str : ""); } break; case DILLO_HTML_INPUT_FILE: { - dw::core::ui::LabelButtonResource *lbr = - (dw::core::ui::LabelButtonResource*)embed->getResource(); + LabelButtonResource *lbr = (LabelButtonResource*)embed->getResource(); lbr->setLabel(init_str); } break; @@ -1819,11 +1794,11 @@ void DilloHtmlInput::reset () } /* - * DilloHtmlSelect + * DilloHtmlSelect */ /* - * Constructor + * Constructor */ DilloHtmlSelect::DilloHtmlSelect () { @@ -1831,7 +1806,7 @@ DilloHtmlSelect::DilloHtmlSelect () } /* - * Destructor + * Destructor */ DilloHtmlSelect::~DilloHtmlSelect () { @@ -1872,7 +1847,7 @@ void DilloHtmlSelect::ensureSelection() } } -void DilloHtmlSelect::addOptionsTo (dw::core::ui::SelectionResource *res) +void DilloHtmlSelect::addOptionsTo (SelectionResource *res) { int size = options->size (); for (int i = 0; i < size; i++) { @@ -1881,8 +1856,7 @@ void DilloHtmlSelect::addOptionsTo (dw::core::ui::SelectionResource *res) } } -void DilloHtmlSelect::appendValuesTo (Dlist *values, - dw::core::ui::SelectionResource *res) +void DilloHtmlSelect::appendValuesTo (Dlist *values, SelectionResource *res) { int size = options->size (); for (int i = 0; i < size; i++) { @@ -1895,11 +1869,11 @@ void DilloHtmlSelect::appendValuesTo (Dlist *values, } /* - * DilloHtmlOption + * DilloHtmlOption */ /* - * Constructor + * Constructor */ DilloHtmlOption::DilloHtmlOption (char *value2, bool selected2, @@ -1912,7 +1886,7 @@ DilloHtmlOption::DilloHtmlOption (char *value2, } /* - * Destructor + * Destructor */ DilloHtmlOption::~DilloHtmlOption () { @@ -1921,48 +1895,38 @@ DilloHtmlOption::~DilloHtmlOption () } /* - * Utilities + * Utilities */ /* * Create input image for the form */ -static dw::core::ui::Embed *Html_input_image(DilloHtml *html, - const char *tag, int tagsize) +static Embed *Html_input_image(DilloHtml *html, const char *tag, int tagsize) { const char *attrbuf; - StyleAttrs style_attrs; DilloImage *Image; - dw::core::ui::Embed *button = NULL; + Embed *button = NULL; DilloUrl *url = NULL; - + if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src")) && (url = a_Html_url_new(html, attrbuf, NULL, 0))) { - style_attrs = *S_TOP(html)->style; - style_attrs.cursor = CURSOR_POINTER; - style_attrs.backgroundColor = - style::Color::createShaded(HT2LT(html), S_TOP(html)->current_bg_color); + + html->styleEngine->setPseudoLink (); /* create new image and add it to the button */ - if ((Image = a_Html_add_new_image(html, tag, tagsize, url, &style_attrs, - false))) { - Style *style = Style::create (HT2LT(html), &style_attrs); - IM2DW(Image)->setStyle (style); - dw::core::ui::ComplexButtonResource *complex_b_r = - HT2LT(html)->getResourceFactory()->createComplexButtonResource( - IM2DW(Image), false); - button = new dw::core::ui::Embed(complex_b_r); - DW2TB(html->dw)->addWidget (button, style); + if ((Image = a_Html_image_new(html, tag, tagsize, url))) { + IM2DW(Image)->setStyle (html->styleEngine->backgroundStyle ()); + ResourceFactory *factory = HT2LT(html)->getResourceFactory(); + ComplexButtonResource *complex_b_r = + factory->createComplexButtonResource(IM2DW(Image), false); + button = new Embed(complex_b_r); + HT2TB(html)->addWidget (button, html->styleEngine->style ()); // gtk_widget_set_sensitive(widget, FALSE); /* Until end of FORM! */ - style->unref(); - /* a right button press brings up the image menu */ - html->connectSignals((Widget*)Image->dw); } else { a_Url_free(url); } } - if (!button) MSG("Html_input_image: unable to create image submit.\n"); return button; @@ -1978,7 +1942,6 @@ static void Html_option_finish(DilloHtml *html) input->type == DILLO_HTML_INPUT_SEL_LIST) { DilloHtmlOption *option = input->select->getCurrentOption (); - option->content = - a_Html_parse_entities(html, html->Stash->str, html->Stash->len); + option->content = dStrndup(html->Stash->str, html->Stash->len); } } |