summaryrefslogtreecommitdiff
path: root/alf/alflayout.cpp
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2020-04-28 10:57:22 +0200
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2020-04-28 10:57:22 +0200
commit65d9985bdcaed63b52bfe8c35c61d8a4a43a8292 (patch)
tree4ee14cce7d4916b58b7f0683713a8c33066f374e /alf/alflayout.cpp
parent7bc8d9583e0c088c42d5bbf0ecbada77c7cb8bd1 (diff)
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.
Diffstat (limited to 'alf/alflayout.cpp')
-rw-r--r--alf/alflayout.cpp51
1 files changed, 49 insertions, 2 deletions
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;
+ }
}
}
@@ -206,6 +213,42 @@ ALF_Layout_CalcEditSize(HWND hwndWindow, ALFLayout *layout, HWND hwndEdit, SIZE
}
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)
{
if (c->flags & ALF_LAYOUT_SIZE_PX) {
@@ -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;