From f9ee3cdc45ab3c5530505daa119ef01ccfdcc262 Mon Sep 17 00:00:00 2001 From: David Bailes Date: Thu, 5 Apr 2018 10:57:12 +0100 Subject: [PATCH] Fix some of the accessibility names that disappeared with the move to WX 3.1.1 The main change in wxWidgets for the setting of accessibility names is: https://github.com/wxWidgets/wxWidgets/commit/7dab555f7118f24e70444ff6d6411433b730b889#diff-04f5191d86f95b1c4d5d9c979da65878 Before this change, with wxUSE_ACCESSIBILITY set to 1, for wxWindow and all the classes derived from it, wxWidgets automatically created accessible objects to handle accessibility itself. Because the way wxWindowAccessible::GetName() was written, the accessibility names of lots of windows and controls had to be set using SetName(). After the change, by default, the accessibility of instances of these classes is handled by Windows. Where the accessibility of a control is handled by Windows, then the accessibility name is automatically set to so the appropriate value. However, an accessible can still be set using SetAccessible() then wxWidgets handles the accessibility for this object. So for many controls we can just leave Windows to set the accessibility name. However, for controls which don't have any visible labels, or where we want to accessibility name to different from the visible text, then we have to set an accessible object for that control, and then call SetName(). The Class WindowAccessible can be used for this purpose. And for custom widgets, like the TrackPanel, and the NumericTextCtrl, SetAccessible() still has to be called, since they need bespoke accessible objects So in the cases where we want the accessible name to be different from normal, we now need to explicitly set an accessible object. (Before, this wasn't needed, as accessible objects were automatically created.). Some notes of the fixes included in this commit: 1. The fixes cover the main window, preferences, and built-in effects. Other fixes will follow. 2. In ShuttleGui, I've set accessible objects for wxTextCtrls and wxSliders. So all of these widgets still need the name set. This was done because there are a lot of instances where these controls need non standard accessibility names, and so it saves having to put lots of SetAccessibles throughout the code. 3. For wxPanel, Windows picks up the accessibility name from the label, and so SetLabel() can be used instead of SetName(). This is just as well, since for windows that contain other windows or controls, setting WindowAccessible as the accessibility object breaks the accessibility tree. Note that at some stage a lot of calls to SetName() can be removed from the code as they are no longer needed, but it might be better to leave them there for the moment, just in case they are unexpectedly needed. --- src/Project.cpp | 18 ++++++++++++++++-- src/ShuttleGui.cpp | 24 ++++++++++++++++++++++++ src/prefs/KeyConfigPrefs.cpp | 15 ++++++++++++++- src/prefs/PrefsDialog.cpp | 8 ++++++++ src/toolbars/DeviceToolBar.cpp | 21 ++++++++++++++++++++- src/toolbars/SelectionBar.cpp | 16 ++++++++++++++++ src/toolbars/SpectralSelectionBar.cpp | 8 ++++++++ 7 files changed, 106 insertions(+), 4 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index c21dc7a25..665cc67dd 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -172,6 +172,10 @@ scroll information. It also has some status flags. #include "../images/AudacityLogoAlpha.xpm" +#if wxUSE_ACCESSIBILITY +#include "widgets/WindowAccessible.h" +#endif + std::shared_ptr AudacityProject::msClipboard{ TrackList::Create() }; double AudacityProject::msClipT0 = 0.0; double AudacityProject::msClipT1 = 0.0; @@ -947,6 +951,11 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, // field. Currently there are no such help strings, but it they were introduced, then // there would need to be an event handler to send them to the appropriate field. mStatusBar = CreateStatusBar(4); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mStatusBar->SetAccessible(safenew WindowAccessible(mStatusBar)); +#endif + mStatusBar->SetName(wxT("status_line")); // not localized mProjectNo = mProjectCounter++; // Bug 322 wxGetApp().SetMissingAliasedFileWarningShouldShow(true); @@ -990,7 +999,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, this, wxID_ANY, wxDefaultPosition, wxSize{ this->GetSize().GetWidth(), -1 } }; - mTopPanel->SetName( "Top Panel" );// Not localised + mTopPanel->SetLabel( "Top Panel" );// Not localised mTopPanel->SetAutoLayout(true); #ifdef EXPERIMENTAL_DA2 mTopPanel->SetBackgroundColour(theTheme.Colour( clrMedium )); @@ -1040,7 +1049,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, wxDefaultSize, wxNO_BORDER); mMainPanel->SetSizer( safenew wxBoxSizer(wxVERTICAL) ); - mMainPanel->SetName("Main Panel");// Not localised. + mMainPanel->SetLabel("Main Panel");// Not localised. pPage = mMainPanel; // Set the colour here to the track panel background to avoid // flicker when Audacity starts up. @@ -1128,6 +1137,11 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, // several focus problems. mHsbar = safenew ScrollBar(pPage, HSBarID, wxSB_HORIZONTAL); mVsbar = safenew ScrollBar(pPage, VSBarID, wxSB_VERTICAL); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mHsbar->SetAccessible(safenew WindowAccessible(mHsbar)); + mVsbar->SetAccessible(safenew WindowAccessible(mVsbar)); +#endif mHsbar->SetName(_("Horizontal Scrollbar")); mVsbar->SetName(_("Vertical Scrollbar")); diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index b8d815d51..23f3a7a81 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -113,6 +113,10 @@ for registering for changes. #include "widgets/wxPanelWrapper.h" #include "AllThemeResources.h" +#if wxUSE_ACCESSIBILITY +#include "widgets/WindowAccessible.h" +#endif + ShuttleGuiBase::ShuttleGuiBase(wxWindow * pParent, teShuttleMode ShuttleMode ) { wxASSERT( (pParent != NULL ) || ( ShuttleMode != eIsCreating)); @@ -503,6 +507,10 @@ wxSlider * ShuttleGuiBase::AddSlider(const wxString &Prompt, int pos, int Max, i wxDefaultPosition, wxDefaultSize, Style( wxSL_HORIZONTAL | wxSL_LABELS | wxSL_AUTOTICKS ) ); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mpWind->SetAccessible(safenew WindowAccessible(mpWind)); +#endif mpWind->SetName(wxStripMenuCodes(Prompt)); miProp=1; UpdateSizers(); @@ -552,6 +560,10 @@ wxTextCtrl * ShuttleGuiBase::AddTextBox(const wxString &Caption, const wxString mpWind = pTextCtrl = safenew wxTextCtrl(GetParent(), miId, Value, wxDefaultPosition, Size, Style( flags )); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mpWind->SetAccessible(safenew WindowAccessible(mpWind)); +#endif mpWind->SetName(wxStripMenuCodes(Caption)); UpdateSizers(); return pTextCtrl; @@ -583,6 +595,10 @@ wxTextCtrl * ShuttleGuiBase::AddNumericTextBox(const wxString &Caption, const wx wxDefaultPosition, Size, Style( flags ), Validator // It's OK to pass this. It will be cloned. ); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mpWind->SetAccessible(safenew WindowAccessible(mpWind)); +#endif mpWind->SetName(wxStripMenuCodes(Caption)); UpdateSizers(); return pTextCtrl; @@ -598,6 +614,10 @@ wxTextCtrl * ShuttleGuiBase::AddTextWindow(const wxString &Value) SetProportions( 1 ); mpWind = pTextCtrl = safenew wxTextCtrl(GetParent(), miId, Value, wxDefaultPosition, wxDefaultSize, Style( wxTE_MULTILINE )); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mpWind->SetAccessible(safenew WindowAccessible(mpWind)); +#endif UpdateSizers(); // Start off at start of window... pTextCtrl->SetInsertionPoint( 0 ); @@ -2274,6 +2294,10 @@ std::unique_ptr CreateStdButtonSizer(wxWindow *parent, long buttons, wx // bs->AddButton(safenew wxButton(parent, wxID_HELP)); b = safenew wxBitmapButton(parent, wxID_HELP, theTheme.Bitmap( bmpHelpIcon )); b->SetToolTip( _("Help") ); +#if wxUSE_ACCESSIBILITY + b->SetAccessible(safenew WindowAccessible(b)); // so that name can be set on a standard control + b->SetName(_("Help")); +#endif bs->AddButton( b ); } diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index 396a7a7e7..739295adb 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -43,6 +43,10 @@ KeyConfigPrefs and MousePrefs use. #include "../widgets/KeyView.h" #include "../widgets/ErrorDialog.h" +#if wxUSE_ACCESSIBILITY +#include "../widgets/WindowAccessible.h" +#endif + // // KeyConfigPrefs // @@ -159,6 +163,12 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S) if( mViewByName ) mViewByName->SetName(_("View by name")); mViewByKey = S.Id(ViewByKeyID).TieRadioButton(_("&Key"), wxT("key")); if( mViewByKey ) mViewByKey->SetName(_("View by key")); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mViewByTree->SetAccessible(safenew WindowAccessible(mViewByTree)); + mViewByName->SetAccessible(safenew WindowAccessible(mViewByName)); + mViewByKey->SetAccessible(safenew WindowAccessible(mViewByKey)); +#endif } S.EndRadioButtonGroup(); } @@ -224,7 +234,10 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S) wxSize(210, -1), #endif wxTE_PROCESS_ENTER); - +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mKey->SetAccessible(safenew WindowAccessible(mKey)); +#endif mKey->SetName(_("Short cut")); mKey->Bind(wxEVT_KEY_DOWN, &KeyConfigPrefs::OnHotkeyKeyDown, diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index d0f046973..b68bd444a 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -71,6 +71,10 @@ #include "../Theme.h" #include "../widgets/HelpSystem.h" +#if wxUSE_ACCESSIBILITY +#include "../widgets/WindowAccessible.h" +#endif + BEGIN_EVENT_TABLE(PrefsDialog, wxDialogWrapper) EVT_BUTTON(wxID_OK, PrefsDialog::OnOK) EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel) @@ -245,6 +249,10 @@ PrefsDialog::PrefsDialog wxASSERT(factories.size() > 0); if (!uniquePage) { mCategories = safenew wxTreebookExt(this, wxID_ANY, mTitlePrefix); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mCategories->GetTreeCtrl()->SetAccessible(safenew WindowAccessible(mCategories->GetTreeCtrl())); +#endif // RJH: Prevent NVDA from reading "treeCtrl" mCategories->GetTreeCtrl()->SetName(_("Category")); S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, true); diff --git a/src/toolbars/DeviceToolBar.cpp b/src/toolbars/DeviceToolBar.cpp index 68c7565ee..319ea8d91 100644 --- a/src/toolbars/DeviceToolBar.cpp +++ b/src/toolbars/DeviceToolBar.cpp @@ -45,6 +45,10 @@ #include "../DeviceManager.h" #include "../widgets/ErrorDialog.h" +#if wxUSE_ACCESSIBILITY +#include "../widgets/WindowAccessible.h" +#endif + IMPLEMENT_CLASS(DeviceToolBar, ToolBar); //////////////////////////////////////////////////////////// @@ -93,7 +97,10 @@ void DeviceToolBar::Populate() wxID_ANY, wxDefaultPosition, wxDefaultSize); - +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mHost->SetAccessible(safenew WindowAccessible(mHost)); +#endif Add(mHost, 0, wxALIGN_CENTER); // Input device @@ -104,12 +111,20 @@ void DeviceToolBar::Populate() wxID_ANY, wxDefaultPosition, wxDefaultSize); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mInput->SetAccessible(safenew WindowAccessible(mInput)); +#endif // Input channels Add(mInput, 0, wxALIGN_CENTER); mInputChannels = safenew wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mInputChannels->SetAccessible(safenew WindowAccessible(mInputChannels)); +#endif Add(mInputChannels, 0, wxALIGN_CENTER); // Output device @@ -120,6 +135,10 @@ void DeviceToolBar::Populate() wxID_ANY, wxDefaultPosition, wxDefaultSize); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mOutput->SetAccessible(safenew WindowAccessible(mOutput)); +#endif Add(mOutput, 0, wxALIGN_CENTER); diff --git a/src/toolbars/SelectionBar.cpp b/src/toolbars/SelectionBar.cpp index ddf40df50..1787f80d5 100644 --- a/src/toolbars/SelectionBar.cpp +++ b/src/toolbars/SelectionBar.cpp @@ -57,6 +57,10 @@ with changes in the SelectionBar. #include "../widgets/NumericTextCtrl.h" #include "../AllThemeResources.h" +#if wxUSE_ACCESSIBILITY +#include "../widgets/WindowAccessible.h" +#endif + IMPLEMENT_CLASS(SelectionBar, ToolBar); const static wxChar *numbers[] = @@ -276,6 +280,10 @@ void SelectionBar::Populate() (this, ChoiceID, wxDefaultPosition, wxDefaultSize, 4, choices, 0, wxDefaultValidator, _("Show")); mChoice->SetSelection(0); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mChoice->SetAccessible(safenew WindowAccessible(mChoice)); +#endif #ifdef __WXGTK__ // Combo boxes are taller on Linux, and if we don't do the following, the selection toolbar will // be three units high. @@ -293,6 +301,10 @@ void SelectionBar::Populate() mRateBox = safenew wxComboBox(this, RateID, wxT(""), wxDefaultPosition, wxSize(80, -1)); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mRateBox->SetAccessible(safenew WindowAccessible(mRateBox)); +#endif mRateBox->SetName(_("Project Rate (Hz)")); //mRateBox->SetForegroundColour( clrText2 ); wxTextValidator vld(wxFILTER_INCLUDE_CHAR_LIST); @@ -352,6 +364,10 @@ void SelectionBar::Populate() mainSizer->Add(mSnapTo, 0, wxALIGN_TOP | wxRIGHT, 5); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mSnapTo->SetAccessible(safenew WindowAccessible(mSnapTo)); +#endif mSnapTo->SetName(_("Snap To")); //mSnapTo->SetForegroundColour( clrText2 ); mSnapTo->SetSelection(mListener ? mListener->AS_GetSnapTo() : SNAP_OFF); diff --git a/src/toolbars/SpectralSelectionBar.cpp b/src/toolbars/SpectralSelectionBar.cpp index bd8a3eb5b..b8c26c793 100644 --- a/src/toolbars/SpectralSelectionBar.cpp +++ b/src/toolbars/SpectralSelectionBar.cpp @@ -59,6 +59,10 @@ with changes in the SpectralSelectionBar. #include "../Experimental.h" #include "../Internat.h" +#if wxUSE_ACCESSIBILITY +#include "../widgets/WindowAccessible.h" +#endif + #ifdef EXPERIMENTAL_SPECTRAL_EDITING IMPLEMENT_CLASS(SpectralSelectionBar, ToolBar); @@ -148,6 +152,10 @@ void SpectralSelectionBar::Populate() (this, OnChoiceID, wxDefaultPosition, wxDefaultSize, 2, choices, 0, wxDefaultValidator, _("Spectral Selection")); mChoice->SetSelection(mbCenterAndWidth ? 0 : 1); +#if wxUSE_ACCESSIBILITY + // so that name can be set on a standard control + mChoice->SetAccessible(safenew WindowAccessible(mChoice)); +#endif #ifdef __WXGTK__ // Combo boxes are taller on Linux, and if we don't do the following, the selection toolbar will // be three units high.