JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ButtonAccessibilityHandler.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::detail
27{
28
29//==============================================================================
31{
32public:
35 isRadioButton (buttonToWrap) ? AccessibilityRole::radioButton : roleIn,
36 getAccessibilityActions (buttonToWrap),
37 getAccessibilityInterfaces (buttonToWrap)),
38 button (buttonToWrap)
39 {}
40
41
43 {
45
46 if (button.isToggleable())
47 {
48 state = state.withCheckable();
49
50 if (button.getToggleState())
51 state = state.withChecked();
52 }
53
54 return state;
55 }
56
57
58 String getTitle() const override
59 {
60 auto title = AccessibilityHandler::getTitle();
61
62 if (title.isEmpty())
63 return button.getButtonText();
64
65 return title;
66 }
67
68 String getHelp() const override
69 {
70 return button.getTooltip();
71 }
72
73
74private:
75 class ButtonValueInterface : public AccessibilityTextValueInterface
76 {
77 public:
78 explicit ButtonValueInterface (Button& buttonToWrap)
79 : button (buttonToWrap)
80 {
81 }
82
83 bool isReadOnly() const override { return true; }
84 String getCurrentValueAsString() const override { return button.getToggleState() ? "On" : "Off"; }
85 void setValueAsString (const String&) override {}
86
87 private:
88 Button& button;
89
90 //==============================================================================
92 };
93
94 static bool isRadioButton (const Button& button) noexcept
95 {
96 return button.getRadioGroupId() != 0;
97 }
98
99 static AccessibilityActions getAccessibilityActions (Button& button)
100 {
101 auto actions = AccessibilityActions().addAction (AccessibilityActionType::press,
102 [&button] { button.triggerClick(); });
103
104 if (button.isToggleable())
105 actions = actions.addAction (AccessibilityActionType::toggle,
106 [&button] { button.setToggleState (! button.getToggleState(), sendNotification); });
107
108 return actions;
109 }
110
111 static Interfaces getAccessibilityInterfaces (Button& button)
112 {
113 if (button.isToggleable())
114 return { std::make_unique<ButtonValueInterface> (button) };
115
116 return {};
117 }
118
119 Button& button;
120
121 //==============================================================================
122 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonAccessibilityHandler)
123};
124
125} // namespace juce::detail
Base class for accessible Components.
virtual AccessibleState getCurrentState() const
Returns the current state of the UI element.
virtual String getTitle() const
The title of the UI element.
A value interface that represents a text value.
Represents the state of an accessible UI element.
A base class for buttons.
Definition juce_Button.h:43
bool getToggleState() const noexcept
Returns true if the button is 'on'.
bool isToggleable() const noexcept
Returns true if the button's on/off state is toggleable.
const String & getButtonText() const
Returns the text displayed in the button.
Definition juce_Button.h:67
int getRadioGroupId() const noexcept
Returns the ID of the group to which this button belongs.
String getTooltip() override
Returns the tooltip assigned to this object.
The JUCE String class!
Definition juce_String.h:53
String getHelp() const override
Some help text for the UI element (if required).
AccessibleState getCurrentState() const override
Returns the current state of the UI element.
String getTitle() const override
The title of the UI element.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
@ sendNotification
Requests a notification message, either synchronous or not.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
@ toggle
Represents a "toggle" action.
@ press
Represents a "press" action.
AccessibilityRole
The list of available roles for an AccessibilityHandler object.