diff --git a/modules/juce_gui_basics/widgets/juce_ListBox.cpp b/modules/juce_gui_basics/widgets/juce_ListBox.cpp index 87ec67c783..f9c529b69b 100644 --- a/modules/juce_gui_basics/widgets/juce_ListBox.cpp +++ b/modules/juce_gui_basics/widgets/juce_ListBox.cpp @@ -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 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 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 ListBox::createAccessibilityHandler() private: const AccessibilityHandler* getHeaderHandler() const { - if (listBox.headerComponent != nullptr) + if (listBox.hasAccessibleHeaderComponent()) return listBox.headerComponent->getAccessibilityHandler(); return nullptr; diff --git a/modules/juce_gui_basics/widgets/juce_ListBox.h b/modules/juce_gui_basics/widgets/juce_ListBox.h index 60af118ec3..3eba5d7f02 100644 --- a/modules/juce_gui_basics/widgets/juce_ListBox.h +++ b/modules/juce_gui_basics/widgets/juce_ListBox.h @@ -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.