Unified all column width accesses to a columnWidth() function.

This commit is contained in:
Pietro Gagliardi 2014-12-14 16:23:32 -05:00
parent f56ae488f0
commit 33f7ac1142
4 changed files with 17 additions and 17 deletions

View File

@ -38,7 +38,6 @@ static struct rowcol clientCoordToRowColumn(struct table *t, POINT pt)
RECT r;
struct rowcol rc;
intptr_t i;
RECT colrect;
// initial values for the PtInRect() check
rc.row = -1;
@ -59,9 +58,7 @@ static struct rowcol clientCoordToRowColumn(struct table *t, POINT pt)
pt.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));
pt.x -= colrect.right - colrect.left;
pt.x -= columnWidth(t, i);
// use <, not <=, here:
// assume r.left and t->hscrollpos == 0;
// given the first column is 100 wide,
@ -92,7 +89,6 @@ static BOOL rowColumnToClientRect(struct table *t, struct rowcol rc, RECT *r)
{
RECT client;
RECT out; // don't change r if we return FALSE
RECT colrect;
LONG height;
intptr_t xpos;
intptr_t i;
@ -114,18 +110,13 @@ static BOOL rowColumnToClientRect(struct table *t, struct rowcol rc, RECT *r)
// 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;
}
for (i = 0; i < rc.column; i++)
xpos += columnWidth(t, i);
// 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);
out.right = xpos + columnWidth(t, rc.column);
// 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;

View File

@ -57,7 +57,6 @@ static void drawCell(struct table *t, HDC dc, struct drawCellParams *p)
static void draw(struct table *t, HDC dc, RECT cliprect, RECT client)
{
intptr_t i, j;
RECT r;
int x = 0;
HFONT prevfont, newfont;
struct drawCellParams p;
@ -76,9 +75,7 @@ static void draw(struct table *t, HDC dc, RECT cliprect, RECT client)
p.x = client.left - t->hscrollpos;
for (j = 0; j < t->nColumns; j++) {
p.column = j;
// TODO error check
SendMessage(t->header, HDM_GETITEMRECT, (WPARAM) j, (LPARAM) (&r));
p.width = r.right - r.left;
p.width = columnWidth(t, p.column);
drawCell(t, dc, &p);
p.x += p.width;
}

View File

@ -68,6 +68,7 @@ static void updateTableWidth(struct table *t)
t->width = 0;
// TODO count dividers?
// TODO use columnWidth()
for (i = 0; i < t->nColumns; i++) {
ZeroMemory(&item, sizeof (HDITEMW));
item.mask = HDI_WIDTH;

View File

@ -78,3 +78,14 @@ static void deselectFont(HDC dc, HFONT prevfont, HFONT newfont)
panic("error deselecting Table font from Table DC");
// doin't delete newfont here, even if it is the system font (see http://msdn.microsoft.com/en-us/library/windows/desktop/dd144925%28v=vs.85%29.aspx)
}
// and back to other functions
static LONG columnWidth(struct table *t, intptr_t n)
{
RECT r;
if (SendMessageW(t->header, HDM_GETITEMRECT, (WPARAM) n, (LPARAM) (&r)) == 0)
panic("error getting Table column width");
return r.right - r.left;
}