Selection-box widgets (CwSelectionBox) are used to obtain a selection from a list of alternatives provided to the user. A selection box can contain some or all of the following components: a scrollable list of alternatives, an editable text field for the selected alternative, labels for the list and text field, and four buttons. By default, the buttons are labelled
OK,
Apply,
Cancel and
Help.
A selection box is usually created in a dialog shell to prompt the user to select a list item. Selection-box widgets are created using the createSelectionBox:argBlock: and
createSelectionDialog:argBlock: convenience methods. The latter method is similar to the first, but also creates a
CwDialogShell as the parent of the
CwSelectionBox so that it can be popped up separately from the main widget tree. As with pop-up menus a selection dialog can be created and left unmanaged until it is to be presented to the user. It is popped up by sending the selection box the
manageChild message. The default behavior is to remain open until either the OK or Cancel button is pressed, or the dialog's close box is double-clicked. The application can explicitly close the dialog by sending
unmanageChild to the selection box.
The okCallback,
applyCallback,
cancelCallback, and
helpCallback of the selection box are run when the corresponding buttons are pressed. If a callback is not added, the corresponding button will still appear, but nothing will happen when it is pressed. When the selection box is in a dialog shell, it is unmanaged when the OK or Cancel button is pressed, unless the
autoUnmanage resource is set to
false.
Using the mustMatch resource, the selection box can be configured to test whether the text typed in the text widget matches any item in the list. If
mustMatch is
true and the text does not match any item in the list when the OK button is pressed, the
noMatch callback is run, otherwise the
ok callback is run. Note that if the
noMatch callback is run, a selection dialog will not be unmanaged.