summaryrefslogtreecommitdiff
path: root/alf/alflayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alf/alflayout.cpp')
-rw-r--r--alf/alflayout.cpp48
1 files changed, 41 insertions, 7 deletions
diff --git a/alf/alflayout.cpp b/alf/alflayout.cpp
index 5c1ad55..15b8f5d 100644
--- a/alf/alflayout.cpp
+++ b/alf/alflayout.cpp
@@ -76,6 +76,7 @@ ALF_Layout_Init(ALFLayout *layout)
layout->rows = ALF_New(ALFLayoutRowOrColumn, (SIZE_T)layout->nRows);
layout->nColumns = 1;
layout->columns = ALF_New(ALFLayoutRowOrColumn, (SIZE_T)layout->nColumns);
+ layout->dpi = 96;
}
void
@@ -127,6 +128,20 @@ ALF_Layout_ForwardBgColor(ALFLayout *layout, HWND window, WPARAM wparam, LPARAM
}
static void
+ALF_Layout_ForwardDpiChange(ALFLayout *layout, HWND window, WPARAM wparam, LPARAM lparam)
+{
+ ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, i) {
+ if (i->flags & ALF_LAYOUT_SENDDPICHANGE) {
+ SendMessage(i->hwnd, ALF_WM_DPICHANGE, wparam, lparam);
+ }
+
+ if (i->flags & ALF_LAYOUT_SIZE_EDIT) {
+ ALF_Layout_Invalidate(layout, window);
+ }
+ }
+}
+
+static void
ALF_Layout_HandleBackgroundChange(ALFLayout *layout, HWND window)
{
(void)window;
@@ -162,7 +177,7 @@ ALF_Layout_EnsureColumnExists(ALFLayout *layout, int colno)
static void
ALF_Layout_CalcEditSize(HWND hwndWindow, ALFLayout *layout, HWND hwndEdit, SIZE *ps)
{
- (void)layout;
+ (void)hwndWindow;
HDC hDc = GetDC(hwndEdit);
HFONT font = (HFONT)SendMessage(hwndEdit, WM_GETFONT, 0, 0);
@@ -174,12 +189,12 @@ ALF_Layout_CalcEditSize(HWND hwndWindow, ALFLayout *layout, HWND hwndEdit, SIZE
if (GetTextMetrics(hDc, &tm)) {
if (!ps->cx) {
- ps->cx = ALF_CentipointsToPixels(hwndWindow, 12000);
+ ps->cx = ALF_CentipointsToPixels(12000, layout->dpi);
}
if (!ps->cy) {
ps->cy = tm.tmHeight + 2*ALF_Compat_GetSystemMetricsForDpi(
- SM_CYEDGE, (UINT)ALF_CentipointsToPixels(hwndWindow, 7200))
+ SM_CYEDGE, (UINT)layout->dpi)
+ 4 /* padding internal to the edit control */;
}
}
@@ -196,8 +211,8 @@ ALF_Layout_CalcMinWidgetSize(ALFLayout *layout, ALFWidgetPriv *c, HWND window, S
s->cx = c->width;
s->cy = c->height;
} else {
- s->cx = ALF_CentipointsToPixels(window, c->width);
- s->cy = ALF_CentipointsToPixels(window, c->height);
+ s->cx = ALF_CentipointsToPixels(c->width, layout->dpi);
+ s->cy = ALF_CentipointsToPixels(c->height, layout->dpi);
}
switch (c->flags & ALF_LAYOUT_SIZETYPE_MASK) {
@@ -224,7 +239,7 @@ ALF_Layout_CalcSizes(ALFLayout* layout, HWND window)
if (layout->columns[i].requestedFlags & ALF_LAYOUT_SIZE_PX) {
layout->columns[i].calculatedMinWidth = layout->columns[i].requestedMinWidth;
} else {
- layout->columns[i].calculatedMinWidth = ALF_CentipointsToPixels(window, layout->columns[i].requestedMinWidth);
+ layout->columns[i].calculatedMinWidth = ALF_CentipointsToPixels(layout->columns[i].requestedMinWidth, layout->dpi);
}
layout->columns[i].calculatedExpandNumerator = layout->columns[i].requestedExpandNumerator;
@@ -239,7 +254,7 @@ ALF_Layout_CalcSizes(ALFLayout* layout, HWND window)
if (layout->rows[i].requestedFlags & ALF_LAYOUT_SIZE_PX) {
layout->rows[i].calculatedMinWidth = layout->rows[i].requestedMinWidth;
} else {
- layout->rows[i].calculatedMinWidth = ALF_CentipointsToPixels(window, layout->rows[i].requestedMinWidth);
+ layout->rows[i].calculatedMinWidth = ALF_CentipointsToPixels(layout->rows[i].requestedMinWidth, layout->dpi);
}
layout->rows[i].calculatedExpandNumerator = layout->rows[i].requestedExpandNumerator;
layout->rowExpandDenominator += layout->rows[i].requestedExpandNumerator;
@@ -447,6 +462,9 @@ ALF_Layout_AddWidget(ALFLayout* layout, HWND window, const ALFAddWidgetParams* p
if (w->flags & ALF_LAYOUT_INHERITBGCOLOR) {
SendMessage(w->hwnd, ALF_WM_SETBGCOLOR, 0, (LPARAM)ALF_BackgroundColor(window));
}
+ if (w->flags & ALF_LAYOUT_SENDDPICHANGE) {
+ SendMessage(w->hwnd, ALF_WM_DPICHANGE, 0, (LPARAM)layout->dpi);
+ }
ALF_ListInsert(layout->widgets.prev, &w->list);
@@ -602,6 +620,8 @@ ALF_Layout_SetWidgetFlags(ALFLayout *layout, HWND window, HWND needle, DWORD fla
ALF_Layout_ForwardFontToWidget(layout, window, w, (HFONT)SendMessage(window, WM_GETFONT, 0, 0), 0);
if (flags & ALF_LAYOUT_INHERITBGCOLOR)
SendMessage(w->hwnd, ALF_WM_SETBGCOLOR, 0, (LPARAM)ALF_BackgroundColor(window));
+ if (flags & ALF_LAYOUT_SENDDPICHANGE)
+ SendMessage(w->hwnd, ALF_WM_DPICHANGE, 0, (LPARAM)layout->dpi);
ALF_Layout_Invalidate(layout, window);
@@ -792,6 +812,20 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam,
return TRUE;
}
+ if (msg == ALF_WM_DPICHANGE) {
+ int dpi = (int)lparam;
+ if (dpi != layout->dpi) {
+ layout->dpi = dpi;
+ ALF_Layout_ForwardDpiChange(layout, hwnd, wparam, lparam);
+ ALF_Layout_Invalidate(layout, hwnd);
+ }
+ return TRUE;
+ }
+
+ if (msg == ALF_WM_GETDPI) {
+ return (LRESULT)layout->dpi;
+ }
+
if (msg == ALF_WM_INVALIDATELAYOUT) {
ALF_Layout_Invalidate(layout, hwnd);
return TRUE;