Mercurial > dwindows
changeset 1055:140d04226c86
Added dw_font_choose() on OS/2 for 2.1.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 02 Jun 2011 10:56:16 +0000 |
parents | 818698b4a0df |
children | 240bd5fb8453 |
files | dw.def os2/dw.c |
diffstat | 2 files changed, 58 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/dw.def Thu Jun 02 10:12:08 2011 +0000 +++ b/dw.def Thu Jun 02 10:56:16 2011 +0000 @@ -236,6 +236,7 @@ dw_tree_get_parent @382 dw_font_text_extents_get @385 + dw_font_choose @386 dw_slider_new @390 dw_slider_get_pos @391
--- a/os2/dw.c Thu Jun 02 10:12:08 2011 +0000 +++ b/os2/dw.c Thu Jun 02 10:56:16 2011 +0000 @@ -4073,6 +4073,63 @@ WinSetParent(handle, blah ? blah : newparent, TRUE); } +/* Allows the user to choose a font using the system's font chooser dialog. + * Parameters: + * currfont: current font + * Returns: + * A malloced buffer with the selected font or NULL on error. + */ +char * API dw_font_choose(char *currfont) +{ + FONTDLG fd = { 0 }; + char *buf = calloc(1,100); + int size = 9; + + /* Fill in the family name if possible */ + if(currfont) + { + char *name = strchr(currfont, "."); + if(name) + { + int newsize = atoi(currfont); + if(newsize > 0) + size = newsize; + name++; + strcpy(buf, name); + strcpy(fd.fAttrs.szFacename, name); + } + else + { + strcpy(buf, currfont); + strcpy(fd.fAttrs.szFacename, currfont); + } + } + + /* Fill in the font dialog struct */ + fd.cbSize = sizeof(fd); + fd.hpsScreen = WinGetScreenPS(HWND_DESKTOP); + fd.pszTitle = "Choose Font"; + fd.clrFore = CLR_BLACK; + fd.clrBack = CLR_WHITE; + fd.pszFamilyname = buf; + fd.usFamilyBufLen = 100; + fd.fxPointSize = MAKEFIXED(size,0); + fd.fl = FNTS_INITFROMFATTRS; + + /* Show the dialog and wait for a response */ + if(!WinFontDlg(HWND_DESKTOP, HWND_OBJECT, &fd) || fd.lReturn != DID_OK) + { + WinReleasePS(fd.hpsScreen); + free(buf); + return NULL; + } + WinReleasePS(fd.hpsScreen); + /* Figure out what the user selected and return that */ + size = FIXEDINT(fd.fxPointSize); + sprintf(buf, "%d.%s", size, fd.fAttrs.szFacename); + return buf; +} + /* * Sets the font used by a specified window (widget) handle. * Parameters: