Rewrote the tab height calculation function from the previous commit to consider all tabs, just to be safe.

This commit is contained in:
Pietro Gagliardi 2014-08-02 12:24:04 -04:00
parent 1f6ad99afb
commit 668cf5e46e
1 changed files with 12 additions and 24 deletions

View File

@ -62,33 +62,21 @@ void tabGetContentRect(HWND hwnd, RECT *r)
SendMessageW(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM) r); SendMessageW(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM) r);
} }
/* TODO this assumes that all inactive tabs have the same height */ /* theoretically we don't need to iterate over every tab for this, but let's do it just to be safe */
LONG tabGetTabHeight(HWND hwnd) LONG tabGetTabHeight(HWND hwnd)
{ {
RECT r; RECT r;
RECT r2; LRESULT i, n;
LRESULT n, current, other; LONG tallest;
n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0); n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0);
/* if there are no tabs, then the control just draws a box over the full window rect, reserving no space for tabs (TODO check on windows xp and 7) */ /* if there are no tabs, then the control just draws a box over the full window rect, reserving no space for tabs (TODO check on windows xp and 7); this is handled here */
if (n == 0) tallest = 0;
return 0; for (i = 0; i < n; i++) {
/* get the current tab's height */ if (SendMessageW(hwnd, TCM_GETITEMRECT, (WPARAM) i, (LPARAM) (&r)) == FALSE)
/* note that Windows calls the tabs themselves "items" */ xpanic("error getting tab height for Tab.preferredSize()", GetLastError());
current = SendMessageW(hwnd, TCM_GETCURSEL, 0, 0); if (tallest < (r.bottom - r.top))
if (SendMessageW(hwnd, TCM_GETITEMRECT, (WPARAM) current, (LPARAM) (&r)) == FALSE) tallest = r.bottom - r.top;
xpanic("error getting current tab's tab height for Tab.preferredSize()", GetLastError()); }
/* if there's only one tab, then it's the current one; just get its size and return it */ return tallest;
if (n == 1)
goto onlyOne;
/* otherwise, get an inactive tab's height and return the taller of the two heights */
other = current + 1;
if (other >= n)
other = 0;
if (SendMessageW(hwnd, TCM_GETITEMRECT, (WPARAM) other, (LPARAM) (&r2)) == FALSE)
xpanic("error getting other tab's tab height for Tab.preferredSize()", GetLastError());
if ((r2.bottom - r2.top) > (r.bottom - r.top))
return r2.bottom - r2.top;
onlyOne:
return r.bottom - r.top;
} }