Chapter 8. Using Xme Functions Within a Widget

Motif provides widget writers with several dozen convenience routines known collectively as the Xme functions. Motif provides these to simplify widget writing. Widget writers should use these Xme functions whenever possible.

The Xme routines perform the following kinds of widget-writing services:

This chapter provides an overview of the Xme functions. Chapter 17 contains reference documentation for each Xme function.

Xme functions were not available in releases of Motif prior to Release 2.0. Prior to Release 2.0, Motif provided several dozen undocumented _Xm routines for widget writers and for internal use. Motif strongly recommends that you not use any of these _Xm routines in your widgets.

Many of the _Xm routines have Xme equivalents. For example, _XmClearBorder is equivalent to XmeClearBorder . To help users make the transition from _Xm routines to Xme routines, the Motif Release 2.0 XmP.h header file contains #define statements that convert some of the old _Xm calls into their new Xme equivalents. Thus, if your code calls any of the _Xm routines listed in these #define statements, and you compile against the Release 2.0 header files, the C preprocessor will automatically convert the _Xm calls to the proper Xme calls. However, Motif does not guarantee that these #define statements will continue to be available in future releases.

Calling an Xme function

The Xme functions are bound into the standard Motif library (typically stored in file libXm.a). Therefore, you do not need to bind your widget with any special libraries in order to call an Xme function. Similarly, you do not need a Motif source license in order to call an Xme function.

You call an Xme function just as you would call any Xm convenience function. That is, you must include the appropriate header file, and you must provide the correct type and number of arguments to the call. The reference pages in Chapter 17 detail the required information for each Xme function.

Xme Trait Functions

Motif provides two Xme functions for handling traits. These functions are summarized in Table 8-1. See Chapter 5 for details on traits.

Table 8-1. Xme Trait Functions

Xme FunctionWhat It Does:
XmeTraitGetReturns the trait record associated with a given object
XmeTraitSetInstalls a trait on a specified widget class

Rendering Geometric Objects

Motif provides several Xme functions for rendering geometric objects (arrows, diamonds, and so on). Whenever possible, your Motif widgets should render geometric objects with these Xme routines. By using the Xme functions, you are ensuring that the geometric objects in your Motif widget will look like the geometric objects in other Motif widgets.

Table 8-2 lists the Xme functions pertaining to drawing.

Table 8-2. Xme Drawing Functions

Xme FunctionWhat It Does:
XmeClearBorderClears any rectangular area (such as a widget border)
XmeDrawArrowDraws a Motif-style, three-dimensional arrow
XmeDrawCircleDraws a Motif-style, three-dimensional circle
XmeDrawDiamondDraws a Motif-style, three-dimensional diamond
XmeDrawHighlightDraws a Motif-style highlight around a widget's border
XmeDrawIndicatorDraws a Motif-style cross or check mark
XmeDrawPolygonShadowDraws a Motif-style, three-dimensional shadow around a polygon
XmeDrawSeparatorDraws a Motif-style, three-dimensional line to separate two visual components
XmeDrawShadowsDraws a Motif-style, three-dimensional shadow around a rectangle

For example, the ExmSimple widget calls the XmeDrawShadows function to draw its border shadows. In order to make this call, the Simple.c file includes the header file for the Xme drawing functions as follows:

#include <Xm/DrawP.h>

The call to XmeDrawShadows appears as follows:

XmeDrawShadows (XtDisplay (sw), XtWindow (sw),
                sw->primitive.top_shadow_GC,
                sw->primitive.bottom_shadow_GC,
                sw->primitive.highlight_thickness,
                sw->primitive.highlight_thickness,
                sw->core.width - (2 * sw->primitive.highlight_thickness),
                sw->core.height - (2 * sw->primitive.highlight_thickness),
                sw->primitive.shadow_thickness,
                XmSHADOW_ETCHED_OUT);

Most Motif widgets inherit routines to draw and erase window decorations. However, if your widget takes the responsibility for its own window decorations, then your widget will draw the decorations with XmeDrawHighlight and XmeDrawShadows and clear the decorations with XmeClearBorders. Actually, the XmeClearBorders call can be used to clear out any rectangular area, not just window decorations.

If you want to draw shadows around any polygon (instead of just a rectangle), call XmeDrawPolygonShadows instead of XmeDrawShadows.

XmeDrawDiamond, XmeDrawCircle, and XmeDrawIndicator are particularly useful for creating toggle indicators.

Xme Resolution Independence Functions

Motif provides four Xme functions that govern resolution independence. (See Chapter 6 for information about resolution independence.)

The four functions shown in Table 8-3 are typically called from a synthetic resource table rather than from a widget method.

Table 8-3. Xme Resolution Independence Functions

Xme FunctionWhat It Does:
XmeFromHorizontalPixelsConverts from pixels to real-world dimensions based on horizontal resolution of the screen
XmeFromVerticalPixelsConverts from pixels to real-world dimensions based on vertical resolution of the screen
XmeToHorizontalPixelsConverts from real-world dimensions to pixels based on horizontal resolution of the screen
XmeToVerticalPixelsConverts from real-world dimensions to pixels based on vertical resolution of the screen

Xme String Functions

Table 8-4 contains a list of Xme functions that are useful for manipulating strings.

Table 8-4. Xme String Functions

Xme FunctionWhat It Does:
XmeGetDefaultRenderTableReturns the default render table associated with a specified widget
XmeGetDirectionA compound string parse procedure ( XmParseProc) to insert a direction component
XmeGetLocalizedStringReturns a localized version of the input string
XmeGetNextCharacterA compound string parse procedure ( XmParseProc) to insert a character
XmeNamesAreEqualCompares two strings for equality
XmeRenderTableGetDefaultFontGets information on the default font associated with a specified render table

See Chapter 9 for complete details on using these functions.

Implementing Data Transfer

Motif provides widget writers with several Xme functions for implementing the Uniform Transfer Model (UTM). UTM is a mechanism for transferring data between and within widgets. UTM was introduced in Motif Release 2.0. (See Chapter 10 for details.)

Table 8-5 summarizes the Xme functions useful for transferring data between and within widgets.

Table 8-5. Xme Data Transfer Functions

Xme FunctionWhat It Does:
XmeClipboardSinkTransfers data from the clipboard to a widget
XmeClipboardSourcePlaces data on the clipboard
XmeConvertMergeMerges data converted during a transfer operation
XmeDragSourceStarts a drag and drop operation
XmeDropSinkEstablishes a widget as a drop site
XmeGetLocaleAtomReturns the encoding of the locale
XmeGetTextualDragIconReturns an icon widget symbolizing a textual drag operation in progress
XmeNamedSinkTransfers data from the named selection to a widget
XmeNamedSourceTakes ownership of a named selection
XmePrimarySinkTransfers data from the primary selection to a widget
XmePrimarySourceTakes ownership of the primary selection
XmeSecondarySinkEstablishes a widget as the destination for secondary transfer
XmeSecondarySourceTakes ownership of the secondary selection
XmeSecondaryTransferTransfers data from the secondary selection to the destination widget
XmeStandardConvertConverts selections to standard targets
XmeStandardTargetsReturns a list of standard Motif targets
XmeTransferAddDoneProcEstablishes a procedure to be called when data transfer is complete

In addition to the list of Xme routines shown in the previous table, Motif provides many Xm data transfer routines. The Xm routines are detailed in the Motif Programmer's Reference.

Xme Geometry Functions

Motif provides the Xme calls shown in Table 8-6 to help widget writers manage geometry:

Table 8-6. Xme Geometry Functions

Xme FunctionWhat It Does:
XmeConfigureObjectChanges a child's position, size, or border width
XmeRedisplayGadgetsRedisplays all the gadget children of a manager
XmeReplyToQueryGeometryHandles standard geometry requests

See Chapter 12 for examples involving these functions.

Xme Focus/Traversal Functions

Motif provides the Xme calls shown in Table 8-7 to help widget writers handle focus changes.

Table 8-7. Xme Focus Functions

Xme FunctionWhat It Does:
XmeAddFocusChangeCallbackRegisters a callback for focus changes
XmeNavigChangeManagedHelps a change_managed method establish the correct keyboard traversal policy
XmeRemoveFocusChangeCallbackRemoves a focus change callback

Xme Miscellaneous Functions

Motif also provides the Xme functions shown in Table 8-8.

Table 8-8. Xme Miscellaneous Functions

Xme FunctionWhat It Does:
XmeCreateClassDialogCreates a dialog shell containing the specified widget
XmeGetDefaultPixelFinds a color associated with the given widget
XmeGetNullCursorReturns the null cursor associated with a given display
XmeGetPixmapDataReturns details about a cached pixmap
XmeMicroSleepSuspends execution for a specified number of microseconds
XmeGetHomeDirNameReturns the pathname of the user's home directory
XmeQueryBestCursorSizeFinds the best cursor size
XmeResolvePartOffsetsAllows writing of binary-compatible applications and widgets
XmeSetWMShellTitleA compound string function that updates the window manager title
XmeVirtualToActualKeysymsFinds the physical keysyms associated with a given virtual keysym
XmeWarningWrites a warning message to the standard error stream