1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-23 15:50:05 +02:00

Move most of ProjectWindow initialization into nonmember function

This commit is contained in:
Paul Licameli 2019-06-26 10:10:11 -04:00
parent 52ff705b0d
commit d0c4677ab1
3 changed files with 53 additions and 38 deletions

View File

@ -363,7 +363,7 @@ AudacityProject *ProjectManager::New()
auto &projectHistory = ProjectHistory::Get( project ); auto &projectHistory = ProjectHistory::Get( project );
auto &projectManager = Get( project ); auto &projectManager = Get( project );
auto &window = ProjectWindow::Get( *p ); auto &window = ProjectWindow::Get( *p );
window.Init(); InitProjectWindow( window );
ProjectFileIO::Get( *p ).SetProjectTitle(); ProjectFileIO::Get( *p ).SetProjectTitle();

View File

@ -641,15 +641,37 @@ ProjectWindow::ProjectWindow(wxWindow * parent, wxWindowID id,
mPlaybackScroller = std::make_unique<PlaybackScroller>( &project ); mPlaybackScroller = std::make_unique<PlaybackScroller>( &project );
// PRL: Old comments below. No longer observing the ordering that it
// recommends. ProjectWindow::OnActivate puts the focus directly into
// the TrackPanel, which avoids the problems.
// LLL: When Audacity starts or becomes active after returning from
// another application, the first window that can accept focus
// will be given the focus even if we try to SetFocus(). By
// creating the scrollbars after the TrackPanel, we resolve
// several focus problems.
mHsbar = safenew ScrollBar(pPage, HSBarID, wxSB_HORIZONTAL);
mVsbar = safenew ScrollBar(pPage, VSBarID, wxSB_VERTICAL);
#if wxUSE_ACCESSIBILITY
// so that name can be set on a standard control
mHsbar->SetAccessible(safenew WindowAccessible(mHsbar));
mVsbar->SetAccessible(safenew WindowAccessible(mVsbar));
#endif
mHsbar->SetLayoutDirection(wxLayout_LeftToRight);
mHsbar->SetName(_("Horizontal Scrollbar"));
mVsbar->SetName(_("Vertical Scrollbar"));
project.Bind( EVT_UNDO_MODIFIED, &ProjectWindow::OnUndoPushedModified, this ); project.Bind( EVT_UNDO_MODIFIED, &ProjectWindow::OnUndoPushedModified, this );
project.Bind( EVT_UNDO_PUSHED, &ProjectWindow::OnUndoPushedModified, this ); project.Bind( EVT_UNDO_PUSHED, &ProjectWindow::OnUndoPushedModified, this );
project.Bind( EVT_UNDO_OR_REDO, &ProjectWindow::OnUndoRedo, this ); project.Bind( EVT_UNDO_OR_REDO, &ProjectWindow::OnUndoRedo, this );
project.Bind( EVT_UNDO_RESET, &ProjectWindow::OnUndoReset, this ); project.Bind( EVT_UNDO_RESET, &ProjectWindow::OnUndoReset, this );
wxTheApp->Bind(EVT_THEME_CHANGE, &ProjectWindow::OnThemeChange, this);
} }
void ProjectWindow::Init() void InitProjectWindow( ProjectWindow &window )
{ {
auto &project = mProject; auto &project = window.GetProject();
#ifdef EXPERIMENTAL_DA2 #ifdef EXPERIMENTAL_DA2
SetBackgroundColour(theTheme.Colour( clrMedium )); SetBackgroundColour(theTheme.Colour( clrMedium ));
@ -661,7 +683,7 @@ void ProjectWindow::Init()
// In addition, the help strings of menu items are by default sent to the first // In addition, the help strings of menu items are by default sent to the first
// field. Currently there are no such help strings, but it they were introduced, then // field. Currently there are no such help strings, but it they were introduced, then
// there would need to be an event handler to send them to the appropriate field. // there would need to be an event handler to send them to the appropriate field.
auto statusBar = CreateStatusBar(4); auto statusBar = window.CreateStatusBar(4);
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY
// so that name can be set on a standard control // so that name can be set on a standard control
statusBar->SetAccessible(safenew WindowAccessible(statusBar)); statusBar->SetAccessible(safenew WindowAccessible(statusBar));
@ -695,57 +717,47 @@ void ProjectWindow::Init()
// Create the TrackPanel and the scrollbars // Create the TrackPanel and the scrollbars
// //
auto topPanel = window.GetTopPanel();
{ {
auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL); auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
ubs->Add( ToolManager::Get( project ).GetTopDock(), 0, wxEXPAND | wxALIGN_TOP ); ubs->Add( ToolManager::Get( project ).GetTopDock(), 0, wxEXPAND | wxALIGN_TOP );
ubs->Add(&ruler, 0, wxEXPAND); ubs->Add(&ruler, 0, wxEXPAND);
mTopPanel->SetSizer(ubs.release()); topPanel->SetSizer(ubs.release());
} }
// Ensure that the topdock comes before the ruler in the tab order, // Ensure that the topdock comes before the ruler in the tab order,
// irrespective of the order in which they were created. // irrespective of the order in which they were created.
ToolManager::Get(project).GetTopDock()->MoveBeforeInTabOrder(&ruler); ToolManager::Get(project).GetTopDock()->MoveBeforeInTabOrder(&ruler);
const auto pPage = GetMainPage(); const auto pPage = window.GetMainPage();
wxBoxSizer *bs; wxBoxSizer *bs;
{ {
auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL); auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
bs = ubs.get(); bs = ubs.get();
bs->Add(mTopPanel, 0, wxEXPAND | wxALIGN_TOP); bs->Add(topPanel, 0, wxEXPAND | wxALIGN_TOP);
bs->Add(pPage, 1, wxEXPAND); bs->Add(pPage, 1, wxEXPAND);
bs->Add( ToolManager::Get( project ).GetBotDock(), 0, wxEXPAND ); bs->Add( ToolManager::Get( project ).GetBotDock(), 0, wxEXPAND );
SetAutoLayout(true); window.SetAutoLayout(true);
SetSizer(ubs.release()); window.SetSizer(ubs.release());
} }
bs->Layout(); bs->Layout();
auto &trackPanel = TrackPanel::Get( project ); auto &trackPanel = TrackPanel::Get( project );
// LLL: When Audacity starts or becomes active after returning from
// another application, the first window that can accept focus
// will be given the focus even if we try to SetFocus(). By
// creating the scrollbars after the TrackPanel, we resolve
// several focus problems.
mHsbar = safenew ScrollBar(pPage, HSBarID, wxSB_HORIZONTAL);
mVsbar = safenew ScrollBar(pPage, VSBarID, wxSB_VERTICAL);
#if wxUSE_ACCESSIBILITY
// so that name can be set on a standard control
mHsbar->SetAccessible(safenew WindowAccessible(mHsbar));
mVsbar->SetAccessible(safenew WindowAccessible(mVsbar));
#endif
mHsbar->SetLayoutDirection(wxLayout_LeftToRight);
mHsbar->SetName(_("Horizontal Scrollbar"));
mVsbar->SetName(_("Vertical Scrollbar"));
// LLL: When Audacity starts or becomes active after returning from // LLL: When Audacity starts or becomes active after returning from
// another application, the first window that can accept focus // another application, the first window that can accept focus
// will be given the focus even if we try to SetFocus(). By // will be given the focus even if we try to SetFocus(). By
// making the TrackPanel that first window, we resolve several // making the TrackPanel that first window, we resolve several
// keyboard focus problems. // keyboard focus problems.
pPage->MoveBeforeInTabOrder(mTopPanel); pPage->MoveBeforeInTabOrder(topPanel);
bs = (wxBoxSizer *)pPage->GetSizer(); bs = (wxBoxSizer *)pPage->GetSizer();
auto vsBar = &window.GetVerticalScrollBar();
auto hsBar = &window.GetHorizontalScrollBar();
{ {
// Top horizontal grouping // Top horizontal grouping
auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL); auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
@ -758,7 +770,7 @@ void ProjectWindow::Init()
auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL); auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL);
// Vertical scroll bar // Vertical scroll bar
vs->Add(mVsbar, 1, wxEXPAND | wxALIGN_TOP); vs->Add(vsBar, 1, wxEXPAND | wxALIGN_TOP);
hs->Add(vs.release(), 0, wxEXPAND | wxALIGN_TOP); hs->Add(vs.release(), 0, wxEXPAND | wxALIGN_TOP);
} }
@ -771,8 +783,8 @@ void ProjectWindow::Init()
// Bottom scrollbar // Bottom scrollbar
hs->Add(viewInfo.GetLeftOffset() - 1, 0); hs->Add(viewInfo.GetLeftOffset() - 1, 0);
hs->Add(mHsbar, 1, wxALIGN_BOTTOM); hs->Add(hsBar, 1, wxALIGN_BOTTOM);
hs->Add(mVsbar->GetSize().GetWidth(), 0); hs->Add(vsBar->GetSize().GetWidth(), 0);
bs->Add(hs.release(), 0, wxEXPAND | wxALIGN_LEFT); bs->Add(hs.release(), 0, wxEXPAND | wxALIGN_LEFT);
} }
@ -784,14 +796,16 @@ void ProjectWindow::Init()
AddPages(this, Factory, pNotebook); AddPages(this, Factory, pNotebook);
#endif #endif
mMainPanel->Layout(); auto mainPanel = window.GetMainPanel();
mainPanel->Layout();
wxASSERT( trackPanel.GetProject() == &project ); wxASSERT( trackPanel.GetProject() == &project );
// MM: Give track panel the focus to ensure keyboard commands work // MM: Give track panel the focus to ensure keyboard commands work
trackPanel.SetFocus(); trackPanel.SetFocus();
FixScrollbars(); window.FixScrollbars();
ruler.SetLeftOffset(viewInfo.GetLeftOffset()); // bevel on AdornedRuler ruler.SetLeftOffset(viewInfo.GetLeftOffset()); // bevel on AdornedRuler
// //
@ -809,18 +823,15 @@ void ProjectWindow::Init()
wxIcon ic{}; wxIcon ic{};
ic.CopyFromBitmap(theTheme.Bitmap(bmpAudacityLogo48x48)); ic.CopyFromBitmap(theTheme.Bitmap(bmpAudacityLogo48x48));
#endif #endif
SetIcon(ic); window.SetIcon(ic);
} }
#endif #endif
mIconized = false;
UpdateStatusWidths(); window.UpdateStatusWidths();
wxString msg = wxString::Format(_("Welcome to Audacity version %s"), wxString msg = wxString::Format(_("Welcome to Audacity version %s"),
AUDACITY_VERSION_STRING); AUDACITY_VERSION_STRING);
statusBar->SetStatusText(msg, mainStatusBarField); statusBar->SetStatusText(msg, mainStatusBarField);
wxTheApp->Bind(EVT_THEME_CHANGE, &ProjectWindow::OnThemeChange, this);
#ifdef EXPERIMENTAL_DA2 #ifdef EXPERIMENTAL_DA2
ClearBackground();// For wxGTK. ClearBackground();// For wxGTK.
#endif #endif

View File

@ -22,6 +22,9 @@ class Track;
class wxScrollBar; class wxScrollBar;
class wxPanel; class wxPanel;
class ProjectWindow;
void InitProjectWindow( ProjectWindow &window );
///\brief A top-level window associated with a project, and handling scrollbars ///\brief A top-level window associated with a project, and handling scrollbars
/// and zooming /// and zooming
class ProjectWindow final : public wxFrame class ProjectWindow final : public wxFrame
@ -34,6 +37,7 @@ public:
static ProjectWindow *Find( AudacityProject *pProject ); static ProjectWindow *Find( AudacityProject *pProject );
static const ProjectWindow *Find( const AudacityProject *pProject ); static const ProjectWindow *Find( const AudacityProject *pProject );
AudacityProject &GetProject() { return mProject; } AudacityProject &GetProject() { return mProject; }
const AudacityProject &GetProject() const { return mProject; }
explicit ProjectWindow( explicit ProjectWindow(
wxWindow * parent, wxWindowID id, wxWindow * parent, wxWindowID id,
@ -44,8 +48,6 @@ public:
// Next available ID for sub-windows // Next available ID for sub-windows
int NextWindowID(); int NextWindowID();
void Init();
bool IsActive() override; bool IsActive() override;
bool IsIconized() const override; bool IsIconized() const override;
@ -53,6 +55,7 @@ public:
void SetIsBeingDeleted() { mIsDeleting = true; } void SetIsBeingDeleted() { mIsDeleting = true; }
wxWindow *GetMainPage() { return mMainPage; } wxWindow *GetMainPage() { return mMainPage; }
wxPanel *GetMainPanel() { return mMainPanel; }
wxPanel *GetTopPanel() { return mTopPanel; } wxPanel *GetTopPanel() { return mTopPanel; }
void UpdateStatusWidths(); void UpdateStatusWidths();
@ -101,6 +104,7 @@ public:
// Scrollbars // Scrollbars
wxScrollBar &GetVerticalScrollBar() { return *mVsbar; } wxScrollBar &GetVerticalScrollBar() { return *mVsbar; }
wxScrollBar &GetHorizontalScrollBar() { return *mHsbar; }
void ScrollIntoView(double pos); void ScrollIntoView(double pos);
void ScrollIntoView(int x); void ScrollIntoView(int x);
@ -185,7 +189,7 @@ private:
bool mAutoScrolling{ false }; bool mAutoScrolling{ false };
bool mActive{ true }; bool mActive{ true };
bool mIconized; bool mIconized{ false };
bool mShownOnce{ false }; bool mShownOnce{ false };