diff options
| author | Pietro Gagliardi <[email protected]> | 2014-12-13 12:17:18 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-12-13 12:17:18 -0500 |
| commit | 516173916e598781f22c42580aecbf75b109f6d3 (patch) | |
| tree | 7bc4ebba91e0831c6eb8d479e2503477cd762d22 | |
| parent | e966a9b725010de21248bb09bdd41ac830880046 (diff) | |
Implemented clientCoordToRowColumn().
| -rw-r--r-- | wintable/new/coord.h | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/wintable/new/coord.h b/wintable/new/coord.h index fff807d..5716db4 100644 --- a/wintable/new/coord.h +++ b/wintable/new/coord.h @@ -1,19 +1,55 @@ // 4 december 2014 -typedef struct rowcol rowcol; - struct rowcol { intptr_t row; intptr_t column; }; -static rowcol clientCoordToRowColumn(struct table *t, POINT pt) +static struct rowcol clientCoordToRowColumn(struct table *t, POINT pt) { - // TODO + RECT r; + struct rowcol rc; + intptr_t i; + RECT colrect; + + // initial values for the PtInRect() check + rc.row = -1; + rc.column = -1; + + if (GetClientRect(t->hwnd, &r) == 0) + panic("error getting Table client rect in clientCoordToRowColumn()"); + r.top += t->headerHeight; + if (PtInRect(&r, p) == 0) + return rc; + + // the row is easy + rc.row = (pt.y / rowht(t)) + t->yscrollpos; + + // the column... not so much + // we scroll p.x, then subtract column widths until we cross the left edge of the control + p.x += t->hscrollpos; + rc.column = 0; + for (i = 0; i < t->nColumns; i++) { + // TODO error check + SendMessage(t->header, HDM_GETITEMRECT, (WPARAM) i, (LPARAM) (&colrect)); + p.x -= colrect.right - colrect.left; + // use <, not <=, here: + // assume r.left and t->hscrollpos == 0; + // given the first column is 100 wide, + // p.x == 0 (first pixel of col 0) -> p.x - 100 == -100 < 0 -> break + // p.x == 99 (last pixel of col 0) -> p.x - 100 == -1 < 0 -> break + // p.x == 100 (first pixel of col 1) -> p.x - 100 == 0 >= 0 -> next column + if (p.x < r.left) + break; + rc.column++; + } + // TODO what happens if the break was never taken? + + return rc; } // same as client coordinates, but stored in a lParam (like the various mouse messages provide) -static rowcol lParamToRowColumn(struct table *t, LPARAM lParam) +static struct rowcol lParamToRowColumn(struct table *t, LPARAM lParam) { POINT pt; @@ -23,7 +59,7 @@ static rowcol lParamToRowColumn(struct table *t, LPARAM lParam) } // returns TRUE if the row is visible and thus has client coordinates; FALSE otherwise -static BOOL rowColumnToClientCoord(struct table *t, rowcol rc, struct POINT *pt) +static BOOL rowColumnToClientCoord(struct table *t, struct rowcol rc, struct POINT *pt) { // TODO } |
