diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index fc3a7de78..d6cb4ea02 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -1214,8 +1214,18 @@ int LabelTrack::OverGlyph(int x, int y) return result; } +int LabelTrack::OverATextBox(int xx, int yy) const +{ + for (int nn = (int)mLabels.Count(); nn--;) { + if (OverTextBox(mLabels[nn], xx, yy)) + return nn; + } + + return -1; +} + // return true if the mouse is over text box, false otherwise -bool LabelTrack::OverTextBox(const LabelStruct *pLabel, int x, int y) +bool LabelTrack::OverTextBox(const LabelStruct *pLabel, int x, int y) const { if( (pLabel->xText-(mIconWidth/2) < x) && (xxText+pLabel->width+(mIconWidth/2)) && @@ -1483,7 +1493,7 @@ void LabelTrack::HandleTextDragRelease(const wxMouseEvent & evt) } void LabelTrack::HandleClick(const wxMouseEvent & evt, - wxRect & r, const ZoomInfo &zoomInfo, + const wxRect & r, const ZoomInfo &zoomInfo, SelectedRegion *newSel) { if (evt.ButtonDown()) @@ -1543,20 +1553,14 @@ void LabelTrack::HandleClick(const wxMouseEvent & evt, if (evt.LeftDown()) mDragXPos = -1; - mSelIndex = -1; - LabelStruct * pLabel; - for (int i = 0; i < (int)mLabels.Count(); i++) { - pLabel = mLabels[i]; - if(OverTextBox(pLabel, evt.m_x, evt.m_y)) - { - mSelIndex = i; - *newSel = mLabels[i]->selectedRegion; - // set mouseXPos to set current cursor position - if (changeCursor) - mMouseXPos = evt.m_x; - // set mInBox flag - mInBox = true; - } + mSelIndex = OverATextBox(evt.m_x, evt.m_y); + if (mSelIndex != -1) { + *newSel = mLabels[mSelIndex]->selectedRegion; + // set mouseXPos to set current cursor position + if (changeCursor) + mMouseXPos = evt.m_x; + // set mInBox flag + mInBox = true; } // reset the highlight indicator diff --git a/src/LabelTrack.h b/src/LabelTrack.h index aead7b223..df3783aae 100644 --- a/src/LabelTrack.h +++ b/src/LabelTrack.h @@ -169,7 +169,8 @@ class AUDACITY_DLL_API LabelTrack : public Track void ResetFlags(); - bool OverTextBox(const LabelStruct *pLabel, int x, int y); + int OverATextBox(int xx, int yy) const; + bool OverTextBox(const LabelStruct *pLabel, int x, int y) const; bool CutSelectedText(); bool CopySelectedText(); bool PasteSelectedText(double sel0, double sel1); @@ -182,7 +183,7 @@ class AUDACITY_DLL_API LabelTrack : public Track void SetWrongDragging(bool rightFlag) { mRightDragging = rightFlag; } void SetDrawCursor(bool drawCursorFlag) { mDrawCursor = drawCursorFlag; } - void HandleClick(const wxMouseEvent & evt, wxRect & r, const ZoomInfo &zoomInfo, + void HandleClick(const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo, SelectedRegion *newSel); bool HandleGlyphDragRelease(const wxMouseEvent & evt, wxRect & r, const ZoomInfo &zoomInfo, SelectedRegion *newSel);