fltk::Choice Class Reference

Inherits fltk::Menu.

Inherited by fltk::ComboBox.

List of all members.

Public Member Functions

 Choice (int, int, int, int, const char *=0)
void draw ()
int handle (int)
int handle (int, const Rectangle &)

Static Public Attributes

static NamedStyledefault_style = &::style

Detailed Description

Subclass of fltk::Menu that provides a button that pops up the menu, and also displays the text of the most-recently selected menu item.


The appearance is designed to look like an "uneditable ComboBox" in Windows, but it is somewhat different in that it does not contain a text editor, also the menu pops up with the current item under the cursor, which is immensely easier to use once you get used to it. This is the same UI as the Macintosh and Motif, which called this an OptionButton.

The user can change the value by popping up the menu by clicking anywhere in the widget and moving the cursor to a different item, or by typing up and down arrow keys to cycle amoung the items. Typing the fltk::Widget::shortcut() of any of the items will also change the value to that item.

If you set a shortcut() on this widget itself or put &x in the label, that shortcut will pop up the menu. The user can then use arrow keys or the mouse to change the selected item.

When the user changes the value() the callback is done.

If you wish to display text that is different than any of the menu items, you may instead want an fltk::PopupMenu. It works identically but instead displays an empty box with the label() inside it, you can then change the label() as needed.

If you want a "real" ComboBox where the user edits the text, this is a planned addition to the fltk::Input widget. All text input will have menus of possible replacements and completions. Not yet implemented, unfortunately.

Constructor & Destructor Documentation

Choice::Choice ( int  x,
int  y,
int  w,
int  h,
const char *  l = 0 

The constructor makes the menu empty. See Menu and StringList for information on how to set the menu to a list of items.

xThe x position of the Choice, relative to the Group
yThe y position of the Choice, relative to the Group
wThe width of the Choice, relative to the Group
hThe height of the Choice, relative to the Group
lThe label of the Choice

Member Function Documentation

void Choice::draw ( void  ) [virtual]

You can change the icon drawn on the right edge by setting glyph() to your own function that draws whatever you want. Otherwise, draw draws its default glyph on the right of the box

Reimplemented from fltk::Group.

int Choice::handle ( int  e) [virtual]

The default handle() passes control to handle(e, rectangle) which attempts popup the menu / close the menu based on click area

eThe event to handle
1 if the event was successfully handled,
0 otherwise

Reimplemented from fltk::Group.

int Choice::handle ( int  e,
const Rectangle rectangle 

This function attempts to deal with where the user clicked in an effort to pop the menu up in the right place.

eThe event to handle
rectangleThe Choice's rectangle
1 if the event was successfully handled.
0 otherwise

Member Data Documentation

NamedStyle * Choice::default_style = &::style [static]

Sets the default style to nothing unless either of MOTIF_STYLE or MAC_STYLE are defined (within the source file) which they aren't, by default. Inherits from Group::default_style and the "default" style, unless either of the above are defined (in which case the glyph will be changed and, for MOTIF_STYLE, the buttonbox_ will be changed

Reimplemented from fltk::Menu.

The documentation for this class was generated from the following files: