summaryrefslogtreecommitdiff
path: root/alf/alfbutton.cpp
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2018-12-27 20:50:39 +0100
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2018-12-27 20:50:39 +0100
commitb0b0e97aa5a06b22768bb9c9ea5e8caf383d78a4 (patch)
tree8432ca1d8bf811bc7de6240e5988fb84e35b1f40 /alf/alfbutton.cpp
parent64b6b40ace30693f0e12d56799abc40c997df07c (diff)
split into multiple files
Diffstat (limited to 'alf/alfbutton.cpp')
-rw-r--r--alf/alfbutton.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/alf/alfbutton.cpp b/alf/alfbutton.cpp
new file mode 100644
index 0000000..079da75
--- /dev/null
+++ b/alf/alfbutton.cpp
@@ -0,0 +1,95 @@
+#include "alfpriv.h"
+
+/* BUTTON */
+static LRESULT CALLBACK
+ALF__ButtonSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
+{
+ (void)uIdSubclass;
+ (void)dwRefData;
+
+ ALFAPP app = (ALFAPP)dwRefData;
+
+ if (uMsg == ALF_WM_QUERYSIZE) {
+ HDC hdc = GetDC(hwnd);
+ HFONT font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
+ HFONT oldFont = 0;
+ if (font)
+ oldFont = SelectFont(hdc, font);
+
+ // calc drawtext style
+ DWORD style = GetWindowLong(hwnd, GWL_STYLE);
+ UINT format = DT_LEFT | DT_EXPANDTABS | DT_CALCRECT;
+ if ((style & BS_MULTILINE) == 0)
+ format |= DT_SINGLELINE;
+
+ RECT r = { 0, 0, 100, 100 };
+
+ int textlen = GetWindowTextLength(hwnd);
+ TCHAR *textbuf = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, (textlen + 1)*sizeof(TCHAR));
+ GetWindowText(hwnd, textbuf, textlen+1);
+
+ DrawText(hdc, textbuf, -1, &r, format);
+
+ HeapFree(GetProcessHeap(), 0, textbuf);
+
+ // TODO: calculate from system metrics
+ int padding = ALF_CentipointsToPixels(GetParent(hwnd), 525);
+
+ SIZE *pSize = (SIZE*)(void*)lParam;
+ if (pSize->cx < r.right - r.left + padding) {
+ pSize->cx = r.right - r.left + padding;
+ }
+ if (pSize->cy < r.bottom - r.top + padding) {
+ pSize->cy = r.bottom - r.top + padding;
+ }
+ if (pSize->cx < pSize->cy) {
+ pSize->cx = pSize->cy;
+ }
+
+ if (font)
+ SelectFont(hdc, oldFont);
+
+ ReleaseDC(hwnd, hdc);
+ }
+
+ return app->compatFn->DefSubclassProc(hwnd, uMsg, wParam, lParam);
+}
+
+HWND
+ALF_AddButton(HWND win, WORD id, UINT x, UINT y, const WCHAR *text)
+{
+ HWND hwndButton = CreateWindowEx(0,
+ L"BUTTON",
+ text,
+ WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE,
+ 0, 0, 100, 100,
+ win,
+ (HMENU)(int)id,
+ (HINSTANCE)GetWindowLongPtr(win, GWLP_HINSTANCE),
+ NULL);
+
+ ALFAPP app = ALF_ApplicationFromWindow(win);
+
+ app->compatFn->SetWindowSubclass(hwndButton, ALF__ButtonSubclassProc, 0, (DWORD_PTR)app);
+
+ ALFAddWidgetParams p;
+ ZeroMemory(&p, sizeof(p));
+ p.hwnd = hwndButton;
+ p.x = x;
+ p.y = y;
+ p.width = 5625;
+ p.height = 0;
+ p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT;
+
+ ALF_AddWidgetEx(win, &p);
+
+ return hwndButton;
+}
+
+
+void
+ALF_SetDefaultButton(HWND win, WORD id)
+{
+ SendMessage(win, DM_SETDEFID, (WPARAM)id, 0);
+}
+