Audacity 3.2.0
AccessibilityUtils.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 AccessibilityUtils.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
11
12#include "AccessibilityUtils.h"
13
14#include <deque>
15#include <tuple>
16#include <type_traits>
17
18#include <wx/window.h>
19
20#include <wx/checkbox.h>
21#include <wx/choice.h>
22#include <wx/radiobut.h>
23#include <wx/slider.h>
24#include <wx/statbox.h>
25#include <wx/textctrl.h>
26
27#if wxUSE_ACCESSIBILITY
28# include "WindowAccessible.h"
29#endif
30
31template<typename... Types>
32bool IsOfType(wxWindow* window)
33{
34 std::tuple<std::add_pointer_t<Types>...> types;
35
36 return std::apply(
37 [window](auto... args) -> bool
38 { return ((dynamic_cast<decltype(args)>(window) != nullptr) || ...); },
39 types);
40}
41
42void SetupAccessibility(wxWindow* window)
43{
44 std::deque<wxWindow*> elementsQueue;
45 elementsQueue.push_back(window);
46
47 while (!elementsQueue.empty())
48 {
49 auto element = elementsQueue.front();
50 elementsQueue.pop_front();
51
52 for (auto child : element->GetChildren())
53 elementsQueue.push_back(child);
54
55#if wxUSE_ACCESSIBILITY
56 if (element->GetAccessible() == nullptr)
57 {
58 if (IsOfType<
59 wxCheckBox, wxChoice, wxSlider, wxTextCtrl, wxStaticBox,
60 wxRadioButton>(element))
61 element->SetAccessible(safenew WindowAccessible(element));
62 }
63#endif
64
65 const auto label = element->GetLabel();
66
67 if (!label.empty())
68 element->SetName(wxStripMenuCodes(label));
69 }
70}
void SetupAccessibility(wxWindow *window)
bool IsOfType(wxWindow *window)
#define safenew
Definition: MemoryX.h:10
TranslatableString label
Definition: TagsEditor.cpp:165
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...