From a9ab31dedbc7cb10ed368ef3f56b50c7e8237185 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 21 Aug 2015 12:02:48 -0400 Subject: [PATCH] Allow NULL arguments in TrackPanel::GetTracksUsableArea() --- src/Menus.cpp | 8 ++++---- src/TrackPanel.cpp | 16 +++++++++------- src/TrackPanel.h | 1 + src/widgets/Ruler.cpp | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 48a00426a..4a768e86e 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -4952,8 +4952,8 @@ void AudacityProject::OnZoomFit() if (len <= 0.0) return; - int w, h; - mTrackPanel->GetTracksUsableArea(&w, &h); + int w; + mTrackPanel->GetTracksUsableArea(&w, NULL); w -= 10; Zoom(w / len); @@ -4962,9 +4962,9 @@ void AudacityProject::OnZoomFit() void AudacityProject::DoZoomFitV() { - int width, height, count; + int height, count; - mTrackPanel->GetTracksUsableArea(&width, &height); + mTrackPanel->GetTracksUsableArea(NULL, &height); height -= 28; diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index be1716227..a1472eb76 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -1074,9 +1074,11 @@ void TrackPanel::SelectTrackLength(Track *t) void TrackPanel::GetTracksUsableArea(int *width, int *height) const { GetSize(width, height); - *width -= GetLeftOffset(); - *width -= kRightMargin; - *width = std::max(0, *width); + if (width) { + *width -= GetLeftOffset(); + *width -= kRightMargin; + *width = std::max(0, *width); + } } /// Gets the pointer to the AudacityProject that @@ -4150,8 +4152,8 @@ void TrackPanel::DoSlide(wxMouseEvent & event) if (mouseTrack == NULL) { // Allow sliding if the pointer is not over any track, but only if x is // within the bounds of the tracks area. - int width, height; - GetTracksUsableArea(&width, &height); + int width; + GetTracksUsableArea(&width, NULL); if (event.m_x >= GetLeftOffset() && event.m_x < GetLeftOffset() + width) mouseTrack = mCapturedTrack; else @@ -8254,8 +8256,8 @@ void TrackPanel::ScrollIntoView(double pos) { const int screenWidth = rint(mViewInfo->GetScreenWidth()); - int w, h; - GetTracksUsableArea( &w, &h ); + int w; + GetTracksUsableArea( &w, NULL ); // Or should we just set w = screenWidth ? int pixel = mViewInfo->TimeToPosition(pos); diff --git a/src/TrackPanel.h b/src/TrackPanel.h index d30165cdc..c823c39d6 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -166,6 +166,7 @@ class AUDACITY_DLL_API TrackPanel:public wxPanel { virtual int GetLeftOffset() const { return GetLabelWidth() + 1;} // Width and height, relative to upper left corner at (GetLeftOffset(), 0) + // Either argument may be NULL virtual void GetTracksUsableArea(int *width, int *height) const; virtual void SelectNone(); diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 9e19fd1b2..533c65a0b 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -1936,8 +1936,8 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) // Keep Quick-Play within usable track area. TrackPanel *tp = mProject->GetTrackPanel(); - int mousePosX, width, height; - tp->GetTracksUsableArea(&width, &height); + int mousePosX, width; + tp->GetTracksUsableArea(&width, NULL); mousePosX = std::max(evt.GetX(), tp->GetLeftOffset()); mousePosX = std::min(mousePosX, tp->GetLeftOffset() + width - 1);