summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-12-16 11:34:26 -0500
committerPietro Gagliardi <[email protected]>2014-12-16 11:34:26 -0500
commit25e51003609d1f472ed0c7d8858ed32c16166169 (patch)
tree56881884df497ab79eaa137ee2e5f4077a68557b
parent3f42acb475e687883e85d9c13727155cd6cde1a6 (diff)
Attempted to fix broken coordinate calculations for out-of-cell clicks...
-rw-r--r--wintable/new/coord.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/wintable/new/coord.h b/wintable/new/coord.h
index d42ab67..592b141 100644
--- a/wintable/new/coord.h
+++ b/wintable/new/coord.h
@@ -38,6 +38,7 @@ static struct rowcol clientCoordToRowColumn(struct table *t, POINT pt)
RECT r;
struct rowcol rc;
intptr_t i;
+ intptr_t row, column;
// initial values for the PtInRect() check
rc.row = -1;
@@ -51,12 +52,15 @@ static struct rowcol clientCoordToRowColumn(struct table *t, POINT pt)
// the row is easy
pt.y -= t->headerHeight;
- rc.row = (pt.y / rowht(t)) + t->vscrollpos;
+ row = (pt.y / rowht(t)) + t->vscrollpos;
+ if (row > t->count - 1)
+ // after the last row; don't select anything
+ return rc;
// the column... not so much
// we scroll p.x, then subtract column widths until we cross the left edge of the control
pt.x += t->hscrollpos;
- rc.column = 0;
+ column = 0;
for (i = 0; i < t->nColumns; i++) {
pt.x -= columnWidth(t, i);
// use <, not <=, here:
@@ -67,10 +71,14 @@ static struct rowcol clientCoordToRowColumn(struct table *t, POINT pt)
// pt.x == 100 (first pixel of col 1) -> p.x - 100 == 0 >= 0 -> next column
if (pt.x < r.left)
break;
- rc.column++;
+ column++;
}
- // TODO what happens if the break was never taken?
+ if (column > t->nColumns - 1)
+ // to the right of all columns; select nothing
+ return rc;
+ rc.row = row;
+ rc.column = column;
return rc;
}