class Fl_Menu_


Class Hierarchy

Include Files

Description

All widgets that have a menu in FLTK are subclassed off of this class. Currently FLTK provides you with Fl_Menu_Button, Fl_Menu_Bar, and Fl_Choice .

The class contains a pointer to an array of structures of type Fl_Menu_Item. These describe the contents of the menu. Usually the array is a large initialization constant, but there are methods to build it dynamically.

Methods

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

Creates a new Fl_Menu_ widget using the given position, size, and label string. The default boxtype is FL_NO_BOX.

virtual Fl_Menu_::~Fl_Menu_()

Destroys the menu and its items.

const Fl_Menu_Item* Fl_Menu_::menu() const
void Fl_Menu_::menu(const Fl_Menu_Item*)

Get or set the menu array directly. Setting it to NULL indicates that you want the widget to allocate its own array.

int Fl_Menu_::value() const
int Fl_Menu_::value(int)
int Fl_Menu_::value(const Fl_Menu_Item*)

The value is the index into menu() 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.

const Fl_Menu_Item* Fl_Menu_::test_shortcut()

Only call this in response to FL_SHORTCUT events. If the event matches an entry in the menu that entry is selected and the callback will be done (or changed() will be set). This allows shortcuts directed at one window to call menus in another.

void Fl_Menu_::global()

Make the shortcuts for this menu work no matter what window has the focus when you type it. This is done by using Fl::add_handler(). This Fl_Menu_ widget does not have to be visible (ie the window it is in can be hidden, or it does not have to be put in a window at all).

Currently there can be only one global()menu. Setting a new one will replace the old one. There is no way to remove the global() setting (including destroying the menu).

const char* Fl_Menu_::text() const
const char* Fl_Menu_::text(int i) const

Returns the title of the last item chosen, or of item i.

int Fl_Menu_::size() const

This returns menu()->size(), which is how many entries are in the array, not counting the NULL ending, but including all submenus titles and the NULL's that end them. If the menu is NULL this returns zero.

int Fl_Menu_::add(const char *,const char *,Fl_Callback *,void *v=0,int f=0)
int Fl_Menu_::add(const char *)

The first form adds a new menu item, with a title string, shortcut string, callback, argument to the callback, and flags. If menu() was originally set with NULL then space is allocated for the new item. If instead you gave it an array then the array must have enough empty space for the new item. The title string is copied, but the shortcut is not.

The second form splits the string at any | characters and then does add(s,0,0,0,0) with each section. This is often useful if you are just using the value, and is compatable with some Forms programs.

Text is a string of the form "foo/bar/baz", this example will result in a submenu called "foo" and one in that called "bar" and and entry called "baz". The text is copied to new memory and can be freed. The other arguments are copied into the menu item unchanged.

If an item exists already with that name then it is replaced with this new one. Otherwise this new one is added to the end of the correct menu or submenu. The return value is the offset into the array that the new entry was placed at.

No bounds checking is done, the table must be big enough for all the entries you plan to add. Don't forget that there is a NULL terminator on the end, and the first time a item is added to a submenu three items are added (the title and the NULL terminator, as well as the actual menu item)

The return value is the index into the array that the entry was put.

void Fl_Menu_::clear()

Delete all the menu items. Don't do this if you used menu(x) to set it to your own array. You should do this before destroying the Fl_Menu_ widget if it uses it's own array.

void Fl_Menu_::replace(int n, const char *)

Changes the text of item n. The passed string is copied.

void Fl_Menu_::remove(int n)

Deletes item n from the menu.

void Fl_Menu_::shortcut(int i, int n);

Changes the shortcut of item i to n.

void Fl_Menu_::mode(int i,int x);

Changes the flags of item i.

Fl_Color Fl_Menu_::textcolor() const
void Fl_Menu_::textcolor(Fl_Color)

Get or set the current color of menu item labels.

Fl_Font Fl_Menu_::textfont() const
void Fl_Menu_::textfont(Fl_Font)

Get or set the current font of menu item labels.

uchar Fl_Menu_::textsize() const
void Fl_Menu_::textsize(uchar)

Get or set the font size of menu item labels.

Fl_Boxtype Fl_Menu_::down_box() const
void Fl_Menu_::down_box(Fl_Boxtype)

This box type is used to surround the currently-selected items in the menus. If this is FL_NO_BOX then it acts like FL_THIN_UP_BOX and selection_color() acts like FL_WHITE, for back compatability.