diff --git a/include/audacity/EffectInterface.h b/include/audacity/EffectInterface.h index b8765019b..8ada2661e 100644 --- a/include/audacity/EffectInterface.h +++ b/include/audacity/EffectInterface.h @@ -149,9 +149,6 @@ class EffectUIHostInterface { public: virtual ~EffectUIHostInterface() {}; - -// virtual wxScrolledWindow *GetScrollableClientArea(); -// virtual wxScrolledWindow *GetStaticClientArea(); }; class EffectUIClientInterface diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index f674e87d9..a932dbb8d 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -1905,6 +1905,52 @@ void EffectDialog::OnPreview(wxCommandEvent & WXUNUSED(event)) return; } +/////////////////////////////////////////////////////////////////////////////// +// +// EffectPanel +// +/////////////////////////////////////////////////////////////////////////////// + +class EffectPanel : public wxScrolledWindow +{ +public: + EffectPanel(wxWindow *parent) + : wxScrolledWindow(parent, + wxID_ANY, + wxDefaultPosition, + wxDefaultSize, + wxVSCROLL | wxTAB_TRAVERSAL) + { + } + + virtual ~EffectPanel() + { + } + + // ============================================================================ + // wxWindow implementation + // ============================================================================ + + virtual bool AcceptsFocus() const + { + // Only accept focus if we're not a GUI host. + // + // This assumes that any effect will have more than one control in its + // interface unless it is a GUI interface. It's a fairly safe assumption. +#if defined(__WXMAC__) + return GetChildren().GetCount() > 2; +#else + return GetChildren().GetCount() > 1; +#endif + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// EffectUIHost +// +/////////////////////////////////////////////////////////////////////////////// + enum { kSaveAsID = 30001, @@ -1919,7 +1965,6 @@ enum }; BEGIN_EVENT_TABLE(EffectUIHost, wxDialog) -// EVT_WINDOW_DESTROY(EffectUIHost::OnDestroy) EVT_CLOSE(EffectUIHost::OnClose) EVT_BUTTON(wxID_OK, EffectUIHost::OnOk) EVT_BUTTON(wxID_CANCEL, EffectUIHost::OnCancel) @@ -1958,15 +2003,15 @@ EffectUIHost::~EffectUIHost() } } +// ============================================================================ +// EffectUIHost implementation +// ============================================================================ + bool EffectUIHost::Initialize() { wxBoxSizer *vs = new wxBoxSizer(wxVERTICAL); - wxScrolledWindow *w = new wxScrolledWindow(this, - wxID_ANY, - wxDefaultPosition, - wxDefaultSize, - wxVSCROLL | wxTAB_TRAVERSAL); + EffectPanel *w = new EffectPanel(this); // Try to give the window a sensible default/minimum size w->SetMinSize(wxSize(wxMax(600, mParent->GetSize().GetWidth() * 2/3), @@ -1989,6 +2034,12 @@ bool EffectUIHost::Initialize() Fit(); Center(); +#if defined(__WXMAC__) + (w->GetChildren().GetCount() > 2 ? w : FindWindowById(wxID_OK))->SetFocus(); +#else + (w->GetChildren().GetCount() > 1 ? w : FindWindowById(wxID_OK))->SetFocus(); +#endif + LoadUserPresets(); mClient->LoadUserPreset(mHost->GetCurrentSettingsGroup()); @@ -1996,13 +2047,10 @@ bool EffectUIHost::Initialize() return true; } -void EffectUIHost::OnDestroy(wxWindowDestroyEvent & WXUNUSED(evt)) -{ - mClient->CloseUI(); -} - void EffectUIHost::OnClose(wxCloseEvent & WXUNUSED(evt)) { + Hide(); + mClient->CloseUI(); mClient = NULL; @@ -2037,6 +2085,8 @@ void EffectUIHost::OnOk(wxCommandEvent & WXUNUSED(evt)) return; } + Hide(); + Close(); return; @@ -2050,6 +2100,8 @@ void EffectUIHost::OnCancel(wxCommandEvent & WXUNUSED(evt)) return; } + Hide(); + Close(); return; diff --git a/src/effects/Effect.h b/src/effects/Effect.h index 3e833b2d9..b1aaf4895 100644 --- a/src/effects/Effect.h +++ b/src/effects/Effect.h @@ -485,7 +485,6 @@ public: bool Initialize(); private: - void OnDestroy(wxWindowDestroyEvent & evt); void OnClose(wxCloseEvent & evt); void OnOk(wxCommandEvent & evt); void OnCancel(wxCommandEvent & evt); diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp index ec71c6190..6f9d5e842 100644 --- a/src/effects/VST/VSTEffect.cpp +++ b/src/effects/VST/VSTEffect.cpp @@ -819,11 +819,6 @@ void VSTEffectEventHelper::OnSlider(wxCommandEvent & evt) mEffect->OnSlider(evt); } -void VSTEffectEventHelper::ControlSetFocus(wxFocusEvent & evt) -{ - mEffect->ControlSetFocus(evt); -} - void VSTEffectEventHelper::OnSizeWindow(wxCommandEvent & evt) { mEffect->OnSizeWindow(evt); @@ -2070,7 +2065,6 @@ bool VSTEffect::PopulateUI(wxWindow *parent) #endif #endif - // Determine if the VST editor is supposed to be used or not mHost->GetSharedConfig(wxT("Settings"), wxT("UseGUI"), @@ -3114,6 +3108,7 @@ void VSTEffect::BuildFancy() #elif defined(__WXMSW__) + // Use a panel to host the plugins GUI wxPanel *w = new wxPanel(mParent, wxID_ANY); mHwnd = w->GetHWND(); callDispatcher(effEditOpen, 0, 0, mHwnd, 0.0); @@ -3121,9 +3116,9 @@ void VSTEffect::BuildFancy() #else // Use a panel to host the plugins GUI - wxPanel *w = new wxPanel(mParent); + wxPanel *w = new wxPanel(mParent, wxID_ANY); - // Make sure is has a window + // Make sure the parent has a window if (!GTK_WIDGET(w->m_wxwindow)->window) { gtk_widget_realize(GTK_WIDGET(w->m_wxwindow)); @@ -3218,7 +3213,6 @@ void VSTEffect::BuildPlain() gridSizer->Add(mDuration, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); - ConnectFocus(mDuration); } // Find the longest parameter name. @@ -3362,48 +3356,6 @@ void VSTEffect::OnSlider(wxCommandEvent & evt) RefreshParameters(i); } -void VSTEffect::ConnectFocus(wxControl *c) -{ - c->GetEventHandler()->Connect(wxEVT_SET_FOCUS, - wxFocusEventHandler(VSTEffectEventHelper::ControlSetFocus)); -} - -void VSTEffect::DisconnectFocus(wxControl *c) -{ - c->GetEventHandler()->Disconnect(wxEVT_SET_FOCUS, - wxFocusEventHandler(VSTEffectEventHelper::ControlSetFocus)); -} - -void VSTEffect::ControlSetFocus(wxFocusEvent & evt) -{ - wxControl *c = (wxControl *) evt.GetEventObject(); - wxScrolledWindow *p = (wxScrolledWindow *) c->GetParent(); - wxRect r = c->GetRect(); - wxRect rv = p->GetRect(); - rv.y = 0; - - evt.Skip(); - - int y; - int yppu; - p->GetScrollPixelsPerUnit(NULL, &yppu); - - if (r.y >= rv.y && r.GetBottom() <= rv.GetBottom()) { - return; - } - - if (r.y < rv.y) { - p->CalcUnscrolledPosition(0, r.y, NULL, &r.y); - y = r.y / yppu; - } - else { - p->CalcUnscrolledPosition(0, r.y, NULL, &r.y); - y = (r.GetBottom() - rv.GetBottom() + yppu) / yppu; - } - - p->Scroll(-1, y); -}; - bool VSTEffect::LoadFXB(const wxFileName & fn) { bool ret = false; diff --git a/src/effects/VST/VSTEffect.h b/src/effects/VST/VSTEffect.h index ebd4c4482..706acbdea 100644 --- a/src/effects/VST/VSTEffect.h +++ b/src/effects/VST/VSTEffect.h @@ -178,10 +178,6 @@ private: // UI void OnSlider(wxCommandEvent & evt); - void ConnectFocus(wxControl *c); - void DisconnectFocus(wxControl *c); - void ControlSetFocus(wxFocusEvent & evt); - void OnSizeWindow(wxCommandEvent & evt); void OnUpdateDisplay(wxCommandEvent & evt); diff --git a/src/effects/ladspa/LadspaEffect.cpp b/src/effects/ladspa/LadspaEffect.cpp index 66e385add..c37f60ddd 100644 --- a/src/effects/ladspa/LadspaEffect.cpp +++ b/src/effects/ladspa/LadspaEffect.cpp @@ -415,11 +415,6 @@ void LadspaEffectEventHelper::OnTextCtrl(wxCommandEvent & evt) mEffect->OnTextCtrl(evt); } -void LadspaEffectEventHelper::ControlSetFocus(wxFocusEvent & evt) -{ - mEffect->ControlSetFocus(evt); -} - /////////////////////////////////////////////////////////////////////////////// // // LadspaEffect @@ -1054,7 +1049,6 @@ bool LadspaEffect::PopulateUI(wxWindow *parent) gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); - ConnectFocus(mDuration); } for (unsigned long p = 0; p < mData->PortCount; p++) @@ -1078,7 +1072,6 @@ bool LadspaEffect::PopulateUI(wxWindow *parent) mToggles[p]->SetName(labelText); mToggles[p]->SetValue(mInputControls[p] > 0); gridSizer->Add(mToggles[p], 0, wxALL, 5); - ConnectFocus(mToggles[p]); gridSizer->Add(1, 1, 0); gridSizer->Add(1, 1, 0); @@ -1118,7 +1111,6 @@ bool LadspaEffect::PopulateUI(wxWindow *parent) mFields[p] = new wxTextCtrl(mParent, ID_TEXTS + p); mFields[p]->SetName(labelText); gridSizer->Add(mFields[p], 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); - ConnectFocus(mFields[p]); wxString str; if (haslo) @@ -1145,7 +1137,6 @@ bool LadspaEffect::PopulateUI(wxWindow *parent) wxSize(200, -1)); mSliders[p]->SetName(labelText); gridSizer->Add(mSliders[p], 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5); - ConnectFocus(mSliders[p]); if (hashi) { @@ -1240,7 +1231,6 @@ bool LadspaEffect::PopulateUI(wxWindow *parent) wxTE_READONLY); mFields[p]->SetName(labelText); gridSizer->Add(mFields[p], 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); - ConnectFocus(mFields[p]); } paramSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5); @@ -1600,45 +1590,3 @@ void LadspaEffect::RefreshControls(bool outputOnly) mFields[p]->SetValue(fieldText); } } - -void LadspaEffect::ConnectFocus(wxControl *c) -{ - c->GetEventHandler()->Connect(wxEVT_SET_FOCUS, - wxFocusEventHandler(LadspaEffectEventHelper::ControlSetFocus)); -} - -void LadspaEffect::DisconnectFocus(wxControl *c) -{ - c->GetEventHandler()->Disconnect(wxEVT_SET_FOCUS, - wxFocusEventHandler(LadspaEffectEventHelper::ControlSetFocus)); -} - -void LadspaEffect::ControlSetFocus(wxFocusEvent & evt) -{ - wxControl *c = (wxControl *) evt.GetEventObject(); - wxScrolledWindow *p = (wxScrolledWindow *) c->GetParent(); - wxRect r = c->GetRect(); - wxRect rv = p->GetRect(); - rv.y = 0; - - evt.Skip(); - - int y; - int yppu; - p->GetScrollPixelsPerUnit(NULL, &yppu); - - if (r.y >= rv.y && r.GetBottom() <= rv.GetBottom()) { - return; - } - - if (r.y < rv.y) { - p->CalcUnscrolledPosition(0, r.y, NULL, &r.y); - y = r.y / yppu; - } - else { - p->CalcUnscrolledPosition(0, r.y, NULL, &r.y); - y = (r.GetBottom() - rv.GetBottom() + yppu) / yppu; - } - - p->Scroll(-1, y); -}; diff --git a/src/effects/ladspa/LadspaEffect.h b/src/effects/ladspa/LadspaEffect.h index a3098e30e..c710a930e 100644 --- a/src/effects/ladspa/LadspaEffect.h +++ b/src/effects/ladspa/LadspaEffect.h @@ -134,9 +134,6 @@ private: void OnSlider(wxCommandEvent & evt); void OnTextCtrl(wxCommandEvent & evt); void RefreshControls(bool outputOnly = false); - void ConnectFocus(wxControl *c); - void DisconnectFocus(wxControl *c); - void ControlSetFocus(wxFocusEvent & evt); private: