changeset 917:f1f95cb69505

merge with main
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Fri, 06 Feb 2009 21:20:34 +0100
parents 6ab291295a2d (current diff) 45830a274847 (diff)
children fa79176adf1a
files src/html.cc
diffstat 13 files changed, 79 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkplatform.cc	Fri Feb 06 21:17:42 2009 +0100
+++ b/dw/fltkplatform.cc	Fri Feb 06 21:20:34 2009 +0100
@@ -182,9 +182,9 @@
 FltkPlatform::FltkResourceFactory::createListResource (core::ui
                                                        ::ListResource
                                                        ::SelectionMode
-                                                       selectionMode)
+                                                       selectionMode, int rows)
 {
-   return new ui::FltkListResource (platform, selectionMode);
+   return new ui::FltkListResource (platform, selectionMode, rows);
 }
 
 core::ui::OptionMenuResource *
--- a/dw/fltkplatform.hh	Fri Feb 06 21:17:42 2009 +0100
+++ b/dw/fltkplatform.hh	Fri Feb 06 21:20:34 2009 +0100
@@ -78,7 +78,8 @@
       core::ui::ComplexButtonResource *
       createComplexButtonResource (core::Widget *widget, bool relief);
       core::ui::ListResource *
-      createListResource (core::ui::ListResource::SelectionMode selectionMode);
+      createListResource (core::ui::ListResource::SelectionMode selectionMode,
+                          int rows);
       core::ui::OptionMenuResource *createOptionMenuResource ();
       core::ui::EntryResource *createEntryResource (int maxLength,
                                                     bool password,
--- a/dw/fltkui.cc	Fri Feb 06 21:17:42 2009 +0100
+++ b/dw/fltkui.cc	Fri Feb 06 21:20:34 2009 +0100
@@ -36,7 +36,6 @@
 #include <fltk/CheckButton.h>
 #include <fltk/Choice.h>
 #include <fltk/Browser.h>
-#include <fltk/MultiBrowser.h>
 #include <fltk/Font.h>
 #include <fltk/draw.h>
 #include <fltk/Symbol.h>
@@ -1226,10 +1225,12 @@
 
 FltkListResource::FltkListResource (FltkPlatform *platform,
                                     core::ui::ListResource::SelectionMode
-                                    selectionMode):
+                                    selectionMode, int rowCount):
    FltkSelectionResource <dw::core::ui::ListResource> (platform),
    itemsSelected(8)
 {
+   mode = selectionMode;
+   showRows = rowCount;
    init (platform);
 }
 
@@ -1241,9 +1242,10 @@
 ::fltk::Menu *FltkListResource::createNewMenu (core::Allocation *allocation)
 {
    ::fltk::Menu *menu =
-      new ::fltk::MultiBrowser (allocation->x, allocation->y,
-                                allocation->width,
-                                allocation->ascent + allocation->descent);
+      new ::fltk::Browser (allocation->x, allocation->y, allocation->width,
+                           allocation->ascent + allocation->descent);
+   if (mode == SELECTION_MULTIPLE)
+      menu->type(::fltk::Browser::MULTI);
    menu->set_flag (::fltk::RAW_LABEL);
    menu->callback(widgetCallback,this);
    menu->when(::fltk::WHEN_CHANGED);
@@ -1253,7 +1255,9 @@
 void FltkListResource::widgetCallback (::fltk::Widget *widget, void *data)
 {
    ::fltk::Widget *fltkItem = ((::fltk::Menu *) widget)->item ();
-   int index = (long) (fltkItem->user_data ());
+   int index = -1;
+   if (fltkItem)
+      index = (long) (fltkItem->user_data ());
    if (index > -1) {
       bool selected = fltkItem->selected ();
       ((FltkListResource *) data)->itemsSelected.set (index, selected);
@@ -1275,13 +1279,19 @@
    if (style) {
       FltkFont *font = (FltkFont*)style->font;
       ::fltk::setfont(font->font,font->size);
-      int maxStringWidth = getMaxStringWidth ();
-      requisition->ascent = font->ascent + RELIEF_Y_THICKNESS;
-      requisition->descent =
-         (getNumberOfItems () - 1) * (font->ascent) + font->descent;
-      requisition->width = maxStringWidth
-         + (font->ascent + font->descent) * 4 / 5
-         + 2 * RELIEF_X_THICKNESS;
+      int rows = getNumberOfItems();
+      if (showRows < rows) {
+         rows = showRows;
+      }
+      /*
+       * The widget sometimes shows scrollbars when they are not required.
+       * The following values try to keep any scrollbars from obscuring
+       * options, at the cost of showing too much whitespace at times.
+       */
+      requisition->width = getMaxStringWidth() + 24;
+      requisition->ascent = font->ascent + 2;
+      requisition->descent = font->descent + 3 +
+                             (rows - 1) * (font->ascent + font->descent + 1);
    } else {
       requisition->width = 1;
       requisition->ascent = 1;
--- a/dw/fltkui.hh	Fri Feb 06 21:17:42 2009 +0100
+++ b/dw/fltkui.hh	Fri Feb 06 21:20:34 2009 +0100
@@ -538,10 +538,12 @@
 private:
    static void widgetCallback (::fltk::Widget *widget, void *data);
    misc::SimpleVector <bool> itemsSelected;
-
+   int showRows;
+   ListResource::SelectionMode mode;
 public:
    FltkListResource (FltkPlatform *platform,
-                     core::ui::ListResource::SelectionMode selectionMode);
+                     core::ui::ListResource::SelectionMode selectionMode,
+                     int rows);
    ~FltkListResource ();
 
    void addItem (const char *str, bool enabled, bool selected);
--- a/dw/ui.hh	Fri Feb 06 21:17:42 2009 +0100
+++ b/dw/ui.hh	Fri Feb 06 21:20:34 2009 +0100
@@ -539,7 +539,7 @@
                                                                bool relief)
       = 0;
    virtual ListResource *createListResource (ListResource::SelectionMode
-                                             selectionMode) = 0;
+                                             selectionMode, int rows) = 0;
    virtual OptionMenuResource *createOptionMenuResource () = 0;
    virtual EntryResource *createEntryResource (int maxLength, bool password,
                                                const char *label) = 0;
--- a/src/cookies.c	Fri Feb 06 21:17:42 2009 +0100
+++ b/src/cookies.c	Fri Feb 06 21:20:34 2009 +0100
@@ -203,8 +203,10 @@
 
    if (dpip_tag != NULL) {
       char *cookie = a_Dpip_get_attr(dpip_tag, strlen(dpip_tag), "cookie");
+      char *old_query = query;
+      query = dStrconcat(old_query, cookie, NULL);
+      dFree(old_query);
       dFree(dpip_tag);
-      query = dStrconcat(query, cookie, NULL);
       dFree(cookie);
    }
    return query;
--- a/src/dicache.c	Fri Feb 06 21:17:42 2009 +0100
+++ b/src/dicache.c	Fri Feb 06 21:20:34 2009 +0100
@@ -19,7 +19,6 @@
 #include "imgbuf.hh"
 #include "web.hh"
 #include "dicache.h"
-#include "cache.h"
 #include "dpng.h"
 #include "dgif.h"
 #include "djpeg.h"
--- a/src/form.cc	Fri Feb 06 21:17:42 2009 +0100
+++ b/src/form.cc	Fri Feb 06 21:20:34 2009 +0100
@@ -713,8 +713,8 @@
 /* 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");
@@ -727,12 +727,25 @@
    ResourceFactory *factory = HT2LT(html)->getResourceFactory ();
    DilloHtmlInputType type;
    SelectionResource *res;
-   if (a_Html_get_attr(html, tag, tagsize, "multiple")) {
-      type = DILLO_HTML_INPUT_SEL_LIST;
-      res = factory->createListResource (ListResource::SELECTION_MULTIPLE);
-   } else {
+   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;
+   }
+   if (rows < 1)
+      rows = multi ? 10 : 1;
+
+   if (rows == 1 && multi == false) {
       type = DILLO_HTML_INPUT_SELECT;
       res = factory->createOptionMenuResource ();
+   } else {
+      type = DILLO_HTML_INPUT_SEL_LIST;
+      res = factory->createListResource (multi ?
+                                         ListResource::SELECTION_MULTIPLE :
+                                         ListResource::SELECTION_EXACTLY_ONE,
+                                         rows);
    }
    Embed *embed = new Embed(res);
 
@@ -748,26 +761,6 @@
                      Color::createShaded (HT2LT(html), bg));
    DW2TB(html->dw)->addWidget (embed, html->styleEngine->style ());
 
-// 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;
-// }
-
    Html_add_input(html, type, embed, name, NULL, false);
    a_Html_stash_init(html);
    dFree(name);
--- a/src/html.cc	Fri Feb 06 21:17:42 2009 +0100
+++ b/src/html.cc	Fri Feb 06 21:20:34 2009 +0100
@@ -456,7 +456,6 @@
    InVisitedLink = false;
    ReqTagClose = false;
    TagSoup = true;
-   NameVal = NULL;
 
    Num_HTML = Num_HEAD = Num_BODY = Num_TITLE = 0;
 
@@ -2392,11 +2391,24 @@
    html->styleEngine->inheritBackgroundColor ();
 
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "name"))) {
+      char *nameVal;
+      const char *id = html->styleEngine->getId ();
+
       if (prefs.show_extra_warnings)
          Html_check_name_val(html, attrbuf, "name");
-      /* html->NameVal is freed in Html_process_tag */
-      html->NameVal = a_Url_decode_hex_str(attrbuf);
-      Html_add_anchor(html, html->NameVal);
+
+      nameVal = a_Url_decode_hex_str(attrbuf);
+
+      if (nameVal) {
+         /* We compare the "id" value with the url-decoded "name" value */
+         if (!id || strcmp(nameVal, id)) {
+            if (id)
+               BUG_MSG("'id' and 'name' attribute of <a> tag differ\n");
+            Html_add_anchor(html, nameVal);
+         }
+
+         dFree(nameVal);
+      }
    }
 }
 
@@ -3325,24 +3337,13 @@
        * spec states in Sec. 7.5.2 that anchor ids are case-sensitive.
        * So we don't do it and hope for better specs in the future ...
        */
-      if (attrbuf)
-         html->styleEngine->setId (attrbuf);
-
       Html_check_name_val(html, attrbuf, "id");
-      /* We compare the "id" value with the url-decoded "name" value */
-      if (!html->NameVal || strcmp(html->NameVal, attrbuf)) {
-         if (html->NameVal)
-            BUG_MSG("'id' and 'name' attribute of <a> tag differ\n");
-         Html_add_anchor(html, attrbuf);
-      }
+
+      html->styleEngine->setId(attrbuf);
+      Html_add_anchor(html, attrbuf);
    }
-   /* Reset NameVal */
-   if (html->NameVal) {
-      dFree(html->NameVal);
-      html->NameVal = NULL;
-   }
-
-   if (tagsize >= 10) {       /* length of "<t class=i>" */
+
+   if (tagsize >= 11) {       /* length of "<t class=i>" */
       attrbuf = Html_get_attr2(html, tag, tagsize, "class",
                                HTML_LeftTrim | HTML_RightTrim);
       if (attrbuf)
--- a/src/html_common.hh	Fri Feb 06 21:17:42 2009 +0100
+++ b/src/html_common.hh	Fri Feb 06 21:20:34 2009 +0100
@@ -198,7 +198,6 @@
    bool ReqTagClose;      /* Flag to help handling bad-formed HTML */
    bool WordAfterLI;      /* Flag to help ignoring the 1st <P> after <LI> */
    bool TagSoup;          /* Flag to enable the parser's cleanup functions */
-   char *NameVal;         /* used for validation of "NAME" and "ID" in <A> */
 
    /* element counters: used for validation purposes */
    uchar_t Num_HTML, Num_HEAD, Num_BODY, Num_TITLE;
--- a/src/styleengine.hh	Fri Feb 06 21:17:42 2009 +0100
+++ b/src/styleengine.hh	Fri Feb 06 21:20:34 2009 +0100
@@ -48,6 +48,7 @@
       void parse (const char *buf, int buflen, CssOrigin origin);
       void startElement (int tag);
       void setId (const char *id);
+      const char * getId () { return top ()->id; };
       void setClass (const char *klass);
       void setStyle (const char *style);
       void endElement (int tag);
--- a/test/dw_resource_test.cc	Fri Feb 06 21:17:42 2009 +0100
+++ b/test/dw_resource_test.cc	Fri Feb 06 21:20:34 2009 +0100
@@ -40,7 +40,7 @@
    FltkPlatform *platform = new FltkPlatform ();
    Layout *layout = new Layout (platform);
 
-   ::fltk::Window *window = new ::fltk::Window(410, 210, "Dw Simple Image");
+   ::fltk::Window *window = new ::fltk::Window(410, 210, "Dw Resource test");
    window->begin();
 
    FltkViewport *viewport = new FltkViewport (0, 0, 410, 210);
@@ -72,7 +72,7 @@
    styleAttrs.backgroundColor = NULL;
 
    SelectionResource *res = layout->getResourceFactory()->createListResource
-      (ListResource::SELECTION_AT_MOST_ONE);
+      (ListResource::SELECTION_AT_MOST_ONE, 4);
    //SelectionResource *res =
    //   layout->getResourceFactory()->createOptionMenuResource ();
    
--- a/test/dw_ui_test.cc	Fri Feb 06 21:17:42 2009 +0100
+++ b/test/dw_ui_test.cc	Fri Feb 06 21:20:34 2009 +0100
@@ -95,7 +95,7 @@
    SelectionResource *selres[2];
    selres[0] = layout->getResourceFactory()->createOptionMenuResource ();
    selres[1] = layout->getResourceFactory()->createListResource
-      (ListResource::SELECTION_AT_MOST_ONE);
+      (ListResource::SELECTION_AT_MOST_ONE, 4);
    LabelButtonResource *buttonres =
       layout->getResourceFactory()->createLabelButtonResource ("Run!");