From d81b3653964fe00e2084a12f240b41ea09cab5fe Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 17 Jun 2018 21:22:57 -0400 Subject: [PATCH] More edit control stuff. We've almost got it, but it's too wide and the text is still aligned wrong. --- windows/tableevents.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/windows/tableevents.cpp b/windows/tableevents.cpp index cceb1598..ac043fd1 100644 --- a/windows/tableevents.cpp +++ b/windows/tableevents.cpp @@ -76,7 +76,7 @@ static HRESULT openEditControl(uiTable *t, int iItem, int iSubItem, uiprivTableC return E_FAIL; } uiprivFree(wstr); - // TODO set font here + SendMessageW(t->edit, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE); // and this is what the real list view does to size the edit control SendMessageW(t->edit, EM_GETRECT, 0, (LPARAM) (&r)); @@ -85,10 +85,42 @@ static HRESULT openEditControl(uiTable *t, int iItem, int iSubItem, uiprivTableC // TODO check error InflateRect(&subitemLabel, xInflate, yInflate); + // TODO rewrite and integrate the variables of this; I'm not fully comfortable keeping it as it is + // TODO check errors everywhere + { + HDC dc; + HFONT prevFont; + RECT textRect, editRect; + int cxIconSpacing; + LONG offsetY; + + // yes, the list view control uses the list view DC for this + dc = GetDC(t->hwnd); + prevFont = (HFONT) SelectObject(dc, hMessageFont); + ZeroMemory(&textRect, sizeof (RECT)); + cxIconSpacing = GetSystemMetrics(SM_CXICONSPACING); + textRect.right = cxIconSpacing - 2 * GetSystemMetrics(SM_CXEDGE); + // yes, the real edit control uses DT_CENTER for some reason + // TODO the real edit control filters out certain types of characters but I'm not sure what + DrawTextW(dc, wstr, -1, &textRect, DT_CENTER | DT_NOPREFIX | DT_SINGLELINE | DT_EDITCONTROL | DT_CALCRECT); + ReleaseDC(t->hwnd, dc); + if (textRect.right < cxIconSpacing / 4) + textRect.right = cxIconSpacing / 4; + offsetY = subitemLabel.top + ((textRect.bottom - textRect.top) - (subitemLabel.bottom - subitemLabel.top)) / 2; + OffsetRect(&textRect, subitemLabel.left, offsetY); + textRect.right += 4 * GetSystemMetrics(SM_CXEDGE) + GetSystemMetrics(SM_CYEDGE); + SendMessageW(t->edit, EM_GETRECT, 0, (LPARAM) (&editRect)); + editRect.left = -editRect.left; + editRect.top = -editRect.top; + AdjustWindowRectEx(&editRect, getStyle(t->edit), FALSE, getExStyle(t->edit)); + r = textRect; + InflateRect(&r, -editRect.left, -editRect.top); + } + // TODO check error or use the right function SetWindowPos(t->edit, NULL, - subitemLabel.left, subitemLabel.top, - subitemLabel.right - subitemLabel.left, subitemLabel.bottom - subitemLabel.top, + r.left, r.top, + r.right - r.left, r.bottom - r.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER); // TODO get the correct constant from the real list view ShowWindow(t->edit, SW_SHOWDEFAULT);