Mercurial > dillo_port1.3
changeset 477:9a41a7db39f5
Added a popup menu to form's submit button
author | corvid <corvid@lavabit.com> |
---|---|
date | Sun, 21 Dec 2008 08:39:20 -0300 |
parents | 97e5244798b7 |
children | 76cb7e80f48e |
files | src/form.cc src/form.hh src/html.cc src/html.hh src/menu.cc src/menu.hh src/uicmd.cc src/uicmd.hh |
diffstat | 8 files changed, 132 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/form.cc Sun Dec 21 08:29:51 2008 -0300 +++ b/src/form.cc Sun Dec 21 08:39:20 2008 -0300 @@ -76,7 +76,6 @@ DilloHtml *html; void eventHandler(Resource *resource, EventButton *event); - void submit(DilloHtmlInput *active_input, EventButton *event); DilloUrl *buildQueryUrl(DilloHtmlInput *active_input); Dstr *buildQueryData(DilloHtmlInput *active_submit); char *makeMultipartBoundary(iconv_t char_encoder, @@ -113,6 +112,7 @@ ~DilloHtmlForm (); DilloHtmlInput *getInput (Resource *resource); DilloHtmlInput *getRadioInput (const char *name); + void submit(DilloHtmlInput *active_input, EventButton *event); void reset (); void addInput(DilloHtmlInput *input, DilloHtmlInputType type); }; @@ -206,6 +206,16 @@ delete input; } +void a_Html_form_submit2(void *vform) +{ + ((DilloHtmlForm *)vform)->submit(NULL, NULL); +} + +void a_Html_form_reset2(void *vform) +{ + ((DilloHtmlForm *)vform)->reset(); +} + /* * Form parsing functions */ @@ -945,7 +955,7 @@ { MSG("DilloHtmlForm::eventHandler\n"); if (event && (event->button == 3)) { - MSG("Form menu\n"); + a_UIcmd_form_popup(html->bw, html->page_url, this); } else { DilloHtmlInput *input = getInput(resource); if (input) { @@ -996,7 +1006,7 @@ _MSG("DilloHtmlForm::buildQueryUrl: action=%s\n",URL_STR_(action)); - if (num_submit_buttons > 0) { + if (active_input && num_submit_buttons > 0) { if ((active_input->type == DILLO_HTML_INPUT_SUBMIT) || (active_input->type == DILLO_HTML_INPUT_IMAGE) || (active_input->type == DILLO_HTML_INPUT_BUTTON_SUBMIT)) { @@ -1727,6 +1737,7 @@ switch (type) { case DILLO_HTML_INPUT_TEXT: case DILLO_HTML_INPUT_PASSWORD: + case DILLO_HTML_INPUT_INDEX: { EntryResource *entryres = (EntryResource*)embed->getResource(); entryres->setText(init_str ? init_str : "");
--- a/src/form.hh Sun Dec 21 08:29:51 2008 -0300 +++ b/src/form.hh Sun Dec 21 08:39:20 2008 -0300 @@ -38,6 +38,9 @@ void a_Html_form_delete(DilloHtmlForm* form); void a_Html_input_delete(DilloHtmlInput* input); +void a_Html_form_submit2(void *v_form); +void a_Html_form_reset2(void *v_form); + /* * Form parsing functions
--- a/src/html.cc Sun Dec 21 08:29:51 2008 -0300 +++ b/src/html.cc Sun Dec 21 08:39:20 2008 -0300 @@ -219,6 +219,45 @@ } /* + * Search for form + */ +static bool Html_contains_form(DilloHtml *html, void *v_form) +{ + for (int i = 0; i < html->forms->size(); i++) { + if (html->forms->get(i) == v_form) { + return true; + } + } + return false; +} + +/* + * Used by the "Submit form" form menuitem. + */ +void a_Html_form_submit(void *v_html, void *v_form) +{ + DilloHtml *html = (DilloHtml*)v_html; + + if (Html_contains_form(html, v_form)) { + /* it's still valid */ + a_Html_form_submit2(v_form); + } +} + +/* + * Used by the "Reset form" form menuitem. + */ +void a_Html_form_reset(void *v_html, void *v_form) +{ + DilloHtml *html = (DilloHtml*)v_html; + + if (Html_contains_form(html, v_form)) { + /* it's still valid */ + a_Html_form_reset2(v_form); + } +} + +/* * Set the URL data for image maps. */ static void Html_set_link_coordinates(DilloHtml *html, int link, int x, int y)
--- a/src/html.hh Sun Dec 21 08:29:51 2008 -0300 +++ b/src/html.hh Sun Dec 21 08:39:20 2008 -0300 @@ -11,6 +11,8 @@ * Exported functions */ void a_Html_load_images(void *v_html, DilloUrl *pattern); +void a_Html_form_submit(void *v_html, void *v_form); +void a_Html_form_reset(void *v_html, void *v_form); #ifdef __cplusplus }
--- a/src/menu.cc Sun Dec 21 08:29:51 2008 -0300 +++ b/src/menu.cc Sun Dec 21 08:39:20 2008 -0300 @@ -212,6 +212,44 @@ } } +/* + * Submit form + */ +static void Menu_form_submit_cb(Widget*, void *v_form) +{ + if (popup_bw && popup_bw->Docs) { + if (dList_find_custom(popup_bw->PageUrls, popup_url, + (dCompareFunc)a_Url_cmp)){ + /* HTML page is still there */ + int n = dList_length(popup_bw->Docs); + if (n == 1) { + a_Html_form_submit(dList_nth_data(popup_bw->Docs, 0), v_form); + } else if (n > 1) { + MSG ("Menu_form_submit_cb multiple Docs not implemented\n"); + } + } + } +} + +/* + * Reset form + */ +static void Menu_form_reset_cb(Widget*, void *v_form) +{ + if (popup_bw && popup_bw->Docs) { + if (dList_find_custom(popup_bw->PageUrls, popup_url, + (dCompareFunc)a_Url_cmp)){ + /* HTML page is still there */ + int n = dList_length(popup_bw->Docs); + if (n == 1) { + a_Html_form_reset(dList_nth_data(popup_bw->Docs, 0), v_form); + } else if (n > 1) { + MSG ("Menu_form_reset_cb multiple Docs not implemented\n"); + } + } + } +} + /* * Validate URL with the W3C */ @@ -452,6 +490,31 @@ } /* + * Form popup menu (construction & popup) + */ +void a_Menu_form_popup(BrowserWindow *bw, const DilloUrl *page_url, + void *formptr) +{ + static PopupMenu *pm = 0; + + popup_bw = bw; + a_Url_free(popup_url); + popup_url = a_Url_dup(page_url); + if (!pm) { + Item *i; + pm = new PopupMenu(0,0,0,0,"FORM OPTIONS"); + pm->add(i = new Item("Submit form")); + i->callback(Menu_form_submit_cb); + pm->add(i = new Item("Reset form")); + i->callback(Menu_form_reset_cb); + pm->type(PopupMenu::POPUP123); + } + pm->user_data(formptr); + + a_Timeout_add(0.0, Menu_popup_cb, (void *)pm); +} + +/* * File popup menu (construction & popup) */ void a_Menu_file_popup(BrowserWindow *bw, void *v_wid)
--- a/src/menu.hh Sun Dec 21 08:29:51 2008 -0300 +++ b/src/menu.hh Sun Dec 21 08:39:20 2008 -0300 @@ -12,6 +12,8 @@ void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url); void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url, bool_t loaded_img, DilloUrl *link_url); +void a_Menu_form_popup(BrowserWindow *bw, const DilloUrl *page_url, + void *vform); void a_Menu_file_popup(BrowserWindow *bw, void *v_wid); void a_Menu_bugmeter_popup(BrowserWindow *bw, const DilloUrl *url); void a_Menu_history_popup(BrowserWindow *bw, int direction);
--- a/src/uicmd.cc Sun Dec 21 08:29:51 2008 -0300 +++ b/src/uicmd.cc Sun Dec 21 08:39:20 2008 -0300 @@ -666,6 +666,14 @@ } /* + * Pop up the form menu + */ +void a_UIcmd_form_popup(void *vbw, const DilloUrl *url, void *vform) +{ + a_Menu_form_popup((BrowserWindow*)vbw, url, vform); +} + +/* * Pop up the file menu */ void a_UIcmd_file_popup(void *vbw, void *v_wid)
--- a/src/uicmd.hh Sun Dec 21 08:29:51 2008 -0300 +++ b/src/uicmd.hh Sun Dec 21 08:39:20 2008 -0300 @@ -41,6 +41,7 @@ void a_UIcmd_link_popup(void *vbw, const DilloUrl *url); void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img, DilloUrl *link_url); +void a_UIcmd_form_popup(void *vbw, const DilloUrl *url, void *vform); void a_UIcmd_file_popup(void *vbw, void *v_wid); void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr); void a_UIcmd_view_page_source(const DilloUrl *url);