The capability to parse a multibyte character string as a string literal has been added to the User Interface Language (UIL). Creation of a UIL file is performed by using the characteristics of the target language and writing the User Interface Definition (UID) file.
The UIL compiler parses nonstandard charsets as locale text. This requires the UIL compiler to be run in the same locale as any locale text.
If the locale text of a widget requires a font set (more than one font), the font set must be specified within the resource file. The font parameter does not support font sets.
To use a specific language with UIL, a UIL file is written according to characteristics of the target language and compiled into a UID file. The UIL file that contains localized text needs to be compiled in the locale in which it is to run.
The following shows examples of literal strings. The cur_charset value is always set to the default_charset value, which allows the string literal to contain locale text.
To set locale text in the string literal with the default_charset value, enter the following:
XmNlabelString = 'XXXXXX';
OR
XmNlabelString = #default_charset"XXXXXX";
Compile the UIL file with the LANG environment variable matching the encoding of the locale text. Otherwise, the string literal is not compiled properly.
The font set cannot be set through UIL source programming. Whenever the font set is required, you must set it in the resource file as the following example shows:
*fontList: -*-r-*-20-*:
UIL has three functions that are used to create font lists: FONT, FONTSET, and FONT_TABLE. The FONT and FONTSET functions create font list entries. The FONT_TABLE function creates a font list from these font list entries.
The FONT function creates a font list entry containing a font specification. The argument is a string representing an XLFD font name. The FONTSET function creates a font list entry containing a font set specification. The argument is a comma-separated list of XLFD font names representing a base name font list.
Both FONT and FONTSET have optional CHARACTER_SET declaration parameters that specify the font list element tag for the font list entry. In both cases, if no CHARACTER_SET declaration parameter is specified, UIL determines the font list element tag as follows:
If the module contains no CHARACTER_SET declaration and if the uil command was called with the -s option or the Uil() function was started with use_setlocale_flag set, the font list element tag is XmFONTLIST_DEFAULT_TAG.
Otherwise, the font list element tag is the code set component of the LANG environment variable, if it is set in the UIL compilation environment; or it is the value of XmFALLBACK_CHARSET if the LANGenvironment variable is not set or has no code set.
The FONT_TABLE function creates a font list from a comma-separated list of font list entries created by FONT or FONTSET. The resulting font list can be used as the value of a font list resource. If a single font list entry is supplied as the value for such a resource, UIL converts the entry to a font list.
If necessary, set the input method-related resources in the resource file as shown in the following example:
*preeditType: OverTheSpot, OffTheSpot, Root, or None
For a locale-sensitive application, set the UID file to the appropriate directory. Set the UIDPATH or XAPPLRESDIR environment variable to the appropriate value.
For example, to run the uil_sample program with an English environment (LANG environment variable is en_US), set uil_sample.uid with Latin characters at the $HOME/en_US directory, or set uil_sample.uid to a directory and set the UIDPATH environment variable to the full path name of the uil_sample.uid file.
To run the uil_sample program with a Japanese environment (LANG environment variable is ja_JP), create a uil_sample.uid file with Japanese (multibyte) characters at the $HOME/ja_JP directory, or place uil_sample.uid to a unique directory and set the UIDPATH environment variable to the full path name of the uil_sample.uid file. The following list specifies the possible variables:
Specifies the UID file string.
Specifies the class name of the application.
Specifies the value of the xnlLanguage resource or LC_CTYPE category.
Specifies the language component of the xnlLanguage resource or the LC_CTYPE category.
If the XAPPLRESDIR environment variable is set, the MrmOpenHierarchy() function searches the UID file in the following order:
UID file path name
$UIDPATH
%U
$XAPPLRESDIR/%L/uid/%N/%U
$XAPPLRESDIR/%l/uid/%N/%U
$XAPPLRESDIR/uid/%N/%U
$XAPPLRESDIR/%L/uid/%U
$XAPPLRESDIR/%l/uid/%U
$XAPPLRESDIR/uid/%U
$HOME/uid/%U
$HOME/%U
/usr/lib/X11/%L/uid/%N/%U
/usr/lib/X11/%l/uid/%N/%U
/usr/lib/X11/uid/%N/%U
/usr/lib/X11/%L/uid/%U
/usr/lib/X11/%l/uid/%U
/usr/lib/X11/uid/%U
/usr/include/X11/uid/%U
If the XAPPLRESDIR environment variable is not set, the MrmOpenHierarchy() function uses $HOME instead of the XAPPLRESDIR environment variable.
With the default_charset string literal, any characters can be set as a valid string literal. For example, if the LANG environment variable is el_GR, the string literal with default_charset can contain any Greek character. If the LANG environment variable is ja_JP, the default_charset string literal can contain any Japanese character encoded in Japanese EUC.
If no character set is set to a string literal, the character set of the string literal is set as cur_charset. And, in the system environment, the cur_charset value is always set as default_charset.
Figure 4-4 shows a UIL sample program on English and Japanese environments.
In the following sample program, LLL indicates locale text, which can be Japanese, Korean, Traditional Chinese, Greek, French, or others.
uil_sample.uil ! ! sample uil file - uil_sample.uil ! ! C source file - uil_sample.c ! ! Resource file - uil-sample.resource ! module Test version = 'v1.0' names = case_sensitive objects = { XmPushButton = gadget; } !************************************ ! declare callback procedure !************************************ procedure exit_CB ; !*************************************************************** ! declare BulletinBoard as parent of PushButton and Text !*************************************************************** object bb : XmBulletinBoard { arguments{ XmNwidth = 500; XmNheight = 200; }; controls{ XmPushButton pb1; XmText text1; }; }; !**************************** ! declare PushButton !**************************** object pb1 : XmPushButton { arguments{ XmNlabelString = #Normal "LLLexit buttonLLL"; XmNx = 50; XmNy = 50; }; callbacks{ XmNactivateCallback = procedure exit_CB; }; }; !********************* ! declare Text !********************* text1 : XmText { arguments{ XmNx = 50; XmNy = 150; }; }; end module; /* * C source file - uil_sample.c * */ #include <Mrm/MrmAppl.h> #include <locale.h> void exit_CB(); static MrmHierarchy hierarchy; static MrmType *class; /******************************************/ /* specify the UID hierarchy list */ /******************************************/ static char *aray_file[]= {"uil_sample.uid" }; static int num_file = (sizeof aray_file / sizeof aray_file[0]); /******************************************************/ /* define the mapping between UIL procedure names */ /* and their addresses */ /******************************************************/ static MRMRegisterArg reglist[]={ {"exit_CB",(caddr_t) exit_CB}
Three mechanisms exist for specifying strings in UIL files:
As string literals, which may be stored in UID files as either null-terminated strings or compound strings
As compound strings
As wide character strings
Both string literals and compound strings consist of text, a character set, and a writing direction. For string literals and for compound strings with no explicit direction, UIL infers the writing direction from the character set. The UIL concatenation operator (&) concatenates both string literals and compound strings.
Regardless of whether UIL stores string literals in UID files as null-terminated strings or as compound strings, it stores information about each string's character set and writing direction along with the text. In general, UIL stores string literals or string expressions as compound strings in UID files under the following conditions:
When a string expression consists of two or more literals with different character sets or writing directions
When the literal or expression is used as a value that has a compound string data type (such as the value of a resource whose data type is compound string)
UIL recognizes a number of keywords specifying character sets. UIL associates parsing rules, including parsing direction and whether characters have 8 or 16 bits, for each character set it recognizes. It is also possible to define a character set using the UIL CHARACTER_SETfunction.
The syntax of a string literal is one of the following:
'[character_string]'
[#char_set]
"[character_string]"
For each syntax, the character set of the string is determined as follows:
For a string declared as 'character_string', the character set is the code set component of the LANG environment variable, if it is set in the UIL compilation environment; or it is the value of XmFALLBACK_CHARSET if the LANG environment variable is not set or has no code set. By default, the value of XmFALLBACK_CHARSET is ISO8859-1, but vendors may supply different values.
For a string declared as #char_set "string", the character set is char_set.
For a string declared as "character_string", the character set depends on whether the module has a CHARACTER_SET clause and whether the UIL compiler's use_setlocale_flag is set.
If the module has a CHARACTER_SET clause, the character set is the one specified in that clause.
If the module has no CHARACTER_SET clause but the uil command was started with the -s option, or if the Uil() function was started with use_setlocale_flag set, UIL calls the setlocale() function and parses the string in the current locale. The character set of the resulting string is XmFONTLIST_DEFAULT_TAG.
If the module has no CHARACTER_SET clause and the uil command was started without the -s option, or if the Uil() function was started without use_setlocale_flag, the character set is the code set component of the LANG environment variable, if it is set in the UIL compilation environment, or the character set is the value of XmFALLBACK_CHARSET if LANG is not set or has no code set.
UIL always stores a string specified using the COMPOUND_STRING function as a compound string. This function takes as arguments a string expression and optional specifications of a character set, direction, and whether to append a separator to the string. If no character set or direction is specified, UIL derives it from the string expression, as described in the preceding section.
Certain predefined escape sequences, beginning with a \ (backslash), may be displayed in string literals, with the following exceptions:
A string in single quotation marks can span multiple lines, with each new line character escaped by a backslash. A string in double quotation marks cannot span multiple lines.
Escape sequences are processed literally inside a string that is parsed in the current locale (a localized string).