diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-28 14:43:34 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-28 14:43:34 -0400 |
| commit | 13bcf728baf81705ddd09c72991893bffa34b8ae (patch) | |
| tree | 69f3c01b3b88ea979a4e355d00bfdda25a5590c6 /redo/sizing_windows.c | |
| parent | bea4df1abf6f4df34016727a300e4826fc31cc05 (diff) | |
Made the previous commit's changes on Windows. If the Stack Overflow question tells me I'm wrong, we can deal with it then. But yay simple sizing code again :D
Diffstat (limited to 'redo/sizing_windows.c')
| -rw-r--r-- | redo/sizing_windows.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/redo/sizing_windows.c b/redo/sizing_windows.c index 5589ddd..133cbcc 100644 --- a/redo/sizing_windows.c +++ b/redo/sizing_windows.c @@ -3,29 +3,34 @@ #include "winapi_windows.h" #include "_cgo_export.h" -HDC getDC(HWND hwnd) +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) { HDC dc; + HFONT prevFont; + TEXTMETRICW tm; + if (baseUnitsCalculated) + return; dc = GetDC(hwnd); if (dc == NULL) xpanic("error getting DC for preferred size calculations", GetLastError()); - /* TODO save for restoring later */ - if (SelectObject(dc, controlFont) == NULL) + prevFont = (HFONT) SelectObject(dc, controlFont); + if (prevFont == NULL) xpanic("error loading control font into device context for preferred size calculation", GetLastError()); - return dc; -} - -void releaseDC(HWND hwnd, HDC dc) -{ + 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; + 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()); -} - -void getTextMetricsW(HDC dc, TEXTMETRICW *tm) -{ - if (GetTextMetricsW(dc, tm) == 0) - xpanic("error getting text metrics for preferred size calculations", GetLastError()); + baseUnitsCalculated = TRUE; } void moveWindow(HWND hwnd, int x, int y, int width, int height) |
