The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. class UIARangeValueProvider : public UIAProviderBase,
  22. public ComBaseClassHelper<ComTypes::IRangeValueProvider>
  23. {
  24. public:
  25. using UIAProviderBase::UIAProviderBase;
  26. //==============================================================================
  27. JUCE_COMRESULT SetValue (double val) override
  28. {
  29. if (! isElementValid())
  30. return (HRESULT) UIA_E_ELEMENTNOTAVAILABLE;
  31. const auto& handler = getHandler();
  32. if (auto* valueInterface = handler.getValueInterface())
  33. {
  34. auto range = valueInterface->getRange();
  35. if (range.isValid())
  36. {
  37. if (val < range.getMinimumValue() || val > range.getMaximumValue())
  38. return E_INVALIDARG;
  39. if (! valueInterface->isReadOnly())
  40. {
  41. valueInterface->setValue (val);
  42. VARIANT newValue;
  43. VariantHelpers::setDouble (valueInterface->getCurrentValue(), &newValue);
  44. sendAccessibilityPropertyChangedEvent (handler, UIA_RangeValueValuePropertyId, newValue);
  45. return S_OK;
  46. }
  47. }
  48. }
  49. return (HRESULT) UIA_E_NOTSUPPORTED;
  50. }
  51. JUCE_COMRESULT get_Value (double* pRetVal) override
  52. {
  53. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  54. {
  55. return valueInterface.getCurrentValue();
  56. });
  57. }
  58. JUCE_COMRESULT get_IsReadOnly (BOOL* pRetVal) override
  59. {
  60. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  61. {
  62. return valueInterface.isReadOnly();
  63. });
  64. }
  65. JUCE_COMRESULT get_Maximum (double* pRetVal) override
  66. {
  67. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  68. {
  69. return valueInterface.getRange().getMaximumValue();
  70. });
  71. }
  72. JUCE_COMRESULT get_Minimum (double* pRetVal) override
  73. {
  74. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  75. {
  76. return valueInterface.getRange().getMinimumValue();
  77. });
  78. }
  79. JUCE_COMRESULT get_LargeChange (double* pRetVal) override
  80. {
  81. return get_SmallChange (pRetVal);
  82. }
  83. JUCE_COMRESULT get_SmallChange (double* pRetVal) override
  84. {
  85. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  86. {
  87. return valueInterface.getRange().getInterval();
  88. });
  89. }
  90. private:
  91. template <typename Value, typename Callback>
  92. JUCE_COMRESULT withValueInterface (Value* pRetVal, Callback&& callback) const
  93. {
  94. return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
  95. {
  96. if (auto* valueInterface = getHandler().getValueInterface())
  97. {
  98. if (valueInterface->getRange().isValid())
  99. {
  100. *pRetVal = callback (*valueInterface);
  101. return S_OK;
  102. }
  103. }
  104. return (HRESULT) UIA_E_NOTSUPPORTED;
  105. });
  106. }
  107. //==============================================================================
  108. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UIARangeValueProvider)
  109. };
  110. } // namespace juce