class fltk::Choice


Class Hierarchy

fltk::Menu
   |
   +----fltk::Choice

Include Files

#include <fltk/Choice.h>

Description

This is a button that when pushed pops up a menu (or hierarchy of menus) defined by an array of child items. The appearance is designed to look like a Windows "combo box" 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. Motif calls 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 shortcut() of any of the items will also change the value to that item (The '&' character in item names are only looked at when the menu is popped up, however).

The menu will also pop up in response to shortcuts indicated by putting a '&' character in the label() or to the shortcut() of the fltk::Choice widget itself. 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.

Methods

fltk::Choice::Choice(int x, int y, int w, int h, const char *label = 0)

Creates a new fltk::Choice widget using the given position, size, and label string. The default boxtype is fltk::UP_BOX.

The constructor sets menu() to NULL. See fltk::Menu for the methods to set or change the menu.

virtual fltk::Choice::~Choice()

The destructor removes the fltk::Choice widget and all of its menu items.

int fltk::Choice::value() const
int fltk::Choice::value(int)
int fltk::Choice::value(const fltk::Menu *)

The value is the index into the fltk::Menu array of the last item chosen by the user. It is zero initially. You can set it as an integer, or set it with a pointer to a menu item. The set routines return non-zero if the new value is different than the old one. Changing it causes a redraw().

int fltk::Widget::changed() const

This value is true if the user picks a different value. It is turned off by value() and just before doing a callback (the callback can turn it back on if desired).

void fltk::Widget::set_changed()

This method sets the changed() flag.

void fltk::Widget::clear_changed()

This method clears the changed() flag.

fltk::Box fltk::Choice::down_box() const
void fltk::Choice::down_box(fltk::Box b)

The first form gets the current down box, which is used when the menu is popped up. The default down box type is fltk::DOWN_BOX The second form sets the current down box type to b.