From 65d9985bdcaed63b52bfe8c35c61d8a4a43a8292 Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Tue, 28 Apr 2020 10:57:22 +0200 Subject: first try at checkbox The size calculation is really messy and the background stuff does not work with comctl v5. Probably need to go full owner-drawn, again. --- alf/alflayout.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'alf/alflayout.cpp') diff --git a/alf/alflayout.cpp b/alf/alflayout.cpp index 2e56886..6c5326d 100644 --- a/alf/alflayout.cpp +++ b/alf/alflayout.cpp @@ -101,8 +101,15 @@ ALF_Layout_ForwardFontToWidget(ALFLayout *layout, HWND window, ALFWidgetPriv *wi if (widget->flags & ALF_LAYOUT_INHERITFONT) { SendMessage(widget->hwnd, WM_SETFONT, (WPARAM)font, redraw); - if (widget->flags & ALF_LAYOUT_SIZE_EDIT) - ALF_Layout_Invalidate(layout, window); + switch (widget->flags & ALF_LAYOUT_SIZETYPE_MASK) { + case ALF_LAYOUT_SIZE_EDIT: + case ALF_LAYOUT_SIZE_CHECKBOX: + ALF_Layout_Invalidate(layout, window); + break; + default: + // do nothing + break; + } } } @@ -205,6 +212,42 @@ ALF_Layout_CalcEditSize(HWND hwndWindow, ALFLayout *layout, HWND hwndEdit, SIZE ReleaseDC(hwndEdit, hDc); } +static void +ALF_Layout_CalcCheckboxSize(HWND hwndWindow, ALFLayout *layout, HWND hwndCheckbox, SIZE *ps) +{ + (void)hwndWindow; + + int checkwidth = 12 * layout->dpi / 96 + 1; + + HDC hDC = GetDC(hwndCheckbox); + HFONT font = (HFONT)SendMessage(hwndCheckbox, WM_GETFONT, 0, 0); + HFONT oldfont = SelectFont(hDC, font); + + RECT r = { 0, 0, 10, 10 }; + + TCHAR *textbuf = ALF_Text(hwndCheckbox); + DrawText(hDC, textbuf, -1, &r, DT_CALCRECT); + ALF_Free(textbuf); + + if (!ps->cx) { + // lol + int cw = 0; + GetCharWidth(hDC, '0', '0', &cw); + + ps->cx = checkwidth + r.right - r.left + cw; + } + + if (!ps->cy) { + int height = r.bottom - r.top; + if (checkwidth > height) + height = checkwidth; + ps->cy = height; + } + + SelectFont(hDC, oldfont); + ReleaseDC(hwndCheckbox, hDC); +} + static void ALF_Layout_CalcMinWidgetSize(ALFLayout *layout, ALFWidgetPriv *c, HWND window, SIZE *s) { @@ -225,6 +268,10 @@ ALF_Layout_CalcMinWidgetSize(ALFLayout *layout, ALFWidgetPriv *c, HWND window, S break; case ALF_LAYOUT_SIZE_EDIT: ALF_Layout_CalcEditSize(window, layout, c->hwnd, s); + break; + case ALF_LAYOUT_SIZE_CHECKBOX: + ALF_Layout_CalcCheckboxSize(window, layout, c->hwnd, s); + break; default: // FIXME! unimplemented break; -- cgit v1.2.3