Layout direction refers to the direction that is used to display visual elements such as widget children, widget components, and text. In general, this direction matches the direction that people use when reading or writing in a particular language. Languages such as English, French, German, and Swedish are read and written from left to right. Therefore, when users working in those languages enter characters from a computer keyboard, each new character is displayed to the right of the preceding one. These same users would also expect the layout of other visual elements to be displayed from left to right. For example, in a menu bar, the cascade buttons would be laid out from left to right so that a simple menu bar would position the "File" cascade button in the upper left corner, and the "Help" cascade button would appear in the upper right corner of the menu bar.
Languages such as Arabic and Hebrew are read and written from right to left. To display text correctly in these languages on the screen, each successive character that a user enters must appear to the left of the preceding character. Using the example above for layout of other visual elements, these users would expect a menu bar to lay out cascade buttons from right to left. The result would typically position the "File" cascade button in the upper right corner and the "Help" cascade button in the upper left corner of the menu bar.
There are several reasons why it is helpful for programmers to be able to specify the layout direction in applications:
You can use the XmNlayoutDirection resource to set the default layout direction for your entire application. This resource specifies the default layout direction for all widgets that are affected by it. In turn, the XmNlayoutDirection resource sets a default rendering direction for any compound string (XmString) that does not have a component specifying the direction for that string. A widget that needs to render such a string should use this resource value to substitute for the missing direction indicator.
The following two examples clarify the use of the XmNlayoutDirection resource.
Suppose your application contains only unidirectional compound strings; that is, every XmString in the application is either left-to-right or right-to-left. To set the layout direction, all you need to do is set the appropriate value for the XmNlayoutDirection resource. You do not need to create compound strings with specific direction components. When the application renders an XmString, it should look to see if the string was created with an explicit direction (XmStringDirection). If there is no direction component, the application should check the value of the XmNlayoutDirection resource for the current widget and use that value as the default rendering direction for the XmString.
Another more complex example involves an application that runs in a locale with right-to-left languages but includes text widgets for entering numbers, which need to be displayed from left to right. In this example, the application needs to set the XmNlayoutDirection resource to right-to-left for the entire application and then explicitly reset the XmNlayoutDirection resource to left-to-right only for those widgets that display numerical values. You still do not need to set any direction components for the compound strings themselves.
In Motif applications, you can set the layout direction by using the XmNlayoutDirection resource from the VendorShell or MenuShell. Manager and Primitive widgets (as well as Gadgets) also have an XmNlayoutDirection resource. The default value is inherited from the closest ancestor that has the same resource.
The layout direction resource affects some or all of the subwidgets of the following three widget classes:
The specific effects of the XmNlayoutDirection resource vary with the widget in question. The following three sections outline these effects for the widgets in the three listed classes.
The following list describes display situations with elements of the XmLabelGadget class that are dependent on the layout direction.
The widgets XmCascadeButton, XmLabel, XmPushButton, XmTabButton, and XmToggleButton use the XmNlayoutDirection resource in the same manner as their corresponding gadget outlined in the previous section.
Note that the arrow keys osfRight and osfLeft refer to absolute directions within a row, and do not change their meaning when a widget's layout direction changes. Similarly, osfUp and osfDown refer to absolute directions within a column, and do not change their meaning when a widget's layout direction changes. However, a widget's layout direction does affect the interpretation of the arrow keys when the pointer is at the end of a row or column. In other words, a widget's layout direction will affect the way in which the widget "wraps" when it reaches the end of a row or column.
The following list describes display situations with elements of the XmPrimitive class that are dependent on the layout direction.
The following list describes display situations with elements of the XmManager class that are dependent on the layout direction.