summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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/form.cc45
-rw-r--r--test/dw_resource_test.cc2
-rw-r--r--test/dw_ui_test.cc2
8 files changed, 53 insertions, 47 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/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/test/dw_resource_test.cc b/test/dw_resource_test.cc
index 11d87222..0b70550f 100644
--- a/test/dw_resource_test.cc
+++ b/test/dw_resource_test.cc
@@ -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!");