aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/ListWidget.cpp41
-rw-r--r--gui/ListWidget.h2
2 files changed, 29 insertions, 14 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index 10fa1cf243..e46d5e9b1e 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -107,11 +107,14 @@ Widget *ListWidget::findWidget(int x, int y) {
void ListWidget::setSelected(int item) {
assert(item >= -1 && item < (int)_list.size());
+ // We only have to do something if the widget is enabled and the selection actually changes
if (isEnabled() && _selectedItem != item) {
if (_editMode)
abortEditMode();
_selectedItem = item;
+
+ // Notify clients that the selection changed.
sendCommand(kListSelectionChangedCmd, _selectedItem);
_currentPos = _selectedItem - _entriesPerPage / 2;
@@ -123,14 +126,13 @@ void ListWidget::setSelected(int item) {
void ListWidget::setList(const StringList &list) {
if (_editMode && _caretVisible)
drawCaret(true);
- int size = list.size();
- _dataList = list;
// Copy everything
+ _dataList = list;
_list = list;
- _filter = "";
- setFilter(_filter, false);
+ _filter.clear();
+ int size = list.size();
if (_currentPos >= size)
_currentPos = size - 1;
if (_currentPos < 0)
@@ -543,10 +545,11 @@ void ListWidget::reflowLayout() {
}
void ListWidget::setFilter(const String &filter, bool redraw) {
- String filt;
-
- filt = filter;
+ // FIXME: This method does not deal correctly with edit mode!
+ // Until we fix that, let's make sure it isn't called while editing takes place
+ assert(!_editMode);
+ String filt = filter;
filt.toLowercase();
if (_filter == filt) // Filter was not changed
@@ -554,20 +557,22 @@ void ListWidget::setFilter(const String &filter, bool redraw) {
_filter = filt;
- if (_filter == "") {
+ if (_filter.empty()) {
+ // No filter -> display everything
_list = _dataList;
} else {
+ // Restrict the list to everything which contains _filter as a substring,
+ // ignoring case.
String tmp;
int n = 0;
_list.clear();
-
_listIndex.clear();
- for (StringList::iterator i = _dataList.begin(); i != _dataList.end(); ++i, n++) {
+ for (StringList::iterator i = _dataList.begin(); i != _dataList.end(); ++i, ++n) {
tmp = *i;
tmp.toLowercase();
- if (tmp.contains(_filter.c_str())) {
+ if (tmp.contains(_filter)) {
_list.push_back(*i);
_listIndex.push_back(n);
}
@@ -579,8 +584,18 @@ void ListWidget::setFilter(const String &filter, bool redraw) {
if (redraw) {
scrollBarRecalc();
-
- draw();
+ // Redraw the whole dialog. This is annoying, as this might be rather
+ // expensive when really only the list widget and its scroll bar area
+ // to be redrawn. However, since the scrollbar might change its
+ // visibility status, and the list its width, we cannot just redraw
+ // the two.
+ // TODO: A more efficient (and elegant?) way to handle this would be to
+ // introduce a kind of "BoxWidget" or "GroupWidget" which defines a
+ // rectangular region and subwidgets can be placed within it.
+ // Such a widget could also (optionally) draw a border (or even different
+ // kinds of borders) around the objects it groups; and also a 'title'
+ // (I am borrowing these "ideas" from the NSBox class in Cocoa :).
+ _boss->draw();
}
}
diff --git a/gui/ListWidget.h b/gui/ListWidget.h
index 69f309b970..203cd88fb6 100644
--- a/gui/ListWidget.h
+++ b/gui/ListWidget.h
@@ -90,7 +90,7 @@ public:
void setList(const StringList &list);
void append(const String &s);
const StringList &getList() const { return _dataList; }
- int getSelected() const { return (_filter == "" || _selectedItem == -1) ? _selectedItem : _listIndex[_selectedItem]; }
+ int getSelected() const { return (_filter.empty() || _selectedItem == -1) ? _selectedItem : _listIndex[_selectedItem]; }
void setSelected(int item);
const String &getSelectedString() const { return _list[_selectedItem]; }
void setNumberingMode(NumberingMode numberingMode) { _numberingMode = numberingMode; }