diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index 505fed68e..ac71d546e 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -276,13 +276,11 @@ void LabelTrack::WarpLabels(const TimeWarper &warper) { void LabelTrack::ResetFlags() { - mMouseXPos = -1; mXPos1 = -1; mXPos2 = -1; mDragXPos = -1; mInitialCursorPos = 1; mCurrentCursorPos = 1; - mResetCursorPos = false; mRightDragging = false; mDrawCursor = false; } @@ -826,12 +824,6 @@ void LabelTrack::Draw(wxDC & dc, const wxRect & r, { // find the left X pos of highlighted area mLabels[mSelIndex]->getXPos(dc, &mXPos1, mInitialCursorPos); - // for preventing dragging glygh from changing current cursor position - if (mResetCursorPos) { - // set end dragging position to current cursor position - SetCurrentCursorPosition(mDragXPos); - mResetCursorPos = false; - } // find the right X pos of highlighted area mLabels[mSelIndex]->getXPos(dc, &mXPos2, mCurrentCursorPos); mLabels[mSelIndex]->DrawHighlight(dc, mXPos1, mXPos2, mFontHeight); @@ -851,19 +843,6 @@ void LabelTrack::Draw(wxDC & dc, const wxRect & r, i = mSelIndex; int xPos = mLabels[i]->xText; - // if mouse is clicked in text box - if (mMouseXPos != -1) - { - // set current cursor position - SetCurrentCursorPosition((int) mMouseXPos); - // for preventing from resetting by shift+mouse left button - // set initialCursorPos equal to currentCursorPos - if (mLabels[mSelIndex]->changeInitialMouseXPos) - mInitialCursorPos = mCurrentCursorPos; - mDrawCursor = true; - mMouseXPos = -1; - } - if( mCurrentCursorPos > 0) { // Calculate the width of the substring and add it to Xpos @@ -888,7 +867,7 @@ void LabelTrack::Draw(wxDC & dc, const wxRect & r, /// Set the cursor position according to x position of mouse /// uses GetTextExtent to find the character position /// corresponding to the x pixel position. -void LabelTrack::SetCurrentCursorPosition(int xPos) const +void LabelTrack::SetCurrentCursorPosition(int xPos) { wxMemoryDC dc; if(msFont.Ok()) @@ -1489,7 +1468,10 @@ void LabelTrack::HandleTextDragRelease(const wxMouseEvent & evt) // end dragging x position in pixels // set flag to update current cursor position mDragXPos = evt.m_x; - mResetCursorPos = true; + + // for preventing dragging glygh from changing current cursor position + // set end dragging position to current cursor position + SetCurrentCursorPosition(mDragXPos); // if it's an invalid dragging, disable displaying if (mRightDragging) { @@ -1521,9 +1503,6 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt, mIsAdjustingLabel = evt.Button(wxMOUSE_BTN_LEFT) && iGlyph != 0; - // reset mouseXPos if the mouse is pressed in the text box - mMouseXPos = -1; - if (mIsAdjustingLabel) { float t = 0.0; @@ -1572,8 +1551,13 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt, mSelIndex = OverATextBox(evt.m_x, evt.m_y); if (mSelIndex != -1) { *newSel = mLabels[mSelIndex]->selectedRegion; - // set mouseXPos to set current cursor position - mMouseXPos = evt.m_x; + SetCurrentCursorPosition(evt.m_x); + + // for preventing from resetting by shift+mouse left button + // set initialCursorPos equal to currentCursorPos + if (mLabels[mSelIndex]->changeInitialMouseXPos) + mInitialCursorPos = mCurrentCursorPos; + mDrawCursor = true; } // reset the highlight indicator @@ -2031,6 +2015,7 @@ void LabelTrack::ShowContextMenu() menu.Enable(OnDeleteSelectedLabelID, true); menu.Enable(OnEditSelectedLabelID, true); + wxASSERT(mSelIndex >= 0); const LabelStruct *ls = GetLabel(mSelIndex); wxClientDC dc(parent); @@ -2040,16 +2025,9 @@ void LabelTrack::ShowContextMenu() dc.SetFont(msFont); } - int x; - if (mMouseXPos != -1) - { - x = mMouseXPos; - } - else - { - dc.GetTextExtent(ls->title.Left(mCurrentCursorPos), &x, NULL); - x += ls->xText; - } + int x = 0; + bool success = CalcCursorX(&x); + wxASSERT(success); parent->PopupMenu(&menu, x, ls->y + (mIconHeight / 2) - 1); } diff --git a/src/LabelTrack.h b/src/LabelTrack.h index bba4cff6d..dd2c7f0bc 100644 --- a/src/LabelTrack.h +++ b/src/LabelTrack.h @@ -183,7 +183,6 @@ class AUDACITY_DLL_API LabelTrack final : public Track // methods to set flags void SetDragXPos(const int d) { mDragXPos = d; } - void SetResetCursorPos(bool resetFlag) { mResetCursorPos = resetFlag; } void SetWrongDragging(bool rightFlag) { mRightDragging = rightFlag; } void HandleClick(const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo, @@ -264,15 +263,14 @@ class AUDACITY_DLL_API LabelTrack final : public Track static int mFontHeight; mutable int mXPos1; /// left X pos of highlighted area mutable int mXPos2; /// right X pos of highlighted area - mutable int mCurrentCursorPos; /// current cursor position - mutable int mInitialCursorPos; /// initial cursor position - mutable double mMouseXPos; /// mouse X pos + int mCurrentCursorPos; /// current cursor position + int mInitialCursorPos; /// initial cursor position int mDragXPos; /// end X pos of dragging /// in text box - mutable bool mResetCursorPos; /// flag to reset cursor position(used in the dragging the glygh) bool mRightDragging; /// flag to tell if it's a valid dragging - mutable bool mDrawCursor; /// flag to tell if drawing the cursor or not + bool mDrawCursor; /// flag to tell if drawing the + /// cursor or not int mRestoreFocus; /// Restore focus to this track /// when done editing @@ -281,8 +279,11 @@ class AUDACITY_DLL_API LabelTrack final : public Track void ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const; void ComputeTextPosition(const wxRect & r, int index) const; - void SetCurrentCursorPosition(int xPos) const; +public: + void SetCurrentCursorPosition(int xPos); + +private: void calculateFontHeight(wxDC & dc) const; void RemoveSelectedText(); diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index a8bf1db28..0e7891721 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -6318,7 +6318,11 @@ bool TrackPanel::HandleLabelTrackClick(LabelTrack * lTrack, wxRect &rect, wxMous // if the mouse is clicked in text box, set flags if (lTrack->OverTextBox(lTrack->GetLabel(lTrack->getSelectedIndex()), event.m_x, event.m_y)) { lTrack->SetDragXPos(event.m_x); - lTrack->SetResetCursorPos(true); + + // for preventing dragging glygh from changing current cursor position + // set end dragging position to current cursor position + lTrack->SetCurrentCursorPosition(event.m_x); + RefreshTrack(lTrack); return true; }