From 90f35ca449c309763f75f2ff89f660896b62e0dd Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 23 Dec 2020 11:47:19 +0000 Subject: [PATCH] GridCtrl: Selection fixes git-svn-id: svn://ultimatepp.org/upp/trunk@15619 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/GridCtrl/GridCtrl.h | 3 ++- uppsrc/GridCtrl/GridMouse.cpp | 6 +++--- uppsrc/GridCtrl/GridPaint.cpp | 4 ++++ uppsrc/GridCtrl/GridSelect.cpp | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/uppsrc/GridCtrl/GridCtrl.h b/uppsrc/GridCtrl/GridCtrl.h index 8d11592ec..17961a264 100644 --- a/uppsrc/GridCtrl/GridCtrl.h +++ b/uppsrc/GridCtrl/GridCtrl.h @@ -1643,7 +1643,8 @@ class GridCtrl : public Ctrl void UpdateSummary(bool b = true); private: - + bool IsSelect(int n, int m, bool relative); + bool TabKey(bool enter_mode); bool Go0(int jump, bool scroll = true, bool goleft = false, bool ctrlmode = false); diff --git a/uppsrc/GridCtrl/GridMouse.cpp b/uppsrc/GridCtrl/GridMouse.cpp index 33de5175e..0d78a6313 100644 --- a/uppsrc/GridCtrl/GridMouse.cpp +++ b/uppsrc/GridCtrl/GridMouse.cpp @@ -113,13 +113,13 @@ void GridCtrl::LeftDown(Point p, dword keyflags) moveRow = curpos.y; if(keyflags & K_CTRL) { - SelectRange(oldcur, oldcur, !IsSelected(curpos.y, curpos.y, false), select_row); - SelectRange(curpos, curpos, !IsSelected(curpos.y, curpos.y, false), select_row); + SelectRange(curpos, curpos, !IsSelect(curpos.y, curpos.x, false), select_row); } else { ClearSelection(); if((keyflags & K_SHIFT) && multi_select && IsValidCursor(oldcur)) { - SetCursor0(oldcur, CU_HIDECTRLS); + if(oldcur.y >= 0 && oldcur.x >= 0) + SetCursor0(oldcur, CU_HIDECTRLS); Refresh(); } } diff --git a/uppsrc/GridCtrl/GridPaint.cpp b/uppsrc/GridCtrl/GridPaint.cpp index e66fa2d29..269b1944a 100644 --- a/uppsrc/GridCtrl/GridPaint.cpp +++ b/uppsrc/GridCtrl/GridPaint.cpp @@ -343,6 +343,10 @@ void GridCtrl::Paint(Draw &w) Rect r(anchor, curpos); r.Normalize(); r.SetSize(r.GetSize() + 1); + if(select_row) { + r.left = 0; + r.right = INT_MAX; + } if(r.Contains(Point(j, i))) style |= GD::SELECT; } diff --git a/uppsrc/GridCtrl/GridSelect.cpp b/uppsrc/GridCtrl/GridSelect.cpp index fbe8c1ff3..dc8f7ae49 100644 --- a/uppsrc/GridCtrl/GridSelect.cpp +++ b/uppsrc/GridCtrl/GridSelect.cpp @@ -45,11 +45,14 @@ void GridCtrl::SelectRange(Point from, Point to, bool sel /* = true*/, bool full t = from; } - int ymin = f.y; - int ymax = t.y; + int ymin = min(f.y, t.y); + int ymax = max(f.y, t.y); int xmin = f.x; int xmax = t.x; + + if(ymin < 0 || xmin < 0) + return; if(xmin > xmax) { @@ -224,6 +227,14 @@ bool GridCtrl::IsSelected(int n, bool relative) return vitems[id].IsSelect() || vitems[id].IsCursor(); } +bool GridCtrl::IsSelect(int n, int m, bool relative) +{ + int r = relative ? fixed_rows + n : n; + int c = relative ? fixed_cols + m : m; + Item &it = GetItem(r, c); + return it.IsSelect(); +} + bool GridCtrl::IsSelected(int n, int m, bool relative) { int r = relative ? fixed_rows + n : n;