Fixed WhenCursor issues

git-svn-id: svn://ultimatepp.org/upp/trunk@1730 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
unodgs 2009-11-30 22:02:59 +00:00
parent 51caafe446
commit 9b6a5e050c
2 changed files with 47 additions and 23 deletions

View file

@ -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;
}

View file

@ -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(); }
};