From e47f27b1060487312ab9f70fa296123c47ccbad7 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Thu, 1 Apr 2021 20:01:39 -0500 Subject: [PATCH] Prevent keyboard navigation from being blocked on Mac Readonly or non-editable text controls block keyboard navigation on the Mac, so make them normal text controls, but block any edits. --- src/prefs/DirectoriesPrefs.cpp | 7 +++-- src/prefs/LibraryPrefs.cpp | 50 +++++++++------------------------ src/prefs/LibraryPrefs.h | 5 ++-- src/widgets/wxTextCtrlWrapper.h | 27 ++++++++++++++++++ 4 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/prefs/DirectoriesPrefs.cpp b/src/prefs/DirectoriesPrefs.cpp index a03777da3..a6d03f8ed 100644 --- a/src/prefs/DirectoriesPrefs.cpp +++ b/src/prefs/DirectoriesPrefs.cpp @@ -36,6 +36,7 @@ #include "../ShuttleGui.h" #include "../TempDirectory.h" #include "../widgets/AudacityMessageBox.h" +#include "../widgets/wxTextCtrlWrapper.h" using namespace FileNames; using namespace TempDirectory; @@ -245,9 +246,9 @@ void DirectoriesPrefs::PopulateOrExchange(ShuttleGui &S) S.Id(TempButtonID).AddButton(XXO("Brow&se...")); S.AddPrompt(XXO("&Free Space:")); - mFreeSpace = S.Style(wxTE_READONLY).AddTextBox({}, wxT(""), 30); - if( mFreeSpace ) - mFreeSpace->SetName(XO("Free Space").Translation()); + mFreeSpace = S.AddTextBox({}, wxT(""), 30); + mFreeSpace->SetName(XO("Free Space").Translation()); + ((wxTextCtrlWrapper *) mFreeSpace)->SetReadOnly(); } S.EndMultiColumn(); } diff --git a/src/prefs/LibraryPrefs.cpp b/src/prefs/LibraryPrefs.cpp index f8f1a197d..dbe230625 100644 --- a/src/prefs/LibraryPrefs.cpp +++ b/src/prefs/LibraryPrefs.cpp @@ -29,6 +29,7 @@ MP3 and FFmpeg encoding libraries. #include "../export/ExportMP3.h" #include "../widgets/HelpSystem.h" #include "../widgets/AudacityMessageBox.h" +#include "../widgets/wxTextCtrlWrapper.h" //////////////////////////////////////////////////////////////////////////////// @@ -101,32 +102,9 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S) { S.StartTwoColumn(); { - S.AddVariableText(XO("MP3 Library Version:"), - true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); - // Change this text later: - mMP3Version = S.AddVariableText(Verbatim("9.99"), - true, wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); -// Old buttons, not needed now that the lib is built-in. -#ifndef MP3_EXPORT_BUILT_IN - - S.AddVariableText(XO("LAME MP3 Library:"), - true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); - S.Id(ID_MP3_FIND_BUTTON) -#ifdef DISABLE_DYNAMIC_LOADING_LAME - .Disable() -#endif - .AddButton(XXO("&Locate..."), - wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); - S.AddVariableText(XO("LAME MP3 Library:"), - true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); - S.Id(ID_MP3_DOWN_BUTTON) -#ifdef DISABLE_DYNAMIC_LOADING_LAME - .Disable() -#endif - .AddButton(XXO("&Download"), - wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); - -#endif + mMP3Version = S + .AddTextBox(XO("MP3 Library Version:"), "", 50); + ((wxTextCtrlWrapper *) mMP3Version)->SetReadOnly(); } S.EndTwoColumn(); } @@ -136,17 +114,17 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S) { S.StartTwoColumn(); { - S.AddVariableText(XO("FFmpeg Library Version:"), - true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); + auto version = #if defined(USE_FFMPEG) - mFFmpegVersion = S.AddVariableText( - XO("No compatible FFmpeg library was found"), - true, wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); + XO("No compatible FFmpeg library was found"); #else - mFFmpegVersion = S.AddVariableText( - XO("FFmpeg support is not compiled in"), - true, wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); + XO("FFmpeg support is not compiled in"); #endif + + mFFmpegVersion = S + .AddTextBox(XO("FFmpeg Library Version:"), version.Translation(), 50); + ((wxTextCtrlWrapper *) mFFmpegVersion)->SetReadOnly(); + S.AddVariableText(XO("FFmpeg Library:"), true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); S.Id(ID_FFMPEG_FIND_BUTTON); @@ -177,7 +155,7 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S) /// of the MP3 Library version. void LibraryPrefs::SetMP3VersionText(bool prompt) { - mMP3Version->SetLabel(GetMP3Version(this, prompt).Translation()); + mMP3Version->SetValue(GetMP3Version(this, prompt).Translation()); mMP3Version->SetName(mMP3Version->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs) } @@ -197,7 +175,7 @@ void LibraryPrefs::OnMP3DownButton(wxCommandEvent & WXUNUSED(event)) void LibraryPrefs::SetFFmpegVersionText() { - mFFmpegVersion->SetLabel(GetFFmpegVersion().Translation()); + mFFmpegVersion->SetValue(GetFFmpegVersion().Translation()); mFFmpegVersion->SetName(mFFmpegVersion->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs) } diff --git a/src/prefs/LibraryPrefs.h b/src/prefs/LibraryPrefs.h index 886a3afef..fdeeb3c8c 100644 --- a/src/prefs/LibraryPrefs.h +++ b/src/prefs/LibraryPrefs.h @@ -18,6 +18,7 @@ #include "PrefsPanel.h" class wxStaticText; +class wxTextCtrl; class ShuttleGui; #define LIBRARY_PREFS_PLUGIN_SYMBOL ComponentInterfaceSymbol{ XO("Library") } @@ -44,8 +45,8 @@ class LibraryPrefs final : public PrefsPanel void OnFFmpegFindButton(wxCommandEvent & e); void OnFFmpegDownButton(wxCommandEvent & e); - wxStaticText *mMP3Version; - wxStaticText *mFFmpegVersion; + wxTextCtrl *mMP3Version; + wxTextCtrl *mFFmpegVersion; DECLARE_EVENT_TABLE() }; diff --git a/src/widgets/wxTextCtrlWrapper.h b/src/widgets/wxTextCtrlWrapper.h index 17488d48e..d651f44e3 100644 --- a/src/widgets/wxTextCtrlWrapper.h +++ b/src/widgets/wxTextCtrlWrapper.h @@ -31,6 +31,20 @@ public: const wxString &name = wxTextCtrlNameStr) : wxTextCtrl(parent, id, value, pos, size, style, validator, name) { + mReadOnly = false; + + Bind(wxEVT_CHAR, [&](wxKeyEvent &event) + { + auto keyCode = event.GetUnicodeKey(); + if (!mReadOnly || keyCode < WXK_SPACE || keyCode == WXK_DELETE) + { + event.Skip(); + } + else + { + event.Skip(false); + } + }); }; ~wxTextCtrlWrapper() @@ -41,6 +55,19 @@ public: { return true; } + + bool IsReadOnly() + { + return mReadOnly; + } + + void SetReadOnly(bool readonly = true) + { + mReadOnly = readonly; + } + +private: + bool mReadOnly; }; #endif // __AUDACITY_WXTEXTCTRLWRAPPER__