From ac69e7d06d94360bb4907fc4a6e1665745ed8e05 Mon Sep 17 00:00:00 2001 From: jcid Date: Tue, 14 Oct 2008 16:55:52 +0200 Subject: - Cosmetic changes in form handling code. --- src/form.cc | 505 ++++++++++++++++++++++++++++-------------------------------- src/form.hh | 2 +- 2 files changed, 236 insertions(+), 271 deletions(-) (limited to 'src') diff --git a/src/form.cc b/src/form.cc index 78bc43e8..b4da60e8 100644 --- a/src/form.cc +++ b/src/form.cc @@ -28,22 +28,22 @@ 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,31 +75,28 @@ class DilloHtmlForm { friend class DilloHtmlInput; DilloHtml *html; - void eventHandler(dw::core::ui::Resource *resource); - void submit(DilloHtmlInput *input); - DilloUrl *buildQueryUrl(DilloHtmlInput *input); + void eventHandler(Resource *resource); + void submit(DilloHtmlInput *active_input); + 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 *inputs; @@ -110,39 +107,38 @@ public: //BUG: for now everything is public 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); ~DilloHtmlForm (); - DilloHtmlInput *getInput (dw::core::ui::Resource *resource); + DilloHtmlInput *getInput (Resource *resource); DilloHtmlInput *getRadioInput (const char *name); void reset (); void addInput(DilloHtmlInput *input, DilloHtmlInputType type); }; class DilloHtmlReceiver: - public dw::core::ui::Resource::ActivateReceiver, - public dw::core::ui::ButtonResource::ClickedReceiver + public Resource::ActivateReceiver, + public ButtonResource::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 (ButtonResource *resource, int buttonNo, int x, int y); }; 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,15 +150,12 @@ public: //BUG: for now everything is public private: void connectTo(DilloHtmlReceiver *form_receiver); - void activate(DilloHtmlForm *form, bool force_submit); + void activate(DilloHtmlForm *form, bool entry_input_submits); 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(); @@ -178,9 +171,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 +182,18 @@ 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) { - return new DilloHtmlForm (html,method,action,enc,charset); + return new DilloHtmlForm (html, method, action, content_type, charset); } void a_Html_form_delete (DilloHtmlForm *form) @@ -217,14 +207,14 @@ void a_Html_input_delete (DilloHtmlInput *input) } /* - * 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); @@ -283,7 +273,7 @@ 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; @@ -310,11 +300,11 @@ void Html_tag_open_form(DilloHtml *html, const char *tag, int tagsize) action = a_Html_url_new(html, attrbuf, NULL, 0); else 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,7 +325,7 @@ 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); } @@ -346,7 +336,7 @@ void Html_tag_close_form(DilloHtml *html, int TagIdx) ""; 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, @@ -360,7 +350,7 @@ void Html_tag_close_form(DilloHtml *html, int TagIdx) form->num_submit_buttons = 0; } } - + // /* Make buttons sensitive again */ // for (i = 0; i < form->inputs->size(); i++) { // input_i = form->inputs->get(i); @@ -392,11 +382,11 @@ 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; + Embed *embed = NULL; char *value, *name, *type, *init_str; const char *attrbuf, *label; bool init_val = false; - + if (html->InFlags & IN_SELECT) { BUG_MSG(" element inside element inside