When the user enters new text and presses RETURN or activates the OK button, read_name() is called. This
callback routine gets the XmNuserData from the dialog widget. If the value is 0, the label of the PushButton is reset
using the XmNlabelString resource. Since the callback routine provides the text in compound string format, it is
already in the correct format for the label. If the XmNuserData is 1, then the text describes a color name for the
PushButton.
Rather than converting the string into a color explicitly, we use the XtVaTypedArg feature of XtVaSetValues()
to do the conversion for us. This feature converts a value to the format needed by the specified resource. The
XmNforeground resource takes a variable of type Pixel as a value. The conversion works provided there is an
underlying conversion function to support it. For more information on conversion functions, how to write them, or
how to install your own, see Volume Four, X Toolkit Intrinsics Programming Manual. Motif does not supply a
conversion function to change a compound string into a Pixel value, but there is one for converting a C string into a
Pixel. We convert the compound string into a C string using XmStringGetLtoR() and then set the foreground
color as follows:
XtVaSetValues (push_button,
XtVaTypedArg, XmNforeground,
XmRString, text, strlen (text) + 1,
NULL);
The amount of customization that is possible with the predefined Motif dialogs varies greatly between Motif 1.1 and
Motif 1.2. We've described the possibilities ...