Moved Table width calculation out of recomputeHScroll() and into updateTableWidth(); also stored width in the Table itself.
This commit is contained in:
parent
b2b04c6de4
commit
395521b832
|
@ -55,6 +55,19 @@ static void headerAddColumn(struct table *t, WCHAR *name)
|
||||||
|
|
||||||
static void updateTableWidth(struct table *t)
|
static void updateTableWidth(struct table *t)
|
||||||
{
|
{
|
||||||
|
HDITEMW item;
|
||||||
|
intptr_t i;
|
||||||
|
|
||||||
|
t->width = 0;
|
||||||
|
// TODO count dividers?
|
||||||
|
for (i = 0; i < t->nColumns; i++) {
|
||||||
|
ZeroMemory(&item, sizeof (HDITEMW));
|
||||||
|
item.mask = HDI_WIDTH;
|
||||||
|
if (SendMessageW(t->header, HDM_GETITEM, (WPARAM) i, (LPARAM) (&item)) == FALSE)
|
||||||
|
panic("error getting Table column width for updateTableWidth()");
|
||||||
|
t->width += item.cxy;
|
||||||
|
}
|
||||||
|
// TODO replace this with a call to hscrollby(t, 0)
|
||||||
recomputeHScroll(t);
|
recomputeHScroll(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,19 +18,8 @@ static void hscroll(struct table *t, WPARAM wParam, LPARAM lParam)
|
||||||
static void recomputeHScroll(struct table *t)
|
static void recomputeHScroll(struct table *t)
|
||||||
{
|
{
|
||||||
SCROLLINFO si;
|
SCROLLINFO si;
|
||||||
HDITEMW item;
|
|
||||||
intptr_t i, width;
|
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|
||||||
width = 0;
|
|
||||||
// TODO count dividers?
|
|
||||||
for (i = 0; i < t->nColumns; i++) {
|
|
||||||
ZeroMemory(&item, sizeof (HDITEMW));
|
|
||||||
item.mask = HDI_WIDTH;
|
|
||||||
if (SendMessageW(t->header, HDM_GETITEM, (WPARAM) i, (LPARAM) (&item)) == FALSE)
|
|
||||||
panic("error getting Table column width for recomputeHScroll()");
|
|
||||||
width += item.cxy;
|
|
||||||
}
|
|
||||||
if (GetClientRect(t->hwnd, &r) == 0)
|
if (GetClientRect(t->hwnd, &r) == 0)
|
||||||
panic("error getting Table client rect for recomputeHScroll()");
|
panic("error getting Table client rect for recomputeHScroll()");
|
||||||
ZeroMemory(&si, sizeof (SCROLLINFO));
|
ZeroMemory(&si, sizeof (SCROLLINFO));
|
||||||
|
@ -38,7 +27,7 @@ static void recomputeHScroll(struct table *t)
|
||||||
si.fMask = SIF_PAGE | SIF_RANGE;
|
si.fMask = SIF_PAGE | SIF_RANGE;
|
||||||
si.nPage = r.right - r.left;
|
si.nPage = r.right - r.left;
|
||||||
si.nMin = 0;
|
si.nMin = 0;
|
||||||
si.nMax = width - 1; // endpoint inclusive
|
si.nMax = t->width - 1; // endpoint inclusive
|
||||||
SetScrollInfo(t->hwnd, SB_HORZ, &si, TRUE);
|
SetScrollInfo(t->hwnd, SB_HORZ, &si, TRUE);
|
||||||
// TODO what happens if the above call renders the current scroll position moot?
|
// TODO what happens if the above call renders the current scroll position moot?
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ struct table {
|
||||||
HFONT font;
|
HFONT font;
|
||||||
intptr_t nColumns;
|
intptr_t nColumns;
|
||||||
int *columnTypes;
|
int *columnTypes;
|
||||||
|
intptr_t width;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
Loading…
Reference in New Issue