2014-08-14 09:42:10 -05:00
|
|
|
// 17 july 2014
|
2014-08-04 18:46:49 -05:00
|
|
|
|
|
|
|
#include "winapi_windows.h"
|
|
|
|
#include "_cgo_export.h"
|
|
|
|
|
2014-10-18 16:03:07 -05:00
|
|
|
RECT containerBounds(HWND hwnd)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
if (GetClientRect(hwnd, &r) == 0)
|
|
|
|
xpanic("error getting container client rect for container.bounds()", GetLastError());
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-08-09 09:26:42 -05:00
|
|
|
void calculateBaseUnits(HWND hwnd, int *baseX, int *baseY, LONG *internalLeading)
|
|
|
|
{
|
|
|
|
HDC dc;
|
|
|
|
HFONT prevFont;
|
|
|
|
TEXTMETRICW tm;
|
2014-08-12 12:10:30 -05:00
|
|
|
SIZE size;
|
2014-08-09 09:26:42 -05:00
|
|
|
|
|
|
|
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());
|
2014-08-12 12:10:30 -05:00
|
|
|
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);
|
2014-08-09 09:26:42 -05:00
|
|
|
*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());
|
|
|
|
}
|