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:
7dab555f71 (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.
This commit is contained in:
David Bailes 2018-04-05 10:57:12 +01:00
parent 6e59c2e286
commit f9ee3cdc45
7 changed files with 106 additions and 4 deletions

View File

@ -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<TrackList> 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"));

View File

@ -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<wxSizer> 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 );
}

View File

@ -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,

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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.