changeset 1041:6d6bfabeb1b4

disable forms while stylesheets are pending To avoid lost user input on repush, we disable forms until all stylesheets have been loaded. Also open select widgets cause crashes on repush.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Wed, 22 Apr 2009 09:56:52 +0200
parents 4ed33b76809c
children 32daa61ad511
files dw/fltkui.cc dw/ui.cc dw/ui.hh src/form.cc src/form.hh src/html.cc
diffstat 6 files changed, 36 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkui.cc	Sun Apr 19 10:25:22 2009 +0200
+++ b/dw/fltkui.cc	Wed Apr 22 09:56:52 2009 +0200
@@ -235,7 +235,14 @@
 
 void FltkResource::setEnabled (bool enabled)
 {
-   /** \bug Not implemented. */
+   for (Iterator <ViewAndWidget> it = viewsAndWidgets->iterator ();
+        it.hasNext(); ) {
+      ViewAndWidget *viewAndWidget = it.getNext ();
+      if (enabled)
+         viewAndWidget->widget->activate ();
+      else
+         viewAndWidget->widget->deactivate ();
+   }
 }
 
 // ----------------------------------------------------------------------
--- a/dw/ui.cc	Sun Apr 19 10:25:22 2009 +0200
+++ b/dw/ui.cc	Wed Apr 22 09:56:52 2009 +0200
@@ -101,6 +101,11 @@
    resource->setDisplayed (displayed);
 }
 
+void Embed::setEnabled (bool enabled)
+{
+   resource->setEnabled (enabled);
+}
+
 void Embed::draw (View *view, Rectangle *area)
 {
    drawWidgetBox (view, area, false);
--- a/dw/ui.hh	Sun Apr 19 10:25:22 2009 +0200
+++ b/dw/ui.hh	Wed Apr 22 09:56:52 2009 +0200
@@ -244,6 +244,7 @@
    void setAscent (int ascent);
    void setDescent (int descent);
    void setDisplayed (bool displayed);
+   void setEnabled (bool displayed);
    void draw (View *view, Rectangle *area);
    Iterator *iterator (Content::Type mask, bool atEnd);
    void setStyle (style::Style *style);
--- a/src/form.cc	Sun Apr 19 10:25:22 2009 +0200
+++ b/src/form.cc	Wed Apr 22 09:56:52 2009 +0200
@@ -76,6 +76,7 @@
 
    DilloHtml *html;
    bool showing_hiddens;
+   bool enabled;
    void eventHandler(Resource *resource, EventButton *event);
    DilloUrl *buildQueryUrl(DilloHtmlInput *active_input);
    Dstr *buildQueryData(DilloHtmlInput *active_submit);
@@ -108,7 +109,8 @@
 public:
    DilloHtmlForm (DilloHtml *html,
                   DilloHtmlMethod method, const DilloUrl *action,
-                  DilloHtmlEnc content_type, const char *charset);
+                  DilloHtmlEnc content_type, const char *charset,
+                  bool enabled);
    ~DilloHtmlForm ();
    DilloHtmlInput *getInput (Resource *resource);
    DilloHtmlInput *getRadioInput (const char *name);
@@ -116,6 +118,7 @@
    void reset ();
    void display_hiddens(bool display);
    void addInput(DilloHtmlInput *input, DilloHtmlInputType type);
+   void setEnabled(bool enabled);
 };
 
 class DilloHtmlReceiver:
@@ -160,6 +163,7 @@
    ~DilloHtmlInput ();
    void appendValuesTo(Dlist *values, bool is_active_submit);
    void reset();
+   void setEnabled(bool enabled) {if (embed) embed->setEnabled(enabled); };
 };
 
 class DilloHtmlSelect {
@@ -192,9 +196,10 @@
 
 DilloHtmlForm *a_Html_form_new (DilloHtml *html, DilloHtmlMethod method,
                                 const DilloUrl *action,
-                                DilloHtmlEnc content_type, const char *charset)
+                                DilloHtmlEnc content_type, const char *charset,
+                                bool enabled)
 {
-   return new DilloHtmlForm (html, method, action, content_type, charset);
+   return new DilloHtmlForm (html, method, action, content_type, charset, enabled);
 }
 
 void a_Html_form_delete (DilloHtmlForm *form)
@@ -883,7 +888,7 @@
                               DilloHtmlMethod method2,
                               const DilloUrl *action2,
                               DilloHtmlEnc content_type2,
-                              const char *charset)
+                              const char *charset, bool enabled)
 {
    html = html2;
    method = method2;
@@ -893,6 +898,7 @@
    inputs = new misc::SimpleVector <DilloHtmlInput*> (4);
    num_entry_fields = 0;
    showing_hiddens = false;
+   this->enabled = enabled;
    form_receiver = new DilloHtmlReceiver (this);
 }
 
@@ -1411,12 +1417,19 @@
   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);
--- a/src/form.hh	Sun Apr 19 10:25:22 2009 +0200
+++ b/src/form.hh	Wed Apr 22 09:56:52 2009 +0200
@@ -34,7 +34,7 @@
                                DilloHtmlMethod method,
                                const DilloUrl *action,
                                DilloHtmlEnc enc,
-                               const char *charset);
+                               const char *charset, bool enabled);
 
 void a_Html_form_delete(DilloHtmlForm* form);
 void a_Html_input_delete(DilloHtmlInput* input);
--- a/src/html.cc	Sun Apr 19 10:25:22 2009 +0200
+++ b/src/html.cc	Wed Apr 22 09:56:52 2009 +0200
@@ -640,7 +640,10 @@
 int DilloHtml::formNew(DilloHtmlMethod method, const DilloUrl *action,
                        DilloHtmlEnc enc, const char *charset)
 {
-   DilloHtmlForm *form = a_Html_form_new (this,method,action,enc,charset);
+   // avoid data loss on repush after CSS stylesheets have been loaded
+   bool enabled = bw->NumPendingStyleSheets == 0;
+   DilloHtmlForm *form = a_Html_form_new (this, method, action,
+                                          enc, charset, enabled);
    int nf = forms->size ();
    forms->increase ();
    forms->set (nf, form);