diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-23 15:43:55 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-23 15:46:02 +0200 |
| commit | 6280671b1897ac0a47cb7e8f3463d4f60f2490cc (patch) | |
| tree | 5db441a60096e85444b7f3ef3357f17a9aefb3fd /alf/alflayout.cpp | |
| parent | 51daba89072cb66fe5e43015484a554555a40499 (diff) | |
move background color and font handling into layout
It's the same for window and all panel-like widgets, so it makes
sense to share it. Might need to refactor it out if we ever need
a layout without background and fonts
Diffstat (limited to 'alf/alflayout.cpp')
| -rw-r--r-- | alf/alflayout.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/alf/alflayout.cpp b/alf/alflayout.cpp index 15b8f5d..2e56886 100644 --- a/alf/alflayout.cpp +++ b/alf/alflayout.cpp @@ -77,6 +77,7 @@ ALF_Layout_Init(ALFLayout *layout) layout->nColumns = 1; layout->columns = ALF_New(ALFLayoutRowOrColumn, (SIZE_T)layout->nColumns); layout->dpi = 96; + layout->bgcolor = ALF_COLOR_TRANSPARENT; } void @@ -391,8 +392,6 @@ ALF_Layout_Apply(ALFLayout* layout, HWND window) // now apply positions to widgets HDWP hdwp = BeginDeferWindowPos(layout->nColumns * layout->nRows); - ALFColor bgcolor = (ALFColor)SendMessage(window, ALF_WM_GETBGCOLOR, 0, 0); - ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, c) { int col = c->x; int row = c->y; @@ -415,7 +414,7 @@ ALF_Layout_Apply(ALFLayout* layout, HWND window) flags |= SWP_NOCOPYBITS; // transparent background: invalidate if widget moved - if (bgcolor == ALF_COLOR_TRANSPARENT) { + if (layout->bgcolor == ALF_COLOR_TRANSPARENT) { RECT oldR; GetWindowRect(c->hwnd, &oldR); MapWindowRect(NULL, window, &oldR); @@ -457,10 +456,10 @@ ALF_Layout_AddWidget(ALFLayout* layout, HWND window, const ALFAddWidgetParams* p SetParent(w->hwnd, window); if (w->flags & ALF_LAYOUT_INHERITFONT) { - ALF_Layout_ForwardFontToWidget(layout, window, w, (HFONT)SendMessage(window, WM_GETFONT, 0, 0), 0); + ALF_Layout_ForwardFontToWidget(layout, window, w, layout->font, 0); } if (w->flags & ALF_LAYOUT_INHERITBGCOLOR) { - SendMessage(w->hwnd, ALF_WM_SETBGCOLOR, 0, (LPARAM)ALF_BackgroundColor(window)); + SendMessage(w->hwnd, ALF_WM_SETBGCOLOR, 0, (LPARAM)layout->bgcolor); } if (w->flags & ALF_LAYOUT_SENDDPICHANGE) { SendMessage(w->hwnd, ALF_WM_DPICHANGE, 0, (LPARAM)layout->dpi); @@ -617,9 +616,9 @@ ALF_Layout_SetWidgetFlags(ALFLayout *layout, HWND window, HWND needle, DWORD fla w->flags = flags; if (flags & ALF_LAYOUT_INHERITFONT) - ALF_Layout_ForwardFontToWidget(layout, window, w, (HFONT)SendMessage(window, WM_GETFONT, 0, 0), 0); + ALF_Layout_ForwardFontToWidget(layout, window, w, layout->font, 0); if (flags & ALF_LAYOUT_INHERITBGCOLOR) - SendMessage(w->hwnd, ALF_WM_SETBGCOLOR, 0, (LPARAM)ALF_BackgroundColor(window)); + SendMessage(w->hwnd, ALF_WM_SETBGCOLOR, 0, (LPARAM)layout->bgcolor); if (flags & ALF_LAYOUT_SENDDPICHANGE) SendMessage(w->hwnd, ALF_WM_DPICHANGE, 0, (LPARAM)layout->dpi); @@ -797,17 +796,42 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam, } if (msg == WM_SETFONT) { + *pRet = 1; + if (layout->font == (HFONT)wparam) + return TRUE; + + layout->font = (HFONT)wparam; ALF_Layout_ForwardFont(layout, hwnd, (HFONT)wparam, lparam); return TRUE; } + if (msg == WM_GETFONT) { + *pRet = (LRESULT)layout->font; + return TRUE; + } + if (msg == ALF_WM_SETBGCOLOR) { + *pRet = 1; + if (layout->bgcolor == (ALFColor)lparam) + return TRUE; + + layout->bgcolor = (ALFColor)lparam; ALF_Layout_ForwardBgColor(layout, hwnd, wparam, lparam); ALF_Layout_HandleBackgroundChange(layout, hwnd); + InvalidateRect(hwnd, NULL, TRUE); + return TRUE; + } + + if (msg == ALF_WM_GETBGCOLOR) { + *pRet = (LRESULT)layout->bgcolor; return TRUE; } if (msg == ALF_WM_BACKGROUNDCHANGE) { + if (layout->bgcolor != ALF_COLOR_TRANSPARENT) + return TRUE; // solid bg -> nothing to do + + InvalidateRect(hwnd, NULL, TRUE); ALF_Layout_HandleBackgroundChange(layout, hwnd); return TRUE; } @@ -823,7 +847,8 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam, } if (msg == ALF_WM_GETDPI) { - return (LRESULT)layout->dpi; + *pRet = (LRESULT)layout->dpi; + return TRUE; } if (msg == ALF_WM_INVALIDATELAYOUT) { |
