[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Programmer's Guide



Compound Strings and Compound Text

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:

  1. If the associated tag is mapped to XmFONTLIST_DEFAULT_TAG in the registry, the converter passes the text of the compound string component to XmbTextListToTextProperty with an encoding style of XCompoundTextStyle and uses the resulting compound text for that component.

  2. If the associated tag is mapped to an MIT registered charset in the registry, the converter creates the compound text for that component by using the charset (from the registry) and the text of the compound string component as defined in the X Consortium Standard Compound Text Encoding.

  3. If the associated tag is mapped to a charset in the registry that is neither XmFONTLIST_DEFAULT_TAG nor an MIT registered charset, the converter creates the compound text for that component by using the charset (from the registry) and the text of the compound string component as an "extended segment" with a variable number of octets per character.

  4. If the associated tag is not mapped in the registry, the result is implementation dependent.

    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.

    1. XmCvtCTToXmString

    2. XmCvtXmStringToCT

      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.


    3. [ Previous | Next | Contents | Glossary | Home | Search ]