summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2020-04-23 15:43:55 +0200
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2020-04-23 15:46:02 +0200
commit6280671b1897ac0a47cb7e8f3463d4f60f2490cc (patch)
tree5db441a60096e85444b7f3ef3357f17a9aefb3fd
parent51daba89072cb66fe5e43015484a554555a40499 (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
-rw-r--r--alf/alflayout.cpp41
-rw-r--r--alf/alflayout.h2
-rw-r--r--alf/alfpanel.cpp41
-rw-r--r--alf/alfwindow.cpp40
4 files changed, 39 insertions, 85 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) {
diff --git a/alf/alflayout.h b/alf/alflayout.h
index 4d97eb5..bd966cc 100644
--- a/alf/alflayout.h
+++ b/alf/alflayout.h
@@ -54,6 +54,8 @@ typedef struct {
int biggestRowNo;
DWORD layoutValididityFlags;
int dpi;
+ HFONT font;
+ ALFColor bgcolor;
} ALFLayout;
void
diff --git a/alf/alfpanel.cpp b/alf/alfpanel.cpp
index 663dbd0..965264e 100644
--- a/alf/alfpanel.cpp
+++ b/alf/alfpanel.cpp
@@ -4,8 +4,6 @@ TCHAR *_alf_panelClass = NULL;
typedef struct {
ALFLayout layout;
- ALFColor bgcolor;
- HFONT font;
const ALFPanelVTable *vtbl;
void *closure;
} ALFPanelPriv;
@@ -14,7 +12,6 @@ static void
ALF_Panel_IntializePriv(ALFPanelPriv *priv)
{
ALF_Layout_Init(&priv->layout);
- priv->bgcolor = ALF_COLOR_TRANSPARENT;
}
static void
@@ -28,10 +25,10 @@ ALF_Panel_Paint(ALFPanelPriv *priv, HWND hwnd, HDC dc, RECT *r)
{
if (priv->vtbl && priv->vtbl->paint) {
priv->vtbl->paint(priv->closure, hwnd, dc, r);
- } else if (priv->bgcolor == ALF_COLOR_TRANSPARENT) {
+ } else if (priv->layout.bgcolor == ALF_COLOR_TRANSPARENT) {
ALF_Compat_DrawThemeParentBackground(hwnd, dc, r);
} else {
- ALF_FillRect(dc, r, priv->bgcolor);
+ ALF_FillRect(dc, r, priv->layout.bgcolor);
}
}
@@ -60,31 +57,6 @@ ALF_Panel_DefWindowProc(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);
-
- // fallthrough to layout, will propagate font to children
- }
-
- if (msg == ALF_WM_GETBGCOLOR) {
- return (LRESULT)priv->bgcolor;
- }
-
- if (msg == ALF_WM_SETBGCOLOR) {
- priv->bgcolor = (ALFColor)lparam;
-
- InvalidateRect(window, NULL, TRUE);
-
- // fallthrough to layout, will propagate color to children
- // and invalidate the background of transparent children
- }
-
- if (msg == WM_GETFONT) {
- return (LRESULT)priv->font;
- }
-
if (msg == WM_SETTEXT) {
InvalidateRect(window, NULL, TRUE);
}
@@ -122,15 +94,6 @@ ALF_Panel_DefWindowProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
ALF_Layout_Apply(&priv->layout, window);
}
- if (msg == ALF_WM_BACKGROUNDCHANGE) {
- if (priv->bgcolor != ALF_COLOR_TRANSPARENT)
- return 0; // nothing to do here, background is our own solid color
-
- InvalidateRect(window, NULL, TRUE);
-
- // fallthrough to layout, will propagate to transparent children
- }
-
LRESULT ret = 0;
if (ALF_Layout_HandleMessage(&priv->layout, window, msg, wparam, lparam, &ret))
return ret;
diff --git a/alf/alfwindow.cpp b/alf/alfwindow.cpp
index d372ebc..188f791 100644
--- a/alf/alfwindow.cpp
+++ b/alf/alfwindow.cpp
@@ -7,9 +7,7 @@ typedef struct {
ALFLayout layout;
WORD defid;
HWND hwndFocus;
- HFONT font;
HFONT hMessageFont;
- ALFColor bgcolor;
} ALFWindowPriv;
static void
@@ -18,8 +16,8 @@ ALF_InitializeWindowPriv(HWND hwnd, ALFWindowPriv *priv, void *closure)
priv->vtbl = (ALFWindowVTable*)GetClassLongPtr(hwnd, 0);
priv->closure = closure;
priv->defid = (WORD)-1;
- priv->bgcolor = ALF_COLOR_SYS(COLOR_BTNFACE);
ALF_Layout_Init(&priv->layout);
+ priv->layout.bgcolor = ALF_COLOR_SYS(COLOR_BTNFACE);
}
static void
@@ -151,7 +149,7 @@ ALF_Window_Paint(ALFWindowPriv *priv, HWND hwnd, HDC dc, RECT *r)
if (priv->vtbl && priv->vtbl->paint) {
priv->vtbl->paint(priv->closure, hwnd, dc, r);
} else {
- ALF_FillRect(dc, r, priv->bgcolor);
+ ALF_FillRect(dc, r, priv->layout.bgcolor);
}
}
@@ -183,27 +181,6 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 0;
}
- if (msg == WM_SETFONT) {
- priv->font = (HFONT)wparam;
- if (LOWORD(lparam) != 0)
- InvalidateRect(hwnd, NULL, TRUE);
-
- // fallthrough to layout, will propagate font to children
- }
-
- if (msg == ALF_WM_SETBGCOLOR) {
- priv->bgcolor = (ALFColor)lparam;
-
- InvalidateRect(hwnd, NULL, TRUE);
-
- // fallthrough to layout, will propagate color to children
- // and invalidate the background of transparent children
- }
-
- if (msg == ALF_WM_GETBGCOLOR) {
- return (LRESULT)priv->bgcolor;
- }
-
if (msg == WM_ERASEBKGND) {
return TRUE; // handled in WM_PAINT
}
@@ -227,10 +204,6 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
return 0;
}
- if (msg == WM_GETFONT) {
- return (LRESULT)priv->font;
- }
-
if (msg == ALF_WM_PRETRANSLATEMSG) {
return (LRESULT)ALF_PreTranslateMessagePriv(hwnd, priv, (MSG *)lparam);
}
@@ -377,15 +350,6 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
InvalidateRect(hwnd, NULL, TRUE);
}
- if (msg == ALF_WM_BACKGROUNDCHANGE) {
- if (priv->bgcolor != ALF_COLOR_TRANSPARENT)
- return 0; // nothing to do here, background is our own solid color
-
- InvalidateRect(hwnd, NULL, TRUE);
-
- // fallthrough to layout, will propagate to transparent children
- }
-
if (msg == DM_GETDEFID) {
if (priv->defid == (WORD)-1) {
return 0;