mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Slider: Add keyboard control even without accessibility
This commit is contained in:
parent
a91694108c
commit
94dcad52d0
4 changed files with 67 additions and 12 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue