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.

221 lines
6.9KB

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