Compound text is the standard format for exchanging textual data between X window system applications. This is necessary when the user moves text displayed in one code set to another window with text in a different code set. For example, the following figure shows two windows: one titled "UJIS" and the other titled "Shift JIS."
Figure 12. Reason for Compound Text.
View figure.
Both windows represent a Motif Text widget, one with some Japanese UJIS characters displayed, and the other with some Shift JIS characters. If the user wants to cut text from one window and paste it in the other window, compound text is used to pass data between the two. The Motif Text widget does this automatically.
If one of the widgets in the previous figure is a Label widget instead of a Text widget, a different situation exists. This is because the Label widget has its text data in compound string format, while the Text widget data is a simple character string. In order to pass text data between a Text or TextField widget and any other widget, the application needs to convert the compound string to compound text.
Motif has two functions, XmCvtXmStringToCT and XmCvtCTToXmString, for converting between compound strings and compound text.
XmCvtXmStringToCT converts a compound string to compound text. The converter uses the font list tag associated with a given compound string text component to select a compound text format for that component. A registry defines a mapping between font list tags and compound text encoding formats. The converter uses the following algorithm for each compound string text component:
An application can use XmRegisterSegmentEncoding to map a font list element tag to a compound text encoding format. For example, the application may be using a font list element tag of "BOLD" to identify a compound text component consisting of localized text to be displayed in a bold font. To ensure that the component is treated as localized text when converted to compound text, the tag "BOLD" should be mapped to XmFONTLIST_DEFAULT_TAG as follows:
char *old_encoding = XmRegisterSegmentEncoding("BOLD", XmFONTLIST_DEFAULT_TAG); XtFree(old_encoding);
The following functions may be used both to convert text in a Motif compound string into the compound text format, and to create Motif compound strings from compound text.
XmCvtCTToXmString converts compound text to a compound string. This function is implementation dependent. There is also the reverse function, called XmCvtXmStringToCT.
The following example uses the compound text format to change a window title to a string in the language of the locale. Of course, the language environment must be properly set, and the strings used must also translate properly into the target language using the locale's code set. This example uses the EUC coding of Japanese, and produces a XmNtitle reading "Information" and a XmNdialogTitle reading "Unsaved Changes." The following example consists of two pieces: a fragment from an X resource file and a piece of C code. First the X resource file fragment:
mwm*renderTable.fontName: -*-fixed-medium-r-normal--*-150-* mwm*renderTable.fontType: XmFONT_IS_FONTSET
and now the C code:
Widget toplevel; Widget dialog; Arg ArgList[10]; int n; Atom atom; XmString compound_string1, compound_string2; char *compound_text; /* Set compound_string1 to "Information" (EUC coding) */ compound_string1 = XmStringCreateLocalized("%$%s12:55:00)%a!<%7%g%s"); /* Set compound_string2 to "Unsaved Changes" (EUC coding) */ compound_string2 = XmStringCreateLocalized("JQ99$rJ]B8$7$F$$$^$;$s!#"); atom = XmInternAtom(XtDisplay(toplevel), "COMPOUND_TEXT", False); compound_text = XmCvtXmStringToCT(compound_string1); n = 0; XtSetArg(ArgList[n], XmNtitle, compound_text); n++; XtSetArg(ArgList[n], XmNtitleEncoding, atom); n++; XtSetArg(ArgList[n], XmNiconName, compound_text); n++; XtSetArg(ArgList[n], XmNiconNameEncoding, atom); n++; XtSetValues(toplevel, ArgList, n); n = 0; XtSetArg(ArgList[n], XmNdialogTitle, compound_string2); n++; XtSetValues(dialog, ArgList, n);
See Chapter 16 for more information on transferring data between applications. The compound text format is described in the X Consortium Standard Compound Text Encoding.