From bd44a5cc4513166daaf37caa190303616d851d7c Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 10 Aug 2021 08:46:42 -0400 Subject: [PATCH] Accessibility Multi/Radio/Switch (#4819) 1. Restore the multiswitch sub components. Ooops! 2. Use the checkable/checed state on MultiSwitch and Switch Addresses #4616 --- src/gui/widgets/MultiSwitch.cpp | 31 ++++++++++++++++++++++--------- src/gui/widgets/Switch.cpp | 11 +++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/gui/widgets/MultiSwitch.cpp b/src/gui/widgets/MultiSwitch.cpp index 4336566e758..5e7192230db 100644 --- a/src/gui/widgets/MultiSwitch.cpp +++ b/src/gui/widgets/MultiSwitch.cpp @@ -144,15 +144,17 @@ void MultiSwitch::mouseWheelMove(const juce::MouseEvent &event, struct MultiSwitchRadioButton : public juce::Component { - MultiSwitchRadioButton(MultiSwitch *s, float value, const std::string &label) - : mswitch(s), val(value) + MultiSwitchRadioButton(MultiSwitch *s, float value, int ival, const std::string &label) + : mswitch(s), val(value), ival(ival) { setDescription(label); setTitle(label); setInterceptsMouseClicks(false, false); + setAccessible(true); } MultiSwitch *mswitch; float val; + int ival; struct RBAH : public juce::AccessibilityHandler { @@ -180,6 +182,16 @@ struct MultiSwitchRadioButton : public juce::Component mswitch->notifyControlModifierClicked(m); } + juce::AccessibleState getCurrentState() const override + { + auto state = AccessibilityHandler::getCurrentState(); + state = state.withCheckable(); + if (mswitch->getIntegerValue() == button->ival) + state = state.withChecked(); + + return state; + } + MultiSwitch *mswitch; MultiSwitchRadioButton *button; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(RBAH); @@ -196,15 +208,15 @@ void MultiSwitch::setupAccessibility() if (rows * columns <= 1) // i use an alternate handler below return; + setAccessible(true); + setFocusContainerType(juce::Component::FocusContainerType::focusContainer); + if (selectionComponents.size() == rows * columns) { - // Already done it! - return; + removeAllChildren(); + selectionComponents.clear(); } - setAccessible(true); - setFocusContainerType(juce::Component::FocusContainerType::focusContainer); - auto sge = firstListenerOfType(); jassert(sge); if (!sge) @@ -219,9 +231,10 @@ void MultiSwitch::setupAccessibility() { float val = ((float)sel) / (rows * columns - 1); auto title = sge->getDisplayForTag(getTag(), true, val); - sel++; - auto ac = std::make_unique(this, val, title); + auto ac = std::make_unique(this, val, sel, title); + + sel++; ac->getProperties().set("ControlGroup", (int)(c * columns + rows)); ac->setBounds(juce::Rectangle(c * dc, r * dr, dc, dr)); addAndMakeVisible(*ac); diff --git a/src/gui/widgets/Switch.cpp b/src/gui/widgets/Switch.cpp index fec9bf67e9a..f7683c22d5a 100644 --- a/src/gui/widgets/Switch.cpp +++ b/src/gui/widgets/Switch.cpp @@ -126,6 +126,17 @@ struct SwitchAH : public juce::AccessibilityHandler [this]() { this->press(); })) { } + + juce::AccessibleState getCurrentState() const override + { + auto state = AccessibilityHandler::getCurrentState(); + state = state.withCheckable(); + if (mswitch->getValue() > 0.5) + state = state.withChecked(); + + return state; + } + void press() { if (mswitch->isMultiIntegerValued())