Common Desktop Environment: Internationalization Programmer's Guide

Compound String Components

A compound string is an internal encoding, consisting of tag-length-value segments. Semantically, a compound string has components that contain the text to be displayed, a tag (called a font list element tag) that is matched with an element of a font list, and an indicator denoting the direction in which it is to be displayed.

A compound string component can be one of the following four types:

The following describes each of the compound string components:

Font list element tag

Indicates a string value that correlates the text component of a compound string to a font or a font set in a font list.

Direction

Indicates the relationship between the order in which characters are entered on the keyboard and the order in which the characters are displayed on the screen. For example, the display order is left-to-right in English, French, German, and Italian, and right-to-left in Hebrew and Arabic.

Text

Indicates the text to be displayed.

Separator

Indicates a special form of a compound string component that has no value. It is used to separate other segments.

The desktop uses the specified font list element tag identified in the text component to display the compound string. A specified font list element tag is used until a new font list element tag is encountered. The desktop provides a special font list element tag, XmFONTLIST_DEFAULT_TAG, that matches a font that is correct for the current code set. It identifies the default entry in a font list. See "Compound Strings and Font Lists" for more information.

The direction segment of a compound string specifies the direction in which the text is displayed. Direction can be left-to-right or right-to-left.

Compound Strings and Resources

Compound strings are used to display all text except that in the Text and TextField widgets. The compound string is set into the appropriate widget resource so that it can be displayed. For example, the label for the PushButton widget is inherited from the Label widget, and the resource is XmNlabelString, which is of type XmString. This means that the resource expects a value that is a compound string. A compound string can be created with a program or defined in a resource file.

Setting a Compound String Programmatically

An application can set this resource programmatically by creating the compound string using the XmStringCreateLocalized() compound string convenience function.

This function creates a compound string in the encoding of the current locale and automatically sets the font list entry tag to XmFONTLIST_DEFAULT_TAG.

The following code segment shows one way to set the XmNlabelString resource for a push button using a program.

#include <nl_types.h>  
Widget		button;  
Args		args[10];  
int		n; 
 XmString button_label;  
nl_msg my_catd;  
(void)XtSetLanguageProc(NULL,NULL,NULL);
  		.
  		.  
button_label = XmStringCreateLocalized (catgets(my_catd, 1, 1,
  		 	"default label"),
  			XmFONTLIST_DEFAULT_TAG);   

/* Create an argument list for the button */  
n = 0;  
XtSetArg (args[n], XmNlabelString, button_label); n++;   

/* Create and manage the button */  
button = XmCreatePushButton (toplevel, "button", args, n);  
XtManageChild (button);  
XmStringFree (button_label);

Setting a Compound String in a Defaults File

In an internationalized program, the label string for the button label should be obtained from an external source. For example, the button label can come from a resource file instead of the program. For this example, assume that the push button is a child of a Form widget called form1.

*form1.button.labelString:
Push Here

Here, the desktop's string-to-compound-string converter produces a compound string from the resource file text. This converter always uses XmFONTLIST_DEFAULT_TAG.