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.

141 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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<IRangeValueProvider>
  23. {
  24. public:
  25. explicit UIARangeValueProvider (AccessibilityNativeHandle* nativeHandle)
  26. : UIAProviderBase (nativeHandle)
  27. {
  28. }
  29. //==============================================================================
  30. JUCE_COMRESULT SetValue (double val) override
  31. {
  32. if (! isElementValid())
  33. return UIA_E_ELEMENTNOTAVAILABLE;
  34. const auto& handler = getHandler();
  35. if (auto* valueInterface = handler.getValueInterface())
  36. {
  37. auto range = valueInterface->getRange();
  38. if (range.isValid())
  39. {
  40. if (val < range.getMinimumValue() || val > range.getMaximumValue())
  41. return E_INVALIDARG;
  42. if (! valueInterface->isReadOnly())
  43. {
  44. valueInterface->setValue (val);
  45. VARIANT newValue;
  46. VariantHelpers::setDouble (valueInterface->getCurrentValue(), &newValue);
  47. sendAccessibilityPropertyChangedEvent (handler, UIA_RangeValueValuePropertyId, newValue);
  48. return S_OK;
  49. }
  50. }
  51. }
  52. return UIA_E_NOTSUPPORTED;
  53. }
  54. JUCE_COMRESULT get_Value (double* pRetVal) override
  55. {
  56. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  57. {
  58. return valueInterface.getCurrentValue();
  59. });
  60. }
  61. JUCE_COMRESULT get_IsReadOnly (BOOL* pRetVal) override
  62. {
  63. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  64. {
  65. return valueInterface.isReadOnly();
  66. });
  67. }
  68. JUCE_COMRESULT get_Maximum (double* pRetVal) override
  69. {
  70. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  71. {
  72. return valueInterface.getRange().getMaximumValue();
  73. });
  74. }
  75. JUCE_COMRESULT get_Minimum (double* pRetVal) override
  76. {
  77. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  78. {
  79. return valueInterface.getRange().getMinimumValue();
  80. });
  81. }
  82. JUCE_COMRESULT get_LargeChange (double* pRetVal) override
  83. {
  84. return get_SmallChange (pRetVal);
  85. }
  86. JUCE_COMRESULT get_SmallChange (double* pRetVal) override
  87. {
  88. return withValueInterface (pRetVal, [] (const AccessibilityValueInterface& valueInterface)
  89. {
  90. return valueInterface.getRange().getInterval();
  91. });
  92. }
  93. private:
  94. template <typename Value, typename Callback>
  95. JUCE_COMRESULT withValueInterface (Value* pRetVal, Callback&& callback) const
  96. {
  97. return withCheckedComArgs (pRetVal, *this, [&]() -> HRESULT
  98. {
  99. if (auto* valueInterface = getHandler().getValueInterface())
  100. {
  101. if (valueInterface->getRange().isValid())
  102. {
  103. *pRetVal = callback (*valueInterface);
  104. return S_OK;
  105. }
  106. }
  107. return UIA_E_NOTSUPPORTED;
  108. });
  109. }
  110. //==============================================================================
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UIARangeValueProvider)
  112. };
  113. } // namespace juce