2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
29 //==============================================================================
30 class UIARangeValueProvider
: public UIAProviderBase
,
31 public ComBaseClassHelper
<ComTypes::IRangeValueProvider
>
34 using UIAProviderBase::UIAProviderBase
;
36 //==============================================================================
37 JUCE_COMRESULT
SetValue (double val
) override
39 if (! isElementValid())
40 return (HRESULT
) UIA_E_ELEMENTNOTAVAILABLE
;
42 const auto& handler
= getHandler();
44 if (auto* valueInterface
= handler
.getValueInterface())
46 auto range
= valueInterface
->getRange();
50 if (val
< range
.getMinimumValue() || val
> range
.getMaximumValue())
53 if (! valueInterface
->isReadOnly())
55 valueInterface
->setValue (val
);
58 VariantHelpers::setDouble (valueInterface
->getCurrentValue(), &newValue
);
59 sendAccessibilityPropertyChangedEvent (handler
, UIA_RangeValueValuePropertyId
, newValue
);
66 return (HRESULT
) UIA_E_NOTSUPPORTED
;
69 JUCE_COMRESULT
get_Value (double* pRetVal
) override
71 return withValueInterface (pRetVal
, [] (const AccessibilityValueInterface
& valueInterface
)
73 return valueInterface
.getCurrentValue();
77 JUCE_COMRESULT
get_IsReadOnly (BOOL
* pRetVal
) override
79 return withValueInterface (pRetVal
, [] (const AccessibilityValueInterface
& valueInterface
)
81 return valueInterface
.isReadOnly();
85 JUCE_COMRESULT
get_Maximum (double* pRetVal
) override
87 return withValueInterface (pRetVal
, [] (const AccessibilityValueInterface
& valueInterface
)
89 return valueInterface
.getRange().getMaximumValue();
93 JUCE_COMRESULT
get_Minimum (double* pRetVal
) override
95 return withValueInterface (pRetVal
, [] (const AccessibilityValueInterface
& valueInterface
)
97 return valueInterface
.getRange().getMinimumValue();
101 JUCE_COMRESULT
get_LargeChange (double* pRetVal
) override
103 return get_SmallChange (pRetVal
);
106 JUCE_COMRESULT
get_SmallChange (double* pRetVal
) override
108 return withValueInterface (pRetVal
, [] (const AccessibilityValueInterface
& valueInterface
)
110 return valueInterface
.getRange().getInterval();
115 template <typename Value
, typename Callback
>
116 JUCE_COMRESULT
withValueInterface (Value
* pRetVal
, Callback
&& callback
) const
118 return withCheckedComArgs (pRetVal
, *this, [&]() -> HRESULT
120 if (auto* valueInterface
= getHandler().getValueInterface())
122 if (valueInterface
->getRange().isValid())
124 *pRetVal
= callback (*valueInterface
);
129 return (HRESULT
) UIA_E_NOTSUPPORTED
;
133 //==============================================================================
134 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UIARangeValueProvider
)