From 5cbb664bd49cd2b9c035ccfc3024aa436d28c36c Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Thu, 16 Apr 2020 13:12:32 +0200 Subject: layout: invalidate and recalculate, automatically --- alf/alflabel.cpp | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'alf/alflabel.cpp') diff --git a/alf/alflabel.cpp b/alf/alflabel.cpp index fd2cab7..f400f4f 100644 --- a/alf/alflabel.cpp +++ b/alf/alflabel.cpp @@ -69,6 +69,7 @@ ALF__LabelWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return TRUE; } else if (uMsg == WM_SETTEXT) { InvalidateRect(hwnd, NULL, TRUE); + ALF_InvalidateLayout(GetParent(hwnd)); } else if (uMsg == WM_GETDLGCODE) { return DLGC_STATIC; } else if (uMsg == WM_SETFONT) { @@ -76,6 +77,8 @@ ALF__LabelWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (LOWORD(lParam) != 0) InvalidateRect(hwnd, NULL, TRUE); + ALF_InvalidateLayout(GetParent(hwnd)); + return 0; } else if (uMsg == WM_GETFONT) { return (LRESULT)priv->font; @@ -167,40 +170,39 @@ ALF__LabelWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return TRUE; } else if (uMsg == ALF_WM_QUERYSIZE) { - HDC hdcLabel = GetDC(hwnd); - HFONT oldFont = 0; - if (priv->font) - oldFont = SelectFont(hdcLabel, priv->font); + int textlen = GetWindowTextLength(hwnd); + SIZE *pSize = (SIZE*)(void*)lParam; + if (textlen) { + HDC hdcLabel = GetDC(hwnd); + HFONT oldFont = SelectFont(hdcLabel, priv->font); - // calc drawtext style - UINT format = DT_LEFT | DT_EXPANDTABS | DT_CALCRECT; + // calc drawtext style + UINT format = DT_LEFT | DT_EXPANDTABS | DT_CALCRECT; - RECT r = { 0, 0, 100, 100 }; + RECT r = { 0, 0, 100, 100 }; - int textlen = GetWindowTextLength(hwnd); - TCHAR *textbuf = ALF_New(TCHAR, textlen + 1); - GetWindowText(hwnd, textbuf, textlen+1); + TCHAR *textbuf = ALF_New(TCHAR, textlen + 1); + GetWindowText(hwnd, textbuf, textlen+1); - DrawText(hdcLabel, textbuf, -1, &r, format); + DrawText(hdcLabel, textbuf, -1, &r, format); - ALF_Free(textbuf); + ALF_Free(textbuf); - SIZE *pSize = (SIZE*)(void*)lParam; - if (pSize->cx == 0) { - pSize->cx = r.right - r.left; - if ((priv->style & ALF_LABEL_HALIGN_MASK) == ALF_LABEL_ALIGN_LEFT_LIKE_EDIT) - pSize->cx += ALF__LabelLeftPadding(hwnd, hdcLabel); - } - if (pSize->cy == 0) { - pSize->cy = r.bottom - r.top; - if ((priv->style & ALF_LABEL_VALIGN_MASK) == ALF_LABEL_ALIGN_TOP_LIKE_EDIT) - pSize->cy += ALF__LabelTopPadding(hwnd); - } + if (pSize->cx == 0) { + pSize->cx = r.right - r.left; + if ((priv->style & ALF_LABEL_HALIGN_MASK) == ALF_LABEL_ALIGN_LEFT_LIKE_EDIT) + pSize->cx += ALF__LabelLeftPadding(hwnd, hdcLabel); + } + if (pSize->cy == 0) { + pSize->cy = r.bottom - r.top; + if ((priv->style & ALF_LABEL_VALIGN_MASK) == ALF_LABEL_ALIGN_TOP_LIKE_EDIT) + pSize->cy += ALF__LabelTopPadding(hwnd); + } - if (oldFont) SelectFont(hdcLabel, oldFont); - ReleaseDC(hwnd, hdcLabel); + ReleaseDC(hwnd, hdcLabel); + } } else if (uMsg == WM_DESTROY) { ALF_Free(priv); SetWindowLongPtr(hwnd, 0, 0); -- cgit v1.2.3