summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-12-14 16:23:32 -0500
committerPietro Gagliardi <[email protected]>2014-12-14 16:23:32 -0500
commit33f7ac1142c6670a3045f9dba02a5fb32738b8fa (patch)
treefc9a1a475e3323132ca0152e840263015eb4de2d
parentf56ae488f0c9cf073f9b7ba2b4bde616ea702e59 (diff)
Unified all column width accesses to a columnWidth() function.
-rw-r--r--wintable/new/coord.h17
-rw-r--r--wintable/new/draw.h5
-rw-r--r--wintable/new/header.h1
-rw-r--r--wintable/new/util.h11
4 files changed, 17 insertions, 17 deletions
diff --git a/wintable/new/coord.h b/wintable/new/coord.h
index e83e0dd..d42ab67 100644
--- a/wintable/new/coord.h
+++ b/wintable/new/coord.h
@@ -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;
diff --git a/wintable/new/draw.h b/wintable/new/draw.h
index f2f40ea..626f23f 100644
--- a/wintable/new/draw.h
+++ b/wintable/new/draw.h
@@ -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;
}
diff --git a/wintable/new/header.h b/wintable/new/header.h
index d0fe457..709f3d6 100644
--- a/wintable/new/header.h
+++ b/wintable/new/header.h
@@ -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;
diff --git a/wintable/new/util.h b/wintable/new/util.h
index 470cef5..fd6166a 100644
--- a/wintable/new/util.h
+++ b/wintable/new/util.h
@@ -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;
+}