diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-09 19:40:04 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-09 19:40:04 +0000 |
commit | 5956848cf26bd275c8d03db6c92990c4022e57c2 (patch) | |
tree | 419b9ad7a513ce77ac002dff30b045f5a6e7c39a /chrome | |
parent | 5b8cc1957c6b9aea77d2e162ab366f2c77553334 (diff) | |
download | chromium_src-5956848cf26bd275c8d03db6c92990c4022e57c2.zip chromium_src-5956848cf26bd275c8d03db6c92990c4022e57c2.tar.gz chromium_src-5956848cf26bd275c8d03db6c92990c4022e57c2.tar.bz2 |
Fixes bug in TableView where by we return nothing as selected when
there was a selection. This appears to be a bug in Vista. I've worked
around it by iterating over the elements.
BUG=1499
TEST=See my steps in bug. Test on both XP and Vista.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1915 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/views/table_view.cc | 43 | ||||
-rw-r--r-- | chrome/views/table_view.h | 15 |
2 files changed, 22 insertions, 36 deletions
diff --git a/chrome/views/table_view.cc b/chrome/views/table_view.cc index a0d9fba..2ca2f37 100644 --- a/chrome/views/table_view.cc +++ b/chrome/views/table_view.cc @@ -941,37 +941,25 @@ void TableView::OnCheckedStateChanged(int item, bool is_checked) { } } -int TableView::NextSelectedIndex(int item) { - if (!list_view_) - return -1; +int TableView::PreviousSelectedIndex(int item) { DCHECK(item >= 0); - if (item >= RowCount()) { - return LastSelectedIndex(); - } - // It seems if the list has only 1 element and it is selected that - // ListView_GetNextItem always returns 0. - if (RowCount() == 1) { + if (!list_view_ || item <= 0) return -1; - } - return ListView_GetNextItem(list_view_, - item, LVNI_ALL | LVNI_SELECTED | LVNI_ABOVE); + + int row_count = RowCount(); + if (row_count == 0) + return -1; // Empty table, nothing can be selected. + + // For some reason + // ListView_GetNextItem(list_view_,item, LVNI_SELECTED | LVNI_ABOVE) + // fails on Vista (always returns -1), so we iterate through the indices. + item = std::min(item, row_count); + while (--item >= 0 && !IsItemSelected(item)); + return item; } int TableView::LastSelectedIndex() { - if (!list_view_) - return -1; - int row_count = RowCount(); - int last_selected_row = -1; - if (row_count > 0) { - if (ListView_GetItemState(list_view_, row_count - 1, - LVIS_SELECTED) == LVIS_SELECTED) { - last_selected_row = row_count - 1; - } else { - last_selected_row = ListView_GetNextItem(list_view_, - row_count - 1, LVNI_ALL | LVNI_SELECTED | LVNI_ABOVE); - } - } - return last_selected_row; + return PreviousSelectedIndex(RowCount()); } void TableView::UpdateContentOffset() { @@ -1016,7 +1004,7 @@ bool TableSelectionIterator::operator!=(const TableSelectionIterator& other) { } TableSelectionIterator& TableSelectionIterator::operator++() { - index_ = table_view_->NextSelectedIndex(index_); + index_ = table_view_->PreviousSelectedIndex(index_); return *this; } @@ -1025,4 +1013,3 @@ int TableSelectionIterator::operator*() { } } // namespace - diff --git a/chrome/views/table_view.h b/chrome/views/table_view.h index 0668120..db86537 100644 --- a/chrome/views/table_view.h +++ b/chrome/views/table_view.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_VIEWS_TABLE_VIEW_H__ -#define CHROME_VIEWS_TABLE_VIEW_H__ +#ifndef CHROME_VIEWS_TABLE_VIEW_H_ +#define CHROME_VIEWS_TABLE_VIEW_H_ #include <windows.h> @@ -405,9 +405,9 @@ class TableView : public NativeControl, // changed. void OnCheckedStateChanged(int item, bool is_checked); - // Returns the index of the selected item after |item|, or -1 if |item| is - // the last selected item. - int NextSelectedIndex(int item); + // Returns the index of the selected item before |item|, or -1 if |item| is + // the first selected item. + int PreviousSelectedIndex(int item); // Returns the last selected index in the table view, or -1 if the table // is empty, or nothing is selected. @@ -494,10 +494,9 @@ class TableView : public NativeControl, // The offset from the top of the client area to the start of the content. int content_offset_; - DISALLOW_EVIL_CONSTRUCTORS(TableView); + DISALLOW_COPY_AND_ASSIGN(TableView); }; } -#endif // CHROME_VIEWS_TABLE_VIEW_H__ - +#endif // CHROME_VIEWS_TABLE_VIEW_H_ |