aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2009-02-06 12:16:28 -0300
committercorvid <corvid@lavabit.com>2009-02-06 12:16:28 -0300
commitae27fe4f9716901efc6b14854402b32708ab331f (patch)
tree65b9bbf31643fe91fa280b269d80cfc59d13663c /dw
parentca9b558f4444e7f3e8bde5f72d2ec138ab6cb0ed (diff)
Implemented size for SELECT lists
Diffstat (limited to 'dw')
-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
5 files changed, 32 insertions, 19 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;