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.

113 lines
3.2KB

  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. /** An action that can be performed by an accessible UI element.
  16. @tags{Accessibility}
  17. */
  18. enum class AccessibilityActionType
  19. {
  20. /** Represents a "press" action.
  21. This will be called when the user "clicks" the UI element using an
  22. accessibility client.
  23. */
  24. press,
  25. /** Represents a "toggle" action.
  26. This will be called when the user toggles the state of a UI element,
  27. for example a toggle button or the selection of a list item.
  28. */
  29. toggle,
  30. /** Indicates that the UI element has received focus.
  31. This will be called when a UI element receives focus from an accessibility
  32. client, or keyboard focus from the application.
  33. */
  34. focus,
  35. /** Represents the user showing a contextual menu for a UI element.
  36. This will be called for UI elements which expand and collapse to
  37. show contextual information or menus, or show a popup.
  38. */
  39. showMenu
  40. };
  41. /** A simple wrapper for building a collection of supported accessibility actions
  42. and corresponding callbacks for a UI element.
  43. Pass one of these when constructing an `AccessibilityHandler` to enable users
  44. to interact with a UI element via the supported actions.
  45. @tags{Accessibility}
  46. */
  47. class JUCE_API AccessibilityActions
  48. {
  49. public:
  50. /** Constructor.
  51. Creates a default AccessibilityActions object with no action callbacks.
  52. */
  53. AccessibilityActions() = default;
  54. /** Adds an action.
  55. When the user performs this action with an accessibility client
  56. `actionCallback` will be called.
  57. Returns a reference to itself so that several calls can be chained.
  58. */
  59. AccessibilityActions& addAction (AccessibilityActionType type,
  60. std::function<void()> actionCallback)
  61. {
  62. actionMap[type] = std::move (actionCallback);
  63. return *this;
  64. }
  65. /** Returns true if the specified action is supported. */
  66. bool contains (AccessibilityActionType type) const
  67. {
  68. return actionMap.find (type) != actionMap.end();
  69. }
  70. /** If an action has been registered for the provided action type, invokes the
  71. action and returns true. Otherwise, returns false.
  72. */
  73. bool invoke (AccessibilityActionType type) const
  74. {
  75. auto iter = actionMap.find (type);
  76. if (iter == actionMap.end())
  77. return false;
  78. iter->second();
  79. return true;
  80. }
  81. private:
  82. std::map<AccessibilityActionType, std::function<void()>> actionMap;
  83. };
  84. } // namespace juce