Audacity 3.2.0
WindowAccessible.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 WindowAccessible.cpp
6
7 David Bailes
8
9*******************************************************************//*******************************************************************/
16
17#include "WindowAccessible.h"
18
19#include <wx/setup.h> // for wxUSE_* macros
20#include <wx/window.h>
21
22#if wxUSE_ACCESSIBILITY
23
24WindowAccessible::WindowAccessible(wxWindow* win)
25 : wxAccessible(win)
26{
27 if (win) win->SetAccessible(this);
28}
29
30wxAccStatus WindowAccessible::GetName(int childId, wxString* name)
31{
32 wxCHECK( GetWindow() != nullptr, wxACC_FAIL);
33
34 // If the control has children, don't override their names
35 if (childId > 0)
36 return wxACC_NOT_IMPLEMENTED;
37
38 *name = GetWindow()->GetName();
39 return wxACC_OK;
40}
41
42#include <wx/slider.h>
43
44SliderAx::SliderAx(wxWindow * window, const TranslatableString &fmt) :
45WindowAccessible( window )
46{
47 mParent = window;
48 mFmt = fmt;
49}
50
51SliderAx::~SliderAx()
52{
53}
54
55// Retrieves the address of an IDispatch interface for the specified child.
56// All objects must support this property.
57wxAccStatus SliderAx::GetChild( int childId, wxAccessible** child )
58{
59 if( childId == wxACC_SELF )
60 {
61 *child = this;
62 }
63 else
64 {
65 *child = NULL;
66 }
67
68 return wxACC_OK;
69}
70
71// Gets the number of children.
72wxAccStatus SliderAx::GetChildCount(int* childCount)
73{
74 *childCount = 3;
75
76 return wxACC_OK;
77}
78
79// Gets the default action for this object (0) or > 0 (the action for a child).
80// Return wxACC_OK even if there is no action. actionName is the action, or the empty
81// string if there is no action.
82// The retrieved string describes the action that is performed on an object,
83// not what the object does as a result. For example, a toolbar button that prints
84// a document has a default action of "Press" rather than "Prints the current document."
85wxAccStatus SliderAx::GetDefaultAction( int WXUNUSED(childId), wxString *actionName )
86{
87 actionName->clear();
88
89 return wxACC_OK;
90}
91
92// Returns the description for this object or a child.
93wxAccStatus SliderAx::GetDescription( int WXUNUSED(childId), wxString *description )
94{
95 description->clear();
96
97 return wxACC_OK;
98}
99
100// Gets the window with the keyboard focus.
101// If childId is 0 and child is NULL, no object in
102// this subhierarchy has the focus.
103// If this object has the focus, child should be 'this'.
104wxAccStatus SliderAx::GetFocus(int* childId, wxAccessible** child)
105{
106 *childId = 0;
107 *child = this;
108
109 return wxACC_OK;
110}
111
112// Returns help text for this object or a child, similar to tooltip text.
113wxAccStatus SliderAx::GetHelpText( int WXUNUSED(childId), wxString *helpText )
114{
115 helpText->clear();
116
117 return wxACC_OK;
118}
119
120// Returns the keyboard shortcut for this object or child.
121// Return e.g. ALT+K
122wxAccStatus SliderAx::GetKeyboardShortcut( int WXUNUSED(childId), wxString *shortcut )
123{
124 shortcut->clear();
125
126 return wxACC_OK;
127}
128
129// Returns the rectangle for this object (id = 0) or a child element (id > 0).
130// rect is in screen coordinates.
131wxAccStatus SliderAx::GetLocation( wxRect& rect, int WXUNUSED(elementId) )
132{
133 wxSlider *s = wxDynamicCast( GetWindow(), wxSlider );
134
135 rect = s->GetRect();
136 rect.SetPosition( s->GetParent()->ClientToScreen( rect.GetPosition() ) );
137
138 return wxACC_OK;
139}
140
141// Gets the name of the specified object.
142wxAccStatus SliderAx::GetName(int WXUNUSED(childId), wxString* name)
143{
144 wxSlider *s = wxDynamicCast( GetWindow(), wxSlider );
145
146 *name = s->GetName();
147
148 return wxACC_OK;
149}
150
151// Returns a role constant.
152wxAccStatus SliderAx::GetRole(int childId, wxAccRole* role)
153{
154 switch( childId )
155 {
156 case 0:
157 *role = wxROLE_SYSTEM_SLIDER;
158 break;
159
160 case 1:
161 case 3:
162 *role = wxROLE_SYSTEM_PUSHBUTTON;
163 break;
164
165 case 2:
166 *role = wxROLE_SYSTEM_INDICATOR;
167 break;
168 }
169
170 return wxACC_OK;
171}
172
173// Gets a variant representing the selected children
174// of this object.
175// Acceptable values:
176// - a null variant (IsNull() returns TRUE)
177// - a list variant (GetType() == wxT("list"))
178// - an integer representing the selected child element,
179// or 0 if this object is selected (GetType() == wxT("long"))
180// - a "void*" pointer to a wxAccessible child object
181wxAccStatus SliderAx::GetSelections( wxVariant * WXUNUSED(selections) )
182{
183 return wxACC_NOT_IMPLEMENTED;
184}
185
186// Returns a state constant.
187wxAccStatus SliderAx::GetState(int childId, long* state)
188{
189 wxSlider *s = wxDynamicCast( GetWindow(), wxSlider );
190
191 switch( childId )
192 {
193 case 0:
194 *state = wxACC_STATE_SYSTEM_FOCUSABLE;
195 break;
196
197 case 1:
198 if( s->GetValue() == s->GetMin() )
199 {
200 *state = wxACC_STATE_SYSTEM_INVISIBLE;
201 }
202 break;
203
204 case 3:
205 if( s->GetValue() == s->GetMax() )
206 {
207 *state = wxACC_STATE_SYSTEM_INVISIBLE;
208 }
209 break;
210 }
211
212 // Do not use mSliderIsFocused is not set until after this method
213 // is called.
214 *state |= ( s == wxWindow::FindFocus() ? wxACC_STATE_SYSTEM_FOCUSED : 0 );
215
216 return wxACC_OK;
217}
218
219// Returns a localized string representing the value for the object
220// or child.
221wxAccStatus SliderAx::GetValue(int childId, wxString* strValue)
222{
223 wxSlider *s = wxDynamicCast( GetWindow(), wxSlider );
224
225 if( childId == 0 )
226 {
227 strValue->Printf( mFmt.Translation(), s->GetValue() );
228
229 return wxACC_OK;
230 }
231
232 return wxACC_NOT_SUPPORTED;
233}
234
235#endif // wxUSE_ACCESSIBILITY
wxString name
Definition: TagsEditor.cpp:166
Holds a msgid for the translation catalog; may also bind format arguments.
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:383