1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-19 17:40:15 +02:00

Rewrite many calls to Connect() with Bind()...

... it's the more modern way, and does better type checking, without the
dubious casts of pointers-to-member-functions.
This commit is contained in:
Paul Licameli 2018-02-12 16:45:54 -05:00
parent bf5228267a
commit 2f3604bdea
12 changed files with 88 additions and 132 deletions

View File

@ -166,42 +166,28 @@ void AudacityLogger::Show(bool show)
frame->Layout();
// Hook into the frame events
frame->Connect(wxEVT_CLOSE_WINDOW,
frame->Bind(wxEVT_CLOSE_WINDOW,
wxCloseEventHandler(AudacityLogger::OnCloseWindow),
NULL,
this);
frame->Connect(LoggerID_Save,
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(AudacityLogger::OnSave),
NULL,
this);
frame->Connect(LoggerID_Clear,
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(AudacityLogger::OnClear),
NULL,
this);
frame->Connect(LoggerID_Close,
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(AudacityLogger::OnClose),
NULL,
this);
frame->Connect(LoggerID_Save,
wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(AudacityLogger::OnSave),
NULL,
this);
frame->Connect(LoggerID_Clear,
wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(AudacityLogger::OnClear),
NULL,
this);
frame->Connect(LoggerID_Close,
wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(AudacityLogger::OnClose),
NULL,
this);
frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
&AudacityLogger::OnSave,
this, LoggerID_Save);
frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
&AudacityLogger::OnClear,
this, LoggerID_Clear);
frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
&AudacityLogger::OnClose,
this, LoggerID_Close);
frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
&AudacityLogger::OnSave,
this, LoggerID_Save);
frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
&AudacityLogger::OnClear,
this, LoggerID_Clear);
frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
&AudacityLogger::OnClose,
this, LoggerID_Close);
mFrame = std::move( frame );

View File

@ -556,9 +556,8 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES );
mEffects = S.Id(ID_List).AddListControlReportMode();
mEffects->Connect(wxEVT_KEY_DOWN,
wxKeyEventHandler(PluginRegistrationDialog::OnListChar),
NULL,
mEffects->Bind(wxEVT_KEY_DOWN,
&PluginRegistrationDialog::OnListChar,
this);
#if wxUSE_ACCESSIBILITY
mEffects->SetAccessible(mAx = safenew CheckListAx(mEffects));

View File

@ -171,7 +171,7 @@ void VSTControl::CreateCarbon()
{
OSStatus result;
Connect(wxEVT_SIZE, wxSizeEventHandler(VSTControl::OnSize));
Bind(wxEVT_SIZE, &VSTControl::OnSize, this);
VstRect *rect;

View File

@ -186,13 +186,11 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S)
#endif
wxTE_PROCESS_ENTER);
mFilter->SetName(wxStripMenuCodes(mFilterLabel->GetLabel()));
mFilter->Connect(wxEVT_KEY_DOWN,
wxKeyEventHandler(KeyConfigPrefs::OnFilterKeyDown),
NULL,
mFilter->Bind(wxEVT_KEY_DOWN,
&KeyConfigPrefs::OnFilterKeyDown,
this);
mFilter->Connect(wxEVT_CHAR,
wxKeyEventHandler(KeyConfigPrefs::OnFilterChar),
NULL,
mFilter->Bind(wxEVT_CHAR,
&KeyConfigPrefs::OnFilterChar,
this);
}
S.AddWindow(mFilter, wxALIGN_NOT | wxALIGN_LEFT);
@ -228,17 +226,14 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S)
wxTE_PROCESS_ENTER);
mKey->SetName(_("Short cut"));
mKey->Connect(wxEVT_KEY_DOWN,
wxKeyEventHandler(KeyConfigPrefs::OnHotkeyKeyDown),
NULL,
mKey->Bind(wxEVT_KEY_DOWN,
&KeyConfigPrefs::OnHotkeyKeyDown,
this);
mKey->Connect(wxEVT_CHAR,
wxKeyEventHandler(KeyConfigPrefs::OnHotkeyChar),
NULL,
mKey->Bind(wxEVT_CHAR,
&KeyConfigPrefs::OnHotkeyChar,
this);
mKey->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(KeyConfigPrefs::OnHotkeyKillFocus),
NULL,
mKey->Bind(wxEVT_KILL_FOCUS,
&KeyConfigPrefs::OnHotkeyKillFocus,
this);
}
S.AddWindow(mKey);

View File

@ -125,37 +125,29 @@ void DeviceToolBar::Populate()
mHost->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(DeviceToolBar::OnFocus),
NULL,
mHost->Bind(wxEVT_SET_FOCUS,
&DeviceToolBar::OnFocus,
this);
mHost->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(DeviceToolBar::OnFocus),
NULL,
mHost->Bind(wxEVT_KILL_FOCUS,
&DeviceToolBar::OnFocus,
this);
mOutput->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(DeviceToolBar::OnFocus),
NULL,
mOutput->Bind(wxEVT_SET_FOCUS,
&DeviceToolBar::OnFocus,
this);
mOutput->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(DeviceToolBar::OnFocus),
NULL,
mOutput->Bind(wxEVT_KILL_FOCUS,
&DeviceToolBar::OnFocus,
this);
mInput->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(DeviceToolBar::OnFocus),
NULL,
mInput->Bind(wxEVT_SET_FOCUS,
&DeviceToolBar::OnFocus,
this);
mInput->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(DeviceToolBar::OnFocus),
NULL,
mInput->Bind(wxEVT_KILL_FOCUS,
&DeviceToolBar::OnFocus,
this);
mInputChannels->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(DeviceToolBar::OnFocus),
NULL,
mInputChannels->Bind(wxEVT_SET_FOCUS,
&DeviceToolBar::OnFocus,
this);
mInputChannels->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(DeviceToolBar::OnFocus),
NULL,
mInputChannels->Bind(wxEVT_KILL_FOCUS,
&DeviceToolBar::OnFocus,
this);
SetNames();

View File

@ -94,21 +94,17 @@ void MixerToolBar::Populate()
Add(mOutputSlider, 0, wxALIGN_CENTER);
// this bit taken from SelectionBar::Populate()
mInputSlider->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(MixerToolBar::OnFocus),
NULL,
mInputSlider->Bind(wxEVT_SET_FOCUS,
&MixerToolBar::OnFocus,
this);
mInputSlider->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(MixerToolBar::OnFocus),
NULL,
mInputSlider->Bind(wxEVT_KILL_FOCUS,
&MixerToolBar::OnFocus,
this);
mOutputSlider->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(MixerToolBar::OnFocus),
NULL,
mOutputSlider->Bind(wxEVT_SET_FOCUS,
&MixerToolBar::OnFocus,
this);
mOutputSlider->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(MixerToolBar::OnFocus),
NULL,
mOutputSlider->Bind(wxEVT_KILL_FOCUS,
&MixerToolBar::OnFocus,
this);
// Show or hide the input slider based on whether it works
mInputSlider->Enable(gAudioIO->InputMixerWorks());

View File

@ -323,13 +323,11 @@ void SelectionBar::Populate()
}
#endif
mRateText->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(SelectionBar::OnFocus),
NULL,
mRateText->Bind(wxEVT_SET_FOCUS,
&SelectionBar::OnFocus,
this);
mRateText->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(SelectionBar::OnFocus),
NULL,
mRateText->Bind(wxEVT_KILL_FOCUS,
&SelectionBar::OnFocus,
this);
#ifdef __WXGTK__
@ -361,13 +359,11 @@ void SelectionBar::Populate()
//mSnapTo->SetForegroundColour( clrText2 );
mSnapTo->SetSelection(mListener ? mListener->AS_GetSnapTo() : SNAP_OFF);
mSnapTo->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(SelectionBar::OnFocus),
NULL,
mSnapTo->Bind(wxEVT_SET_FOCUS,
&SelectionBar::OnFocus,
this);
mSnapTo->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(SelectionBar::OnFocus),
NULL,
mSnapTo->Bind(wxEVT_KILL_FOCUS,
&SelectionBar::OnFocus,
this);
AddVLine( mainSizer );

View File

@ -382,15 +382,13 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
};
// Hook the creation event...only needed on GTK, but doesn't hurt for all
mIndicator->Connect( wxEVT_CREATE,
wxWindowCreateEventHandler( ToolManager::OnIndicatorCreate ),
NULL,
mIndicator->Bind( wxEVT_CREATE,
&ToolManager::OnIndicatorCreate,
this );
// Hook the paint event...needed for all
mIndicator->Connect( wxEVT_PAINT,
wxPaintEventHandler( ToolManager::OnIndicatorPaint ),
NULL,
mIndicator->Bind( wxEVT_PAINT,
&ToolManager::OnIndicatorPaint,
this );
// It's a little shy
@ -398,17 +396,14 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
// Hook the parents mouse events...using the parent helps greatly
// under GTK
mParent->Connect( wxEVT_LEFT_UP,
wxMouseEventHandler( ToolManager::OnMouse ),
NULL,
mParent->Bind( wxEVT_LEFT_UP,
&ToolManager::OnMouse,
this );
mParent->Connect( wxEVT_MOTION,
wxMouseEventHandler( ToolManager::OnMouse ),
NULL,
mParent->Bind( wxEVT_MOTION,
&ToolManager::OnMouse,
this );
mParent->Connect( wxEVT_MOUSE_CAPTURE_LOST,
wxMouseCaptureLostEventHandler( ToolManager::OnCaptureLost ),
NULL,
mParent->Bind( wxEVT_MOUSE_CAPTURE_LOST,
&ToolManager::OnCaptureLost,
this );
// Create the top and bottom docks

View File

@ -200,13 +200,11 @@ void TranscriptionToolBar::Populate()
mPlaySpeedSlider->Set(mPlaySpeed / 100.0);
mPlaySpeedSlider->SetLabel(_("Playback Speed"));
Add( mPlaySpeedSlider, 0, wxALIGN_CENTER );
mPlaySpeedSlider->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(TranscriptionToolBar::OnFocus),
NULL,
mPlaySpeedSlider->Bind(wxEVT_SET_FOCUS,
&TranscriptionToolBar::OnFocus,
this);
mPlaySpeedSlider->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(TranscriptionToolBar::OnFocus),
NULL,
mPlaySpeedSlider->Bind(wxEVT_KILL_FOCUS,
&TranscriptionToolBar::OnFocus,
this);
#ifdef EXPERIMENTAL_VOICE_DETECTION

View File

@ -198,9 +198,9 @@ Scrubber::Scrubber(AudacityProject *project)
{
if (wxTheApp)
wxTheApp->Connect
wxTheApp->Bind
(wxEVT_ACTIVATE_APP,
wxActivateEventHandler(Scrubber::OnActivateOrDeactivateApp), NULL, this);
&Scrubber::OnActivateOrDeactivateApp, this);
mProject->PushEventHandler(&mForwarder);
}

View File

@ -21,9 +21,9 @@ PopupMenuTable::Menu::~Menu()
void PopupMenuTable::Menu::Extend(PopupMenuTable *pTable)
{
auto connect = [&]( const PopupMenuTable::Entry *pEntry ) {
this->pParent->Connect
(pEntry->id, wxEVT_COMMAND_MENU_SELECTED,
pEntry->func, NULL, pTable);
this->pParent->Bind
(wxEVT_COMMAND_MENU_SELECTED,
pEntry->func, pTable, pEntry->id);
};
for (const PopupMenuTable::Entry *pEntry = &*pTable->Get().begin();
@ -69,8 +69,8 @@ void PopupMenuTable::Menu::DisconnectTable(PopupMenuTable *pTable)
for (const PopupMenuTable::Entry *pEntry = &*pTable->Get().begin();
pEntry->IsValid(); ++pEntry) {
if ( pEntry->IsItem() )
pParent->Disconnect( pEntry->id, wxEVT_COMMAND_MENU_SELECTED,
pEntry->func, NULL, pTable );
pParent->Unbind( wxEVT_COMMAND_MENU_SELECTED,
pEntry->func, pTable, pEntry->id );
else if ( pEntry->IsSubMenu() )
// recur
DisconnectTable(pEntry->subTable);

View File

@ -36,11 +36,11 @@ struct PopupMenuTableEntry
Type type;
int id;
wxString caption;
wxObjectEventFunction func;
wxCommandEventFunction func;
PopupMenuTable *subTable;
PopupMenuTableEntry(Type type_, int id_, wxString caption_,
wxObjectEventFunction func_, PopupMenuTable *subTable_)
wxCommandEventFunction func_, PopupMenuTable *subTable_)
: type(type_)
, id(id_)
, caption(caption_)
@ -165,8 +165,7 @@ void HandlerClass::Populate() { \
type, \
id, \
string, \
(wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction) \
(&My::memFn), \
(wxCommandEventFunction) (&My::memFn), \
nullptr )
#define POPUP_MENU_ITEM(id, string, memFn) \