From c8d95e11174aede13a5c60be0e5c78effb097e56 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 30 Apr 2019 10:41:05 -0400 Subject: [PATCH] Bug2105: Enable TAB to sliders on Mac... ... I think this is a defect in wxWidgets, but one we can work around with a simple wrapper class around wxSlider overriding one method. To make the fix complete, change all occurrences of "safenew wxSlider" but the one in ShuttleGui.cpp covers most cases --- src/FreqWindow.cpp | 2 +- src/ShuttleGui.cpp | 11 ++++++++++- src/ShuttleGui.h | 14 ++++++++++++++ src/effects/Equalization.cpp | 2 +- src/effects/ScoreAlignDialog.cpp | 2 +- src/effects/VST/VSTEffect.cpp | 2 +- src/effects/ladspa/LadspaEffect.cpp | 2 +- src/effects/lv2/LV2Effect.cpp | 2 +- src/export/Export.cpp | 2 +- 9 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/FreqWindow.cpp b/src/FreqWindow.cpp index 749e3a48b..5e46d0d45 100644 --- a/src/FreqWindow.cpp +++ b/src/FreqWindow.cpp @@ -338,7 +338,7 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id, S.AddSpace(5); - mZoomSlider = safenew wxSlider(this, FreqZoomSliderID, 100, 1, 100, + mZoomSlider = safenew wxSliderWrapper(this, FreqZoomSliderID, 100, 1, 100, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL); S.Prop(1); S.AddWindow(mZoomSlider, wxALIGN_CENTER_HORIZONTAL); diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index 4de93f1d1..df8bcb533 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -515,6 +515,15 @@ wxRadioButton * ShuttleGuiBase::AddRadioButtonToGroup(const wxString &Prompt) return pRad; } +#ifdef __WXMAC__ +void wxSliderWrapper::SetFocus() +{ + // bypassing the override in wxCompositeWindow which ends up + // doing nothing + return wxSliderBase::SetFocus(); +} +#endif + wxSlider * ShuttleGuiBase::AddSlider(const wxString &Prompt, int pos, int Max, int Min) { HandleOptionality( Prompt ); @@ -523,7 +532,7 @@ wxSlider * ShuttleGuiBase::AddSlider(const wxString &Prompt, int pos, int Max, i if( mShuttleMode != eIsCreating ) return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxSlider); wxSlider * pSlider; - mpWind = pSlider = safenew wxSlider(GetParent(), miId, + mpWind = pSlider = safenew wxSliderWrapper(GetParent(), miId, pos, Min, Max, wxDefaultPosition, wxDefaultSize, Style( wxSL_HORIZONTAL | wxSL_LABELS | wxSL_AUTOTICKS ) diff --git a/src/ShuttleGui.h b/src/ShuttleGui.h index 1c899b50d..69e4291d5 100644 --- a/src/ShuttleGui.h +++ b/src/ShuttleGui.h @@ -17,6 +17,7 @@ #include "Audacity.h" #include +#include // to inherit #include "MemoryX.h" #include "WrappedType.h" @@ -76,6 +77,19 @@ class Shuttle; class WrappedType; +#ifdef __WXMAC__ +/// Fix a defect in TAB key navigation to sliders, known to happen in wxWidgets +/// 3.1.1 and maybe in earlier versions +class wxSliderWrapper : public wxSlider +{ +public: + using wxSlider::wxSlider; + void SetFocus() override; +}; +#else +using wxSliderWrapper = wxSlider; +#endif + class AUDACITY_DLL_API ShuttleGuiBase /* not final */ { public: diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index 319430dd9..1a6e51b44 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -737,7 +737,7 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S) for (int i = 0; (i < NUMBER_OF_BANDS) && (kThirdOct[i] <= mHiFreq); ++i) { - mSliders[i] = safenew wxSlider(mGraphicPanel, ID_Slider + i, 0, -20, +20, + mSliders[i] = safenew wxSliderWrapper(mGraphicPanel, ID_Slider + i, 0, -20, +20, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE); mSliders[i]->Bind(wxEVT_ERASE_BACKGROUND, diff --git a/src/effects/ScoreAlignDialog.cpp b/src/effects/ScoreAlignDialog.cpp index 6c7fa1efb..81672426a 100644 --- a/src/effects/ScoreAlignDialog.cpp +++ b/src/effects/ScoreAlignDialog.cpp @@ -83,7 +83,7 @@ ScoreAlignDialog::ScoreAlignDialog(ScoreAlignParams ¶ms) //wxButton *ok = safenew wxButton(this, wxID_OK, _("OK")); //wxButton *cancel = safenew wxButton(this, wxID_CANCEL, _("Cancel")); - //wxSlider *sl = safenew wxSlider(this, ID_SLIDER, 0, 0, 100, + //wxSlider *sl = safenew wxSliderWrapper(this, ID_SLIDER, 0, 0, 100, // wxDefaultPosition, wxSize(20, 124), // wxSL_HORIZONTAL); diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp index 1590bb119..fec818fda 100644 --- a/src/effects/VST/VSTEffect.cpp +++ b/src/effects/VST/VSTEffect.cpp @@ -2909,7 +2909,7 @@ void VSTEffect::BuildPlain() wxALIGN_RIGHT | wxST_NO_AUTORESIZE); gridSizer->Add(mNames[i], 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5); - mSliders[i] = safenew wxSlider(scroller, + mSliders[i] = safenew wxSliderWrapper(scroller, ID_Sliders + i, 0, 0, diff --git a/src/effects/ladspa/LadspaEffect.cpp b/src/effects/ladspa/LadspaEffect.cpp index 57e986aa3..78d8b1b0b 100644 --- a/src/effects/ladspa/LadspaEffect.cpp +++ b/src/effects/ladspa/LadspaEffect.cpp @@ -1313,7 +1313,7 @@ bool LadspaEffect::PopulateUI(wxWindow *parent) gridSizer->Add(1, 1, 0); } - mSliders[p] = safenew wxSlider(w, ID_Sliders + p, + mSliders[p] = safenew wxSliderWrapper(w, ID_Sliders + p, 0, 0, 1000, wxDefaultPosition, wxSize(200, -1)); diff --git a/src/effects/lv2/LV2Effect.cpp b/src/effects/lv2/LV2Effect.cpp index 2f2b703f4..69459ee3d 100644 --- a/src/effects/lv2/LV2Effect.cpp +++ b/src/effects/lv2/LV2Effect.cpp @@ -1714,7 +1714,7 @@ bool LV2Effect::BuildPlain() gridSizer->Add(1, 1, 0); } - mSliders[p] = safenew wxSlider(w, ID_Sliders + p, + mSliders[p] = safenew wxSliderWrapper(w, ID_Sliders + p, 0, 0, 1000, wxDefaultPosition, wxSize(150, -1)); diff --git a/src/export/Export.cpp b/src/export/Export.cpp index 4b6ba7919..425a081e8 100644 --- a/src/export/Export.cpp +++ b/src/export/Export.cpp @@ -1356,7 +1356,7 @@ ExportMixerDialog::ExportMixerDialog( const TrackList *tracks, bool selectedOnly mChannelsText = safenew wxStaticText(this, -1, label); horSizer->Add(mChannelsText, 0, wxALIGN_LEFT | wxALL, 5); - wxSlider *channels = safenew wxSlider(this, ID_SLIDER_CHANNEL, + wxSlider *channels = safenew wxSliderWrapper(this, ID_SLIDER_CHANNEL, mMixerSpec->GetNumChannels(), 1, mMixerSpec->GetMaxNumChannels(), wxDefaultPosition, wxSize(300, -1)); channels->SetName(label);