|
||||
![]() |
You surely want to let the user specify a font
list within an application's resource file. This way the user doesn't get
stuck with your set of fonts you've once selected for rendering a XmString.
On the previous page I've showed how to obtain a default font list. But such a font list only contains one fixed font. If you want to get a font list from the application's resource file you have to follow these guidelines:
char *ResourceItem;
XmFontList MyFontList;
Widget MyWidget;
...
static char *LoadStringResource(Widget w,
char *ResourceName,
char *ResourceClass,
char *Default)
{
XtResource Resources[] = {
{ NULL, NULL, XtRString, sizeof(String),
0, XtRString, NULL }
};
String TheString;
char *TempClassName;
Resources[0].resource_name = ResourceName;
if ( ResourceClass )
Resources[0].resource_class = ResourceClass;
else {
TempClassName = XtNewString(ResourceName);
TempClassName[0] = toupper(TempClassName[0]);
Resources[0].resource_class = TempClassName;
}
XtGetApplicationResources(w,
(XtPointer) &TheString,
Resources, XtNumber(Resources),
NULL, 0);
if ( ResourceClass == NULL ) XtFree(TempClassName);
return TheString ? TheString : Default;
} /* LoadStringResource */
...
MyWidget = ...
...
ResourceFontList = LoadStringResource(MyWidget, "fontList",
"FontList", NULL);
If such an entry can be found in the resource database then the variable
ResourceFontList contains the respective ASCII text. The utility
function LoadStringResource() allows one to access the database
easily. You'll also find it in my ButtonFace Library.
if ( ResourceFontList ) {
XrmValue from, to;
from.addr = (XtPointer) ResourceFontList;
from.size = strlen(ResourceFontList) + 1;
to.addr = NULL;
XtConvert(MyWidget, XmRString, &from, XmRFontList, &to);
if ( to.addr )
MyFontList = *((XmFontList *) to.addr);
}
The MyWidget is needed not only for the database look-up in order
to decide which item in the widget hierarchy should be queried but also
for the conversion process. The String-to-XmFontList converter creates
the font list on behalf of the widget specified. Thus the font list can
be destroyed later together with that particular widget.
Contents: Harald Albrecht (albrecht@igpm.rwth-aachen.de) Layout: Harald Albrecht Last Change: 97/08/10 (ab) |