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.

juce_AccessibilityActions.h 3.5KB

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