|
NAMEXmtChooser - a widget that presents a choice to the user.SYNOPSIS
DESCRIPTIONAn XmtChooser is a composite widget which creates and controls the primitive widgets necessary to present a list of selectable items to the user. Depending on the XmtNchooserType resource, a Chooser widget will create an XmList widget, an XmOptionMenu, or a number of button children configured to be used as a radio box, a check box, a button box, or a palette. See the section ``Chooser Types'' below for more information.The choices to be displayed to the user may be specified in a single array on the XmtNstrings or the XmtNpixmaps resource. When pixmaps are being used, the XmtNselectPixmaps and XmtNinsensitivePixmaps resources specify alternate pixmaps to be displayed when an item is selected or insensitive and un-selectable. The Chooser widget keeps track of the choices made by the user in the XmtNstate resource. For Chooser types that have radio-style behavior, (i.e. types for which only one item can be selected at a time) the value of this resource is the index of the selected item. For types that allow multiple selected items, this state value is a bit-mask which indicates which items are selected. If the nth bit is set in this resource, then the nth item displayed by the Chooser is selected. The programmer may query this resource at any time to determine the current selection state. The programmer may also set this resource, and the selection state of the Chooser subwidgets will be changed to reflect the new value. Whenever the state of the Chooser changes, it calls all the procedures registered on its XmtNvalueChangedCallback list. See the section ``Chooser State'' below for more information. The XmtNvalues or XmtNvalueStrings resources specify an array of values to be associated with the items displayed by the Chooser widget. The Chooser widget does not interpret or use these values in any way, but the value of an item is often more convenient to the programmer than that item's index in the Chooser. See the section ``Chooser Values'' for more information on specifying values for a Chooser. The Chooser widget is a subclass of XmRowColumn, and it uses the layout capabilities of and resources of XmRowColumn to arrange its children. Although the Chooser is a composite widget, it creates all of its own children, and should not have additional children added to it. RESOURCES Chooser inherits the resources of the XmRowColumn class, and defines the following new resources. In addition, it overrides the default value for two XmRowColumn resources: it sets the default value of XmNadjustLast to False and of XmNpacking to XmPACK_COLUMN.
Chooser Types The way the Chooser widget presents its choices to the user is specified by the XmtNchooserType resource. This resource is of type XmtChooserType, which has the following enumerated values: typedef enum {
The enumerated values for this type have the following meanings:
Chooser State The XmtNstate resource maintains the selection state of all the items in the Chooser widget. If XmtNchooserType is one of the types with radio behavior (XmtChooserRadioBox, XmtChooserRadioPalette, XmtChooserRadioList or XmtChooserOption), then the state is simply the index of the currently selected item. Items are numbered beginning at zero, so if this resource is 0, it means that the first item is selected. For these Chooser types with radio-box behavior, there is exactly one item selected at all times, including a default item when the Chooser is created. If XmtNchooserType is a type without radio behavior (XmtChooserCheckBox, XmtChooserCheckPalette, or XmtChooserCheckList), then the state is a bit-mask with one bit indicating the state of each item. In this case, the state of item n can be determined with the following C code: (state & (1 << n)) Note that there cannot be more items in a Chooser of this type than there are bits in a variable of type int. This is at least 32 bits on most systems and should be plenty for most practical applications. Finally, note that if XmtNchooserType is XmtChooserButtonBox (which uses XmPushButtons rather than XmToggleButtons), then the XmtNstate resource is ignored. Chooser Values From the XmtNstate resource of a Chooser, you can determine the index of the selected item or items within the list of displayed items. Often however, the application is not interested in the index of the selected item, but instead in some semantic value associated with the item. For a Chooser that lets the user select a font size from a list of 5 values, for example, the states 0, 1, 2, 3, and 4 are not as interesting as the sizes themselves: 8, 10, 12, 14, and 18. An application can easily maintain an array of values to map from item number to item value, but as a convenience, the Chooser widget will maintain this array for the application. The XmtNvalues resource is an untyped array that contains one element for each item in the Chooser. The length of each element, in bytes, is specified by the XmtNvalueSize resource. The Chooser widget never uses or interprets these values, but will pass pointers to them to the application when it invokes the XmtNvalueChangedCallback, or when the application calls XmtChooserGetValue(). The Chooser allows values to be specified from resource files with the XmtNvalueStrings resource and the XmtNvalueType resource. XmtNvalueStrings is an array of strings, and XmtNvalueType is a string representation type, such as XtRInt or XtRPixel, for which a resource converter has been registered. (Values beginning with ``XtR'', ``XmR'', or ``XmtR'' are the symbolic names you would use from C. In a resource file, you'd use the strings these symbols stand for-``Int'' and ``Pixel'' in this case.) If XmtNvalueStrings is specified, each string in the array will be converted to the specified type. The Chooser widget will allocate an array for the XmtNvalues resource, with XmtNvalueSize bytes for each element, and will store the converted values into this array. Note that if you specify the XmtNvalues resource, you must also always specify the XmtNvalueSize resource. If you specify the XmtNvalueStrings resource, you must always specify both the XmtNvalueSize and XmtNvalueType resources. CALLBACKS The Chooser widget defines a single callback list, XmtNvalueChangedCallback. The procedures registered on this list are called when the selection state of the widget changes (ie. when the user chooses on of the displayed items). The call_data argument to this callback is a pointer to an XmtChooserCallbackStruct, which is defined as follows: typedef struct {
The state field of this structure is the new value of the XmtNstate resource. The item field is the index of the item that was just selected. For Chooser types with radio behavior, this is the same as the state field. If the XmtNvalues array or the XmtNvalueStrings array is set, then the valuep field is the address of the element of that array that corresponds to item specified on the item field. The XmtNvalueChangedCallback is generally called when the user changes the state of the Chooser widget. It is also called when XmtChooserSetState() is called with its notify argument set to True. In this case the item field is always set to -1, because although the state changed, there is not any particular item that the user just selected or deselected. For synthetic state changed like this, if the Chooser is in a radio-box mode, then the valuep field is set to point to the value that corresponds to the single selected item. For check-box modes, the valuep field is set to NULL on synthetic state changes. For Chooser widgets of type XmtChooserButtonBox, the state field of this callback structure is always set to -1 because the XmPushButtons of a button box do not maintain any state. The item field will contain the index of the button just pressed, however, which can be useful to dispatch commands in a switch statement, for example. Converters The Chooser class registers converters to convert strings specified in resource files to the types XmtRXmtChooserType and XmtRStringList. The String-to-XmtChooserType converter recognizes strings spelled exactly as its enumerated type is, with the ``Xmt'' and ``Chooser'' prefixes optionally removed. Correct capitalization is required by this converter. The String-to-StringList converter converts a comma separated list of strings within double quotes into a NULL-terminated array of strings suitable for use on the XmtNstrings and XmtNvalueStrings resources. The Xmt library also provides a String-to-PixmapList converter that will convert a string to an array of pixmaps suitable for use on the XmtNpixmaps, XmtNselectPixmaps and XmtNinsensitivePixmaps resources. Because many applications will not use the Chooser widget with pixmaps, this converter is not automatically registered by the widget. You can register it explicitly by calling XmtRegisterPixmapListConverter(). This converter converts a comma separated list of pixmap names within quotes, optionally followed by a color table to specify symbolic color substitutions for those pixmaps. See XmtRegisterPixmapListConverter(), XmtRegisterColorTableConverter(), and XmtGetPixmap() for more information. TRANSLATIONS and ACTIONS The Chooser widget simply inherits the translations of the XmRowColumn widget class, and does not set translations on any of its automatically created children. It defines no new action procedures. Sensitivity Because the Chooser is often used with a caption provided by an XmtLayout parent widget, it takes special care to notice when its own sensitivity state changes, and updates the XmtNlayoutSensitive constraint resource as necessary so that any caption will appear ``greyed out'' when the Chooser is not sensitive. The Chooser widget provides a convenience routine, XmtChooserSetSensitive() which sets the sensitivity of individual items within the Chooser. For Chooser types that use buttons, insensitive items are made insensitive with XtSetSensitive(), and will be displayed with ``greyed out'' textual labels, or with the pixmap, if any, specified in the XmtNinsensitivePixmaps array. An insensitive item is not selectable. For Chooser types that use the XmList widget, insensitive items are not displayed in any special way, but are made unselectable. SEE ALSOChapter 27, Presenting Choices,XmtChooserGetSensitivity(), XmtChooserGetState(), XmtChooserGetValue(), XmtChooserLookupItemByName(), XmtChooserLookupItemByValue(), XmtChooserLookupItemName(), XmtChooserLookupItemValue(), XmtChooserSetItemValue(), XmtChooserSetSensitive(), XmtChooserSetState(), XmtCreateChooser(), XmtRegisterChooser().
Visit the GSP FreeBSD Man Page Interface. |