From a5f3ea9ac12fccbc9faf3f152d4dfbe7f263268e Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Thu, 27 Dec 2018 22:54:55 +0100 Subject: make label, edit and button text line up perfectly --- alf/alfbutton.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'alf/alfbutton.cpp') diff --git a/alf/alfbutton.cpp b/alf/alfbutton.cpp index 079da75..b32831a 100644 --- a/alf/alfbutton.cpp +++ b/alf/alfbutton.cpp @@ -32,15 +32,17 @@ ALF__ButtonSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT HeapFree(GetProcessHeap(), 0, textbuf); - // TODO: calculate from system metrics - int padding = ALF_CentipointsToPixels(GetParent(hwnd), 525); + int xpadding = app->compatFn->GetSystemMetricsForDpi(SM_CXEDGE, + ALF_CentipointsToPixels(GetParent(hwnd), 7200)) * 3; + int ypadding = app->compatFn->GetSystemMetricsForDpi(SM_CYEDGE, + ALF_CentipointsToPixels(GetParent(hwnd), 7200)) * 3; SIZE *pSize = (SIZE*)(void*)lParam; - if (pSize->cx < r.right - r.left + padding) { - pSize->cx = r.right - r.left + padding; + if (pSize->cx < r.right - r.left + xpadding) { + pSize->cx = r.right - r.left + xpadding; } - if (pSize->cy < r.bottom - r.top + padding) { - pSize->cy = r.bottom - r.top + padding; + if (pSize->cy < r.bottom - r.top + ypadding) { + pSize->cy = r.bottom - r.top + ypadding; } if (pSize->cx < pSize->cy) { pSize->cx = pSize->cy; @@ -50,6 +52,21 @@ ALF__ButtonSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT SelectFont(hdc, oldFont); ReleaseDC(hwnd, hdc); + } else if (uMsg == WM_NCCALCSIZE) { + /* HACK: a themed button contains a 1px margin. An unthemed button + * does not, so we add one by shrinking the client area */ + RECT *r = (RECT *)lParam; + + int retval = app->compatFn->DefSubclassProc(hwnd, uMsg, wParam, lParam); + + if (!app->compatFn->IsAppThemed()) { + r->top += 1; + r->bottom -= 1; + } + + return retval; + } else if (uMsg == WM_THEMECHANGED) { + SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED); } return app->compatFn->DefSubclassProc(hwnd, uMsg, wParam, lParam); @@ -71,6 +88,7 @@ ALF_AddButton(HWND win, WORD id, UINT x, UINT y, const WCHAR *text) ALFAPP app = ALF_ApplicationFromWindow(win); app->compatFn->SetWindowSubclass(hwndButton, ALF__ButtonSubclassProc, 0, (DWORD_PTR)app); + SetWindowPos(hwndButton, NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED); ALFAddWidgetParams p; ZeroMemory(&p, sizeof(p)); -- cgit v1.2.3