diff options
Diffstat (limited to 'redo/container_windows.c')
| -rw-r--r-- | redo/container_windows.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/redo/container_windows.c b/redo/container_windows.c index f568440..5f71fe2 100644 --- a/redo/container_windows.c +++ b/redo/container_windows.c @@ -82,3 +82,26 @@ HWND newContainer(void *data) xpanic("container creation failed", GetLastError()); return hwnd; } + +void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY, LONG *internalLeading) +{ + HDC dc; + HFONT prevFont; + TEXTMETRICW tm; + + 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()); + *baseX = (int) tm.tmAveCharWidth; /* TODO not optimal; third reference below has better way */ + *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()); +} |
