ListBox bug?


#1

Hi Jules,

It seems that I found a bug in the ListBox implementation :

If you change the listbox model and the new model has the same number of rows than the previous one, then updateContents doesn’t refresh !

Is it a bug or am I missing something ?


#2

Thanks - I guess it just needs a repaint, e.g.

void ListBox::setModel (ListBoxModel* const newModel) { if (model != newModel) { model = newModel; repaint(); updateContent();

I don’t think I’ve ever written any code that changes the model, so would never have noticed this!


#3

Apparently that’s the test which fails in juce_ListBox.cpp :

[code] if (selected [selected.size() - 1] >= totalItems)
{
selected.removeRange (Range (totalItems, std::numeric_limits::max()));
lastRowSelected = getSelectedRow (0);
selectionChanged = true;
}

viewport->updateVisibleArea (isVisible());
viewport->resized();

if (selectionChanged && model != 0)
    model->selectedRowsChanged (lastRowSelected);

[/code]

In case the models both have the same number of lines, it doesn’t enter the if, and selectionChanged stays false, and therefore “selectedRowsChange” is never called.
HTH


#4

Yes, but the selected rows haven’t changed, so why should it call that? If you want to clear the selection, you should call something like deselectAll() when you change the model, shouldn’t you?


#5

Yes definitely.
I was just stating my obvervations when tracing code. Something like : “When model has a different number of lines, it takes path A then works as expected. When the number of lines is identical, it takes path B and doesn’t work as expected”. I won’t pretend I know Juce insternals better than you, that would be stuipid :smiley:

Now I think I call deselectAll() after changing the model, and it has no effect on the refresh ?! (gotta double check that though)