Resolved sizing woes for now.

This commit is contained in:
Pietro Gagliardi 2018-10-20 19:22:02 -04:00
parent 71ddf6ce91
commit 836e0dc2c7
1 changed files with 21 additions and 16 deletions

View File

@ -266,8 +266,7 @@ void updateTheme(HWND hwnd)
} }
// TODO check errors // TODO check errors
// TODO the width is always off by 4 pixels somehow (according to UI Automation) // TODO the sizes are correct (according to UI Automation) but they don't visually match?
// TODO the height is correct (according to UI Automation) but they don't visually match?
SIZE buttonSize(HWND button) SIZE buttonSize(HWND button)
{ {
HDC dc; HDC dc;
@ -275,14 +274,13 @@ SIZE buttonSize(HWND button)
WCHAR *buf; WCHAR *buf;
RECT textRect; RECT textRect;
RECT contentRect; RECT contentRect;
SIZE minSize; LOGFONTW lf;
TEXTMETRICW tm;
int minStdButtonHeight;
SIZE ret; SIZE ret;
dc = GetDC(button); dc = GetDC(button);
printf("%08I32X ", GetThemePartSize(theme, dc, 3, 1, NULL, TS_TRUE, &ret));
printf("%d %d\n", ret.cx, ret.cy);
n = SendMessageW(button, WM_GETTEXTLENGTH, 0, 0); n = SendMessageW(button, WM_GETTEXTLENGTH, 0, 0);
buf = new WCHAR[n + 1]; buf = new WCHAR[n + 1];
GetWindowTextW(button, buf, n + 1); GetWindowTextW(button, buf, n + 1);
@ -294,8 +292,15 @@ printf("%d %d\n", ret.cx, ret.cy);
contentRect.top = 0; contentRect.top = 0;
contentRect.right = textRect.right - textRect.left; contentRect.right = textRect.right - textRect.left;
contentRect.bottom = textRect.bottom - textRect.top; contentRect.bottom = textRect.bottom - textRect.top;
//wprintf(L"%s ", buf);
delete[] buf; delete[] buf;
printf("%d %d\n", contentRect.right, contentRect.bottom); // dui70.dll adds this to the width when "overhang" is enabled, and it seems to be enabled for our cases, but I can't tell what conditions it's enabled for...
// and yes, it seems to be using the raw lfHeight value here :/
// TODO find the right TMT constant
GetThemeFont(textstyleTheme, dc,
4, 0,
TMT_FONT, &lf);
contentRect.right += 2 * (abs(lf.lfHeight) / 6);
if (button == leftButtons[0] || button == leftButtons[1] || button == leftButtons[2]) { if (button == leftButtons[0] || button == leftButtons[1] || button == leftButtons[2]) {
SIZE arrowSize; SIZE arrowSize;
@ -307,6 +312,7 @@ printf("%d %d\n", contentRect.right, contentRect.bottom);
6, 0, 6, 0,
NULL, TS_TRUE, &arrowSize); NULL, TS_TRUE, &arrowSize);
contentRect.right += arrowSize.cx; contentRect.right += arrowSize.cx;
// TODO I don't think dui70.dll takes this into consideration...
if (contentRect.bottom < arrowSize.cy) if (contentRect.bottom < arrowSize.cy)
contentRect.bottom = arrowSize.cy; contentRect.bottom = arrowSize.cy;
} }
@ -315,19 +321,18 @@ printf("%d %d\n", contentRect.right, contentRect.bottom);
contentRect.right += 13 * 2; contentRect.right += 13 * 2;
contentRect.bottom += 5 * 2; contentRect.bottom += 5 * 2;
// dui70.dll seems to do this, including the TS_TRUE part... // and dui70.dll seems to do a variant of this but for text buttons only...
GetThemePartSize(theme, dc, GetThemeTextMetrics(textstyleTheme, dc,
3, 1, 4, 0,
NULL, TS_TRUE, &minSize); &tm);
if (contentRect.right < minSize.cx) minStdButtonHeight = MulDiv(14, tm.tmHeight, 8);
contentRect.right = minSize.cx; if (contentRect.bottom < minStdButtonHeight)
if (contentRect.bottom < minSize.cy) contentRect.bottom = minStdButtonHeight;
contentRect.bottom = minSize.cy;
ReleaseDC(button, dc); ReleaseDC(button, dc);
ret.cx = contentRect.right - contentRect.left; ret.cx = contentRect.right - contentRect.left;
ret.cy = contentRect.bottom - contentRect.top; ret.cy = contentRect.bottom - contentRect.top;
printf("FINAL %d %d\n", ret.cx, ret.cy); //printf("%d %d\n", ret.cx, ret.cy);
return ret; return ret;
} }