From efc5e9c801a43809b3e4bdb644bd57a3f3c4777d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 4 Jun 2015 15:02:19 -0400 Subject: [PATCH] Some TODO resolution and expository comments. --- redo/windows/text.c | 40 ++++++++++++++++++++++++++++++++++++++++ redo/windows/util.c | 39 --------------------------------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/redo/windows/text.c b/redo/windows/text.c index 6cea0c9a..727eb517 100644 --- a/redo/windows/text.c +++ b/redo/windows/text.c @@ -55,3 +55,43 @@ void uiFreeText(char *text) { uiFree(text); } + +intmax_t uiWindowsWindowTextWidth(HWND hwnd) +{ + LRESULT len; + WCHAR *text; + HDC dc; + HFONT prevfont; + SIZE size; + + size.cx = 0; + size.cy = 0; + + // first we need the window text + // this copies what windowText() does because we need the len + // we could replace this with a call to windowText() but then we'd also need a call to wcslen() (or some other function that both this and windowText() would call to do the real work) + len = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); + if (len == 0) // no text; nothing to do + return 0; + text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); + // note the comparison: the size includes the null terminator, but the return does not + if (GetWindowText(hwnd, text, len + 1) != len) + logLastError("error getting window text in uiWindowsWindowTextWidth()"); + + // now we can do the calculations + dc = GetDC(hwnd); + if (dc == NULL) + logLastError("error getting DC in uiWindowsWindowTextWidth()"); + prevfont = (HFONT) SelectObject(dc, hMessageFont); + if (prevfont == NULL) + logLastError("error loading control font into device context in uiWindowsWindowTextWidth()"); + if (GetTextExtentPoint32W(dc, text, len, &size) == 0) + logLastError("error getting text extent point in uiWindowsWindowTextWidth()"); + if (SelectObject(dc, prevfont) != hMessageFont) + logLastError("error restoring previous font into device context in uiWindowsWindowTextWidth()"); + if (ReleaseDC(hwnd, dc) == 0) + logLastError("error releasing DC in uiWindowsWindowTextWidth()"); + uiFree(text); + + return size.cx; +} diff --git a/redo/windows/util.c b/redo/windows/util.c index 9ca6a7d3..eb5a0e30 100644 --- a/redo/windows/util.c +++ b/redo/windows/util.c @@ -1,45 +1,6 @@ // 6 april 2015 #include "uipriv_windows.h" -// TODO move to text.c -intmax_t uiWindowsWindowTextWidth(HWND hwnd) -{ - LRESULT len; - WCHAR *text; - HDC dc; - HFONT prevfont; - SIZE size; - - size.cx = 0; - size.cy = 0; - - // first we need the window text - len = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); - if (len == 0) // no text; nothing to do - return 0; - text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); - // note the comparison: the size includes the null terminator, but the return does not - if (GetWindowText(hwnd, text, len + 1) != len) - logLastError("error getting window text in uiWindowsWindowTextWidth()"); - - // now we can do the calculations - dc = GetDC(hwnd); - if (dc == NULL) - logLastError("error getting DC in uiWindowsWindowTextWidth()"); - prevfont = (HFONT) SelectObject(dc, hMessageFont); - if (prevfont == NULL) - logLastError("error loading control font into device context in uiWindowsWindowTextWidth()"); - if (GetTextExtentPoint32W(dc, text, len, &size) == 0) - logLastError("error getting text extent point in uiWindowsWindowTextWidth()"); - if (SelectObject(dc, prevfont) != hMessageFont) - logLastError("error restoring previous font into device context in uiWindowsWindowTextWidth()"); - if (ReleaseDC(hwnd, dc) == 0) - logLastError("error releasing DC in uiWindowsWindowTextWidth()"); - uiFree(text); - - return size.cx; -} - // this is a helper function that takes the logic of determining window classes and puts it all in one place // there are a number of places where we need to know what window class an arbitrary handle has // theoretically we could use the class atom to avoid a _wcsicmp()