1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Accessibility: Fix off-by-one row index bug when using a ListBox with an accessible header component

This commit is contained in:
ed 2021-09-01 10:24:36 +01:00
parent 945a7f4477
commit 8bb08f558e
2 changed files with 27 additions and 6 deletions

View file

@ -240,7 +240,16 @@ public:
int getColumnIndex() const override { return 0; }
int getColumnSpan() const override { return 1; }
int getRowIndex() const override { return handler.rowComponent.row; }
int getRowIndex() const override
{
const auto index = handler.rowComponent.row;
if (handler.rowComponent.owner.hasAccessibleHeaderComponent())
return index + 1;
return index;
}
int getRowSpan() const override { return 1; }
int getDisclosureLevel() const override { return 0; }
@ -1010,6 +1019,13 @@ void ListBox::setHeaderComponent (std::unique_ptr<Component> newHeaderComponent)
headerComponent = std::move (newHeaderComponent);
addAndMakeVisible (headerComponent.get());
ListBox::resized();
invalidateAccessibilityHandler();
}
bool ListBox::hasAccessibleHeaderComponent() const
{
return headerComponent != nullptr
&& headerComponent->getAccessibilityHandler() != nullptr;
}
void ListBox::repaintRow (const int rowNumber) noexcept
@ -1100,11 +1116,15 @@ std::unique_ptr<AccessibilityHandler> ListBox::createAccessibilityHandler()
int getNumRows() const override
{
if (listBox.model != nullptr)
return getHeaderHandler() != nullptr ? listBox.model->getNumRows() + 1
: listBox.model->getNumRows();
if (listBox.model == nullptr)
return 0;
return 0;
const auto numRows = listBox.model->getNumRows();
if (listBox.hasAccessibleHeaderComponent())
return numRows + 1;
return numRows;
}
int getNumColumns() const override
@ -1131,7 +1151,7 @@ std::unique_ptr<AccessibilityHandler> ListBox::createAccessibilityHandler()
private:
const AccessibilityHandler* getHeaderHandler() const
{
if (listBox.headerComponent != nullptr)
if (listBox.hasAccessibleHeaderComponent())
return listBox.headerComponent->getAccessibilityHandler();
return nullptr;

View file

@ -592,6 +592,7 @@ private:
void selectRowInternal (int rowNumber, bool dontScrollToShowThisRow,
bool deselectOthersFirst, bool isMouseClick);
bool hasAccessibleHeaderComponent() const;
#if JUCE_CATCH_DEPRECATED_CODE_MISUSE
// This method's bool parameter has changed: see the new method signature.