summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wintable/new/coord.h28
-rw-r--r--wintable/new/draw.h5
-rw-r--r--wintable/new/util.h27
3 files changed, 60 insertions, 0 deletions
diff --git a/wintable/new/coord.h b/wintable/new/coord.h
index 1814e87..fff807d 100644
--- a/wintable/new/coord.h
+++ b/wintable/new/coord.h
@@ -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)
diff --git a/wintable/new/draw.h b/wintable/new/draw.h
index d7c0038..55ffd3c 100644
--- a/wintable/new/draw.h
+++ b/wintable/new/draw.h
@@ -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)
diff --git a/wintable/new/util.h b/wintable/new/util.h
index dc51605..d2f18fb 100644
--- a/wintable/new/util.h
+++ b/wintable/new/util.h
@@ -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)
+}