Mercurial > dwindows
diff win/dw.c @ 1075:3d117071a50b
Renamed Mac _dw_default_font() to dw_font_set_default() and added it on OS/2 and Windows.
Function added to the public export list... GTK2/3 support will be added shortly.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 26 Jun 2011 02:07:49 +0000 |
parents | 659b3c6a8959 |
children | 34f1d6f5f1c3 |
line wrap: on
line diff
--- a/win/dw.c Sat Jun 25 03:16:40 2011 +0000 +++ b/win/dw.c Sun Jun 26 02:07:49 2011 +0000 @@ -73,6 +73,7 @@ HBRUSH _colors[18]; static int screenx, screeny; +HFONT _DefaultFont = NULL; LRESULT CALLBACK _browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void _resize_notebook_page(HWND handle, int pageid); @@ -4038,6 +4039,18 @@ return lf; } +/* Create a duplicate of an existing font handle + * that is safe to call DeleteObject() on. + */ +HFONT _DupFontHandle(HFONT hfont) +{ + LOGFONT lf = {0}; + return GetObject(hfont, sizeof(lf), &lf) ? CreateFontIndirect(&lf) : NULL; +} + +/* Create a font handle from specified font name.. + * or return a handle to the default font. + */ HFONT _acquire_font(HWND handle, char *fontname) { HFONT hfont = 0; @@ -4047,12 +4060,30 @@ LOGFONT lf = _get_logfont(handle, fontname); hfont = CreateFontIndirect(&lf); } + if(!hfont && _DefaultFont) + hfont = _DupFontHandle(_DefaultFont); if(!hfont) hfont = GetStockObject(DEFAULT_GUI_FONT); return hfont; } /* + * Sets the default font used on text based widgets. + * Parameters: + * fontname: Font name in Dynamic Windows format. + */ +void API dw_font_set_default(char *fontname) +{ + HFONT oldfont = _DefaultFont; + + _DefaultFont = _acquire_font(HWND_DESKTOP, fontname); + if(oldfont) + { + DeleteObject(oldfont); + } +} + +/* * Sets the font used by a specified window (widget) handle. * Parameters: * handle: The window (widget) handle.