Update the active line on mouse up rather than mouse down. Should finally fix the accidental multiple line selection issues.

Originally committed to SVN as r5583.
This commit is contained in:
Thomas Goyne 2011-09-01 23:48:28 +00:00
parent 971f5c1e9c
commit f21e991d67
1 changed files with 88 additions and 81 deletions

View File

@ -591,40 +591,53 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
GetClientSize(&w,&h); GetClientSize(&w,&h);
// Modifiers // Modifiers
bool shift = event.m_shiftDown; bool shift = event.ShiftDown();
bool alt = event.m_altDown; bool alt = event.AltDown();
#ifdef __APPLE__ bool ctrl = event.CmdDown();
bool ctrl = event.m_metaDown;
#else
bool ctrl = event.m_controlDown;
#endif
// Row that mouse is over // Row that mouse is over
bool click = event.ButtonDown(wxMOUSE_BTN_LEFT); bool click = event.LeftDown();
bool left_up = event.LeftUp();
bool dclick = event.LeftDClick(); bool dclick = event.LeftDClick();
int row = event.GetY() / lineHeight + yPos - 1; int row = event.GetY() / lineHeight + yPos - 1;
bool headerClick = row < yPos; if (holding) {
if (holding && !click) {
row = MID(0, row, GetRows() - 1); row = MID(0, row, GetRows() - 1);
} }
bool validRow = row >= 0 && row < GetRows();
if (!validRow) row = -1; // If holding is false the left up event has already been handled
if (left_up && !holding) {
return;
}
// Get focus // Get focus
if (event.ButtonDown()) { if (event.ButtonDown() && Options.AsBool(L"Grid Allow Focus")) {
if (Options.AsBool(_T("Grid Allow Focus"))) {
SetFocus(); SetFocus();
} }
// Popup
if (event.RightDown()) {
OnPopupMenu(row < yPos, event.GetPosition());
return;
}
// Mouse wheel
if (event.GetWheelRotation() != 0) {
int step = 3 * event.GetWheelRotation() / event.GetWheelDelta();
ScrollTo(yPos - step);
return;
}
if (row < 0 || row >= GetRows()) {
return;
} }
// Click type // Click type
bool startedHolding = false; if (click) {
if (click && !holding && validRow) {
holding = true; holding = true;
startedHolding = true; if (!shift && !alt) lastRow = row;
CaptureMouse(); CaptureMouse();
} }
if (!event.ButtonIsDown(wxMOUSE_BTN_LEFT) && holding) { if (left_up && holding) {
holding = false; holding = false;
ReleaseMouse(); ReleaseMouse();
} }
@ -635,49 +648,60 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
int minVis = yPos+1; int minVis = yPos+1;
int maxVis = yPos+h/lineHeight-3; int maxVis = yPos+h/lineHeight-3;
int delta = 0; int delta = 0;
if (row < minVis) delta = -1; if (row < minVis) delta = -3;
if (row > maxVis) delta = +1; if (row > maxVis) delta = +3;
// Scroll
if (delta) { if (delta) {
ScrollTo(yPos+delta*3); ScrollTo(yPos + delta);
if (startedHolding) {
// End the hold if this was a mousedown to avoid accidental
// selection of extra lines
if (click) {
holding = false; holding = false;
left_up = true;
ReleaseMouse(); ReleaseMouse();
} }
} }
} }
// Click
if ((click || holding || dclick) && validRow) {
// Disable extending // Disable extending
extendRow = -1; extendRow = -1;
// Toggle selected // Toggle selected
if (click && ctrl && !shift && !alt) { if (left_up && ctrl && !shift && !alt) {
SelectRow(row,true,!IsInSelection(row,0)); SelectRow(row,true,!IsInSelection(row,0));
parentFrame->UpdateToolbar(); parentFrame->UpdateToolbar();
return; return;
} }
// Normal click // Normal click
if ((click || dclick) && !shift && !ctrl && !alt) { if (!shift && !ctrl && !alt) {
editBox->SetToLine(row); if (click || dclick) {
if (dclick) VideoContext::Get()->JumpToFrame(VFR_Output.GetFrameAtTime(GetDialogue(row)->Start.GetMS(),true));
SelectRow(row,false); SelectRow(row,false);
parentFrame->UpdateToolbar(); parentFrame->UpdateToolbar();
lastRow = row; }
if (left_up || dclick) {
int old = editBox->linen;
editBox->SetToLine(row);
RefreshRect(wxRect(0,(row+1-yPos)*lineHeight,w,lineHeight+2),false);
RefreshRect(wxRect(0,(old+1-yPos)*lineHeight,w,lineHeight+2),false);
}
if (dclick)
VideoContext::Get()->JumpToFrame(VFR_Output.GetFrameAtTime(GetDialogue(row)->Start.GetMS(),true));
if (click || dclick || left_up)
return; return;
} }
// Keep selection // Keep selection
if (click && !shift && !ctrl && alt) { if (left_up && !shift && !ctrl && alt) {
editBox->SetToLine(row); editBox->SetToLine(row);
return; return;
} }
// Block select // Block select
if ((click && shift && !ctrl && !alt) || (holding && !ctrl && !alt && !shift)) { if ((left_up && shift && !alt) || (holding && !ctrl && !alt && !shift)) {
if (lastRow != -1) { if (lastRow != -1) {
// Set boundaries // Set boundaries
int i1 = row; int i1 = row;
@ -691,30 +715,13 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
// Toggle each // Toggle each
bool notFirst = false; bool notFirst = false;
for (int i=i1;i<=i2;i++) { for (int i=i1;i<=i2;i++) {
SelectRow(i,notFirst,true); SelectRow(i,notFirst || ctrl,true);
notFirst = true; notFirst = true;
} }
parentFrame->UpdateToolbar(); parentFrame->UpdateToolbar();
} }
return; return;
} }
return;
}
// Popup
if (event.ButtonDown(wxMOUSE_BTN_RIGHT)) {
OnPopupMenu(headerClick, event.GetPosition());
}
// Mouse wheel
if (event.GetWheelRotation() != 0) {
int step = 3 * event.GetWheelRotation() / event.GetWheelDelta();
ScrollTo(yPos - step);
return;
}
event.Skip();
} }