From 91f1a34003d56a5778d1ae48f7d18c3f27eea1ed Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 4 Aug 2014 20:10:23 -0400 Subject: Re-added base units calculation to the resizing code now that container stores a HWND again. --- redo/sizing_windows.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'redo/sizing_windows.c') diff --git a/redo/sizing_windows.c b/redo/sizing_windows.c index 60d57f3..a2cd2cf 100644 --- a/redo/sizing_windows.c +++ b/redo/sizing_windows.c @@ -3,21 +3,14 @@ #include "winapi_windows.h" #include "_cgo_export.h" -/* TODO rename to sizer_windows.c and move all but the first function to control_windows.c */ +/* TODO figure out where these should go */ -BOOL baseUnitsCalculated = FALSE; -int baseX; -int baseY; - -/* called by newWindow() so we can calculate base units when we have a window */ -void calculateBaseUnits(HWND hwnd) +void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY) { HDC dc; HFONT prevFont; TEXTMETRICW tm; - if (baseUnitsCalculated) - return; dc = GetDC(hwnd); if (dc == NULL) xpanic("error getting DC for preferred size calculations", GetLastError()); @@ -26,13 +19,12 @@ void calculateBaseUnits(HWND hwnd) xpanic("error loading control font into device context for preferred size calculation", GetLastError()); if (GetTextMetricsW(dc, &tm) == 0) xpanic("error getting text metrics for preferred size calculations", GetLastError()); - baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */ - baseY = (int) tm.tmHeight; + *baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */ + *baseY = (int) tm.tmHeight; if (SelectObject(dc, prevFont) != controlFont) xpanic("error restoring previous font into device context after preferred size calculations", GetLastError()); if (ReleaseDC(hwnd, dc) == 0) xpanic("error releasing DC for preferred size calculations", GetLastError()); - baseUnitsCalculated = TRUE; } void moveWindow(HWND hwnd, int x, int y, int width, int height) -- cgit v1.2.3