1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-16 16:47:41 +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(); frame->Layout();
// Hook into the frame events // Hook into the frame events
frame->Connect(wxEVT_CLOSE_WINDOW, frame->Bind(wxEVT_CLOSE_WINDOW,
wxCloseEventHandler(AudacityLogger::OnCloseWindow), wxCloseEventHandler(AudacityLogger::OnCloseWindow),
NULL,
this); this);
frame->Connect(LoggerID_Save, frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
wxEVT_COMMAND_MENU_SELECTED, &AudacityLogger::OnSave,
wxCommandEventHandler(AudacityLogger::OnSave), this, LoggerID_Save);
NULL, frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
this); &AudacityLogger::OnClear,
frame->Connect(LoggerID_Clear, this, LoggerID_Clear);
wxEVT_COMMAND_MENU_SELECTED, frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(AudacityLogger::OnClear), &AudacityLogger::OnClose,
NULL, this, LoggerID_Close);
this); frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
frame->Connect(LoggerID_Close, &AudacityLogger::OnSave,
wxEVT_COMMAND_MENU_SELECTED, this, LoggerID_Save);
wxCommandEventHandler(AudacityLogger::OnClose), frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
NULL, &AudacityLogger::OnClear,
this); this, LoggerID_Clear);
frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
frame->Connect(LoggerID_Save, &AudacityLogger::OnClose,
wxEVT_COMMAND_BUTTON_CLICKED, this, LoggerID_Close);
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);
mFrame = std::move( frame ); 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 ); S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES );
mEffects = S.Id(ID_List).AddListControlReportMode(); mEffects = S.Id(ID_List).AddListControlReportMode();
mEffects->Connect(wxEVT_KEY_DOWN, mEffects->Bind(wxEVT_KEY_DOWN,
wxKeyEventHandler(PluginRegistrationDialog::OnListChar), &PluginRegistrationDialog::OnListChar,
NULL,
this); this);
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY
mEffects->SetAccessible(mAx = safenew CheckListAx(mEffects)); mEffects->SetAccessible(mAx = safenew CheckListAx(mEffects));

View File

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

View File

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

View File

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

View File

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

View File

@ -323,13 +323,11 @@ void SelectionBar::Populate()
} }
#endif #endif
mRateText->Connect(wxEVT_SET_FOCUS, mRateText->Bind(wxEVT_SET_FOCUS,
wxFocusEventHandler(SelectionBar::OnFocus), &SelectionBar::OnFocus,
NULL,
this); this);
mRateText->Connect(wxEVT_KILL_FOCUS, mRateText->Bind(wxEVT_KILL_FOCUS,
wxFocusEventHandler(SelectionBar::OnFocus), &SelectionBar::OnFocus,
NULL,
this); this);
#ifdef __WXGTK__ #ifdef __WXGTK__
@ -361,13 +359,11 @@ void SelectionBar::Populate()
//mSnapTo->SetForegroundColour( clrText2 ); //mSnapTo->SetForegroundColour( clrText2 );
mSnapTo->SetSelection(mListener ? mListener->AS_GetSnapTo() : SNAP_OFF); mSnapTo->SetSelection(mListener ? mListener->AS_GetSnapTo() : SNAP_OFF);
mSnapTo->Connect(wxEVT_SET_FOCUS, mSnapTo->Bind(wxEVT_SET_FOCUS,
wxFocusEventHandler(SelectionBar::OnFocus), &SelectionBar::OnFocus,
NULL,
this); this);
mSnapTo->Connect(wxEVT_KILL_FOCUS, mSnapTo->Bind(wxEVT_KILL_FOCUS,
wxFocusEventHandler(SelectionBar::OnFocus), &SelectionBar::OnFocus,
NULL,
this); this);
AddVLine( mainSizer ); 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 // Hook the creation event...only needed on GTK, but doesn't hurt for all
mIndicator->Connect( wxEVT_CREATE, mIndicator->Bind( wxEVT_CREATE,
wxWindowCreateEventHandler( ToolManager::OnIndicatorCreate ), &ToolManager::OnIndicatorCreate,
NULL,
this ); this );
// Hook the paint event...needed for all // Hook the paint event...needed for all
mIndicator->Connect( wxEVT_PAINT, mIndicator->Bind( wxEVT_PAINT,
wxPaintEventHandler( ToolManager::OnIndicatorPaint ), &ToolManager::OnIndicatorPaint,
NULL,
this ); this );
// It's a little shy // 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 // Hook the parents mouse events...using the parent helps greatly
// under GTK // under GTK
mParent->Connect( wxEVT_LEFT_UP, mParent->Bind( wxEVT_LEFT_UP,
wxMouseEventHandler( ToolManager::OnMouse ), &ToolManager::OnMouse,
NULL,
this ); this );
mParent->Connect( wxEVT_MOTION, mParent->Bind( wxEVT_MOTION,
wxMouseEventHandler( ToolManager::OnMouse ), &ToolManager::OnMouse,
NULL,
this ); this );
mParent->Connect( wxEVT_MOUSE_CAPTURE_LOST, mParent->Bind( wxEVT_MOUSE_CAPTURE_LOST,
wxMouseCaptureLostEventHandler( ToolManager::OnCaptureLost ), &ToolManager::OnCaptureLost,
NULL,
this ); this );
// Create the top and bottom docks // Create the top and bottom docks

View File

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

View File

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

View File

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

View File

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