From db1cb406e0b2bc70548b6e34b2731b62be628b93 Mon Sep 17 00:00:00 2001
From: Paul-Licameli <paul.licameli@gmail.com>
Date: Sat, 11 Apr 2015 23:45:46 -0400
Subject: [PATCH] ESC key aborts resizing of mono track, stereo track, or
 channels of stereo track

Resizing may un-minimize a track; I was careful to be sure ESC restores
minimized state too and then that un-minimizing restores correct height
---
 src/TrackPanel.cpp | 49 +++++++++++++++++++++++++++++++++++++++++-----
 src/TrackPanel.h   |  3 +++
 2 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp
index 05fcdf86a..bbd9f8a16 100644
--- a/src/TrackPanel.cpp
+++ b/src/TrackPanel.cpp
@@ -1474,14 +1474,41 @@ void TrackPanel::HandleEscapeKey()
    {
    case IsZooming:
    case IsVZooming:
-      SetCapturedTrack(NULL, IsUncaptured);
-      if (HasCapture())
-         ReleaseMouse();
-      Refresh(false);
-      return;
+      break;
+   case IsResizing:
+      mCapturedTrack->SetHeight(mInitialActualHeight);
+      mCapturedTrack->SetMinimized(mInitialMinimized);
+      break;
+   case IsResizingBetweenLinkedTracks:
+   {
+      Track *const next = mTracks->GetNext(mCapturedTrack);
+      mCapturedTrack->SetHeight(mInitialUpperActualHeight);
+      mCapturedTrack->SetMinimized(mInitialMinimized);
+      next->SetHeight(mInitialActualHeight);
+      next->SetMinimized(mInitialMinimized);
+   }
+      break;
+   case IsResizingBelowLinkedTracks:
+   {
+      Track *const prev = mTracks->GetPrev(mCapturedTrack);
+      mCapturedTrack->SetHeight(mInitialActualHeight);
+      mCapturedTrack->SetMinimized(mInitialMinimized);
+      prev->SetHeight(mInitialUpperActualHeight);
+      prev->SetMinimized(mInitialMinimized);
+   }
+      break;
    default:
       return;
+      ;
    }
+
+   // Common part in all cases that do anything
+   SetCapturedTrack(NULL, IsUncaptured);
+   if (HasCapture())
+      ReleaseMouse();
+   wxMouseEvent dummy;
+   HandleCursor(dummy);
+   Refresh(false);
 }
 
 void TrackPanel::HandleAltKey(bool down)
@@ -5591,6 +5618,7 @@ void TrackPanel::HandleResizeClick( wxMouseEvent & event )
    mMouseClickY = event.m_y;
 
 #ifdef EXPERIMENTAL_OUTPUT_DISPLAY
+   // To do: escape key
    if(MONO_WAVE_PAN(t)){
       //STM:  Determine whether we should rescale one or two tracks
       if (t->GetVirtualStereo()) {
@@ -5613,18 +5641,21 @@ void TrackPanel::HandleResizeClick( wxMouseEvent & event )
       if (prev && prev->GetLink() == t) {
          // mCapturedTrack is the lower track
          mInitialTrackHeight = t->GetHeight();
+         mInitialMinimized = t->GetMinimized();
          mInitialUpperTrackHeight = prev->GetHeight();
          SetCapturedTrack(t, IsResizingBelowLinkedTracks);
       }
       else if (next && t->GetLink() == next) {
          // mCapturedTrack is the upper track
          mInitialTrackHeight = next->GetHeight();
+         mInitialMinimized = next->GetMinimized();
          mInitialUpperTrackHeight = t->GetHeight();
          SetCapturedTrack(t, IsResizingBetweenLinkedTracks);
       }
       else {
          // DM: Save the initial mouse location and the initial height
          mInitialTrackHeight = t->GetHeight();
+         mInitialMinimized = t->GetMinimized();
          SetCapturedTrack(t, IsResizing);
       }
    }
@@ -5636,18 +5667,26 @@ void TrackPanel::HandleResizeClick( wxMouseEvent & event )
    if (prev && prev->GetLink() == t) {
       // mCapturedTrack is the lower track
       mInitialTrackHeight = t->GetHeight();
+      mInitialActualHeight = t->GetActualHeight();
+      mInitialMinimized = t->GetMinimized();
       mInitialUpperTrackHeight = prev->GetHeight();
+      mInitialUpperActualHeight = prev->GetActualHeight();
       SetCapturedTrack(t, IsResizingBelowLinkedTracks);
    }
    else if (next && t->GetLink() == next) {
       // mCapturedTrack is the upper track
       mInitialTrackHeight = next->GetHeight();
+      mInitialActualHeight = next->GetActualHeight();
+      mInitialMinimized = next->GetMinimized();
       mInitialUpperTrackHeight = t->GetHeight();
+      mInitialUpperActualHeight = t->GetActualHeight();
       SetCapturedTrack(t, IsResizingBetweenLinkedTracks);
    }
    else {
       // DM: Save the initial mouse location and the initial height
       mInitialTrackHeight = t->GetHeight();
+      mInitialActualHeight = t->GetActualHeight();
+      mInitialMinimized = t->GetMinimized();
       SetCapturedTrack(t, IsResizing);
    }
 #endif // EXPERIMENTAL_OUTPUT_DISPLAY
diff --git a/src/TrackPanel.h b/src/TrackPanel.h
index 5c637d64c..b5056cce9 100644
--- a/src/TrackPanel.h
+++ b/src/TrackPanel.h
@@ -712,8 +712,11 @@ protected:
        bool onlyWithinSnapDistance,
        double *pPinValue = NULL) const;
 
+   bool mInitialMinimized;
    int mInitialTrackHeight;
+   int mInitialActualHeight;
    int mInitialUpperTrackHeight;
+   int mInitialUpperActualHeight;
    bool mAutoScrolling;
 
    enum   MouseCaptureEnum