Rewrite more Connect() with Bind(), which were type incorrect...

... though harmlessly so.  They called to nonstatic member functions of classes
with improper this pointers; though the functions did not use this.

Bind events to nonmember funtions instead.  Sometimes just to empty lambdas to
consume the event and ignore it, blocking other handlers.
This commit is contained in:
Paul Licameli 2018-02-12 17:27:51 -05:00
parent 2f3604bdea
commit e6e8e3251c
9 changed files with 54 additions and 57 deletions

View File

@ -95,11 +95,15 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
{
// FIXME: Textbox labels have inconsistent capitalization
mTotal = S.Id(ID_TOTAL).AddTextBox(_("&Total space used"), wxT("0"), 10);
mTotal->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(HistoryWindow::OnChar));
mTotal->Bind(wxEVT_KEY_DOWN,
// ignore it
[](wxEvent&){});
S.AddVariableText( {} )->Hide();
mAvail = S.Id(ID_AVAIL).AddTextBox(_("&Undo Levels Available"), wxT("0"), 10);
mAvail->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(HistoryWindow::OnChar));
mAvail->Bind(wxEVT_KEY_DOWN,
// ignore it
[](wxEvent&){});
S.AddVariableText( {} )->Hide();
S.AddPrompt(_("&Levels To Discard"));
@ -117,7 +121,9 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
mDiscard = S.Id(ID_DISCARD).AddButton(_("&Discard"));
mClipboard = S.AddTextBox(_("Clipboard space used"), wxT("0"), 10);
mClipboard->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(HistoryWindow::OnChar));
mClipboard->Bind(wxEVT_KEY_DOWN,
// ignore it
[](wxEvent&){});
S.Id(ID_DISCARD_CLIPBOARD).AddButton(_("Discard"));
}
S.EndMultiColumn();
@ -294,9 +300,3 @@ void HistoryWindow::OnSize(wxSizeEvent & WXUNUSED(event))
if (mList->GetItemCount() > 0)
mList->EnsureVisible(mSelected);
}
void HistoryWindow::OnChar(wxKeyEvent &event)
{
event.Skip(false);
return;
}

View File

@ -38,7 +38,6 @@ class HistoryWindow final : public wxDialogWrapper {
void OnSize(wxSizeEvent & event);
void OnCloseWindow(wxCloseEvent & WXUNUSED(event));
void OnChar(wxKeyEvent & event);
void OnItemSelected(wxListEvent & event);
void OnDiscard(wxCommandEvent & event);
void OnDiscardClipboard(wxCommandEvent & event);

View File

@ -152,6 +152,20 @@ BEGIN_EVENT_TABLE(ContrastDialog,wxDialogWrapper)
EVT_BUTTON(wxID_CANCEL, ContrastDialog::OnClose)
END_EVENT_TABLE()
static void OnChar(wxKeyEvent & event)
{
// Is this still required?
if (event.GetKeyCode() == WXK_TAB) {
// pass to next handler
event.Skip();
return;
}
// ignore any other key
event.Skip(false);
return;
}
/* i18n-hint: WCAG2 is the 'Web Content Accessibility Guidelines (WCAG) 2.0', see http://www.w3.org/TR/WCAG20/ */
ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
const wxString & title,
@ -235,7 +249,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
m_pButton_UseCurrentF = S.Id(ID_BUTTON_USECURRENTF).AddButton(_("&Measure selection"));
mForegroundRMSText=S.Id(ID_FOREGROUNDDB_TEXT).AddTextBox( {}, wxT(""), 17);
mForegroundRMSText->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(ContrastDialog::OnChar));
mForegroundRMSText->Bind(wxEVT_KEY_DOWN, OnChar);
//Background
S.AddFixedText(_("&Background:"));
@ -267,7 +281,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
m_pButton_UseCurrentB = S.Id(ID_BUTTON_USECURRENTB).AddButton(_("Mea&sure selection"));
mBackgroundRMSText = S.Id(ID_BACKGROUNDDB_TEXT).AddTextBox( {}, wxT(""), 17);
mBackgroundRMSText->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(ContrastDialog::OnChar));
mBackgroundRMSText->Bind(wxEVT_KEY_DOWN, OnChar);
}
S.EndMultiColumn();
}
@ -280,11 +294,11 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
{
S.AddFixedText(_("Co&ntrast Result:"));
mPassFailText = S.Id(ID_RESULTS_TEXT).AddTextBox( {}, wxT(""), 50);
mPassFailText->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(ContrastDialog::OnChar));
mPassFailText->Bind(wxEVT_KEY_DOWN, OnChar);
m_pButton_Reset = S.Id(ID_BUTTON_RESET).AddButton(_("R&eset"));
S.AddFixedText(_("&Difference:"));
mDiffText = S.Id(ID_RESULTSDB_TEXT).AddTextBox( {}, wxT(""), 50);
mDiffText->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(ContrastDialog::OnChar));
mDiffText->Bind(wxEVT_KEY_DOWN, OnChar);
m_pButton_Export = S.Id(ID_BUTTON_EXPORT).AddButton(_("E&xport..."));
}
S.EndMultiColumn();
@ -588,15 +602,3 @@ void ContrastDialog::OnReset(wxCommandEvent & /*event*/)
mPassFailText->ChangeValue(wxT(""));
mDiffText->ChangeValue(wxT(""));
}
void ContrastDialog::OnChar(wxKeyEvent & event)
{
// Is this still required?
if (event.GetKeyCode() == WXK_TAB) {
event.Skip();
return;
}
event.Skip(false);
return;
}

View File

@ -62,7 +62,6 @@ private:
void results();
void OnReset(wxCommandEvent & event);
void OnClose(wxCommandEvent & event);
void OnChar(wxKeyEvent &event);
wxTextCtrl *mForegroundRMSText;
wxTextCtrl *mBackgroundRMSText;

View File

@ -717,7 +717,9 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
mSliders[i] = safenew wxSlider(mGraphicPanel, ID_Slider + i, 0, -20, +20,
wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE);
mSliders[i]->Connect(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(EffectEqualization::OnErase));
mSliders[i]->Bind(wxEVT_ERASE_BACKGROUND,
// ignore it
[](wxEvent&){});
#if wxUSE_ACCESSIBILITY
wxString name;
if( kThirdOct[i] < 1000.)
@ -2592,11 +2594,6 @@ void EffectEqualization::OnSize(wxSizeEvent & event)
event.Skip();
}
void EffectEqualization::OnErase(wxEraseEvent & WXUNUSED(event))
{
// Ignore it
}
void EffectEqualization::OnSlider(wxCommandEvent & event)
{
wxSlider *s = (wxSlider *)event.GetEventObject();

View File

@ -172,7 +172,6 @@ private:
double splint(double x[], double y[], size_t n, double y2[], double xr);
void OnSize( wxSizeEvent & event );
void OnErase( wxEraseEvent & event );
void OnSlider( wxCommandEvent & event );
void OnInterp( wxCommandEvent & event );
void OnSliderM( wxCommandEvent & event );

View File

@ -2755,6 +2755,24 @@ void VSTEffect::RemoveHandler()
{
}
static void OnSize(wxSizeEvent & evt)
{
evt.Skip();
// Once the parent dialog reaches its final size as indicated by
// a non-default minimum size, we set the maximum size to match.
// This is a bit of a hack to prevent VSTs GUI windows from resizing
// there's no real reason to allow it. But, there should be a better
// way of handling it.
wxWindow *w = (wxWindow *) evt.GetEventObject();
wxSize sz = w->GetMinSize();
if (sz != wxDefaultSize)
{
w->SetMaxSize(sz);
}
}
void VSTEffect::BuildFancy()
{
// Turn the power on...some effects need this when the editor is open
@ -2782,7 +2800,7 @@ void VSTEffect::BuildFancy()
NeedEditIdle(true);
mDialog->Connect(wxEVT_SIZE, wxSizeEventHandler(VSTEffect::OnSize));
mDialog->Bind(wxEVT_SIZE, OnSize);
#ifdef __WXMAC__
#ifdef __WX_EVTLOOP_BUSY_WAITING__
@ -2968,24 +2986,6 @@ void VSTEffect::RefreshParameters(int skip)
}
}
void VSTEffect::OnSize(wxSizeEvent & evt)
{
evt.Skip();
// Once the parent dialog reaches it's final size as indicated by
// a non-default minimum size, we set the maximum size to match.
// This is a bit of a hack to prevent VSTs GUI windows from resizing
// there's no real reason to allow it. But, there should be a better
// way of handling it.
wxWindow *w = (wxWindow *) evt.GetEventObject();
wxSize sz = w->GetMinSize();
if (sz != wxDefaultSize)
{
w->SetMaxSize(sz);
}
}
void VSTEffect::OnSizeWindow(wxCommandEvent & evt)
{
if (!mControl)

View File

@ -195,7 +195,6 @@ private:
// UI
void OnSlider(wxCommandEvent & evt);
void OnSize(wxSizeEvent & evt);
void OnSizeWindow(wxCommandEvent & evt);
void OnUpdateDisplay(wxCommandEvent & evt);

View File

@ -167,13 +167,15 @@ public:
public:
void ConnectEvent(wxWindow *w)
{
w->GetEventHandler()->Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler(FocusHandler::OnKillFocus));
// Need to use a named function pointer, not a lambda, so that we
// can unbind the same later
w->GetEventHandler()->Bind(wxEVT_KILL_FOCUS, OnKillFocus);
};
void DisconnectEvent(wxWindow *w)
{
w->GetEventHandler()->Disconnect(wxEVT_KILL_FOCUS, wxFocusEventHandler(FocusHandler::OnKillFocus));
w->GetEventHandler()->Unbind(wxEVT_KILL_FOCUS, OnKillFocus);
};
void OnKillFocus(wxFocusEvent & WXUNUSED(event))
static void OnKillFocus(wxFocusEvent & WXUNUSED(event))
{
return;
};