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.

131 lines
4.1KB

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