diff options
| author | Pietro Gagliardi <[email protected]> | 2015-12-11 20:37:59 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-12-11 20:37:59 -0500 |
| commit | f8e3f12ab02b528f2a05a4f713d7af7ea8e44b42 (patch) | |
| tree | 82dedf4d37f0f6d31e88ebb2ca1ce6499dead261 /prev/container_windows.c | |
| parent | e34c561ed5bedeb180437ec165882b98d70d38c1 (diff) | |
LET'S GET THIS FINAL REWRITE EVER STARTED
Diffstat (limited to 'prev/container_windows.c')
| -rw-r--r-- | prev/container_windows.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/prev/container_windows.c b/prev/container_windows.c new file mode 100644 index 0000000..bbad9ec --- /dev/null +++ b/prev/container_windows.c @@ -0,0 +1,39 @@ +// 17 july 2014 + +#include "winapi_windows.h" +#include "_cgo_export.h" + +RECT containerBounds(HWND hwnd) +{ + RECT r; + + if (GetClientRect(hwnd, &r) == 0) + xpanic("error getting container client rect for container.bounds()", GetLastError()); + return r; +} + +void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY, LONG *internalLeading) +{ + HDC dc; + HFONT prevFont; + TEXTMETRICW tm; + SIZE size; + + dc = GetDC(hwnd); + if (dc == NULL) + xpanic("error getting DC for preferred size calculations", GetLastError()); + prevFont = (HFONT) SelectObject(dc, controlFont); + if (prevFont == NULL) + 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()); + if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0) + xpanic("error getting text extent point for preferred size calculations", GetLastError()); + *baseX = (int) ((size.cx / 26 + 1) / 2); + *baseY = (int) tm.tmHeight; + *internalLeading = tm.tmInternalLeading; + 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()); +} |
