diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index a47142b2..ff6363d7 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -1522,9 +1522,37 @@ namespace nana return n; } - template - std::vector> select_display_range_if(const index_pair& fr_abs, index_pair to_dpl, bool deselect_others, Pred pred) + /// Finds a good item or category if an item specified by pos is invaild + index_pair find_next_good(index_pair pos, bool ignore_category) const noexcept { + //Return the pos if it is good + if (this->good(pos)) + return pos; + + while(pos.cat < this->categories_.size()) + { + if ((pos.npos == pos.item) && !ignore_category) + return pos; + + auto cat_item_size = this->get(pos.cat)->items.size(); + + if (pos.item < cat_item_size) + return pos; + + if ((pos.npos == pos.item) && (cat_item_size > 0) && ignore_category) + return index_pair{ pos.cat, 0 }; + + ++pos.cat; + pos.item = pos.npos; + } + return index_pair{}; + } + + template + std::vector> select_display_range_if(index_pair fr_abs, index_pair to_dpl, bool deselect_others, Pred pred) + { + fr_abs = find_next_good(fr_abs, true); + if (to_dpl.empty()) { if (fr_abs.empty()) @@ -1532,6 +1560,7 @@ namespace nana to_dpl = this->last(); } + auto fr_dpl = (fr_abs.is_category() ? fr_abs : this->index_cast(fr_abs, false)); //Converts an absolute position to display position if (fr_dpl > to_dpl)