diff options
Diffstat (limited to 'alf/alfedit.cpp')
| -rw-r--r-- | alf/alfedit.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/alf/alfedit.cpp b/alf/alfedit.cpp new file mode 100644 index 0000000..65f14c8 --- /dev/null +++ b/alf/alfedit.cpp @@ -0,0 +1,76 @@ +#include "alfpriv.h" + +/* EDIT */ +static LRESULT CALLBACK +ALF__EditSubclassProc(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); + + if (font) { + HFONT oldfont = SelectFont(hDc, font); + + TEXTMETRIC tm; + ZeroMemory(&tm, sizeof(tm)); + + if (GetTextMetrics(hDc, &tm)) { + SIZE *ps = (SIZE*)lParam; + if (!ps->cx) { + ps->cx = ALF_CentipointsToPixels(GetParent(hwnd), 12000); + } + + if (!ps->cy) { + ps->cy = tm.tmHeight + 6; // FIXME! use system metrics + } + } + + SelectFont(hDc, oldfont); + } + + ReleaseDC(hwnd, hDc); + return 0; + } + + return app->compatFn->DefSubclassProc(hwnd, uMsg, wParam, lParam); +} + +HWND +ALF_AddEdit(HWND win, WORD id, UINT x, UINT y, const WCHAR *text) +{ + HWND hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, + L"EDIT", + text, + WS_CHILD | WS_VISIBLE | WS_TABSTOP, + 0, 0, 100, 100, + win, + (HMENU)(int)id, + (HINSTANCE)GetWindowLongPtr(win, GWLP_HINSTANCE), + NULL); + + ALFAPP app = ALF_ApplicationFromWindow(win); + + app->compatFn->SetWindowSubclass(hwndEdit, ALF__EditSubclassProc, 0, (DWORD_PTR)app); + SetWindowPos(hwndEdit, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED); + + ALFAddWidgetParams p; + ZeroMemory(&p, sizeof(p)); + p.hwnd = hwndEdit; + p.x = x; + p.y = y; + p.width = 0; + p.height = 0; + p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT; + p.margins[0] = 75; // TODO: pixel-perfect margin from system metrics + p.margins[2] = 75; + + ALF_AddWidgetEx(win, &p); + + return hwndEdit; +} + |
