diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-23 15:07:21 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-23 15:07:21 +0200 |
| commit | 51daba89072cb66fe5e43015484a554555a40499 (patch) | |
| tree | 372502daebee3c3f3b2cfa68047e03f164f3d95c /alf/alfwindow.cpp | |
| parent | d17d8f49777d802b56aa332077afbfa83af691e1 (diff) | |
changed DPI handling: dpi is now pushed into every control and saved there
Diffstat (limited to 'alf/alfwindow.cpp')
| -rw-r--r-- | alf/alfwindow.cpp | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/alf/alfwindow.cpp b/alf/alfwindow.cpp index c11fede..d372ebc 100644 --- a/alf/alfwindow.cpp +++ b/alf/alfwindow.cpp @@ -3,12 +3,12 @@ typedef struct { ALFWindowVTable *vtbl; void *closure; - ALFWindowFonts fonts; int modalResult; ALFLayout layout; WORD defid; HWND hwndFocus; HFONT font; + HFONT hMessageFont; ALFColor bgcolor; } ALFWindowPriv; @@ -30,8 +30,8 @@ ALF_DestroyWindowPriv(ALFWindowPriv *priv) ALF_Layout_Clear(&priv->layout); - if (priv->fonts.hMessageFont) - DeleteObject(priv->fonts.hMessageFont); + if (priv->hMessageFont) + DeleteObject(priv->hMessageFont); ALF_Free(priv); } @@ -39,39 +39,34 @@ ALF_DestroyWindowPriv(ALFWindowPriv *priv) static void ALF_UpdateFontsPriv(HWND win, ALFWindowPriv *priv) { - priv->fonts.dpi = ALF_Compat_GetDpiForWindow(win); - // XXX: SystemParametersInfoForDpi is Unicode-only and needs Vista+ NONCLIENTMETRICS, ALF_NONCLIENTMETRICSW_VISTA ncm; ZeroMemory(&ncm, sizeof(ncm)); ncm.cbSize = sizeof(ncm); - if (ALF_Compat_SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0, priv->fonts.dpi)) { + LOGFONT lfMessageFont; + ZeroMemory(&lfMessageFont, sizeof(lfMessageFont)); + + if (ALF_Compat_SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0, (UINT)priv->layout.dpi)) { #ifdef UNICODE - priv->fonts.lfMessageFont = ncm.lfMessageFont; + lfMessageFont = ncm.lfMessageFont; #else - ALF_Compat_LogFontWtoA(&ncm.lfMessageFont, &priv->fonts.lfMessageFont); + ALF_Compat_LogFontWtoA(&ncm.lfMessageFont, &lfMessageFont); #endif } else { // FIXME! fallback to default font, 8pt MS Shell Dlg - ZeroMemory(&priv->fonts.lfMessageFont, sizeof(priv->fonts.lfMessageFont)); + ZeroMemory(&lfMessageFont, sizeof(lfMessageFont)); - priv->fonts.lfMessageFont.lfHeight = -MulDiv(8, (int)priv->fonts.dpi, 72); - lstrcpy(priv->fonts.lfMessageFont.lfFaceName, TEXT("MS Shell Dlg")); + lfMessageFont.lfHeight = -MulDiv(8, priv->layout.dpi, 72); + lstrcpy(lfMessageFont.lfFaceName, TEXT("MS Shell Dlg")); } - if (priv->fonts.hMessageFont) { - DeleteObject(priv->fonts.hMessageFont); + if (priv->hMessageFont) { + DeleteObject(priv->hMessageFont); } - priv->fonts.hMessageFont = CreateFontIndirect(&priv->fonts.lfMessageFont); - - SendMessage(win, WM_SETFONT, (WPARAM)priv->fonts.hMessageFont, (LPARAM)1); -} + priv->hMessageFont = CreateFontIndirect(&lfMessageFont); -static int -ALF_CentipointsToPxPriv(ALFWindowPriv *priv, int cptValue) -{ - return MulDiv(cptValue, (int)priv->fonts.dpi, 7200); + SendMessage(win, WM_SETFONT, (WPARAM)priv->hMessageFont, (LPARAM)1); } static void @@ -173,8 +168,8 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) return 0; } - if (msg == ALF_WM_CENTIPOINTTOPX) { - return (LRESULT)ALF_CentipointsToPxPriv(priv, (int)wparam); + if (msg == ALF_WM_GETDPI) { + return (LRESULT)priv->layout.dpi; } if (msg == ALF_WM_SETFOCUS) { @@ -327,7 +322,7 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) (DWORD)GetWindowLong(hwnd, GWL_STYLE), GetMenu(hwnd) != NULL, (DWORD)GetWindowLong(hwnd, GWL_EXSTYLE), - priv->fonts.dpi)) { + (UINT)priv->layout.dpi)) { MINMAXINFO *i = (MINMAXINFO *)lparam; i->ptMinTrackSize.x = tmp.right - tmp.left; i->ptMinTrackSize.y = tmp.bottom - tmp.top; @@ -336,7 +331,9 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } if (msg == WM_CREATE) { - ALF_UpdateFontsPriv(hwnd, priv); + int dpi = (int)ALF_Compat_GetDpiForWindow(hwnd); + SendMessage(hwnd, ALF_WM_DPICHANGE, 0, (LPARAM)dpi); // will also update fonts + if (priv->vtbl->create) { priv->vtbl->create(priv->closure, hwnd); } @@ -366,8 +363,9 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } if (msg == WM_DPICHANGED) { - ALF_UpdateFontsPriv(hwnd, priv); - ALF_Layout_Invalidate(&priv->layout, hwnd); + int dpi = LOWORD(wparam); + SendMessage(hwnd, ALF_WM_DPICHANGE, 0, (LPARAM)dpi); // will also update fonts and invalidate layout + RECT *r = (RECT*)lparam; SetWindowPos(hwnd, NULL, r->left, r->top, r->right-r->left, r->bottom-r->top, SWP_NOACTIVATE|SWP_NOZORDER); } @@ -428,6 +426,10 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } } + if (msg == ALF_WM_DPICHANGE) { + ALF_UpdateFontsPriv(hwnd, priv); + } + return ret; } |
