In Motif 1.1, the first font in widget's font list is the default character set for that widget. If the widget does not have a
font list, it uses a default character set referred to by the constant XmSTRING_DEFAULT_CHARSET. If the user has
set the LANG environment variable, its value is used for this character set. If this value is invalid or its associated font
cannot be used, Motif uses the value of XmFALLBACK_CHARSET, which is vendor−defined but typically set to
"ISO8859−1".
For backwards compatibility, Motif 1.2 essentially equates XmFONTLIST_DEFAULT_TAG with
XmSTRING_DEFAULT_CHARSET when it cannot find an exact match between a compound string and a font list.
XmFONTLIST_DEFAULT_TAG in a compound string or font list matches the tag used in creating a compound string
or specifying a font list entry with the tag XmSTRING_DEFAULT_CHARSET. Some Motif widgets define font list
resources that allow them to provide a consistent appearance for all of their children. In Motif 1.2, the VendorShell
widget defines the XmNbuttonFontList, XmNlabelFontList, and XmNtextFontList resources, while the
MenuShell defines XmNbuttonFontList and XmNlabelFontList. These resources apply to all of the buttons,
Labels, and Text widgets that are descendents of the widget. In Motif 1.1, the VendorShell and MenuShell only
defined the XmNdefaultFontList resource; this resource applied to all of the children of the widget. For
backwards compatibility, if one of the more specific font list resources is not set, its value is taken from
XmNdefaultFontList.
The BulletinBoard widget defines the XmNbuttonFontList, XmNlabelFontList, and XmNtextFontList
resources primarily for use in dialog boxes. These font lists apply to the buttons, Labels, and Text widgets that
descend from a BulletinBoard. For more information on the use of the resources in dialog boxes, see Chapter 5,
Introduction to Dialogs.
All of these font list resources are designed to help you maintain a consistent interface. However, you can always
specify the font for a particular button, Label, or Text widget using the widget's XmNfontList resource, as this
resource overrides the more general ones.
20.2.3 Compound String Segments
A compound string is composed of segments, where each segment contains a continuous sequence of text with no
change in font list tag or direction. A compound string segment can be terminated by a separator, which is the
equivalent of a newline in a character string. Separators in compound strings should not be confused with the
Separator widget and gadget class. Segments can be concatenated with other segments or compound strings to create
longer strings; each segment can specify a different tag and direction to make a string that uses mutiple fonts and
directions.
XmStringSegmentCreate() provides complete control over the creation of a compound string, as it allows you
to specify the text, a font list tag, and a direction. This routine also lets you specify whether or not a separator is added
to the compound string. The routine takes the following form:
XmString
XmStringSegmentCreate(text, tag, direction, separator)
char *text;
char *tag;
XmStringDirection direction;
Boolean separator;
Compound strings are rendered either from left−to−right or from right−to−left. If you are going to use left−to−right
strings uniformly in your applications, you really don't need to read this section. There are several ways to build a
compound string that is rendered from right−to−left; the best method is dependent on the nature of your application.
20 Compound Strings 20.2.3 Compound String Segments
570
If your application uses right−to−left strings for all of its widgets, you may want to use the Manager
XmNstringDirection resource. This resource specifies the direction for compound strings used by widgets that
are immediate children of a Manager widget, provided that the string direction is not hard−coded in the compound
strings. If you use this resource, you can continue to use XmStringCreate() or
XmStringCreateLocalized() to create compound strings.
Most right−to−left languages display certain things, like numbers, from left−to−right, so it is not always possible to
use the XmNstringDirection resource. In this case, you have to create compound string segments that hard−code
their directional information. You can create individual string segments with a specific by direction using either
XmStringDirectionCreate() or XmStringSegmentCreate(). Both of these routines take an argument
of type XmStringDirection, which is defined as an unsigned char. You can specify either
XmSTRING_DIRECTION_R_TO_L or XmSTRING_DIRECTION_ L_TO_R for values of this type.
When using XmStringSegmentCreate(), you specify the string direction using the direction parameter. For
example, we can change the call to XmStringCreate() in the source code to the following:
text = XmStringSegmentCreate ("Testing, testing...", "MY_TAG",
XmSTRING_DIRECTION_R_TO_L, False);
Obviously, you would normally do this only if you were using a font that was meant to be read from right−to−left,
such as Hebrew or Arabic. The output that results from this change is shown in the figure.
Output of string.c using a right−to−left string direction
You can also use the function XmStringDirectionCreate() to create a compound string segment that contains
only directional information. This routine takes the following form:
XmString
XmStringDirectionCreate(direction)
XmStringDirection direction;
The routine returns a compound string segment that can be concatenated with another compound string to cause a
directional change. Separators are used to break compound strings into multiple lines, in much the same way that a
newline character does in a character string. To demonstrate separators, we can change the string creation line in the
source code to the following:
text = XmStringCreateLtoR ("Testing,0esting...", "MY_TAG");
In this case, we use XmStringCreateLtoR() not because we need to specify the left−to−right direction
20 Compound Strings 20.2.3 Compound String Segments
571
explicitly, but because this function interprets embedded newline characters (\n) as separators. The effect of this
change is shown in the figure, where the PushButtons display multiple lines of text.
Output of string.c using separators to render multiple lines
XmStringCreate() and XmStringSegmentCreate() do not interpret newline characters as separators; they
create a single compound string segment in which the '\n' is treated just like any other character value in the
associated font or font set, as shown in the figure. XmStringSegmentCreate(), however, can be told to append
a separator to the compound string it creates.
Output of string.c with \n not interpreted as a separator
Most applications need newline characters to be interpreted as separators. For example, if you are using fgets() or
read() to read the contents of a file, and newlines are read into the buffer, you should use
XmStringCreateLtoR() to convert the buffer into a compound string that contains separators. the source code
shows a function that reads the contents of a file into a buffer and then converts that buffer into a compound string.
XmFONTLIST_DEFAULT_TAG replaces XmSTRING_DEFAULT_CHARSET in Motif 1.2.
XmString
ConvertFileToXmString(filename, &lines)
char *filename;
int *lines;
{
struct stat statb;
int fd, len, lines;
char *text;
XmString str;
*lines = 0;
if (!(fd = open (filename, O_RDONLY))) {
20 Compound Strings 20.2.3 Compound String Segments
572
Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.