Class Hierarchy
struct Fl_Menu_Item
Include Files
#include <FL/Fl_Menu_Item.H>
Description
The Fl_Menu_Item structure defines a single menu item that
is used by the Fl_Menu_ class. This
structure is defined in <FL/Fl_Menu_Item.H>
struct Fl_Menu_Item {
const char* text; // label()
ulong shortcut_;
Fl_Callback* callback_;
void* user_data_;
int flags;
uchar labeltype_;
uchar labelfont_;
uchar labelsize_;
uchar labelcolor_;
};
enum { // values for flags:
FL_MENU_INACTIVE = 1,
FL_MENU_TOGGLE = 2,
FL_MENU_VALUE = 4,
FL_MENU_RADIO = 8,
FL_MENU_INVISIBLE = 0x10,
FL_SUBMENU_POINTER = 0x20,
FL_SUBMENU = 0x40,
FL_MENU_DIVIDER = 0x80,
FL_MENU_HORIZONTAL = 0x100
};
Typically menu items are statically defined; for example:
Fl_Menu_Item popup[] = {
{"&alpha", FL_ALT+'a', the_cb, (void*)1},
{"&beta", FL_ALT+'b', the_cb, (void*)2},
{"gamma", FL_ALT+'c', the_cb, (void*)3, FL_MENU_DIVIDER},
{"&strange", 0, strange_cb},
{"&charm", 0, charm_cb},
{"&truth", 0, truth_cb},
{"b&eauty", 0, beauty_cb},
{"sub&menu", 0, 0, 0, FL_SUBMENU},
{"one"},
{"two"},
{"three"},
{0},
{"inactive", FL_ALT+'i', 0, 0, FL_MENU_INACTIVE|FL_MENU_DIVIDER},
{"invisible",FL_ALT+'i', 0, 0, FL_MENU_INVISIBLE},
{"check", FL_ALT+'i', 0, 0, FL_MENU_TOGGLE|FL_MENU_VALUE},
{"box", FL_ALT+'i', 0, 0, FL_MENU_TOGGLE},
{0}};
produces:
A submenu title is identified by the bit FL_SUBMENU in the
flags field, and ends with a label() that is NULL.
You can nest menus to any depth. A pointer to the first item in the
submenu can be treated as an Fl_Menu array itself. It is also
possible to make seperate submenu arrays with FL_SUBMENU_POINTER
flags.
You should use the method functions to access structure members and
not access them directly to avoid compatibility problems with future
releases of FLTK.
Methods
This is the title of the item. A NULL here indicates the end
of the menu (or of a submenu). A '&' in the item will print an
underscore under the next letter, and if the menu is popped up that
letter will be a "shortcut" to pick that item. To get a
real '&' put two
in a row.
A labeltype identifies a routine that draws the label of the
widget. This can be used for special effects such as emboss, or to use
the label() pointer as another form of data such as a bitmap.
The value FL_NORMAL_LABEL prints the label as text.
This color is passed to the labeltype routine, and is typically the
color of the label text. This defaults to FL_BLACK. If this
color is not black fltk will not use overlay bitplanes to draw
the menu - this is so that images put in the menu draw correctly.
Fonts are identified by small 8-bit indexes into a table. See the
enumeration list for predefined fonts. The default value is a
Helvetica font. The function
Fl::set_font() can define new fonts.
Gets or sets the label font pixel size/height.
Each item has space for a callback function and an argument for that
function. Due to back compatability, the Fl_Menu_Item itself
is not passed to the callback, instead you have to get it by calling
((Fl_Menu_*)w)->mvalue() where w is the widget argument.
Get or set the user_data argument that is sent to the
callback function.
For convenience you can also define the callback as taking a long
argument. This is implemented by casting this to a Fl_Callback
and casting the long to a void* and may not be
portable to some machines.
Call the Fl_Menu_Item item's callback, and provide the
Fl_Widget argument (and optionally override the user_data()
argument). You must first check that callback() is non-zero
before calling this.
Sets exactly what key combination will trigger the menu item. The
value is a logical 'or' of a key and a set of shift flags, for instance
FL_ALT+'a' or FL_ALT+FL_F+10 or just 'a'. A value of
zero disables the shortcut.
The key can be any value returned by
Fl::event_key(), but will usually be an ASCII letter. Use
a lower-case letter unless you require the shift key to be held down.
The shift flags can be any set of values accepted by
Fl::event_state(). If the bit is on that shift key must
be pushed. Meta, Alt, Ctrl, and Shift must be off if they are not in
the shift flags (zero for the other bits indicates a "don't care"
setting).
Returns true if either FL_SUBMENU or FL_SUBMENU_POINTER
is on in the flags. FL_SUBMENU indicates an embedded submenu
that goes from the next item through the next one with a NULL
label(). FL_SUBMENU_POINTER indicates that user_data()
is a pointer to another menu array.
Returns true if a checkbox will be drawn next to this item. This is
true if FL_MENU_TOGGLE or FL_MENU_RADIO is set in the
flags.
Returns true if this item is a radio item. When a radio button is
selected all "adjacent" radio buttons are turned off. A set of radio
items is delimited by an item that has radio() false, or by an
item with FL_MENU_DIVIDER turned on.
Returns the current value of the check or radio item.
Turns the check or radio item "on" for the menu item. Note that this
does not turn off any adjacent radio items like set_only()
does.
Turns the radio item "on" for the menu item and turns off adjacent
radio item.
Turns the check or radio item "off" for the menu item.
Gets the visibility of an item.
Makes an item visible in the menu.
Hides an item in the menu.
Get whether or not the item can be picked.
Allows a menu item to be picked.
Prevents a menu item from being picked. Note that this will also cause
the menu item to appear grayed-out.
This method is called by widgets that want to display menus. The menu
stays up until the user picks an item or dismisses it. The selected
item (or NULL if none) is returned. This does not do the
callbacks or change the state of check or radio items.
X,Y is the position of the mouse cursor, relative to the
window that got the most recent event (usually you can pass
Fl::event_x() and Fl::event_y() unchanged here).
title is a character string title for the menu. If
non-zero a small box appears above the menu with the title in it.
The menu is positioned so the cursor is centered over the item
picked. This will work even if picked is in a submenu.
If picked is zero or not in the menu item table the menu is
positioned with the cursor in the top-left corner.
button is a pointer to an
Fl_Menu_ from which the color and boxtypes for the menu are
pulled. If NULL then defaults are used.
pulldown() is similar to popup(), but a rectangle is
provided to position the menu. The menu is made at least W
wide, and the picked item is centered over the rectangle
(like Fl_Choice uses). If picked is zero or not
found, the menu is aligned just below the rectangle (like a pulldown
menu).
The title and menubar arguments are used
internally by the Fl_Menu_ widget.
This is designed to be called by a widgets handle() method in
response to a FL_SHORTCUT event. If the current event matches
one of the items shortcut, that item is returned. If the keystroke
does not match any shortcuts then NULL is returned. This only
matches the shortcut() fields, not the letters in the title
preceeded by '
Returns the number of Fl_Menu_Item structures that make up this menu,
correctly counting submenus. This includes the "terminator" item at
the end. So to copy a menu you need to copy
size()*sizeof(Fl_Menu_Item) bytes.
Advance a pointer by n items through a menu array, skipping
the contents of submenus and invisible items. There are two calls so
that you can advance through const and non-const data.