diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-05-25 21:35:28 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-05-25 21:43:48 +0200 |
| commit | a06c7ff02ce50243cd1e4bef8bad25bd1978bcda (patch) | |
| tree | 48c0462afd5a9566ffd44cb54659ecea934e70c1 /alf | |
| parent | d1be0b5dce72a3bc355e915916955b1a9a267c47 (diff) | |
add explicit functions for adding native buttons
Diffstat (limited to 'alf')
| -rw-r--r-- | alf/alf.h | 10 | ||||
| -rw-r--r-- | alf/alflayout.cpp | 43 | ||||
| -rw-r--r-- | alf/alfnativebtn.cpp | 55 |
3 files changed, 108 insertions, 0 deletions
@@ -438,6 +438,16 @@ ALF_AddRadioButton(HWND parent, WORD id, int x, int y, const TCHAR *text); HWND ALF_AddGroupBox(HWND parent, WORD id, int x, int y, const TCHAR *text); +// native buttons +HWND +ALF_AddNativeButton(HWND win, WORD id, int x, int y, const TCHAR *text); + +HWND +ALF_AddNativeCheckbox(HWND parent, WORD id, int x, int y, const TCHAR *text); + +HWND +ALF_AddNativeRadioButton(HWND parent, WORD id, int x, int y, const TCHAR *text); + #ifdef __cplusplus } // extern C #endif diff --git a/alf/alflayout.cpp b/alf/alflayout.cpp index 470f728..974cd78 100644 --- a/alf/alflayout.cpp +++ b/alf/alflayout.cpp @@ -257,6 +257,46 @@ ALF_Layout_CalcCheckboxSize(HWND hwndWindow, ALFLayout *layout, HWND hwndCheckbo } static void +ALF_Layout_CalcButtonSize(HWND hwndWindow, ALFLayout *layout, HWND hwndButton, SIZE *pSize) +{ + (void)hwndWindow; + + HDC hdc = GetDC(hwndButton); + HFONT oldFont = SelectFont(hdc, (HFONT)SendMessage(hwndButton, WM_GETFONT, 0, 0)); + + // calc drawtext style + UINT format = DT_LEFT | DT_EXPANDTABS | DT_CALCRECT; + + if (!(GetWindowLong(hwndButton, GWL_STYLE) & BS_MULTILINE)) + format |= DT_SINGLELINE; + + RECT r = { 0, 0, 0x7FFFFFFF, 100 }; + + TCHAR *textbuf = ALF_Text(hwndButton); + DrawText(hdc, textbuf, -1, &r, format); + ALF_Free(textbuf); + + int xpadding = ALF_Compat_GetSystemMetricsForDpi(SM_CXEDGE, + (UINT)layout->dpi) * 2 + 6; + int ypadding = ALF_Compat_GetSystemMetricsForDpi(SM_CYEDGE, + (UINT)layout->dpi) * 2 + 4; + + if (pSize->cx < r.right - r.left + xpadding) { + pSize->cx = r.right - r.left + xpadding; + } + if (pSize->cy < r.bottom - r.top + ypadding) { + pSize->cy = r.bottom - r.top + ypadding; + } + if (pSize->cx < pSize->cy) { + pSize->cx = pSize->cy; + } + + SelectFont(hdc, oldFont); + + ReleaseDC(hwndButton, hdc); +} + +static void ALF_Layout_CalcMinWidgetSize(ALFLayout *layout, ALFWidgetPriv *c, HWND window, SIZE *s) { if (c->flags & ALF_LAYOUT_SIZE_PX) { @@ -280,6 +320,9 @@ ALF_Layout_CalcMinWidgetSize(ALFLayout *layout, ALFWidgetPriv *c, HWND window, S case ALF_LAYOUT_SIZE_CHECKBOX: ALF_Layout_CalcCheckboxSize(window, layout, c->hwnd, s); break; + case ALF_LAYOUT_SIZE_PUSHBUTTON: + ALF_Layout_CalcButtonSize(window, layout, c->hwnd, s); + break; default: // FIXME! unimplemented break; diff --git a/alf/alfnativebtn.cpp b/alf/alfnativebtn.cpp new file mode 100644 index 0000000..23997b5 --- /dev/null +++ b/alf/alfnativebtn.cpp @@ -0,0 +1,55 @@ +#include "alfpriv.h" + +HWND +ALF_AddNativeButton(HWND win, WORD id, int x, int y, const TCHAR *text) +{ + HWND hwndBtn = CreateWindowEx(0, + TEXT("BUTTON"), + text, + WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_PUSHBUTTON, + 0, 0, 100, 100, + win, + (HMENU)(ULONG_PTR)id, + ALF_HINSTANCE, + NULL); + ALF_AddWidget(win, x, y, hwndBtn, 5625, 1725, ALF_LAYOUT_INHERITFONT | ALF_LAYOUT_TRANSPARENTBG | ALF_LAYOUT_SIZE_PUSHBUTTON); + + return hwndBtn; +} + +HWND +ALF_AddNativeCheckbox(HWND parent, WORD id, int x, int y, const TCHAR *text) +{ + HWND hwnd = CreateWindowEx(0, + TEXT("BUTTON"), + text, + WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, + 0, 0, 100, 100, + parent, + (HMENU)(ULONG_PTR)id, + ALF_HINSTANCE, + NULL); + + ALF_AddWidget(parent, x, y, hwnd, 0, 0, ALF_LAYOUT_SIZE_CHECKBOX | ALF_LAYOUT_INHERITFONT | ALF_LAYOUT_TRANSPARENTBG); + + return hwnd; +} + +HWND +ALF_AddNativeRadioButton(HWND parent, WORD id, int x, int y, const TCHAR *text) +{ + HWND hwnd = CreateWindowEx(0, + TEXT("BUTTON"), + text, + WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON, + 0, 0, 100, 100, + parent, + (HMENU)(ULONG_PTR)id, + ALF_HINSTANCE, + NULL); + + ALF_AddWidget(parent, x, y, hwnd, 0, 0, ALF_LAYOUT_SIZE_CHECKBOX | ALF_LAYOUT_INHERITFONT | ALF_LAYOUT_TRANSPARENTBG); + + return hwnd; +} + |
