From 5c8baf9c16147761010b72137bf826cced5b4e6c Mon Sep 17 00:00:00 2001 From: lllucius Date: Wed, 23 Oct 2013 18:06:49 +0000 Subject: [PATCH] Bug 406 - Label creation/other non-dialogue editing and keyboard selection hang on long projects This is part 2... Improve performance of selection via Selection bar This provides a similar type of speed up when selecting with the keyboard via the Selection toolbar. --- src/Project.cpp | 6 +++-- src/Project.h | 2 +- src/toolbars/SelectionBar.cpp | 12 +++++----- src/toolbars/SelectionBar.h | 4 ++-- src/widgets/TimeTextCtrl.cpp | 44 ++++++++++++++++++++++++++++------- src/widgets/TimeTextCtrl.h | 3 ++- 6 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index 0fd98002f..973c73ab6 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -1199,12 +1199,14 @@ void AudacityProject::AS_SetSnapTo(bool state) RedrawProject(); } -void AudacityProject::AS_ModifySelection(double &start, double &end) +void AudacityProject::AS_ModifySelection(double &start, double &end, bool done) { mViewInfo.sel0 = start; mViewInfo.sel1 = end; mTrackPanel->Refresh(false); - ModifyState(); + if (done) { + ModifyState(); + } } void AudacityProject::FinishAutoScroll() diff --git a/src/Project.h b/src/Project.h index e17acc365..42526a457 100644 --- a/src/Project.h +++ b/src/Project.h @@ -364,7 +364,7 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame, virtual void AS_SetRate(double rate); virtual bool AS_GetSnapTo(); virtual void AS_SetSnapTo(bool state); - virtual void AS_ModifySelection(double &start, double &end); + virtual void AS_ModifySelection(double &start, double &end, bool done); void SetStateTo(unsigned int n); diff --git a/src/toolbars/SelectionBar.cpp b/src/toolbars/SelectionBar.cpp index 7771cfb92..95decdefa 100644 --- a/src/toolbars/SelectionBar.cpp +++ b/src/toolbars/SelectionBar.cpp @@ -314,7 +314,7 @@ void SelectionBar::OnSize(wxSizeEvent &evt) evt.Skip(); } -void SelectionBar::ModifySelection() +void SelectionBar::ModifySelection(bool done) { mStart = mLeftTime->GetTimeValue(); double right = mRightTime->GetTimeValue(); @@ -328,17 +328,17 @@ void SelectionBar::ModifySelection() else mEnd = mStart + right; - mListener->AS_ModifySelection(mStart, mEnd); + mListener->AS_ModifySelection(mStart, mEnd, done); } -void SelectionBar::OnLeftTime(wxCommandEvent & WXUNUSED(event)) +void SelectionBar::OnLeftTime(wxCommandEvent & event) { - ModifySelection(); + ModifySelection(event.GetInt() != 0); } -void SelectionBar::OnRightTime(wxCommandEvent & WXUNUSED(event)) +void SelectionBar::OnRightTime(wxCommandEvent & event) { - ModifySelection(); + ModifySelection(event.GetInt() != 0); } void SelectionBar::OnLengthRadio(wxCommandEvent & WXUNUSED(event)) diff --git a/src/toolbars/SelectionBar.h b/src/toolbars/SelectionBar.h index 45af830a5..f31858f06 100644 --- a/src/toolbars/SelectionBar.h +++ b/src/toolbars/SelectionBar.h @@ -36,7 +36,7 @@ class AUDACITY_DLL_API SelectionBarListener { virtual void AS_SetRate(double rate) = 0; virtual bool AS_GetSnapTo() = 0; virtual void AS_SetSnapTo(bool state) = 0; - virtual void AS_ModifySelection(double &start, double &end) = 0; + virtual void AS_ModifySelection(double &start, double &end, bool done) = 0; }; class SelectionBar:public ToolBar { @@ -80,7 +80,7 @@ class SelectionBar:public ToolBar { void OnSize(wxSizeEvent &evt); - void ModifySelection(); + void ModifySelection(bool done = false); void UpdateRates(); diff --git a/src/widgets/TimeTextCtrl.cpp b/src/widgets/TimeTextCtrl.cpp index 0bfcc3c09..ecefcef1b 100644 --- a/src/widgets/TimeTextCtrl.cpp +++ b/src/widgets/TimeTextCtrl.cpp @@ -198,6 +198,7 @@ BEGIN_EVENT_TABLE(TimeTextCtrl, wxControl) EVT_MENU_RANGE(ID_MENU, ID_MENU+100, TimeTextCtrl::OnMenu) EVT_MOUSE_EVENTS(TimeTextCtrl::OnMouse) EVT_KEY_DOWN(TimeTextCtrl::OnKeyDown) + EVT_KEY_UP(TimeTextCtrl::OnKeyUp) EVT_SET_FOCUS(TimeTextCtrl::OnFocus) EVT_KILL_FOCUS(TimeTextCtrl::OnFocus) EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, TimeTextCtrl::OnCaptureKey) @@ -1081,6 +1082,23 @@ void TimeTextCtrl::OnCaptureKey(wxCommandEvent &event) return; } +void TimeTextCtrl::OnKeyUp(wxKeyEvent &event) +{ + int keyCode = event.GetKeyCode(); + + event.Skip(true); + + if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9)) + keyCode -= WXK_NUMPAD0 - '0'; + + if ((keyCode >= '0' && keyCode <= '9') || + (keyCode == WXK_BACK) || + (keyCode == WXK_UP) || + (keyCode == WXK_DOWN)) { + Updated(true); + } +} + void TimeTextCtrl::OnKeyDown(wxKeyEvent &event) { if (mDigits.GetCount() == 0) @@ -1089,7 +1107,8 @@ void TimeTextCtrl::OnKeyDown(wxKeyEvent &event) return; } - event.Skip(false); + event.Skip(); + int keyCode = event.GetKeyCode(); int digit = mFocusedDigit; @@ -1161,6 +1180,7 @@ void TimeTextCtrl::OnKeyDown(wxKeyEvent &event) nevent.SetEventObject(parent); nevent.SetCurrentFocus(parent); GetParent()->ProcessEvent(nevent); + event.Skip(false); } else if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER) { @@ -1170,6 +1190,7 @@ void TimeTextCtrl::OnKeyDown(wxKeyEvent &event) wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId()); GetParent()->ProcessEvent(cevent); + event.Skip(false); } } @@ -1181,8 +1202,6 @@ void TimeTextCtrl::OnKeyDown(wxKeyEvent &event) if (digit != mFocusedDigit) { SetFieldFocus(mFocusedDigit); } - - event.Skip(false); } void TimeTextCtrl::SetFieldFocus(int digit) @@ -1214,18 +1233,25 @@ void TimeTextCtrl::SetFieldFocus(int digit) #endif } -void TimeTextCtrl::Updated() +void TimeTextCtrl::Updated(bool keyup /* = false */) { wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId()); + + // This will give listeners the ability to do tasks when the + // update has been completed, like when the UP ARROW has been + // held down and is finally released. + event.SetInt(keyup); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); #if wxUSE_ACCESSIBILITY - GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE, - this, - wxOBJID_CLIENT, - mFocusedDigit + 1); - SetFieldFocus(mFocusedDigit); + if (!keyup) { + GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE, + this, + wxOBJID_CLIENT, + mFocusedDigit + 1); + SetFieldFocus(mFocusedDigit); + } #endif } diff --git a/src/widgets/TimeTextCtrl.h b/src/widgets/TimeTextCtrl.h index 1f41fd520..3c925a70c 100644 --- a/src/widgets/TimeTextCtrl.h +++ b/src/widgets/TimeTextCtrl.h @@ -110,6 +110,7 @@ private: void OnCaptureKey(wxCommandEvent &event); void OnKeyDown(wxKeyEvent &event); + void OnKeyUp(wxKeyEvent &event); void OnMouse(wxMouseEvent &event); void OnErase(wxEraseEvent &event); void OnPaint(wxPaintEvent &event); @@ -125,7 +126,7 @@ private: // If autoPos was enabled, focus the first non-zero digit void UpdateAutoFocus(); - void Updated(); + void Updated(bool keyup = false); void Increase(int steps); void Decrease(int steps);