Readded rowHeight(). Also tested font helper functions.
This commit is contained in:
parent
6271fc941a
commit
59054c8932
|
@ -29,3 +29,31 @@ static BOOL rowColumnToClientCoord(struct table *t, rowcol rc, struct POINT *pt)
|
|||
}
|
||||
|
||||
// TODO idealCoordToRowColumn/rowColumnToIdealCoord?
|
||||
|
||||
// TODO find a better place for this
|
||||
static LONG rowHeight(struct table *t, HDC dc, BOOL select)
|
||||
{
|
||||
BOOL release;
|
||||
HFONT prevfont, newfont;
|
||||
TEXTMETRICW tm;
|
||||
|
||||
release = FALSE;
|
||||
if (dc == NULL) {
|
||||
dc = GetDC(t->hwnd);
|
||||
if (dc == NULL)
|
||||
panic("error getting Table DC for rowHeight()");
|
||||
release = TRUE;
|
||||
}
|
||||
if (select)
|
||||
prevfont = selectFont(t, dc, &newfont);
|
||||
if (GetTextMetricsW(dc, &tm) == 0)
|
||||
panic("error getting text metrics for rowHeight()");
|
||||
if (select)
|
||||
deselectFont(dc, prevfont, newfont);
|
||||
if (release)
|
||||
if (ReleaseDC(t->hwnd, dc) == 0)
|
||||
panic("error releasing Table DC for rowHeight()");
|
||||
return tm.tmHeight;
|
||||
}
|
||||
|
||||
#define rowht(t) rowHeight(t, NULL, TRUE)
|
||||
|
|
|
@ -5,6 +5,7 @@ static void draw(struct table *t, HDC dc, RECT cliprect, RECT client)
|
|||
LRESULT i, n;
|
||||
RECT r;
|
||||
int x = 0;
|
||||
HFONT prevfont, newfont;
|
||||
|
||||
n = SendMessageW(t->header, HDM_GETITEMCOUNT, 0, 0);
|
||||
for (i = 0; i < n; i++) {
|
||||
|
@ -14,6 +15,10 @@ static void draw(struct table *t, HDC dc, RECT cliprect, RECT client)
|
|||
FillRect(dc, &r, GetSysColorBrush(x));
|
||||
x++;
|
||||
}
|
||||
|
||||
prevfont = selectFont(t, dc, &newfont);
|
||||
TextOutW(dc, 100, 100, L"come on", 7);
|
||||
deselectFont(dc, prevfont, newfont);
|
||||
}
|
||||
|
||||
HANDLER(drawHandlers)
|
||||
|
|
|
@ -46,3 +46,30 @@ static void tableFree(void *p, const char *panicMessage)
|
|||
if (LocalFree((HLOCAL) p) != NULL)
|
||||
panic(panicMessage);
|
||||
}
|
||||
|
||||
// font selection
|
||||
|
||||
static HFONT selectFont(struct table *t, HDC dc, HFONT *newfont)
|
||||
{
|
||||
HFONT prevfont;
|
||||
|
||||
// copy it in casse we get a WM_SETFONT before this call's respective deselectFont() call
|
||||
*newfont = t->font;
|
||||
if (*newfont == NULL) {
|
||||
// get it on demand in the (unlikely) event it changes while this Table is alive
|
||||
*newfont = GetStockObject(SYSTEM_FONT);
|
||||
if (*newfont == NULL)
|
||||
panic("error getting default font for selecting into Table DC");
|
||||
}
|
||||
prevfont = (HFONT) SelectObject(dc, *newfont);
|
||||
if (prevfont == NULL)
|
||||
panic("error selecting Table font into Table DC");
|
||||
return prevfont;
|
||||
}
|
||||
|
||||
static void deselectFont(HDC dc, HFONT prevfont, HFONT newfont)
|
||||
{
|
||||
if (SelectObject(dc, prevfont) != newfont)
|
||||
panic("error deselecting Table font from Table DC");
|
||||
// doin't delete newfont here, even if it is the system font (see http://msdn.microsoft.com/en-us/library/windows/desktop/dd144925%28v=vs.85%29.aspx)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue