Audio plugin host https://kx.studio/carla
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.

228 lines
7.2KB

  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. /** Represents the state of an accessible UI element.
  21. An instance of this class is returned by `AccessibilityHandler::getCurrentState()`
  22. to convey its current state to an accessibility client.
  23. @see AccessibilityHandler
  24. @tags{Accessibility}
  25. */
  26. class JUCE_API AccessibleState
  27. {
  28. public:
  29. /** Constructor.
  30. Represents a "default" state with no flags set. To set a flag, use one of the
  31. `withX()` methods - these can be chained together to set multiple flags.
  32. */
  33. AccessibleState() = default;
  34. //==============================================================================
  35. /** Sets the checkable flag and returns the new state.
  36. @see isCheckable
  37. */
  38. JUCE_NODISCARD AccessibleState withCheckable() const noexcept { return withFlag (Flags::checkable); }
  39. /** Sets the checked flag and returns the new state.
  40. @see isChecked
  41. */
  42. JUCE_NODISCARD AccessibleState withChecked() const noexcept { return withFlag (Flags::checked); }
  43. /** Sets the collapsed flag and returns the new state.
  44. @see isCollapsed
  45. */
  46. JUCE_NODISCARD AccessibleState withCollapsed() const noexcept { return withFlag (Flags::collapsed); }
  47. /** Sets the expandable flag and returns the new state.
  48. @see isExpandable
  49. */
  50. JUCE_NODISCARD AccessibleState withExpandable() const noexcept { return withFlag (Flags::expandable); }
  51. /** Sets the expanded flag and returns the new state.
  52. @see isExpanded
  53. */
  54. JUCE_NODISCARD AccessibleState withExpanded() const noexcept { return withFlag (Flags::expanded); }
  55. /** Sets the focusable flag and returns the new state.
  56. @see isFocusable
  57. */
  58. JUCE_NODISCARD AccessibleState withFocusable() const noexcept { return withFlag (Flags::focusable); }
  59. /** Sets the focused flag and returns the new state.
  60. @see isFocused
  61. */
  62. JUCE_NODISCARD AccessibleState withFocused() const noexcept { return withFlag (Flags::focused); }
  63. /** Sets the ignored flag and returns the new state.
  64. @see isIgnored
  65. */
  66. JUCE_NODISCARD AccessibleState withIgnored() const noexcept { return withFlag (Flags::ignored); }
  67. /** Sets the selectable flag and returns the new state.
  68. @see isSelectable
  69. */
  70. JUCE_NODISCARD AccessibleState withSelectable() const noexcept { return withFlag (Flags::selectable); }
  71. /** Sets the multiSelectable flag and returns the new state.
  72. @see isMultiSelectable
  73. */
  74. JUCE_NODISCARD AccessibleState withMultiSelectable() const noexcept { return withFlag (Flags::multiSelectable); }
  75. /** Sets the selected flag and returns the new state.
  76. @see isSelected
  77. */
  78. JUCE_NODISCARD AccessibleState withSelected() const noexcept { return withFlag (Flags::selected); }
  79. /** Sets the accessible offscreen flag and returns the new state.
  80. @see isSelected
  81. */
  82. JUCE_NODISCARD AccessibleState withAccessibleOffscreen() const noexcept { return withFlag (Flags::accessibleOffscreen); }
  83. //==============================================================================
  84. /** Returns true if the UI element is checkable.
  85. @see withCheckable
  86. */
  87. bool isCheckable() const noexcept { return isFlagSet (Flags::checkable); }
  88. /** Returns true if the UI element is checked.
  89. @see withChecked
  90. */
  91. bool isChecked() const noexcept { return isFlagSet (Flags::checked); }
  92. /** Returns true if the UI element is collapsed.
  93. @see withCollapsed
  94. */
  95. bool isCollapsed() const noexcept { return isFlagSet (Flags::collapsed); }
  96. /** Returns true if the UI element is expandable.
  97. @see withExpandable
  98. */
  99. bool isExpandable() const noexcept { return isFlagSet (Flags::expandable); }
  100. /** Returns true if the UI element is expanded.
  101. @see withExpanded
  102. */
  103. bool isExpanded() const noexcept { return isFlagSet (Flags::expanded); }
  104. /** Returns true if the UI element is focusable.
  105. @see withFocusable
  106. */
  107. bool isFocusable() const noexcept { return isFlagSet (Flags::focusable); }
  108. /** Returns true if the UI element is focused.
  109. @see withFocused
  110. */
  111. bool isFocused() const noexcept { return isFlagSet (Flags::focused); }
  112. /** Returns true if the UI element is ignored.
  113. @see withIgnored
  114. */
  115. bool isIgnored() const noexcept { return isFlagSet (Flags::ignored); }
  116. /** Returns true if the UI element supports multiple item selection.
  117. @see withMultiSelectable
  118. */
  119. bool isMultiSelectable() const noexcept { return isFlagSet (Flags::multiSelectable); }
  120. /** Returns true if the UI element is selectable.
  121. @see withSelectable
  122. */
  123. bool isSelectable() const noexcept { return isFlagSet (Flags::selectable); }
  124. /** Returns true if the UI element is selected.
  125. @see withSelected
  126. */
  127. bool isSelected() const noexcept { return isFlagSet (Flags::selected); }
  128. /** Returns true if the UI element is accessible offscreen.
  129. @see withSelected
  130. */
  131. bool isAccessibleOffscreen() const noexcept { return isFlagSet (Flags::accessibleOffscreen); }
  132. private:
  133. enum Flags
  134. {
  135. checkable = (1 << 0),
  136. checked = (1 << 1),
  137. collapsed = (1 << 2),
  138. expandable = (1 << 3),
  139. expanded = (1 << 4),
  140. focusable = (1 << 5),
  141. focused = (1 << 6),
  142. ignored = (1 << 7),
  143. multiSelectable = (1 << 8),
  144. selectable = (1 << 9),
  145. selected = (1 << 10),
  146. accessibleOffscreen = (1 << 11)
  147. };
  148. JUCE_NODISCARD AccessibleState withFlag (int flag) const noexcept
  149. {
  150. auto copy = *this;
  151. copy.flags |= flag;
  152. return copy;
  153. }
  154. bool isFlagSet (int flag) const noexcept
  155. {
  156. return (flags & flag) != 0;
  157. }
  158. int flags = 0;
  159. };
  160. } // namespace juce