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.

72 lines
2.3KB

  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 UIAToggleProvider : public UIAProviderBase,
  17. public ComBaseClassHelper<ComTypes::IToggleProvider>
  18. {
  19. public:
  20. using UIAProviderBase::UIAProviderBase;
  21. //==============================================================================
  22. JUCE_COMRESULT Toggle() override
  23. {
  24. if (! isElementValid())
  25. return (HRESULT) UIA_E_ELEMENTNOTAVAILABLE;
  26. const auto& handler = getHandler();
  27. if (handler.getActions().invoke (AccessibilityActionType::toggle)
  28. || handler.getActions().invoke (AccessibilityActionType::press))
  29. {
  30. VARIANT newValue;
  31. VariantHelpers::setInt (getCurrentToggleState(), &newValue);
  32. sendAccessibilityPropertyChangedEvent (handler, UIA_ToggleToggleStatePropertyId, newValue);
  33. return S_OK;
  34. }
  35. return (HRESULT) UIA_E_NOTSUPPORTED;
  36. }
  37. JUCE_COMRESULT get_ToggleState (ComTypes::ToggleState* pRetVal) override
  38. {
  39. return withCheckedComArgs (pRetVal, *this, [&]
  40. {
  41. *pRetVal = getCurrentToggleState();
  42. return S_OK;
  43. });
  44. }
  45. private:
  46. ComTypes::ToggleState getCurrentToggleState() const
  47. {
  48. return getHandler().getCurrentState().isChecked() ? ComTypes::ToggleState_On
  49. : ComTypes::ToggleState_Off;
  50. }
  51. //==============================================================================
  52. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UIAToggleProvider)
  53. };
  54. } // namespace juce