summaryrefslogtreecommitdiff
path: root/wintable/new/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'wintable/new/util.h')
-rw-r--r--wintable/new/util.h27
1 files changed, 27 insertions, 0 deletions
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)
+}