[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Programmer's Guide



OptionMenu

An OptionMenu lets the user choose among a set of usually mutually exclusive options. The OptionMenu is always visible. It consists of a label (a LabelGadget), a selection area (a CascadeButtonGadget), and an associated PulldownMenu. The label of the CascadeButtonGadget displays the currently selected option, one of the items in the PulldownMenu. When the user activates the CascadeButtonGadget, the PulldownMenu becomes visible with the currently selected item directly above the selection area. When the user activates an item in the PulldownMenu, the PulldownMenu is unposted and the item the user chose becomes the currently selected option.

The PulldownMenu normally contains only PushButtons. It must not contain any ToggleButtons, and Motif does not support CascadeButtons.

RowColumn has a number of resources for use specifically with an OptionMenu:

XmNlabelString

The text of the label. Setting this resource also sets the XmNlabelString of the LabelGadget.

XmNmnemonic

A keysym that, when pressed along with the MAlt modifier, posts the PulldownMenu. Motif underlines the first character in the label string that matches the mnemonic and that is in a segment whose font list element tag matches XmNmnemonicCharSet. Setting this resource also sets the XmNmnemonic of the LabelGadget.

XmNmnemonicCharSet

The font list element tag used for underlining the mnemonic. Setting this resource also sets the XmNmnemonicCharSet of the LabelGadget.

XmNsubMenuId

The widget ID of the PulldownMenu. Setting this resource also sets the XmNsubMenuId of the CascadeButtonGadget.

If the application needs to get or set any of these four resources for the LabelGadget or CascadeButtonGadget, it should always get or set it in the OptionMenu RowColumn, not the gadget itself. To get or set other resources for the gadgets, the application should use XmOptionLabelGadget or XmOptionButtonGadget and then call XtGetValues or XtSetValues on the returned widget ID. A user or application can also specify resource values in resource files by using the names of the gadgets, "OptionLabel" and "OptionButton".

Setting the XmNmenuHistory resource also has a special effect in OptionMenus. Setting XmNmenuHistory to an item in the PulldownMenu makes that item the currently selected option. It updates the label of the CascadeButtonGadget and causes the PulldownMenu to appear, when posted, with the selected item over the CascadeButtonGadget.

XmCreateOptionMenu creates an OptionMenu RowColumn and its LabelGadget and CascadeButtonGadget children. It does not create the associated PulldownMenu.

The following example creates a simple OptionMenu with three options:

Widget         parent, pulldown, option, pb1, pb2, pb3;
Arg            args[10];
Cardinal       n;
n = 0;
pulldown = XmCreatePulldownMenu(parent, "option_pd",
                                  args, n);
pb1 = XmCreatePushButtonGadget(pulldown, "option_pb1",
                                  args, n);
pb2 = XmCreatePushButtonGadget(pulldown, "option_pb2",
                                  args, n);
pb3 = XmCreatePushButtonGadget(pulldown, "option_pb3",
                                  args, n);
XtSetArg(args[n], XmNsubMenuId, pulldown);       n++;
XtSetArg(args[n], XmNmenuHistory, pb2);          n++;
option = XmCreateOptionMenu(parent, "option_rc", args, n);

The following application-class defaults file provides labels and mnemonics for an English-language locale:

*option_pb1.labelString:   Option 1
*option_pb2.labelString:   Option 2
*option_pb3.labelString:   Option 3
*option_rc.labelString:   Options
*option_rc.mnemonic:   O


[ Previous | Next | Contents | Glossary | Home | Search ]