diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-16 10:47:38 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-16 10:47:38 +0200 |
| commit | 090203fff7a05929816b49b19ea24959e2f518e5 (patch) | |
| tree | 88a7a227fa0f5d59307e972802fd2e4f4f84511e | |
| parent | 02ffd45d5cb15b7d025b9a72a21ec1fd32de8c6f (diff) | |
panel: show centered text like Delphi
| -rw-r--r-- | alf/alfnotebook.cpp | 6 | ||||
| -rw-r--r-- | alf/alfpanel.cpp | 40 | ||||
| -rw-r--r-- | widgetfactory.cpp | 1 |
3 files changed, 46 insertions, 1 deletions
diff --git a/alf/alfnotebook.cpp b/alf/alfnotebook.cpp index d60ea6b..705d314 100644 --- a/alf/alfnotebook.cpp +++ b/alf/alfnotebook.cpp @@ -208,6 +208,12 @@ ALF__NotebookWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return TRUE; } else if (uMsg == WM_SETFONT) { SendMessage(priv->hwndTabCtrl, WM_SETFONT, wParam, lParam); + + int n = ALF_Notebook_InternalTabCount(hwnd, priv->hwndTabCtrl); + for (int i = 0; i < n; ++i) { + HWND p = ALF_Notebook_InternalTabPanel(hwnd, priv->hwndTabCtrl, i); + SendMessage(p, WM_SETFONT, wParam, lParam); + } } else if (uMsg == ALF_WM_QUERYSIZE) { int n = ALF_Notebook_InternalTabCount(hwnd, priv->hwndTabCtrl); RECT r = { 0, 0, 0, 0 }; diff --git a/alf/alfpanel.cpp b/alf/alfpanel.cpp index b8ef8b3..ce640a2 100644 --- a/alf/alfpanel.cpp +++ b/alf/alfpanel.cpp @@ -4,6 +4,7 @@ TCHAR *_alf_panelClass = NULL; typedef struct { ALFLayout layout; + HFONT font; } ALFPanelPriv; static void @@ -23,6 +24,27 @@ ALF_Panel_Paint(ALFPanelPriv *priv, HWND hwnd, HDC dc, RECT *r) { (void)priv; ALF_Compat_DrawThemeParentBackground(hwnd, dc, r); + + int textlen = GetWindowTextLength(hwnd); + if (textlen < 1) + return; + + TCHAR *textbuf = ALF_New(TCHAR, textlen + 1); + GetWindowText(hwnd, textbuf, textlen+1); + + HFONT oldFont = SelectFont(dc, priv->font); + + SetTextColor(dc, GetSysColor(COLOR_BTNTEXT)); + SetBkMode(dc, TRANSPARENT); + + RECT rc; + GetClientRect(hwnd, &rc); + + DrawText(dc, textbuf, -1, &rc, DT_SINGLELINE | DT_EXPANDTABS | DT_HIDEPREFIX | DT_CENTER | DT_VCENTER); + + ALF_Free(textbuf); + + SelectFont(dc, oldFont); } static LRESULT WINAPI @@ -48,6 +70,22 @@ ALF__PanelWindowProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam) return TRUE; } + if (msg == WM_SETFONT) { + priv->font = (HFONT)wparam; + if (LOWORD(lparam) != 0) + InvalidateRect(window, NULL, TRUE); + + return 0; + } + + if (msg == WM_GETFONT) { + return (LRESULT)priv->font; + } + + if (msg == WM_SETTEXT) { + InvalidateRect(window, NULL, TRUE); + } + if (msg == WM_PRINTCLIENT) { RECT r = { 0, 0, 0, 0 }; GetClientRect(window, &r); @@ -129,7 +167,7 @@ ALF_AddPanel(HWND parent, WORD id, UINT x, UINT y) p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_SENDAPPLYFONTS; + p.flags = ALF_QUERYSIZE | ALF_SENDAPPLYFONTS | ALF_MESSAGEFONT; ALF_AddWidgetEx(parent, &p); diff --git a/widgetfactory.cpp b/widgetfactory.cpp index e4127f0..b9cef4e 100644 --- a/widgetfactory.cpp +++ b/widgetfactory.cpp @@ -204,6 +204,7 @@ WinMain ALF_AddLabel(hwndTabPanel1, (WORD)-1, 0, 2, TEXT("No 3")); ALF_AddEdit(hwndTabPanel1, (WORD)-1, 0, 3, TEXT("Dummy")); + ALF_SetText(hwndTabPanel2, TEXT("Panel Text Demo Test Test Test")); ALF_ApplyFonts(win); ALF_RecalculateLayout(win); |
