summaryrefslogtreecommitdiff
path: root/new/util_windows.c
diff options
context:
space:
mode:
Diffstat (limited to 'new/util_windows.c')
-rw-r--r--new/util_windows.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/new/util_windows.c b/new/util_windows.c
index 6292967..39bffc3 100644
--- a/new/util_windows.c
+++ b/new/util_windows.c
@@ -70,3 +70,32 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *
*/ }
return FALSE;
}
+
+// TODO add function names
+void resize(uiControl *control, HWND parent, RECT r)
+{
+ uiSizing d;
+ HDC dc;
+ HFONT prevFont;
+ TEXTMETRICW tm;
+ SIZE size;
+
+ dc = GetDC(parent);
+ if (dc == NULL)
+ logLastError("error getting DC for preferred size calculations");
+ prevFont = (HFONT) SelectObject(dc, hMessageFont);
+ if (prevFont == NULL)
+ logLastError("error loading control font into device context for preferred size calculation");
+ if (GetTextMetricsW(dc, &tm) == 0)
+ logLastError("error getting text metrics for preferred size calculations");
+ if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0)
+ logLastError("error getting text extent point for preferred size calculations");
+ d.baseX = (int) ((size.cx / 26 + 1) / 2);
+ d.baseY = (int) tm.tmHeight;
+ d.internalLeading = tm.tmInternalLeading;
+ if (SelectObject(dc, prevFont) != hMessageFont)
+ logLastError("error restoring previous font into device context after preferred size calculations");
+ if (ReleaseDC(parent, dc) == 0)
+ logLastError("error releasing DC for preferred size calculations");
+ (*(control->resize))(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d);
+}