summaryrefslogtreecommitdiff
path: root/alf/alfbutton.cpp
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2018-12-27 22:54:55 +0100
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2018-12-27 23:01:28 +0100
commita5f3ea9ac12fccbc9faf3f152d4dfbe7f263268e (patch)
tree7e66ed4d7cb7e4b4ae56d8b562ff08121bf43026 /alf/alfbutton.cpp
parentb0b0e97aa5a06b22768bb9c9ea5e8caf383d78a4 (diff)
make label, edit and button text line up perfectly
Diffstat (limited to 'alf/alfbutton.cpp')
-rw-r--r--alf/alfbutton.cpp30
1 files changed, 24 insertions, 6 deletions
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));