diff --git a/src/Project.cpp b/src/Project.cpp index 4296931d8..fce477137 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -882,7 +882,8 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, // or else the device toolbar doesn't make initial widths of the choice // controls correct. mTopPanel = safenew wxPanelWrapper { - this, wxID_ANY, wxDefaultPosition, { this->GetSize().GetWidth(), -1 } + this, wxID_ANY, wxDefaultPosition, + wxSize{ this->GetSize().GetWidth(), -1 } }; mTopPanel->SetAutoLayout(true); diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index 4a76638fb..4898dd0ec 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -379,7 +379,7 @@ void PrefsDialog::OnTreeKeyDown(wxTreeEvent & event) void PrefsDialog::OnCharHook(wxKeyEvent &event) { // Common behavior, let's define it in just one place - wxPanelWrapper::DoCharHook(event); + wxTabTraversalWrapperCharHook(event); } void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event)) diff --git a/src/widgets/wxPanelWrapper.cpp b/src/widgets/wxPanelWrapper.cpp index 95970fa73..134b7ea13 100644 --- a/src/widgets/wxPanelWrapper.cpp +++ b/src/widgets/wxPanelWrapper.cpp @@ -9,16 +9,7 @@ #include "../Audacity.h" #include "wxPanelWrapper.h" -IMPLEMENT_CLASS(wxPanelWrapper, wxPanel) - -wxPanelWrapper::wxPanelWrapper(wxWindow * parent, wxWindowID id, - const wxPoint & pos, - const wxSize & size, - long style) -: wxPanel(parent, id, pos, size, style) -{} - -void wxPanelWrapper::DoCharHook(wxKeyEvent &event) +void wxTabTraversalWrapperCharHook(wxKeyEvent &event) { #ifdef __WXMAC__ // Compensate for the regressions in TAB key navigation @@ -35,12 +26,3 @@ void wxPanelWrapper::DoCharHook(wxKeyEvent &event) event.Skip(); } - -void wxPanelWrapper::OnCharHook(wxKeyEvent &event) -{ - DoCharHook(event); -} - -BEGIN_EVENT_TABLE(wxPanelWrapper, wxPanel) - EVT_CHAR_HOOK(wxPanelWrapper::OnCharHook) -END_EVENT_TABLE() diff --git a/src/widgets/wxPanelWrapper.h b/src/widgets/wxPanelWrapper.h index 92e6b0757..106ea7384 100644 --- a/src/widgets/wxPanelWrapper.h +++ b/src/widgets/wxPanelWrapper.h @@ -9,26 +9,30 @@ #ifndef __AUDACITY_WXPANEL_WRAPPER__ #define __AUDACITY_WXPANEL_WRAPPER__ +#include #include -class AUDACITY_DLL_API wxPanelWrapper /* not final */ : public wxPanel { +void wxTabTraversalWrapperCharHook(wxKeyEvent &event); + +template +class wxTabTraversalWrapper : public Base +{ public: - wxPanelWrapper() : wxPanel {} {} + template + wxTabTraversalWrapper(Args&&... args) + : Base( std::forward(args)... ) + { + this->Bind(wxEVT_CHAR_HOOK, wxTabTraversalWrapperCharHook); + } - wxPanelWrapper(wxWindow * parent, wxWindowID id = wxID_ANY, - const wxPoint & pos = wxDefaultPosition, - const wxSize & size = wxDefaultSize, - // default as for wxPanel: - long style = wxTAB_TRAVERSAL | wxNO_BORDER); - - static void DoCharHook(wxKeyEvent &event); - -private: - void OnCharHook(wxKeyEvent &event); - - DECLARE_DYNAMIC_CLASS(wxPanelWrapper); - - DECLARE_EVENT_TABLE() + ~wxTabTraversalWrapper() + { + this->Unbind(wxEVT_CHAR_HOOK, wxTabTraversalWrapperCharHook); + } }; +class wxPanel; +using wxPanelWrapper = wxTabTraversalWrapper; + + #endif