From d4d1a79af89fbf4a3cbd390ff3cd3ee52a8b5d90 Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Tue, 5 May 2015 13:57:44 +0200 Subject: [PATCH] FIX: a +1 error during navigation of listbox with categories --- include/nana/gui/widgets/listbox.hpp | 1 + source/gui/widgets/listbox.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 8a2f1938..fc487460 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -366,6 +366,7 @@ namespace nana return iter; } + /// Append an item at abs end of the category, using the strins to set the columns (cells) of the new item. void append(std::initializer_list); size_type columns() const; diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 6fc0bdd9..8618d4c0 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -1747,13 +1747,12 @@ namespace nana return true; } - if(list_.size() <= from.cat) return false; - if(from.is_category()) { // this is a category, so... // and offs is not 0, this category would not be candidated. // the algorithm above to calc the offset item is always starting with a item. + // we can not select, navigate or highlight begining from a cat? --offs; from.item = 0; } @@ -1762,7 +1761,7 @@ namespace nana if(icat->expand) { - std::size_t item_left_in_this_cat = icat->items.size() -1- from.item; + std::size_t item_left_in_this_cat = icat->items.size()- from.item -1; if(offs <= item_left_in_this_cat ) { item = from; @@ -1771,14 +1770,15 @@ namespace nana } else { - offs -= item_left_in_this_cat ; + offs -= (item_left_in_this_cat+1) ; item = from; - item.item += item_left_in_this_cat ; + item.item += item_left_in_this_cat ;// select the last item } } ++from.cat; ++icat; + for(; icat != list_.end(); ++icat, ++from.cat) { item.cat = from.cat; @@ -2203,7 +2203,7 @@ namespace nana } else { - new_where.second = (y - header_visible_px() + 1) / item_size; + new_where.second = ((y + 1) - header_visible_px()) / item_size; // y>1 ! new_where.first = parts::lister; if(checkable) { @@ -3444,7 +3444,7 @@ namespace nana { auto i = ess_->lister.cat_container().begin(); std::advance(i, pos.cat); - cat_ = &(*i); + cat_ = &(*i); // what is pos is a cat? } } @@ -3489,7 +3489,7 @@ namespace nana /// is ignored if no change (maybe set last_selected anyway??), but if change emit event, deselect others if need ans set/unset last_selected item_proxy & item_proxy::select(bool s) { - auto & m = cat_->items.at(pos_.item); // a ref to the real item + auto & m = cat_->items.at(pos_.item); // a ref to the real item // what is pos is a cat? if(m.flags.selected == s) return *this; // ignore if no change m.flags.selected = s; // actually change selection