diff --git a/uppsrc/GridCtrl/GridCtrl.cpp b/uppsrc/GridCtrl/GridCtrl.cpp index 04b99dc80..a0c8122d1 100644 --- a/uppsrc/GridCtrl/GridCtrl.cpp +++ b/uppsrc/GridCtrl/GridCtrl.cpp @@ -3094,14 +3094,7 @@ GridCtrl::CurState GridCtrl::SetCursor0(Point p, int opt, int dirx, int diry) CurState cs; if(!row_changing) return cs; - - WhenCursor(); - if(cancel_cursor) - { - cancel_cursor = false; - return cs; - } - + bool mouse = opt & CU_MOUSE; bool highlight = opt & CU_HIGHLIGHT; bool ctrlmode = opt & CU_CTRLMODE; @@ -3316,6 +3309,33 @@ GridCtrl::CurState GridCtrl::SetCursor0(Point p, int opt, int dirx, int diry) cs.newx = isnewcol; cs.newy = isnewrow; + Point t_curpos = curpos; + Point t_curid = curid; + int t_colidx = colidx; + int t_rowidx = rowidx; + bool t_valid_cursor = valid_cursor; + + valid_cursor = true; + curpos = tmpcur; + colidx = curpos.x; + rowidx = curpos.y; + + curid.x = hitems[curpos.x].id; + curid.y = vitems[curpos.y].id; + + WhenCursor(); + if(cancel_cursor) + { + cancel_cursor = false; + curpos = t_curpos; + curid = t_curid; + colidx = t_colidx; + rowidx = t_rowidx; + valid_cursor = t_valid_cursor; + cs.Clear(); + return cs; + } + if(oldvalid) { SetItemCursor(oldcur, false, highlight); @@ -3325,16 +3345,7 @@ GridCtrl::CurState GridCtrl::SetCursor0(Point p, int opt, int dirx, int diry) SetItemCursor(tmpcur, true, false); if(isnewrow || (!select_row && isnewcol)) RefreshRow(tmpcur.y, 0); - - valid_cursor = true; - - curpos = tmpcur; - colidx = curpos.x; - rowidx = curpos.y; - - curid.x = hitems[curpos.x].id; - curid.y = vitems[curpos.y].id; - + if(call_whenchangerow && isnewrow) { #ifdef LOG_CALLBACKS @@ -3355,7 +3366,7 @@ GridCtrl::CurState GridCtrl::SetCursor0(Point p, int opt, int dirx, int diry) if(isnewrow) SetCtrlsData(); - + LG("cur(%d, %d)", curpos.x, curpos.y); return cs; @@ -5569,6 +5580,9 @@ void GridCtrl::Clear(bool columns) Refresh(); } + WhenEmpty(); + WhenCursor(); + doscroll = true; } @@ -6472,9 +6486,6 @@ bool GridCtrl::Remove0(int row, int cnt /* = 1*/, bool recalc /* = true*/, bool WhenRemovedRow(); } - if(IsEmpty()) - WhenEmpty(); - if(ready && recalc) { RecalcRows(); @@ -6497,6 +6508,12 @@ bool GridCtrl::Remove0(int row, int cnt /* = 1*/, bool recalc /* = true*/, bool firstRow = -1; + if(IsEmpty()) + { + WhenEmpty(); + WhenCursor(); + } + return cancel; } diff --git a/uppsrc/GridCtrl/GridCtrl.h b/uppsrc/GridCtrl/GridCtrl.h index ba6d1189c..f963e45c7 100644 --- a/uppsrc/GridCtrl/GridCtrl.h +++ b/uppsrc/GridCtrl/GridCtrl.h @@ -350,12 +350,19 @@ class GridCtrl : public Ctrl bool accepted; bool valid; - CurState() : newx(false), newy(false), accepted(false), valid(true) {} + CurState() { Clear(); } bool IsNewRow() { return newy; } bool IsNewCol() { return newx; } bool IsNew() { return newx || newy; } bool IsAccepted() { return accepted; } bool IsValid() { return valid; } + + void Clear() + { + newx = newy = false; + accepted = false; + valid = true; + } operator bool() { return IsNew() && IsAccepted(); } };