aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-02-06 21:20:34 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-02-06 21:20:34 +0100
commit17c9dc7f581ca55e931ce2987cb34bc505bf75d3 (patch)
tree7ce6844ff84cb9e3d65a73dfa14f34a34a5e5ee3
parentb65e704d76928e1a3f3984e8206840d87ea19a64 (diff)
parentfd6ff6812d018df008ca4ec8a2b3992cc962d3dd (diff)
merge with main
-rw-r--r--dw/fltkplatform.cc4
-rw-r--r--dw/fltkplatform.hh3
-rw-r--r--dw/fltkui.cc36
-rw-r--r--dw/fltkui.hh6
-rw-r--r--dw/ui.hh2
-rw-r--r--src/cookies.c4
-rw-r--r--src/dicache.c1
-rw-r--r--src/form.cc45
-rw-r--r--src/html.cc39
-rw-r--r--src/html_common.hh1
-rw-r--r--src/styleengine.hh1
-rw-r--r--test/dw_resource_test.cc4
-rw-r--r--test/dw_ui_test.cc2
13 files changed, 78 insertions, 70 deletions
diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc
index e070b7d9..4338f0a8 100644
--- a/dw/fltkplatform.cc
+++ b/dw/fltkplatform.cc
@@ -182,9 +182,9 @@ core::ui::ListResource *
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 *
diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh
index 776204a6..238af582 100644
--- a/dw/fltkplatform.hh
+++ b/dw/fltkplatform.hh
@@ -78,7 +78,8 @@ private:
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,
diff --git a/dw/fltkui.cc b/dw/fltkui.cc
index 676cde51..250ee981 100644
--- a/dw/fltkui.cc
+++ b/dw/fltkui.cc
@@ -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 @@ bool FltkOptionMenuResource::isSelected (int index)
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 @@ FltkListResource::~FltkListResource ()
::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 @@ FltkListResource::~FltkListResource ()
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 @@ void FltkListResource::sizeRequest (core::Requisition *requisition)
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;
diff --git a/dw/fltkui.hh b/dw/fltkui.hh
index 3d19fc63..77c8a7b0 100644
--- a/dw/fltkui.hh
+++ b/dw/fltkui.hh
@@ -538,10 +538,12 @@ protected:
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);
diff --git a/dw/ui.hh b/dw/ui.hh
index 306883c2..419284cd 100644
--- a/dw/ui.hh
+++ b/dw/ui.hh
@@ -539,7 +539,7 @@ public:
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;
diff --git a/src/cookies.c b/src/cookies.c
index b4843a1d..52364943 100644
--- a/src/cookies.c
+++ b/src/cookies.c
@@ -203,8 +203,10 @@ char *a_Cookies_get_query(const DilloUrl *request_url)
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;
diff --git a/src/dicache.c b/src/dicache.c
index 939ebff0..a95b1a52 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -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"
diff --git a/src/form.cc b/src/form.cc
index d0796ddf..eb4c3e59 100644
--- a/src/form.cc
+++ b/src/form.cc
@@ -713,8 +713,8 @@ void Html_tag_close_textarea(DilloHtml *html, int TagIdx)
/* 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 @@ void Html_tag_open_select(DilloHtml *html, const char *tag, int tagsize)
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 @@ void Html_tag_open_select(DilloHtml *html, const char *tag, int tagsize)
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);
diff --git a/src/html.cc b/src/html.cc
index d59afe97..b2b8cd92 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -456,7 +456,6 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw, const DilloUrl *url,
InVisitedLink = false;
ReqTagClose = false;
TagSoup = true;
- NameVal = NULL;
Num_HTML = Num_HEAD = Num_BODY = Num_TITLE = 0;
@@ -2392,11 +2391,24 @@ static void Html_tag_open_a(DilloHtml *html, const char *tag, int tagsize)
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 @@ static void Html_parse_common_attrs(DilloHtml *html, char *tag, int tagsize)
* 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);
- }
- }
- /* Reset NameVal */
- if (html->NameVal) {
- dFree(html->NameVal);
- html->NameVal = NULL;
+
+ html->styleEngine->setId(attrbuf);
+ Html_add_anchor(html, attrbuf);
}
- 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)
diff --git a/src/html_common.hh b/src/html_common.hh
index 7983ea5a..fc0800f7 100644
--- a/src/html_common.hh
+++ b/src/html_common.hh
@@ -198,7 +198,6 @@ public: //BUG: for now everything is public
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;
diff --git a/src/styleengine.hh b/src/styleengine.hh
index 75f8fdd1..a17a350c 100644
--- a/src/styleengine.hh
+++ b/src/styleengine.hh
@@ -48,6 +48,7 @@ class StyleEngine : public Doctree {
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);
diff --git a/test/dw_resource_test.cc b/test/dw_resource_test.cc
index 2c90d3ce..0b70550f 100644
--- a/test/dw_resource_test.cc
+++ b/test/dw_resource_test.cc
@@ -40,7 +40,7 @@ int main(int argc, char **argv)
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 @@ int main(int argc, char **argv)
styleAttrs.backgroundColor = NULL;
SelectionResource *res = layout->getResourceFactory()->createListResource
- (ListResource::SELECTION_AT_MOST_ONE);
+ (ListResource::SELECTION_AT_MOST_ONE, 4);
//SelectionResource *res =
// layout->getResourceFactory()->createOptionMenuResource ();
diff --git a/test/dw_ui_test.cc b/test/dw_ui_test.cc
index 88595a76..b57479fb 100644
--- a/test/dw_ui_test.cc
+++ b/test/dw_ui_test.cc
@@ -95,7 +95,7 @@ int main(int argc, char **argv)
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!");