It's likely not a big deal, but if you perform a click that ends up with the same exact selection (or lack thereof), you get extra callbacks through selectedRowsChanged().
In my case, I've set up the backgroundClicked() method to always clear the selection.
setSelectedRows (SparseSet<int>())
Now, every time I click the background, it clears the selection as expected - except it always results in a selectedRowsChanged() call per click.
It seems like the best route is to simply check if the selected rows have changed in ListBox::setSelectedRows() before doing any updating and selectedRowsChanged() call.
void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
const NotificationType sendNotificationEventToModel)
{
if (selected != setOfRowsToBeSelected) //ie: doing this
{
selected = setOfRowsToBeSelected;
selected.removeRange (Range<int> (totalItems, std::numeric_limits<int>::max()));
if (! isRowSelected (lastRowSelected))
lastRowSelected = getSelectedRow (0);
viewport->updateContents();
if (model != nullptr && sendNotificationEventToModel == sendNotification)
model->selectedRowsChanged (lastRowSelected);
}
}
