1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Menu item header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2024-04-05 00:40:29 +03:00
|
|
|
// Copyright 1998-2024 by Bill Spitzak and others.
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#ifndef Fl_Menu_Item_H
|
|
|
|
#define Fl_Menu_Item_H
|
|
|
|
|
2023-12-23 20:51:43 +03:00
|
|
|
#include <FL/Fl_Widget.H>
|
|
|
|
#include <FL/Fl_Image.H>
|
|
|
|
#include <FL/Fl_Multi_Label.H>
|
|
|
|
#include <FL/platform_types.h> // for FL_COMMAND and FL_CONTROL
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2016-07-20 02:50:09 +03:00
|
|
|
// doxygen needs the following line to enable e.g. ::FL_MENU_TOGGLE to link to the enums
|
|
|
|
/// @file
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
enum { // values for flags:
|
2022-03-07 20:23:53 +03:00
|
|
|
FL_MENU_INACTIVE = 1, ///< Deactivate menu item (gray out)
|
|
|
|
FL_MENU_TOGGLE = 2, ///< Item is a checkbox toggle (shows checkbox for on/off state)
|
|
|
|
FL_MENU_VALUE = 4, ///< The on/off state for checkbox/radio buttons (if set, state is 'on')
|
|
|
|
FL_MENU_RADIO = 8, ///< Item is a radio button (one checkbox of many can be on)
|
|
|
|
FL_MENU_INVISIBLE = 0x10, ///< Item will not show up (shortcut will work)
|
|
|
|
FL_SUBMENU_POINTER = 0x20, ///< Indicates user_data() is a pointer to another menu array
|
|
|
|
FL_SUBMENU = 0x40, ///< Item is a submenu to other items
|
|
|
|
FL_MENU_DIVIDER = 0x80, ///< Creates divider line below this item. Also ends a group of radio buttons
|
2024-10-19 16:58:25 +03:00
|
|
|
FL_MENU_HORIZONTAL = 0x100 ///< ??? -- reserved, internal (do not use)
|
|
|
|
///< Note: \b ALL other bits in \p flags are reserved: do not use them for your own purposes!
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
2009-09-18 02:12:24 +04:00
|
|
|
extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
class Fl_Menu_;
|
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
|
|
|
The Fl_Menu_Item structure defines a single menu item that
|
2020-07-01 19:03:10 +03:00
|
|
|
is used by the Fl_Menu_ class.
|
2008-09-15 23:21:20 +04:00
|
|
|
\code
|
2008-09-15 04:27:28 +04:00
|
|
|
struct Fl_Menu_Item {
|
2015-01-04 21:41:37 +03:00
|
|
|
const char* text; // label()
|
2022-04-07 13:12:20 +03:00
|
|
|
int shortcut_;
|
2015-01-04 21:41:37 +03:00
|
|
|
Fl_Callback* callback_;
|
|
|
|
void* user_data_;
|
|
|
|
int flags;
|
|
|
|
uchar labeltype_;
|
|
|
|
uchar labelfont_;
|
|
|
|
uchar labelsize_;
|
|
|
|
uchar labelcolor_;
|
2008-09-15 04:27:28 +04:00
|
|
|
};
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
enum { // values for flags:
|
2022-03-07 20:23:53 +03:00
|
|
|
FL_MENU_INACTIVE = 1, // Deactivate menu item (gray out)
|
|
|
|
FL_MENU_TOGGLE = 2, // Item is a checkbox toggle (shows checkbox for on/off state)
|
|
|
|
FL_MENU_VALUE = 4, // The on/off state for checkbox/radio buttons (if set, state is 'on')
|
|
|
|
FL_MENU_RADIO = 8, // Item is a radio button (one checkbox of many can be on)
|
|
|
|
FL_MENU_INVISIBLE = 0x10, // Item will not show up (shortcut will work)
|
|
|
|
FL_SUBMENU_POINTER = 0x20, // Indicates user_data() is a pointer to another menu array
|
|
|
|
FL_SUBMENU = 0x40, // This item is a submenu to other items
|
|
|
|
FL_MENU_DIVIDER = 0x80, // Creates divider line below this item. Also ends a group of radio buttons.
|
2024-10-19 16:58:25 +03:00
|
|
|
FL_MENU_HORIZONTAL = 0x100 // ??? -- reserved, internal (do not use)
|
2008-09-15 04:27:28 +04:00
|
|
|
};
|
2008-09-15 23:21:20 +04:00
|
|
|
\endcode
|
2024-10-19 16:58:25 +03:00
|
|
|
|
|
|
|
\note \b All other bits in \p flags are reserved for FLTK usage, do not use any bits of the
|
|
|
|
\p flags variable for your own purposes. Even \b undocumented bits can be used for internal
|
|
|
|
purposes in this or any future FLTK version.
|
|
|
|
|
|
|
|
Some \p flags bits may be changed during runtime by user code, particularly if you need to change
|
|
|
|
the value of a menu item (ON/OFF) or make it active or inactive. Such changes must be done with
|
|
|
|
caution so they don't affect other (maybe undocumented) bits, i.e. you need to make proper bit
|
|
|
|
operations to set or clear only these particular bits.
|
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
Typically menu items are statically defined; for example:
|
2008-09-15 23:21:20 +04:00
|
|
|
\code
|
2008-09-15 04:27:28 +04:00
|
|
|
Fl_Menu_Item popup[] = {
|
2015-01-04 21:41:37 +03:00
|
|
|
{"&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},
|
2008-09-17 19:44:43 +04:00
|
|
|
{"one"},
|
|
|
|
{"two"},
|
|
|
|
{"three"},
|
2008-09-15 04:27:28 +04:00
|
|
|
{0},
|
2008-09-17 19:44:43 +04:00
|
|
|
{"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},
|
2008-09-15 04:27:28 +04:00
|
|
|
{0}};
|
2008-09-15 23:21:20 +04:00
|
|
|
\endcode
|
2008-09-15 04:27:28 +04:00
|
|
|
produces:
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2010-12-09 02:53:04 +03:00
|
|
|
\image html menu.png
|
|
|
|
\image latex menu.png "menu" width=10cm
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
A submenu title is identified by the bit FL_SUBMENU in the
|
2008-09-15 04:27:28 +04:00
|
|
|
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
|
2008-12-13 21:31:54 +03:00
|
|
|
possible to make separate submenu arrays with FL_SUBMENU_POINTER flags.
|
|
|
|
|
|
|
|
You should use the method functions to access structure members and
|
2008-09-15 04:27:28 +04:00
|
|
|
not access them directly to avoid compatibility problems with future
|
|
|
|
releases of FLTK.
|
2022-03-07 20:23:53 +03:00
|
|
|
|
|
|
|
\note Adding menu items with insert(), add(), or any of its overloaded
|
|
|
|
variants copies the entire menu to internal storage. Using the
|
|
|
|
memory of a static menu array after that would access unused (but not
|
|
|
|
released) memory and thus have no effect.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2002-08-14 20:49:38 +04:00
|
|
|
struct FL_EXPORT Fl_Menu_Item {
|
2020-07-01 19:03:10 +03:00
|
|
|
const char *text; ///< menu item text, returned by label()
|
|
|
|
int shortcut_; ///< menu item shortcut
|
2008-12-13 21:31:54 +03:00
|
|
|
Fl_Callback *callback_; ///< menu item callback
|
2020-07-01 19:03:10 +03:00
|
|
|
void *user_data_; ///< menu item user_data for the menu's callback
|
|
|
|
int flags; ///< menu item flags like FL_MENU_TOGGLE, FL_MENU_RADIO
|
|
|
|
uchar labeltype_; ///< how the menu item text looks like
|
|
|
|
Fl_Font labelfont_; ///< which font for this menu item text
|
2008-12-13 21:31:54 +03:00
|
|
|
Fl_Fontsize labelsize_; ///< size of menu item text
|
2020-07-01 19:03:10 +03:00
|
|
|
Fl_Color labelcolor_; ///< menu item text color
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// advance N items, skipping submenus:
|
2002-08-14 20:49:38 +04:00
|
|
|
const Fl_Menu_Item *next(int=1) const;
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2008-12-13 21:31:54 +03:00
|
|
|
Advances a pointer by n items through a menu array, skipping
|
|
|
|
the contents of submenus and invisible items. There are two calls so
|
2008-09-15 04:27:28 +04:00
|
|
|
that you can advance through const and non-const data.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Menu_Item *next(int i=1) {
|
|
|
|
return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/** Returns the first menu item, same as next(0). */
|
2004-06-07 23:23:12 +04:00
|
|
|
const Fl_Menu_Item *first() const { return next(0); }
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/** Returns the first menu item, same as next(0). */
|
2004-06-07 23:23:12 +04:00
|
|
|
Fl_Menu_Item *first() { return next(0); }
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// methods on menu items:
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2023-12-23 20:51:43 +03:00
|
|
|
Returns the title (label) of the menu item.
|
|
|
|
|
2008-12-13 21:31:54 +03:00
|
|
|
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,
|
2023-12-23 20:51:43 +03:00
|
|
|
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.
|
|
|
|
|
|
|
|
The returned value depends on the labeltype() that has been used
|
|
|
|
to store the label.
|
|
|
|
|
|
|
|
\returns A pointer to the label cast to (const char *)
|
|
|
|
|
|
|
|
\retval (a) A pointer to text (const char *)
|
|
|
|
\retval (b) A pointer to an image (Fl_Image *)
|
|
|
|
\retval (c) A pointer to a "multi label" (Fl_Multi_Label *)
|
|
|
|
\retval NULL End of menu or submenu
|
|
|
|
|
|
|
|
\see Fl_Menu_Item::label(const char *)
|
|
|
|
\see Fl_Menu_Item::label(Fl_Labeltype, const char *)
|
|
|
|
\see Fl_Menu_Item::image_label(const Fl_Image *)
|
|
|
|
\see Fl_Menu_Item::multi_label(const Fl_Multi_Label *)
|
|
|
|
\see Fl_Multi_Label::label(Fl_Menu_Item *)
|
|
|
|
*/
|
|
|
|
const char* label() const { return text; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the title (label) of the menu item.
|
|
|
|
|
|
|
|
\note This does \b not change the labeltype() for backwards compatibility.
|
|
|
|
Take care to assign the correct labeltype() if you assign different
|
|
|
|
label types to the same menu item sequentially.
|
|
|
|
|
|
|
|
The default labeltype() is FL_NORMAL_LABEL.
|
|
|
|
|
|
|
|
\see label(Fl_Labeltype, const char*)
|
|
|
|
\see const char* Fl_Menu_Item::label() const
|
|
|
|
*/
|
|
|
|
void label(const char* a) { text = a; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the title (label) and the label type of the menu item.
|
|
|
|
|
|
|
|
The default Fl_Labeltype when using Fl_Menu_Item::label(const char* a)
|
|
|
|
is FL_NORMAL_LABEL but you can set any other label type, for instance
|
|
|
|
FL_EMBOSSED_LABEL.
|
|
|
|
|
|
|
|
Special labeltypes are:
|
|
|
|
|
|
|
|
- FL_ICON_LABEL: draws the icon (Fl_Image) associated with the text
|
|
|
|
- FL_IMAGE_LABEL: draws the image (Fl_Image) associated with the text
|
|
|
|
- FL_MULTI_LABEL: draws multiple parts side by side, see Fl_Multi_Label
|
|
|
|
|
|
|
|
\see const char* Fl_Menu_Item::label() const
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2023-12-23 20:51:43 +03:00
|
|
|
void label(Fl_Labeltype a, const char* b) {
|
|
|
|
labeltype_ = a;
|
|
|
|
text = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the title (label()) and labeltype() to an Fl_Multi_Label.
|
|
|
|
|
|
|
|
This sets the labeltype() to \_FL_MULTI_LABEL (note the leading
|
|
|
|
underscore).
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2023-12-23 20:51:43 +03:00
|
|
|
\see const char* Fl_Menu_Item::label() const
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2023-12-23 20:51:43 +03:00
|
|
|
\since 1.4.0
|
|
|
|
|
|
|
|
\internal Overloading Fl_Menu_Item::image() would lead to ambiguities
|
|
|
|
when used like `item->label(0)`, hence we need our own method name.
|
|
|
|
Otherwise existing programs might not compile w/o error (e.g. fluid).
|
|
|
|
*/
|
|
|
|
void multi_label(const Fl_Multi_Label *ml) {
|
|
|
|
label(FL_MULTI_LABEL, (const char *)ml);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the title (label()) to an icon or image.
|
|
|
|
|
|
|
|
This sets the labeltype() to \_FL_IMAGE_LABEL (note the leading
|
|
|
|
underscore).
|
|
|
|
|
|
|
|
\see const char* Fl_Menu_Item::label() const
|
|
|
|
|
|
|
|
\since 1.4.0
|
|
|
|
|
|
|
|
\internal Overloading Fl_Menu_Item::image() would lead to ambiguities
|
|
|
|
when used like `item->label(0)`, hence we need our own method name.
|
|
|
|
Otherwise existing programs might not compile w/o error (e.g. fluid).
|
|
|
|
*/
|
|
|
|
void image_label(const Fl_Image *image) {
|
|
|
|
label(FL_IMAGE_LABEL, (const char *)image);
|
|
|
|
}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Returns the menu item's labeltype.
|
2008-09-15 04:27:28 +04:00
|
|
|
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.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Sets the menu item's labeltype.
|
2008-09-15 04:27:28 +04:00
|
|
|
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.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void labeltype(Fl_Labeltype a) {labeltype_ = a;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Gets the menu item's label color.
|
2008-09-15 04:27:28 +04:00
|
|
|
This color is passed to the labeltype routine, and is typically the
|
|
|
|
color of the label text. This defaults to FL_BLACK. If this
|
2010-12-09 03:04:06 +03:00
|
|
|
color is not black fltk will \b not use overlay bitplanes to draw
|
2008-09-15 04:27:28 +04:00
|
|
|
the menu - this is so that images put in the menu draw correctly.
|
|
|
|
*/
|
2009-09-27 15:06:56 +04:00
|
|
|
Fl_Color labelcolor() const {return labelcolor_;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2010-12-09 03:04:06 +03:00
|
|
|
/**
|
|
|
|
Sets the menu item's label color.
|
|
|
|
\see Fl_Color Fl_Menu_Item::labelcolor() const
|
|
|
|
*/
|
2009-09-27 15:06:56 +04:00
|
|
|
void labelcolor(Fl_Color a) {labelcolor_ = a;}
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Gets the menu item's label font.
|
|
|
|
Fonts are identified by small 8-bit indexes into a table. See the
|
2008-09-15 04:27:28 +04:00
|
|
|
enumeration list for predefined fonts. The default value is a
|
2008-12-13 21:31:54 +03:00
|
|
|
Helvetica font. The function Fl::set_font() can define new fonts.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2008-04-23 23:09:28 +04:00
|
|
|
Fl_Font labelfont() const {return labelfont_;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Sets the menu item's label font.
|
|
|
|
Fonts are identified by small 8-bit indexes into a table. See the
|
2008-09-15 04:27:28 +04:00
|
|
|
enumeration list for predefined fonts. The default value is a
|
2008-12-13 21:31:54 +03:00
|
|
|
Helvetica font. The function Fl::set_font() can define new fonts.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2008-04-23 23:09:28 +04:00
|
|
|
void labelfont(Fl_Font a) {labelfont_ = a;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2010-12-09 03:04:06 +03:00
|
|
|
/** Gets the label font pixel size/height. */
|
2008-08-16 01:11:21 +04:00
|
|
|
Fl_Fontsize labelsize() const {return labelsize_;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/** Sets the label font pixel size/height.*/
|
2008-08-16 01:11:21 +04:00
|
|
|
void labelsize(Fl_Fontsize a) {labelsize_ = a;}
|
2008-09-15 04:27:28 +04:00
|
|
|
|
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Returns the callback function that is set for the menu item.
|
|
|
|
Each item has space for a callback function and an argument for that
|
|
|
|
function. Due to back compatibility, 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.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
1999-03-18 23:04:13 +03:00
|
|
|
Fl_Callback_p callback() const {return callback_;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2010-12-09 03:04:06 +03:00
|
|
|
/**
|
|
|
|
Sets the menu item's callback function and userdata() argument.
|
|
|
|
\see Fl_Callback_p Fl_MenuItem::callback() const
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2010-12-09 03:04:06 +03:00
|
|
|
/**
|
|
|
|
Sets the menu item's callback function.
|
|
|
|
This method does not set the userdata() argument.
|
|
|
|
\see Fl_Callback_p Fl_MenuItem::callback() const
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void callback(Fl_Callback* c) {callback_=c;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2010-12-09 03:04:06 +03:00
|
|
|
/**
|
|
|
|
Sets the menu item's callback function.
|
|
|
|
This method does not set the userdata() argument.
|
|
|
|
\see Fl_Callback_p Fl_MenuItem::callback() const
|
|
|
|
*/
|
2024-04-05 00:40:29 +03:00
|
|
|
void callback(Fl_Callback0 *c) {
|
|
|
|
callback_ = (Fl_Callback *)(void *)c;
|
|
|
|
}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2010-12-09 03:04:06 +03:00
|
|
|
/**
|
|
|
|
Sets the menu item's callback function and userdata() argument.
|
|
|
|
The argument \p is cast to void* and stored as the userdata()
|
|
|
|
for the menu item's callback function.
|
|
|
|
\see Fl_Callback_p Fl_MenuItem::callback() const
|
|
|
|
*/
|
2024-04-05 00:40:29 +03:00
|
|
|
void callback(Fl_Callback1 *c, long p = 0) {
|
|
|
|
callback_ = (Fl_Callback *)(void *)c;
|
|
|
|
user_data_ = (void *)(fl_intptr_t)p;
|
|
|
|
}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Gets the user_data() argument that is sent to the callback function.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void* user_data() const {return user_data_;}
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Sets the user_data() argument that is sent to the callback function.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void user_data(void* v) {user_data_ = v;}
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Gets the user_data() argument that is sent to the callback function.
|
2008-09-15 04:27:28 +04:00
|
|
|
For convenience you can also define the callback as taking a long
|
2010-12-09 03:04:06 +03:00
|
|
|
argument. This method casts the stored userdata() argument to long
|
|
|
|
and returns it as a \e long value.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2010-12-08 17:00:35 +03:00
|
|
|
long argument() const {return (long)(fl_intptr_t)user_data_;}
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Sets the user_data() argument that is sent to the callback function.
|
2008-09-15 04:27:28 +04:00
|
|
|
For convenience you can also define the callback as taking a long
|
2010-12-09 03:04:06 +03:00
|
|
|
argument. This method casts the given argument \p v to void*
|
|
|
|
and stores it in the menu item's userdata() member.
|
|
|
|
This may not be portable to some machines.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2015-04-04 12:52:53 +03:00
|
|
|
void argument(long v) {user_data_ = (void*)(fl_intptr_t)v;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/** Gets what key combination shortcut will trigger the menu item. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int shortcut() const {return shortcut_;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
|
|
|
Sets exactly what key combination will trigger the menu item. The
|
2020-07-01 19:03:10 +03:00
|
|
|
value is a logical 'or' of a key and a set of shift flags, for instance
|
2008-09-15 04:27:28 +04:00
|
|
|
FL_ALT+'a' or FL_ALT+FL_F+10 or just 'a'. A value of
|
|
|
|
zero disables the shortcut.
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
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
|
2008-12-13 21:31:54 +03:00
|
|
|
key to be held down.
|
|
|
|
|
|
|
|
The shift flags can be any set of values accepted by Fl::event_state().
|
2020-07-01 19:03:10 +03:00
|
|
|
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
|
2008-12-13 21:31:54 +03:00
|
|
|
other bits indicates a "don't care" setting).
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void shortcut(int s) {shortcut_ = s;}
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
|
|
|
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.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
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.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int checkbox() const {return flags&FL_MENU_TOGGLE;}
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
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.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int radio() const {return flags&FL_MENU_RADIO;}
|
2014-09-06 23:03:43 +04:00
|
|
|
/** Returns the current value of the check or radio item.
|
2020-09-18 14:39:04 +03:00
|
|
|
This is zero (0) if the menu item is not checked and non-zero otherwise.
|
|
|
|
\since 1.4.0 this method returns 1 if the item is checked but you
|
|
|
|
should not rely on a particular value, only zero or non-zero.
|
|
|
|
\note The returned value for a checked menu item was FL_MENU_VALUE (4)
|
|
|
|
before FLTK 1.4.0.
|
2014-09-06 23:03:43 +04:00
|
|
|
*/
|
2020-09-18 14:39:04 +03:00
|
|
|
int value() const {return (flags & FL_MENU_VALUE) ? 1 : 0;}
|
2023-03-18 19:33:27 +03:00
|
|
|
|
|
|
|
/** Sets the current value of the check or radio item. */
|
|
|
|
void value(int v) { v ? set() : clear(); }
|
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2008-09-17 19:44:43 +04:00
|
|
|
Turns the check or radio item "on" for the menu item. Note that this
|
2022-01-13 16:20:55 +03:00
|
|
|
does not turn off any adjacent radio items like setonly() does.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void set() {flags |= FL_MENU_VALUE;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
|
|
|
/** Turns the check or radio item "off" for the menu item. */
|
1998-10-06 22:21:25 +04:00
|
|
|
void clear() {flags &= ~FL_MENU_VALUE;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2023-03-18 19:33:27 +03:00
|
|
|
void setonly(Fl_Menu_Item const* first = NULL);
|
2008-12-13 21:31:54 +03:00
|
|
|
|
|
|
|
/** Gets the visibility of an item. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int visible() const {return !(flags&FL_MENU_INVISIBLE);}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
|
|
|
/** Makes an item visible in the menu. */
|
1998-10-06 22:21:25 +04:00
|
|
|
void show() {flags &= ~FL_MENU_INVISIBLE;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
|
|
|
/** Hides an item in the menu. */
|
1998-10-06 22:21:25 +04:00
|
|
|
void hide() {flags |= FL_MENU_INVISIBLE;}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
|
|
|
/** Gets whether or not the item can be picked. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int active() const {return !(flags&FL_MENU_INACTIVE);}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
|
|
|
/** Allows a menu item to be picked. */
|
1998-10-06 22:21:25 +04:00
|
|
|
void activate() {flags &= ~FL_MENU_INACTIVE;}
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
|
|
|
Prevents a menu item from being picked. Note that this will also cause
|
|
|
|
the menu item to appear grayed-out.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void deactivate() {flags |= FL_MENU_INACTIVE;}
|
2008-09-15 04:27:28 +04:00
|
|
|
/** Returns non 0 if FL_INACTIVE and FL_INVISIBLE are cleared, 0 otherwise. */
|
|
|
|
int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-08-01 06:02:03 +04:00
|
|
|
// compatibility for FLUID so it can set the image of a menu item...
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2017-09-11 21:54:10 +03:00
|
|
|
/** Compatibility API for FLUID, same as image->label(this).
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2017-09-11 21:54:10 +03:00
|
|
|
\note This method is intended for internal use by fluid and may
|
|
|
|
not do what you expect.
|
|
|
|
*/
|
|
|
|
void image(Fl_Image* image) {image->label(this);}
|
|
|
|
|
|
|
|
/** Compatibility API for FLUID, same as image.label(this).
|
|
|
|
|
|
|
|
\note This method is intended for internal use by fluid and may
|
|
|
|
not do what you expect.
|
|
|
|
*/
|
|
|
|
void image(Fl_Image& image) {image.label(this);}
|
2002-08-01 06:02:03 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
// used by menubar:
|
2002-08-14 20:49:38 +04:00
|
|
|
int measure(int* h, const Fl_Menu_*) const;
|
|
|
|
void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// popup menus without using an Fl_Menu_ widget:
|
2002-08-14 20:49:38 +04:00
|
|
|
const Fl_Menu_Item* popup(
|
1998-10-06 22:21:25 +04:00
|
|
|
int X, int Y,
|
|
|
|
const char *title = 0,
|
|
|
|
const Fl_Menu_Item* picked=0,
|
|
|
|
const Fl_Menu_* = 0) const;
|
2002-08-14 20:49:38 +04:00
|
|
|
const Fl_Menu_Item* pulldown(
|
1998-10-06 22:21:25 +04:00
|
|
|
int X, int Y, int W, int H,
|
|
|
|
const Fl_Menu_Item* picked = 0,
|
|
|
|
const Fl_Menu_* = 0,
|
|
|
|
const Fl_Menu_Item* title = 0,
|
|
|
|
int menubar=0) const;
|
2002-08-14 20:49:38 +04:00
|
|
|
const Fl_Menu_Item* test_shortcut() const;
|
2010-11-11 12:12:05 +03:00
|
|
|
const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Calls the Fl_Menu_Item item's callback, and provides the Fl_Widget argument.
|
|
|
|
The callback is called with the stored user_data() as its second argument.
|
|
|
|
You must first check that callback() is non-zero before calling this.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2023-01-05 15:51:30 +03:00
|
|
|
void do_callback(Fl_Widget* o) const {Fl::callback_reason_=FL_REASON_SELECTED; callback_(o, user_data_);}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Calls the Fl_Menu_Item item's callback, and provides the Fl_Widget argument.
|
|
|
|
This call overrides the callback's second argument with the given value \p arg.
|
|
|
|
You must first check that callback() is non-zero before calling this.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2023-01-05 15:51:30 +03:00
|
|
|
void do_callback(Fl_Widget* o,void* arg) const {Fl::callback_reason_=FL_REASON_SELECTED; callback_(o, arg);}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/**
|
2010-12-09 03:04:06 +03:00
|
|
|
Calls the Fl_Menu_Item item's callback, and provides the Fl_Widget argument.
|
|
|
|
This call overrides the callback's second argument with the
|
|
|
|
given value \p arg. long \p arg is cast to void* when calling
|
|
|
|
the callback.
|
|
|
|
You must first check that callback() is non-zero before calling this.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2023-01-05 15:51:30 +03:00
|
|
|
void do_callback(Fl_Widget* o,long arg) const {Fl::callback_reason_=FL_REASON_SELECTED; callback_(o, (void*)(fl_intptr_t)arg);}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2020-09-18 18:17:36 +03:00
|
|
|
/** Back compatibility only.
|
|
|
|
\deprecated
|
|
|
|
Please use Fl_Menu_Item::value() instead.
|
|
|
|
This method will be removed in FLTK 1.5.0 or later.
|
|
|
|
\see value()
|
|
|
|
*/
|
|
|
|
inline int checked() const {return value();}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2020-09-18 18:17:36 +03:00
|
|
|
/** Back compatibility only.
|
|
|
|
\deprecated
|
|
|
|
Please use Fl_Menu_Item::set() instead.
|
|
|
|
This method will be removed in FLTK 1.5.0 or later.
|
|
|
|
\see set()
|
|
|
|
*/
|
|
|
|
inline void check() {set();}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2020-09-18 18:17:36 +03:00
|
|
|
/** Back compatibility only.
|
|
|
|
\deprecated
|
|
|
|
Please use Fl_Menu_Item::clear() instead.
|
|
|
|
This method will be removed in FLTK 1.5.0 or later.
|
|
|
|
\see clear()
|
|
|
|
*/
|
|
|
|
inline void uncheck() {clear();}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2010-04-16 21:55:45 +04:00
|
|
|
int insert(int,const char*,int,Fl_Callback*,void* =0, int =0);
|
2002-08-14 20:49:38 +04:00
|
|
|
int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2008-09-15 04:27:28 +04:00
|
|
|
/** See int add(const char*, int shortcut, Fl_Callback*, void*, int) */
|
1998-10-06 22:21:25 +04:00
|
|
|
int add(const char*a, const char* b, Fl_Callback* c,
|
2020-07-01 19:03:10 +03:00
|
|
|
void* d = 0, int e = 0) {
|
1998-10-06 22:21:25 +04:00
|
|
|
return add(a,fl_old_shortcut(b),c,d,e);}
|
2008-12-13 21:31:54 +03:00
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
int size() const ;
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
2008-09-15 21:46:42 +04:00
|
|
|
typedef Fl_Menu_Item Fl_Menu; // back compatibility
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
enum { // back-compatibility enum:
|
|
|
|
FL_PUP_NONE = 0,
|
|
|
|
FL_PUP_GREY = FL_MENU_INACTIVE,
|
|
|
|
FL_PUP_GRAY = FL_MENU_INACTIVE,
|
|
|
|
FL_MENU_BOX = FL_MENU_TOGGLE,
|
|
|
|
FL_PUP_BOX = FL_MENU_TOGGLE,
|
|
|
|
FL_MENU_CHECK = FL_MENU_VALUE,
|
|
|
|
FL_PUP_CHECK = FL_MENU_VALUE,
|
|
|
|
FL_PUP_RADIO = FL_MENU_RADIO,
|
1998-10-06 22:21:25 +04:00
|
|
|
FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
|
|
|
|
FL_PUP_SUBMENU = FL_SUBMENU_POINTER
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|