comparison os2/dw.c @ 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 5dbb931bac5a
children 240bd5fb8453
comparison
equal deleted inserted replaced
1054:818698b4a0df 1055:140d04226c86
4071 { 4071 {
4072 HWND blah = WinWindowFromID(newparent, FID_CLIENT); 4072 HWND blah = WinWindowFromID(newparent, FID_CLIENT);
4073 WinSetParent(handle, blah ? blah : newparent, TRUE); 4073 WinSetParent(handle, blah ? blah : newparent, TRUE);
4074 } 4074 }
4075 4075
4076 /* Allows the user to choose a font using the system's font chooser dialog.
4077 * Parameters:
4078 * currfont: current font
4079 * Returns:
4080 * A malloced buffer with the selected font or NULL on error.
4081 */
4082 char * API dw_font_choose(char *currfont)
4083 {
4084 FONTDLG fd = { 0 };
4085 char *buf = calloc(1,100);
4086 int size = 9;
4087
4088 /* Fill in the family name if possible */
4089 if(currfont)
4090 {
4091 char *name = strchr(currfont, ".");
4092 if(name)
4093 {
4094 int newsize = atoi(currfont);
4095 if(newsize > 0)
4096 size = newsize;
4097 name++;
4098 strcpy(buf, name);
4099 strcpy(fd.fAttrs.szFacename, name);
4100 }
4101 else
4102 {
4103 strcpy(buf, currfont);
4104 strcpy(fd.fAttrs.szFacename, currfont);
4105 }
4106 }
4107
4108 /* Fill in the font dialog struct */
4109 fd.cbSize = sizeof(fd);
4110 fd.hpsScreen = WinGetScreenPS(HWND_DESKTOP);
4111 fd.pszTitle = "Choose Font";
4112 fd.clrFore = CLR_BLACK;
4113 fd.clrBack = CLR_WHITE;
4114 fd.pszFamilyname = buf;
4115 fd.usFamilyBufLen = 100;
4116 fd.fxPointSize = MAKEFIXED(size,0);
4117 fd.fl = FNTS_INITFROMFATTRS;
4118
4119 /* Show the dialog and wait for a response */
4120 if(!WinFontDlg(HWND_DESKTOP, HWND_OBJECT, &fd) || fd.lReturn != DID_OK)
4121 {
4122 WinReleasePS(fd.hpsScreen);
4123 free(buf);
4124 return NULL;
4125 }
4126 WinReleasePS(fd.hpsScreen);
4127 /* Figure out what the user selected and return that */
4128 size = FIXEDINT(fd.fxPointSize);
4129 sprintf(buf, "%d.%s", size, fd.fAttrs.szFacename);
4130 return buf;
4131 }
4132
4076 /* 4133 /*
4077 * Sets the font used by a specified window (widget) handle. 4134 * Sets the font used by a specified window (widget) handle.
4078 * Parameters: 4135 * Parameters:
4079 * handle: The window (widget) handle. 4136 * handle: The window (widget) handle.
4080 * fontname: Name and size of the font in the form "size.fontname" 4137 * fontname: Name and size of the font in the form "size.fontname"