changeset 484:cdfdb006f193

Added a right-click menu to the form submit button (allows to show hiddens)
author Jorge Arellano Cid <jcid@dillo.org>
date Mon, 05 Jan 2009 17:12:43 -0300
parents ba5eed484075
children a65c6a280da4 55719bfa903d
files ChangeLog dw/fltkplatform.cc dw/fltkplatform.hh dw/fltkui.cc dw/fltkui.hh dw/ui.cc dw/ui.hh src/form.cc src/form.hh src/html.cc src/html.hh src/menu.cc src/menu.hh src/uicmd.cc src/uicmd.hh test/dw_ui_test.cc
diffstat 16 files changed, 161 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jan 02 19:18:06 2009 -0300
+++ b/ChangeLog	Mon Jan 05 17:12:43 2009 -0300
@@ -23,6 +23,7 @@
  - Ported the command line interface from dillo1 (XID not working yet).
  - Switched file dpi error messages to HTML.
  - Added a popup menu to form's submit button.
+ - Added a right-click menu to the form submit button (allows to show hiddens).
    Patches: place (AKA corvid)
 +- Switched SSL-enabled to configure.in (./configure --enable-ssl).
  - Standardised the installation of dpid/dpidrc with auto* tools.
--- a/dw/fltkplatform.cc	Fri Jan 02 19:18:06 2009 -0300
+++ b/dw/fltkplatform.cc	Mon Jan 05 17:12:43 2009 -0300
@@ -200,9 +200,10 @@
 
 core::ui::EntryResource *
 FltkPlatform::FltkResourceFactory::createEntryResource (int maxLength,
-                                                        bool password)
+                                                        bool password,
+                                                        const char *label)
 {
-   return new ui::FltkEntryResource (platform, maxLength, password);
+   return new ui::FltkEntryResource (platform, maxLength, password, label);
 }
 
 core::ui::MultiLineTextResource *
--- a/dw/fltkplatform.hh	Fri Jan 02 19:18:06 2009 -0300
+++ b/dw/fltkplatform.hh	Mon Jan 05 17:12:43 2009 -0300
@@ -81,7 +81,8 @@
       createListResource (core::ui::ListResource::SelectionMode selectionMode);
       core::ui::OptionMenuResource *createOptionMenuResource ();
       core::ui::EntryResource *createEntryResource (int maxLength,
-                                                    bool password);
+                                                    bool password,
+                                                    const char *label);
       core::ui::MultiLineTextResource *createMultiLineTextResource (int cols,
                                                                     int rows);
       core::ui::CheckButtonResource *createCheckButtonResource (bool
--- a/dw/fltkui.cc	Fri Jan 02 19:18:06 2009 -0300
+++ b/dw/fltkui.cc	Mon Jan 05 17:12:43 2009 -0300
@@ -199,7 +199,35 @@
       }
    }
 }
-   
+
+void FltkResource::setDisplayed(bool displayed)
+{
+   for (Iterator <ViewAndWidget> it = viewsAndWidgets->iterator ();
+        it.hasNext(); ) {
+      ViewAndWidget *viewAndWidget = it.getNext ();
+      if (displayed)
+         viewAndWidget->widget->show();
+      else
+         viewAndWidget->widget->hide();
+   }
+}
+
+bool FltkResource::displayed()
+{
+   bool ret;
+   Iterator <ViewAndWidget> it = viewsAndWidgets->iterator ();
+
+   if (it.hasNext()) {
+      ViewAndWidget *viewAndWidget = it.getNext ();
+      // visible() is not the same thing as being show()n exactly, but
+      // show()/hide() set it appropriately for our purposes.
+      ret = viewAndWidget->widget->visible();
+   } else {
+      ret = false;
+   }
+   return ret;
+}
+
 bool FltkResource::isEnabled ()
 {
    /** \bug Not implemented. */
@@ -487,11 +515,12 @@
 // ----------------------------------------------------------------------
 
 FltkEntryResource::FltkEntryResource (FltkPlatform *platform, int maxLength,
-                                      bool password):  
+                                      bool password, const char *label):  
    FltkSpecificResource <dw::core::ui::EntryResource> (platform)
 {
    this->maxLength = maxLength;
    this->password = password;
+   this->label = label ? strdup(label) : NULL;
    
    initText = NULL;
    editable = false;
@@ -503,6 +532,8 @@
 {
    if (initText)
       delete initText;
+   if (label)
+      delete label;
 }
 
 ::fltk::Widget *FltkEntryResource::createNewWidget (core::Allocation
@@ -518,6 +549,10 @@
    input->callback (widgetCallback, this);
    input->when (::fltk::WHEN_ENTER_KEY_ALWAYS);
 
+   if (label) {
+      input->label(label);
+      input->set_flag(::fltk::ALIGN_INSIDE_LEFT);
+   }
    if (viewsAndWidgets->isEmpty ()) {
       // First widget created, attach the set text.
       if (initText)
@@ -529,9 +564,15 @@
    return input;
 }
 
+void FltkEntryResource::setDisplayed(bool displayed)
+{
+   FltkResource::setDisplayed(displayed);
+   queueResize(true);
+}
+
 void FltkEntryResource::sizeRequest (core::Requisition *requisition)
 {
-   if (style) {
+   if (displayed() && style) {
       FltkFont *font = (FltkFont*)style->font;
       ::fltk::setfont(font->font,font->size);
       requisition->width =
@@ -541,8 +582,8 @@
       requisition->ascent = font->ascent + RELIEF_Y_THICKNESS;
       requisition->descent = font->descent + RELIEF_Y_THICKNESS;
    } else {
-      requisition->width = 1;
-      requisition->ascent = 1;
+      requisition->width = 0;
+      requisition->ascent = 0;
       requisition->descent = 0;
    }
 }
--- a/dw/fltkui.hh	Fri Jan 02 19:18:06 2009 -0300
+++ b/dw/fltkui.hh	Mon Jan 05 17:12:43 2009 -0300
@@ -195,6 +195,8 @@
    virtual ::fltk::Widget *createNewWidget (core::Allocation *allocation) = 0;
 
    void setWidgetStyle (::fltk::Widget *widget, core::style::Style *style);
+   void setDisplayed (bool displayed);
+   bool displayed();
 public:
    ~FltkResource ();
 
@@ -298,15 +300,18 @@
    int maxLength;
    bool password;
    const char *initText;
+   char *label;
    bool editable;
 
    static void widgetCallback (::fltk::Widget *widget, void *data);
+   void setDisplayed (bool displayed);
 
 protected:
    ::fltk::Widget *createNewWidget (core::Allocation *allocation);
 
 public:
-   FltkEntryResource (FltkPlatform *platform, int maxLength, bool password);
+   FltkEntryResource (FltkPlatform *platform, int maxLength, bool password,
+                      const char *label);
    ~FltkEntryResource ();
 
    void sizeRequest (core::Requisition *requisition);
--- a/dw/ui.cc	Fri Jan 02 19:18:06 2009 -0300
+++ b/dw/ui.cc	Mon Jan 05 17:12:43 2009 -0300
@@ -97,6 +97,11 @@
    resource->setDescent (descent);
 }
 
+void Embed::setDisplayed (bool displayed)
+{
+   resource->setDisplayed (displayed);
+}
+
 void Embed::draw (View *view, Rectangle *area)
 {
    drawWidgetBox (view, area, false);
@@ -196,6 +201,10 @@
 {
 }
 
+void Resource::setDisplayed (bool displayed)
+{
+}
+
 void Resource::draw (View *view, Rectangle *area)
 {
 }
--- a/dw/ui.hh	Fri Jan 02 19:18:06 2009 -0300
+++ b/dw/ui.hh	Mon Jan 05 17:12:43 2009 -0300
@@ -243,6 +243,7 @@
    void setWidth (int width);
    void setAscent (int ascent);
    void setDescent (int descent);
+   void setDisplayed (bool displayed);
    void draw (View *view, Rectangle *area);
    Iterator *iterator (Content::Type mask, bool atEnd);
    void setStyle (style::Style *style);
@@ -336,6 +337,7 @@
    virtual void setWidth (int width);
    virtual void setAscent (int ascent);
    virtual void setDescent (int descent);
+   virtual void setDisplayed (bool displayed);
    virtual void draw (View *view, Rectangle *area);
    virtual Iterator *iterator (Content::Type mask, bool atEnd) = 0; 
    virtual void setStyle (style::Style *style);
@@ -539,8 +541,8 @@
    virtual ListResource *createListResource (ListResource::SelectionMode
                                              selectionMode) = 0;
    virtual OptionMenuResource *createOptionMenuResource () = 0;
-   virtual EntryResource *createEntryResource (int maxLength,
-                                               bool password) = 0;
+   virtual EntryResource *createEntryResource (int maxLength, bool password,
+                                               const char *label) = 0;
    virtual MultiLineTextResource *createMultiLineTextResource (int cols,
                                                                int rows) = 0;
    virtual CheckButtonResource *createCheckButtonResource (bool activated) = 0;
--- a/src/form.cc	Fri Jan 02 19:18:06 2009 -0300
+++ b/src/form.cc	Mon Jan 05 17:12:43 2009 -0300
@@ -75,6 +75,7 @@
    friend class DilloHtmlInput;
 
    DilloHtml *html;
+   bool showing_hiddens;
    void eventHandler(Resource *resource, EventButton *event);
    DilloUrl *buildQueryUrl(DilloHtmlInput *active_input);
    Dstr *buildQueryData(DilloHtmlInput *active_submit);
@@ -114,6 +115,7 @@
    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);
 };
 
@@ -216,6 +218,11 @@
    ((DilloHtmlForm *)vform)->reset();
 }
 
+void a_Html_form_display_hiddens2(void *vform, bool display)
+{
+   ((DilloHtmlForm *)vform)->display_hiddens(display);
+}
+
 /*
  * Form parsing functions
  */
@@ -438,7 +445,7 @@
       inp_type = DILLO_HTML_INPUT_PASSWORD;
       attrbuf = a_Html_get_attr(html, tag, tagsize, "size");
       int size = Html_input_get_size(html, attrbuf);
-      resource = factory->createEntryResource (size, true);
+      resource = factory->createEntryResource (size, true, NULL);
       init_str = value;
    } else if (!dStrcasecmp(type, "checkbox")) {
       inp_type = DILLO_HTML_INPUT_CHECKBOX;
@@ -457,6 +464,8 @@
    } else if (!dStrcasecmp(type, "hidden")) {
       inp_type = DILLO_HTML_INPUT_HIDDEN;
       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");
@@ -514,7 +523,7 @@
       inp_type = DILLO_HTML_INPUT_TEXT;
       attrbuf = a_Html_get_attr(html, tag, tagsize, "size");
       int size = Html_input_get_size(html, attrbuf);
-      resource = factory->createEntryResource(size, false);
+      resource = factory->createEntryResource(size, false, NULL);
       init_str = value;
    } else {
       /* Unknown input type */
@@ -531,6 +540,10 @@
 
    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) {
          if (a_Html_get_attr(html, tag, tagsize, "readonly"))
@@ -587,7 +600,7 @@
       DW2TB(html->dw)->addText(attrbuf, S_TOP(html)->style);
 
    ResourceFactory *factory = HT2LT(html)->getResourceFactory();
-   EntryResource *entryResource = factory->createEntryResource (20, false);
+   EntryResource *entryResource = factory->createEntryResource (20,false,NULL);
    embed = new Embed (entryResource);
    Html_add_input(html, DILLO_HTML_INPUT_INDEX, embed, NULL, NULL, FALSE);
 
@@ -934,6 +947,7 @@
    inputs = new misc::SimpleVector <DilloHtmlInput*> (4);
    num_entry_fields = 0;
    num_submit_buttons = 0;
+   showing_hiddens = false;
    form_receiver = new DilloHtmlReceiver (this);
 }
 
@@ -955,7 +969,7 @@
 {
    MSG("DilloHtmlForm::eventHandler\n");
    if (event && (event->button == 3)) {
-      a_UIcmd_form_popup(html->bw, html->page_url, this);
+      a_UIcmd_form_popup(html->bw, html->page_url, this, showing_hiddens);
    } else {
       DilloHtmlInput *input = getInput(resource);
       if (input) {
@@ -1438,6 +1452,21 @@
 }
 
 /*
+ * 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;
+}
+
+/*
  * Add a new input.
  */
 void DilloHtmlForm::addInput(DilloHtmlInput *input, DilloHtmlInputType type)
@@ -1660,6 +1689,7 @@
    case DILLO_HTML_INPUT_TEXT:
    case DILLO_HTML_INPUT_PASSWORD:
    case DILLO_HTML_INPUT_INDEX:
+   case DILLO_HTML_INPUT_HIDDEN:
       {
          EntryResource *entryres = (EntryResource*)embed->getResource();
          dList_append(values, dStr_new(entryres->getText()));
@@ -1687,9 +1717,6 @@
       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:
       {
@@ -1738,6 +1765,7 @@
    case DILLO_HTML_INPUT_TEXT:
    case DILLO_HTML_INPUT_PASSWORD:
    case DILLO_HTML_INPUT_INDEX:
+   case DILLO_HTML_INPUT_HIDDEN:
       {
          EntryResource *entryres = (EntryResource*)embed->getResource();
          entryres->setText(init_str ? init_str : "");
--- a/src/form.hh	Fri Jan 02 19:18:06 2009 -0300
+++ b/src/form.hh	Mon Jan 05 17:12:43 2009 -0300
@@ -40,6 +40,7 @@
 void a_Html_input_delete(DilloHtmlInput* input);
 void a_Html_form_submit2(void *v_form);
 void a_Html_form_reset2(void *v_form);
+void a_Html_form_display_hiddens2(void *v_form, bool display);
 
 
 /*
--- a/src/html.cc	Fri Jan 02 19:18:06 2009 -0300
+++ b/src/html.cc	Mon Jan 05 17:12:43 2009 -0300
@@ -258,6 +258,19 @@
 }
 
 /*
+ * Used by the "Show/Hide hiddens" form menuitem.
+ */
+void a_Html_form_display_hiddens(void *v_html, void *v_form, bool_t display)
+{
+   DilloHtml *html = (DilloHtml*)v_html;
+
+   if (Html_contains_form(html, v_form)) {
+      /* it's still valid */
+      a_Html_form_display_hiddens2(v_form, (display != 0));
+   }
+}
+
+/*
  * 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	Fri Jan 02 19:18:06 2009 -0300
+++ b/src/html.hh	Mon Jan 05 17:12:43 2009 -0300
@@ -13,6 +13,7 @@
 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);
+void a_Html_form_display_hiddens(void *v_html, void *v_form, bool_t display);
 
 #ifdef __cplusplus
 }
--- a/src/menu.cc	Fri Jan 02 19:18:06 2009 -0300
+++ b/src/menu.cc	Mon Jan 05 17:12:43 2009 -0300
@@ -250,6 +250,29 @@
    }
 }
 
+/*
+ * Toggle display of 'hidden' form controls.
+ */
+static void Menu_form_hiddens_cb(Widget *w, void *user_data)
+{
+   void *v_form = w->parent()->user_data();
+   bool visible = *((bool *) user_data);
+
+   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_display_hiddens(dList_nth_data(popup_bw->Docs, 0),
+                                        v_form, !visible);
+         } else if (n > 1) {
+            MSG ("Menu_form_hiddens_cb multiple Docs not implemented\n");
+         }
+      }
+   }
+}
+
 /* 
  * Validate URL with the W3C
  */
@@ -493,9 +516,11 @@
  * Form popup menu (construction & popup)
  */
 void a_Menu_form_popup(BrowserWindow *bw, const DilloUrl *page_url,
-                       void *formptr)
+                       void *formptr, bool_t hidvis)
 {
    static PopupMenu *pm = 0;
+   static Item *hiddens_item = 0;
+   static bool hiddens_visible;
 
    popup_bw = bw;
    a_Url_free(popup_url);
@@ -507,10 +532,16 @@
       i->callback(Menu_form_submit_cb);
       pm->add(i = new Item("Reset form"));
       i->callback(Menu_form_reset_cb);
+      pm->add(hiddens_item = new Item(""));
+      hiddens_item->callback(Menu_form_hiddens_cb);
+      hiddens_item->user_data(&hiddens_visible);
       pm->type(PopupMenu::POPUP123);
    }
    pm->user_data(formptr);
 
+   hiddens_visible = hidvis;
+   hiddens_item->label(hiddens_visible ? "Hide hiddens": "Show hiddens");
+
    a_Timeout_add(0.0, Menu_popup_cb, (void *)pm);
 }
 
--- a/src/menu.hh	Fri Jan 02 19:18:06 2009 -0300
+++ b/src/menu.hh	Mon Jan 05 17:12:43 2009 -0300
@@ -13,7 +13,7 @@
 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 *vform, bool_t showing_hiddens);
 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	Fri Jan 02 19:18:06 2009 -0300
+++ b/src/uicmd.cc	Mon Jan 05 17:12:43 2009 -0300
@@ -668,9 +668,10 @@
 /*
  * Pop up the form menu
  */
-void a_UIcmd_form_popup(void *vbw, const DilloUrl *url, void *vform)
+void a_UIcmd_form_popup(void *vbw, const DilloUrl *url, void *vform,
+                        bool_t showing_hiddens)
 {
-   a_Menu_form_popup((BrowserWindow*)vbw, url, vform);
+   a_Menu_form_popup((BrowserWindow*)vbw, url, vform, showing_hiddens);
 }
 
 /*
--- a/src/uicmd.hh	Fri Jan 02 19:18:06 2009 -0300
+++ b/src/uicmd.hh	Mon Jan 05 17:12:43 2009 -0300
@@ -41,7 +41,8 @@
 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_form_popup(void *vbw, const DilloUrl *url, void *vform,
+                        bool_t showing_hiddens);
 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);
--- a/test/dw_ui_test.cc	Fri Jan 02 19:18:06 2009 -0300
+++ b/test/dw_ui_test.cc	Mon Jan 05 17:12:43 2009 -0300
@@ -79,10 +79,10 @@
    // First of all, the resources. Later, they are embedded into the
    // widget tree.
    EntryResource *entryres1 =
-      layout->getResourceFactory()->createEntryResource (10, false);
+      layout->getResourceFactory()->createEntryResource (10, false, NULL);
    entryres1->setText ("Hi!");
    EntryResource *entryres2 =
-      layout->getResourceFactory()->createEntryResource (10, true);
+      layout->getResourceFactory()->createEntryResource (10, true, NULL);
    MultiLineTextResource *textres =
       layout->getResourceFactory()->createMultiLineTextResource (15,3);
    RadioButtonResource *radiores1 =