styles : font_table (iso_latin1 = normal,
iso_cyrillic = russian,
character_set('latin1−bold') = bold);
object root : XmLabel {
arguments {
XmNlabelString = album & " : " & artist & " − " & title;
XmNfontList = styles;
};
};
end module;
The module begins with the definition of three strings, each with a different character set. Two of the character sets
are built−in and one is user−defined. The built−in ones represent two different languages, while the user−defined
character set represents both a language and a font style. The characters in the second string are shown in their
decimal form, as we are unable to print the corresponding characters in this book. You could enter the actual
characters directly with a Cyrillic editor, as they are not control characters. We've specified the character sets
explicitly because we are using more than one language and don't want to worry about the setting of the LANG
environment variable.
The font definitions for the text come next. We define three fonts, one for each string. Each font is defined using an
XLFD font name. We combine the fonts in the styles font list definition, which is where we establish the
connection between the character sets used by the strings and the fonts. The character set names in the compound
string definitions must match the character set names used in the font_table. Finally, we define a Label that
displays the concatenated string. The output of this module is shown in the figure.
User interface of joel.uil
In early releases of Motif 1.2, the user−defined character set in the font list definition may cause a compilation error,
or it may cause the UIL compiler to crash. You can work around this problem by specifying the font list in an X
resource file. In this case, you must specify the character set names of the built−in character sets using the names
shown in the second column of The proper resource specification for this module is:
Demos*XmLabel.fontList: *fixed−medium−r−normal−*−*−140−*−iso8859−1=ISO8859−1, *fixed−medium−r−normal−*−*−140−*−iso8859−5=ISO8859−5, *fixed−bold−r−normal−*−*−140−*−iso8859−1=latin1−bold
The name of the user−defined character set is the same as the name we used in the module. In general, placing font list
definitions in an app−defaults file is a good idea anyway, since it lets the users of an application customize the font
settings.
25.3.5 Colors
The UIL compiler supports color values, which means that you can set all of the different Motif color resources in a
UIL module. In addition, UIL color values play an important role in the specification of color pixmaps in UIL. Color
25 Creating a User Interface With UIL 25.3.5 Colors
684
values in UIL can be specified by the name of the color or by the amount of red, green, and blue (RGB) that compose
the color. Both types of color values are easy to define, as shown in the following fragment:
object button : XmPushButton {
arguments {
XmNbackground = color ('wheat');
XmNforeground = rgb (500, 0, 65535); }; }; A named color value is specified with the keyword color followed by a
color name. Mrm converts the color name to the corresponding RGB value at run−time using Xlib. On most UNIX
systems, Xlib converts colors from names to values using the mappings defined in the file /usr/lib/X11/rgb.txt. You
can find more details on this process in Volume Two, Xlib Reference Manual. You specify RGB values with the
keyword rgb and the amount of red, green, and blue present in the color. Each amount can range from 0 to 65535,
which represents 0 to 100 percent of a color.
Like other values, you can assign both color and rgb values to UIL variables, pass them as arguments to callback
functions, and use them to specify resources. If Mrm cannot allocate a color at run−time for setting a resource, the
resource is simply not set, and Mrm prints a warning message by calling XtAppWarning(). If Mrm cannot allocate
a color that you use as a callback argument, your application may crash when the callback is invoked. As a result, you
should avoid passing color arguments from UIL and allocate or fetch colors directly in application code instead.
For the most part, we recommend that you avoid setting color resources in a UIL module because users cannot
override UIL resource settings using a resource file. Color is one of the most frequently customized aspects of an
application, so you should not hard−code color values. However, colors do have their place in UIL. They are still
useful for defining color pixmaps, where you don't have to worry about allowing users to change the colors. Color
values are one of the types that cannot be fetched with MrmFetchLiteral() because Mrm requires a colormap in
which to allocate the color. The MrmFetchColorLiteral() function exists to allow the retrieval of color values.
This function takes the following form:
Cardinal
MrmFetchColorLiteral(hierarchy, name, display, colormap, pixel_return)
MrmHierarchy hierarchy;
String name;
Display *display;
Colormap colormap;
Pixel *pixel_return;
As with MrmFetchLiteral(), the hierarchy and name arguments specify the Mrm hierarchy to search and
the exported color variable to fetch. Mrm allocates the color in the colormap specified by the colormap parameter.
If this argument is NULL, Mrm allocates the color in the colormap returned by the DefaultColormap() macro.
When Mrm successfully fetches the color, the pixel_return argument contains the allocated color, and the
function returns MrmSUCCESS. If Mrm cannot find a variable by the specified name, the routine returns
MrmNOT_FOUND. If Mrm finds a variable with the specified name, but it isn't a color value, the function returns
MrmWRONG_TYPE. The routine can also return MrmBAD_HIERARCHY if the hierarchy argument is invalid or
MrmFAILURE if anything else goes wrong. As usual, you should check the return value against MrmSUCCESS before
testing for a specific failure. If MrmFetchColorLiteral() fails to allocate a color, Mrm should substitute black
or white and print a warning message by calling XtAppWarning(). However, in early releases of Motif 1.2 this
fallback mechanism does not take place, and the function returns MrmNOT_FOUND instead. When you are finished
using a color retrieved with this function, you must free it with a call to XFreeColors().
25 Creating a User Interface With UIL 25.3.5 Colors
685

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.