Browse Source

Slider: Add keyboard control even without accessibility

pull/22/head
attila 3 years ago
parent
commit
94dcad52d0
4 changed files with 67 additions and 12 deletions
  1. +7
    -3
      modules/juce_gui_basics/native/accessibility/juce_win32_Accessibility.cpp
  2. +14
    -0
      modules/juce_gui_basics/native/accessibility/juce_win32_UIAHelpers.h
  3. +44
    -9
      modules/juce_gui_basics/widgets/juce_Slider.cpp
  4. +2
    -0
      modules/juce_gui_basics/widgets/juce_Slider.h

+ 7
- 3
modules/juce_gui_basics/native/accessibility/juce_win32_Accessibility.cpp View File

@@ -206,10 +206,14 @@ void AccessibilityHandler::notifyAccessibilityEvent (AccessibilityEvent eventTyp
{
if (auto* valueInterface = getValueInterface())
{
VARIANT newValue;
VariantHelpers::setString (valueInterface->getCurrentValueAsString(), &newValue);
const auto propertyType = getRole() == AccessibilityRole::slider ? UIA_RangeValueValuePropertyId
: UIA_ValueValuePropertyId;
sendAccessibilityPropertyChangedEvent (*this, UIA_ValueValuePropertyId, newValue);
const auto value = getRole() == AccessibilityRole::slider
? VariantHelpers::getWithValue (valueInterface->getCurrentValue())
: VariantHelpers::getWithValue (valueInterface->getCurrentValueAsString());
sendAccessibilityPropertyChangedEvent (*this, propertyType, value);
}
return;


+ 14
- 0
modules/juce_gui_basics/native/accessibility/juce_win32_UIAHelpers.h View File

@@ -28,6 +28,17 @@ namespace juce
namespace VariantHelpers
{
namespace Detail
{
template <typename Fn, typename ValueType>
inline VARIANT getWithValueGeneric (Fn&& setter, ValueType value)
{
VARIANT result{};
setter (value, &result);
return result;
}
}
inline void clear (VARIANT* variant)
{
variant->vt = VT_EMPTY;
@@ -56,6 +67,9 @@ namespace VariantHelpers
variant->vt = VT_R8;
variant->dblVal = value;
}
inline VARIANT getWithValue (double value) { return Detail::getWithValueGeneric (&setDouble, value); }
inline VARIANT getWithValue (const String& value) { return Detail::getWithValueGeneric (&setString, value); }
}
inline JUCE_COMRESULT addHandlersToArray (const std::vector<const AccessibilityHandler*>& handlers, SAFEARRAY** pRetVal)


+ 44
- 9
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -26,6 +26,14 @@
namespace juce
{
static double getStepSize (const Slider& slider)
{
const auto interval = slider.getInterval();
return interval != 0.0 ? interval
: slider.getRange().getLength() * 0.01;
}
class Slider::Pimpl : public AsyncUpdater, // this needs to be public otherwise it will cause an
// error when JUCE_DLL_BUILD=1
private Value::Listener
@@ -991,6 +999,38 @@ public:
popupDisplay.reset();
}
bool keyPressed (const KeyPress& key)
{
if (key.getModifiers().isAnyModifierKeyDown())
return false;
const auto getInterval = [this]
{
if (auto* accessibility = owner.getAccessibilityHandler())
if (auto* valueInterface = accessibility->getValueInterface())
return valueInterface->getRange().getInterval();
return getStepSize (owner);
};
const auto valueChange = [&]
{
if (key == KeyPress::rightKey || key == KeyPress::upKey)
return getInterval();
if (key == KeyPress::leftKey || key == KeyPress::downKey)
return -getInterval();
return 0.0;
}();
if (valueChange == 0.0)
return false;
setValue (getValue() + valueChange, sendNotificationSync);
return true;
}
void showPopupDisplay()
{
if (style == IncDecButtons)
@@ -1661,6 +1701,9 @@ void Slider::mouseExit (const MouseEvent&) { pimpl->mouseExit(); }
// it is shown when dragging the mouse over a slider and releasing
void Slider::mouseEnter (const MouseEvent&) { pimpl->mouseMove(); }
/** @internal */
bool Slider::keyPressed (const KeyPress& k) { return pimpl->keyPressed (k); }
void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
{
if (isEnabled())
@@ -1734,18 +1777,10 @@ private:
AccessibleValueRange getRange() const override
{
return { { slider.getMinimum(), slider.getMaximum() },
getStepSize() };
getStepSize (slider) };
}
private:
double getStepSize() const
{
auto interval = slider.getInterval();
return interval != 0.0 ? interval
: slider.getRange().getLength() * 0.01;
}
Slider& slider;
const bool useMaxValue;


+ 2
- 0
modules/juce_gui_basics/widgets/juce_Slider.h View File

@@ -991,6 +991,8 @@ public:
void mouseExit (const MouseEvent&) override;
/** @internal */
void mouseEnter (const MouseEvent&) override;
/** @internal */
bool keyPressed (const KeyPress&) override;
//==============================================================================
#ifndef DOXYGEN


Loading…
Cancel
Save