diff options
| author | Pietro Gagliardi <[email protected]> | 2014-12-14 02:51:34 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-12-14 02:52:31 -0500 |
| commit | ad12b8b1af7bd2686416555e169cd10a51700fa9 (patch) | |
| tree | efb27e3ab4d4ea42c5f41dfe0cf64d78a1e095a4 | |
| parent | fa89a497ede5f5cf35d1fc5ab43081bc532a7d68 (diff) | |
Implemented rowColumnToClientRect() (was rowColumnToClientCoord() but decided that the full RECT would be more useful); not sure if I'm going to actually use it now though since full-on redrawing the old and new rows would probably be more correct in doselect()...
| -rw-r--r-- | wintable/new/coord.h | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/wintable/new/coord.h b/wintable/new/coord.h index 16f93a3..e83e0dd 100644 --- a/wintable/new/coord.h +++ b/wintable/new/coord.h @@ -87,10 +87,51 @@ static struct rowcol lParamToRowColumn(struct table *t, LPARAM lParam) return clientCoordToRowColumn(t, pt); } -// returns TRUE if the row is visible and thus has client coordinates; FALSE otherwise -static BOOL rowColumnToClientCoord(struct table *t, struct rowcol rc, POINT *pt) +// returns TRUE if the row is visible (even partially visible) and thus has a rectangle in the client area; FALSE otherwise +static BOOL rowColumnToClientRect(struct table *t, struct rowcol rc, RECT *r) { - // TODO + RECT client; + RECT out; // don't change r if we return FALSE + RECT colrect; + LONG height; + intptr_t xpos; + intptr_t i; + + if (rc.row < t->vscrollpos) + return FALSE; + rc.row -= t->vscrollpos; // align with client.top + + if (GetClientRect(t->hwnd, &client) == 0) + panic("error getting Table client rect in rowColumnToClientRect()"); + client.top += t->headerHeight; + + height = rowht(t); + out.top = client.top + (rc.row * height); + if (out.top >= client.bottom) // >= because RECT.bottom is the first pixel outside the rectangle + return FALSE; + out.bottom = out.top + height; + + // and again the columns are the hard part + // so we start with client.left - t->hscrollpos, then keep adding widths until we get to the column we want + xpos = client.left - t->hscrollpos; + for (i = 0; i < rc.column; i++) { + // TODO error check + SendMessage(t->header, HDM_GETITEMRECT, (WPARAM) i, (LPARAM) (&colrect)); + xpos += colrect.right - colrect.left; + } + // did we stray too far to the right? if so it's not visible + if (xpos >= client.right) // >= because RECT.right is the first pixel outside the rectangle + return FALSE; + out.left = xpos; + // TODO error check + SendMessage(t->header, HDM_GETITEMRECT, (WPARAM) (rc.column), (LPARAM) (&colrect)); + out.right = xpos + (colrect.right - colrect.left); + // and is this too far to the left? + if (out.right < client.left) // < because RECT.left is the first pixel inside the rect + return FALSE; + + *r = out; + return TRUE; } // TODO idealCoordToRowColumn/rowColumnToIdealCoord? |
