fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Menu_ Class Reference

#include <Fl_Menu_.H>

Inheritance diagram for Fl_Menu_:
[legend]
Collaboration diagram for Fl_Menu_:
[legend]

Public Member Functions

 Fl_Menu_ (int, int, int, int, const char *=0)
 
 ~Fl_Menu_ ()
 
int item_pathname (char *name, int namelen, const Fl_Menu_Item *finditem=0) const
 
const Fl_Menu_Itempicked (const Fl_Menu_Item *)
 
const Fl_Menu_Itemfind_item (const char *name)
 
const Fl_Menu_Itemfind_item (Fl_Callback *)
 
int find_index (const char *name) const
 
int find_index (const Fl_Menu_Item *item) const
 
int find_index (Fl_Callback *cb) const
 
const Fl_Menu_Itemtest_shortcut ()
 
void global ()
 
const Fl_Menu_Itemmenu () const
 
void menu (const Fl_Menu_Item *m)
 
void copy (const Fl_Menu_Item *m, void *user_data=0)
 
int insert (int index, const char *, int shortcut, Fl_Callback *, void *=0, int=0)
 
int add (const char *, int shortcut, Fl_Callback *, void *=0, int=0)
 
int add (const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
 
int insert (int index, const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
 
int add (const char *)
 
int size () const
 
void size (int W, int H)
 
void clear ()
 
int clear_submenu (int index)
 
void replace (int, const char *)
 
void remove (int)
 
void shortcut (int i, int s)
 
void mode (int i, int fl)
 
int mode (int i) const
 
const Fl_Menu_Itemmvalue () const
 
int value () const
 
int value (const Fl_Menu_Item *)
 
int value (int i)
 
const char * text () const
 
const char * text (int i) const
 
Fl_Font textfont () const
 
void textfont (Fl_Font c)
 
Fl_Fontsize textsize () const
 
void textsize (Fl_Fontsize c)
 
Fl_Color textcolor () const
 
void textcolor (Fl_Color c)
 
Fl_Boxtype down_box () const
 
void down_box (Fl_Boxtype b)
 
Fl_Color down_color () const
 
void down_color (unsigned c)
 
void setonly (Fl_Menu_Item *item)
 
- Public Member Functions inherited from Fl_Widget
virtual ~Fl_Widget ()
 
virtual void draw ()=0
 
virtual int handle (int event)
 
int is_label_copied () const
 
Fl_Groupparent () const
 
void parent (Fl_Group *p)
 
uchar type () const
 
void type (uchar t)
 
int x () const
 
int y () const
 
int w () const
 
int h () const
 
virtual void resize (int x, int y, int w, int h)
 
int damage_resize (int, int, int, int)
 
void position (int X, int Y)
 
void size (int W, int H)
 
Fl_Align align () const
 
void align (Fl_Align alignment)
 
Fl_Boxtype box () const
 
void box (Fl_Boxtype new_box)
 
Fl_Color color () const
 
void color (Fl_Color bg)
 
Fl_Color selection_color () const
 
void selection_color (Fl_Color a)
 
void color (Fl_Color bg, Fl_Color sel)
 
const char * label () const
 
void label (const char *text)
 
void copy_label (const char *new_label)
 
void label (Fl_Labeltype a, const char *b)
 
Fl_Labeltype labeltype () const
 
void labeltype (Fl_Labeltype a)
 
Fl_Color labelcolor () const
 
void labelcolor (Fl_Color c)
 
Fl_Font labelfont () const
 
void labelfont (Fl_Font f)
 
Fl_Fontsize labelsize () const
 
void labelsize (Fl_Fontsize pix)
 
Fl_Imageimage ()
 
const Fl_Imageimage () const
 
void image (Fl_Image *img)
 
void image (Fl_Image &img)
 
Fl_Imagedeimage ()
 
const Fl_Imagedeimage () const
 
void deimage (Fl_Image *img)
 
void deimage (Fl_Image &img)
 
const char * tooltip () const
 
void tooltip (const char *text)
 
void copy_tooltip (const char *text)
 
Fl_Callback_p callback () const
 
void callback (Fl_Callback *cb, void *p)
 
void callback (Fl_Callback *cb)
 
void callback (Fl_Callback0 *cb)
 
void callback (Fl_Callback1 *cb, long p=0)
 
void * user_data () const
 
void user_data (void *v)
 
long argument () const
 
void argument (long v)
 
Fl_When when () const
 
void when (uchar i)
 
unsigned int visible () const
 
int visible_r () const
 
virtual void show ()
 
virtual void hide ()
 
void set_visible ()
 
void clear_visible ()
 
unsigned int active () const
 
int active_r () const
 
void activate ()
 
void deactivate ()
 
unsigned int output () const
 
void set_output ()
 
void clear_output ()
 
unsigned int takesevents () const
 
unsigned int changed () const
 
void set_changed ()
 
void clear_changed ()
 
void clear_active ()
 
void set_active ()
 
int take_focus ()
 
void set_visible_focus ()
 
void clear_visible_focus ()
 
void visible_focus (int v)
 
unsigned int visible_focus ()
 
void do_callback ()
 
void do_callback (Fl_Widget *o, long arg)
 
void do_callback (Fl_Widget *o, void *arg=0)
 
int test_shortcut ()
 
void _set_fullscreen ()
 
void _clear_fullscreen ()
 
int contains (const Fl_Widget *w) const
 
int inside (const Fl_Widget *wgt) const
 
void redraw ()
 
void redraw_label ()
 
uchar damage () const
 
void clear_damage (uchar c=0)
 
void damage (uchar c)
 
void damage (uchar c, int x, int y, int w, int h)
 
void draw_label (int, int, int, int, Fl_Align) const
 
void measure_label (int &ww, int &hh) const
 
Fl_Windowwindow () const
 
Fl_Windowtop_window () const
 
Fl_Windowtop_window_offset (int &xoff, int &yoff) const
 
virtual Fl_Groupas_group ()
 
virtual Fl_Windowas_window ()
 
virtual class Fl_Gl_Windowas_gl_window ()
 
int use_accents_menu ()
 
Fl_Color color2 () const
 
void color2 (unsigned a)
 

Protected Member Functions

int item_pathname_ (char *name, int namelen, const Fl_Menu_Item *finditem, const Fl_Menu_Item *menu=0) const
 
- Protected Member Functions inherited from Fl_Widget
 Fl_Widget (int x, int y, int w, int h, const char *label=0L)
 
void x (int v)
 
void y (int v)
 
void w (int v)
 
void h (int v)
 
unsigned int flags () const
 
void set_flag (unsigned int c)
 
void clear_flag (unsigned int c)
 
void draw_box () const
 
void draw_box (Fl_Boxtype t, Fl_Color c) const
 
void draw_box (Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) const
 
void draw_backdrop () const
 
void draw_focus ()
 
void draw_focus (Fl_Boxtype t, int x, int y, int w, int h) const
 
void draw_label () const
 
void draw_label (int, int, int, int) const
 

Protected Attributes

uchar alloc
 
uchar down_box_
 
Fl_Font textfont_
 
Fl_Fontsize textsize_
 
Fl_Color textcolor_
 

Private Attributes

Fl_Menu_Itemmenu_
 
const Fl_Menu_Itemvalue_
 

Additional Inherited Members

- Static Public Member Functions inherited from Fl_Widget
static void default_callback (Fl_Widget *cb, void *d)
 
static unsigned int label_shortcut (const char *t)
 
static int test_shortcut (const char *, const bool require_alt=false)
 
- Protected Types inherited from Fl_Widget
enum  {
  INACTIVE = 1<<0, INVISIBLE = 1<<1, OUTPUT = 1<<2, NOBORDER = 1<<3,
  FORCE_POSITION = 1<<4, NON_MODAL = 1<<5, SHORTCUT_LABEL = 1<<6, CHANGED = 1<<7,
  OVERRIDE = 1<<8, VISIBLE_FOCUS = 1<<9, COPIED_LABEL = 1<<10, CLIP_CHILDREN = 1<<11,
  MENU_WINDOW = 1<<12, TOOLTIP_WINDOW = 1<<13, MODAL = 1<<14, NO_OVERLAY = 1<<15,
  GROUP_RELATIVE = 1<<16, COPIED_TOOLTIP = 1<<17, FULLSCREEN = 1<<18, MAC_USE_ACCENTS_MENU = 1<<19,
  USERFLAG3 = 1<<29, USERFLAG2 = 1<<30, USERFLAG1 = 1<<31
}
 

Detailed Description

Base class of all widgets that have a menu in FLTK.

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. The array may either be supplied directly by the user program, or it may be "private": a dynamically allocated array managed by the Fl_Menu_.

When the user clicks a menu item, value() is set to that item and then:

  • If the Fl_Menu_Item has a callback set, that callback is invoked with any userdata configured for it. (The Fl_Menu_ widget's callback is NOT invoked.)
  • For any Fl_Menu_Items that don't have a callback set, the Fl_Menu_ widget's callback is invoked with any userdata configured for it. The callback can determine which item was picked using value(), mvalue(), item_pathname(), etc.

Definition at line 51 of file Fl_Menu_.H.

Constructor & Destructor Documentation

◆ Fl_Menu_()

Fl_Menu_::Fl_Menu_ ( int  X,
int  Y,
int  W,
int  H,
const char *  l = 0 
)

◆ ~Fl_Menu_()

Fl_Menu_::~Fl_Menu_ ( )

Definition at line 443 of file Fl_Menu_.cxx.

References clear().

Member Function Documentation

◆ add() [1/3]

int Fl_Menu_::add ( const char *  str)

This is a Forms (and SGI GL library) compatible add function, it adds many menu items, with '|' separating the menu items, and tab separating the menu item names from an optional shortcut string.

The passed string is split at any '|' characters and then add(s,0,0,0,0) is done with each section. This is often useful if you are just using the value, and is compatible with Forms and other GL programs. The section strings use the same special characters as described for the long version of add().

No items must be added to a menu during a callback to the same menu.

Parameters
strstring containing multiple menu labels as described above
Returns
the index into the menu() array, where the entry was added

Definition at line 435 of file Fl_Menu_add.cxx.

References add(), buf, and fl_old_shortcut().

◆ add() [2/3]

int Fl_Menu_::add ( const char *  label,
int  shortcut,
Fl_Callback callback,
void *  userdata = 0,
int  flags = 0 
)

Adds a new menu item.

Parameters
[in]labelThe text label for the menu item.
[in]shortcutOptional keyboard shortcut that can be an int or string: (FL_CTRL+'a') or "^a". Default 0 if none.
[in]callbackOptional callback invoked when user clicks the item. Default 0 if none.
[in]userdataOptional user data passed as an argument to the callback. Default 0 if none.
[in]flagsOptional flags that control the type of menu item; see below. Default is 0 for none.
Returns
The index into the menu() array, where the entry was added.
Description
If the menu array was directly set with menu(x), then copy() is done to make a private array.
Since this method can change the internal menu array, any menu item pointers or indices the application may have cached can become stale, and should be recalculated/refreshed.
A menu item's callback must not add() items to its parent menu during the callback.

Detailed Description of Parameters

label
The menu item's label. This argument is required and must not be NULL.
The characters "&", "/", "\", and "_" are treated as special characters in the label string. The "&" character specifies that the following character is an accelerator and will be underlined. The "\" character is used to escape the next character in the string. Labels starting with the "_" character cause a divider to be placed after that menu item.
A label of the form "File/Quit" will create the submenu "File" with a menu item called "Quit". The "/" character is ignored if it appears as the first character of the label string, e.g. "/File/Quit".
The label string is copied to new memory and can be freed. The other arguments (including the shortcut) 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.
shortcut
The keyboard shortcut for this menu item.
This parameter is optional, and defaults to 0 to indicate no shortcut.
The shortcut can either be a raw integer value (eg. FL_CTRL+'A') or a string (eg. "^c" or "^97").
Raw integer shortcuts can be a combination of keyboard chars (eg. 'A') and optional keyboard modifiers (see Fl::event_state(), e.g. FL_SHIFT, etc). In addition, FL_COMMAND can be used to denote FL_META under Mac OS X and FL_CTRL under other platforms.
String shortcuts can be specified in one of two ways:
 [#+^]<ascii_value>    e.g. "97", "^97", "+97", "#97"
 [#+^]<ascii_char>     e.g. "a", "^a", "+a", "#a"
..where <ascii_value> is a decimal value representing an ASCII character (eg. 97 is the ascii code for 'a'), and the optional prefixes enhance the value that follows. Multiple prefixes must appear in the order below.
 # - Alt
 + - Shift
 ^ - Control
Internally, the text shortcuts are converted to integer values using fl_old_shortcut(const char*).
callback
The callback to invoke when this menu item is selected.
This parameter is optional, and defaults to 0 for no callback.
userdata
The callback's 'user data' that is passed to the callback.
This parameter is optional, and defaults to 0.
flags
These are bit flags to define what kind of menu item this is.
This parameter is optional, and defaults to 0 to define a 'regular' menu item.
These flags can be 'OR'ed together:
FL_MENU_INACTIVE // Deactivate menu item (gray out)
FL_MENU_TOGGLE // Item is a checkbox toggle (shows checkbox for on/off state)
FL_MENU_VALUE // The on/off state for checkbox/radio buttons (if set, state is 'on')
FL_MENU_RADIO // Item is a radio button (one checkbox of many can be on)
FL_MENU_INVISIBLE // Item will not show up (shortcut will work)
FL_SUBMENU_POINTER // Indicates user_data() is a pointer to another menu array
FL_SUBMENU // This item is a submenu to other items
FL_MENU_DIVIDER // Creates divider line below this item. Also ends a group of radio buttons.

If FL_SUBMENU is set in an item's flags, then actually two items are added: the first item is the menu item (submenu title), as expected, and the second item is the submenu terminating item with the label and all other members set to 0. If you add submenus with the 'path' technique, then the corresponding submenu terminators (maybe more than one) are added as well.

Todo:
Raw integer shortcut needs examples. Dependent on responses to http://fltk.org/newsgroups.php?gfltk.development+v:10086 and results of STR#2344

Definition at line 332 of file Fl_Menu_add.cxx.

References Fl_Widget::callback(), Fl_Widget::flags(), insert(), Fl_Widget::label(), and shortcut().

Referenced by add(), Fl_File_Chooser::favoritesButtonCB(), Fl_File_Chooser::filter(), Fl_Comment_Type::open(), print_load(), Fl_File_Chooser::showChoiceCB(), and Fl_File_Chooser::update_favorites().

◆ add() [3/3]

int Fl_Menu_::add ( const char *  a,
const char *  b,
Fl_Callback c,
void *  d = 0,
int  e = 0 
)
inline

See int Fl_Menu_::add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0)

Definition at line 116 of file Fl_Menu_.H.

References b, and fl_old_shortcut().

◆ clear()

void Fl_Menu_::clear ( )

Same as menu(NULL), set the array pointer to null, indicating a zero-length menu.

Menus must not be cleared during a callback to the same menu.

Definition at line 457 of file Fl_Menu_.cxx.

References alloc, fl_menu_array_owner, free(), menu_, size(), text(), and value_.

Referenced by Fl_File_Chooser::filter(), menu(), Fl_Comment_Type::open(), print_load(), Fl_File_Chooser::update_favorites(), and ~Fl_Menu_().

◆ clear_submenu()

int Fl_Menu_::clear_submenu ( int  index)

Clears the specified submenu pointed to by index of all menu items.

This method is useful for clearing a submenu so that it can be re-populated with new items. Example: a "File/Recent Files/..." submenu that shows the last few files that have been opened.

The specified index must point to a submenu.

The submenu is cleared with remove(). If the menu array was directly set with menu(x), then copy() is done to make a private array.

Warning
Since this method can change the internal menu array, any menu item pointers or indices the application may have cached can become stale, and should be recalculated/refreshed.

Example:

int index = menubar->find_index("File/Recent"); // get index of "File/Recent" submenu
if ( index != -1 ) menubar->clear_submenu(index); // clear the submenu
menubar->add("File/Recent/Aaa");
menubar->add("File/Recent/Bbb");
[..]
Parameters
indexThe index of the submenu to be cleared
Returns
0 on success, -1 if the index is out of range or not a submenu
See also
remove(int)

Definition at line 501 of file Fl_Menu_.cxx.

References FL_SUBMENU, Fl_Widget::flags(), menu_, remove(), size(), and text().

◆ copy()

void Fl_Menu_::copy ( const Fl_Menu_Item m,
void *  ud = 0 
)

Sets the menu array pointer with a copy of m that will be automatically deleted. If userdata ud is not NULL, then all user data pointers are changed in the menus as well. See void Fl_Menu_::menu(const Fl_Menu_Item* m).

Definition at line 430 of file Fl_Menu_.cxx.

References alloc, Fl_Menu_Item::callback_, menu(), Fl_Menu_Item::size(), and Fl_Menu_Item::user_data_.

Referenced by insert(), remove(), and replace().

◆ down_box() [1/2]

Fl_Boxtype Fl_Menu_::down_box ( ) const
inline

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 compatibility.

Definition at line 173 of file Fl_Menu_.H.

Referenced by Fl_Menu_Type::copy_properties(), Fl_Menu_Item::draw(), Fl_Choice::Fl_Choice(), Fl_File_Chooser::Fl_File_Chooser(), Fl_Menu_(), Fl_Menu_Button::Fl_Menu_Button(), make_data_panel(), make_decl_panel(), make_declblock_panel(), make_function_panel(), make_global_settings_window(), make_print_panel(), make_project_window(), make_settings_window(), and make_widget_panel().

◆ down_box() [2/2]

void Fl_Menu_::down_box ( Fl_Boxtype  b)
inline

See Fl_Boxtype Fl_Menu_::down_box() const

Definition at line 175 of file Fl_Menu_.H.

References b.

◆ down_color() [1/2]

Fl_Color Fl_Menu_::down_color ( ) const
inline

For back compatibility, same as selection_color()

Definition at line 178 of file Fl_Menu_.H.

References Fl_Widget::selection_color().

◆ down_color() [2/2]

void Fl_Menu_::down_color ( unsigned  c)
inline

For back compatibility, same as selection_color()

Definition at line 180 of file Fl_Menu_.H.

References Fl_Widget::selection_color().

◆ find_index() [1/3]

int Fl_Menu_::find_index ( const char *  pathname) const

Find the menu item index for a given menu pathname, such as "Edit/Copy".

This method finds a menu item's index position for the given menu pathname, also traversing submenus, but not submenu pointers (FL_SUBMENU_POINTER).

To get the menu item pointer for a pathname, use find_item()

Parameters
[in]pathnameThe path and name of the menu item to find
Returns
The index of the matching item, or -1 if not found.
See also
item_pathname()

Definition at line 220 of file Fl_Menu_.cxx.

References FL_SUBMENU, Fl_Menu_Item::flags, Fl_Menu_Item::label(), menu_, size(), and strlcat.

Referenced by find_item().

◆ find_index() [2/3]

int Fl_Menu_::find_index ( const Fl_Menu_Item item) const

Find the index into the menu array for a given item.

A way to convert a menu item pointer into an index.

Does not handle items that are in submenu pointers (FL_SUBMENU_POINTER).

-1 is returned if the item is not in this menu or is part of an FL_SUBMENU_POINTER submenu.

Current implementation is fast and not expensive.

// Convert an index-to-item
int index = 12;
const Fl_Menu_Item *item = mymenu->menu() + index;
// Convert an item-to-index
int index = mymenu->find_index(item);
if ( index == -1 ) { ..error.. }
Parameters
[in]itemThe item to be found
Returns
The index of the item, or -1 if not found.
See also
menu()

Definition at line 182 of file Fl_Menu_.cxx.

References max(), menu_, and size().

◆ find_index() [3/3]

int Fl_Menu_::find_index ( Fl_Callback cb) const

Find the index into the menu array for a given callback cb.

This method finds a menu item's index position, also traversing submenus, but not submenu pointers (FL_SUBMENU_POINTER). This is useful if an application uses internationalisation and a menu item can not be found using its label. This search is also much faster.

Parameters
cbFind the first item with this callback
Returns
The index of the item with the specific callback, or -1 if not found
See also
find_index(const char*)

Definition at line 200 of file Fl_Menu_.cxx.

References Fl_Widget::callback_, cb(), menu_, and size().

◆ find_item() [1/2]

const Fl_Menu_Item * Fl_Menu_::find_item ( const char *  pathname)

Find the menu item for a given menu pathname, such as "Edit/Copy".

This method finds a menu item in the menu array, also traversing submenus, but not submenu pointers (FL_SUBMENU_POINTER).

To get the menu item's index, use find_index(const char*)

Example:

Fl_Menu_Bar *menubar = new Fl_Menu_Bar(..);
menubar->add("File/&Open");
menubar->add("File/&Save");
menubar->add("Edit/&Copy");
// [..]
if ( ( item = (Fl_Menu_Item*)menubar->find_item("File/&Open") ) != NULL ) {
}
if ( ( item = (Fl_Menu_Item*)menubar->find_item("Edit/&Copy") ) != NULL ) {
}
Parameters
pathnameThe path and name of the menu item
Returns
The item found, or NULL if not found
See also
find_index(const char*), find_item(Fl_Callback*), item_pathname()

Definition at line 151 of file Fl_Menu_.cxx.

References find_index(), and menu_.

Referenced by make_main_window().

◆ find_item() [2/2]

const Fl_Menu_Item * Fl_Menu_::find_item ( Fl_Callback cb)

Find the menu item for the given callback cb.

This method finds a menu item in a menu array, also traversing submenus, but not submenu pointers. This is useful if an application uses internationalisation and a menu item can not be found using its label. This search is also much faster.

Parameters
[in]cbfind the first item with this callback
Returns
The item found, or NULL if not found
See also
find_item(const char*)

Definition at line 261 of file Fl_Menu_.cxx.

References Fl_Menu_Item::callback_, cb(), menu_, and size().

◆ global()

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 (so don't destroy the widget!)

Definition at line 44 of file Fl_Menu_global.cxx.

References Fl::add_handler(), handler(), and the_widget.

Referenced by make_main_window().

◆ insert() [1/2]

int Fl_Menu_::insert ( int  index,
const char *  label,
int  shortcut,
Fl_Callback callback,
void *  userdata = 0,
int  flags = 0 
)

Inserts a new menu item at the specified index position.

If index is -1, the menu item is appended; same behavior as add().

To properly insert a menu item, label must be the name of the item (eg. "Quit"), and not a 'menu pathname' (eg. "File/Quit"). If a menu pathname is specified, the value of index is ignored, the new item's position defined by the pathname.

For more details, see add(). Except for the index parameter, add() has more detailed information on parameters and behavior, and is functionally equivalent.

Parameters
[in]indexThe menu array's index position where the new item is inserted. If -1, behavior is the same as add().
[in]labelThe text label for the menu item. If the label is a menu pathname, index is ignored, and the pathname indicates the position of the new item.
[in]shortcutOptional keyboard shortcut. Can be an int (FL_CTRL+'a') or a string ("^a"). Default is 0.
[in]callbackOptional callback invoked when user clicks the item. Default 0 if none.
[in]userdataOptional user data passed as an argument to the callback. Default 0 if none.
[in]flagsOptional flags that control the type of menu item; see add() for more info. Default is 0 for none.
Returns
The index into the menu() array, where the entry was added.
See also
add()

Definition at line 368 of file Fl_Menu_add.cxx.

References alloc, Fl_Widget::callback(), copy(), fl_menu_array_owner, Fl_Widget::flags(), Fl_Menu_Item::insert(), Fl_Widget::label(), local_array, local_array_alloc, local_array_size, menu_, shortcut(), size(), and value_.

Referenced by add().

◆ insert() [2/2]

int Fl_Menu_::insert ( int  index,
const char *  a,
const char *  b,
Fl_Callback c,
void *  d = 0,
int  e = 0 
)
inline

See int Fl_Menu_::insert(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0)

Definition at line 120 of file Fl_Menu_.H.

References b, and fl_old_shortcut().

◆ item_pathname()

int Fl_Menu_::item_pathname ( char *  name,
int  namelen,
const Fl_Menu_Item finditem = 0 
) const

Get the menu 'pathname' for the specified menuitem.

If finditem==NULL, mvalue() is used (the most recently picked menuitem).

Example:

Fl_Menu_Bar *menubar = 0;
void my_menu_callback(Fl_Widget*,void*) {
char name[80];
if ( menubar->item_pathname(name, sizeof(name)-1) == 0 ) { // recently picked item
if ( strcmp(name, "File/&Open") == 0 ) { .. } // open invoked
if ( strcmp(name, "File/&Save") == 0 ) { .. } // save invoked
if ( strcmp(name, "Edit/&Copy") == 0 ) { .. } // copy invoked
}
}
int main() {
[..]
menubar = new Fl_Menu_Bar(..);
menubar->add("File/&Open", 0, my_menu_callback);
menubar->add("File/&Save", 0, my_menu_callback);
menubar->add("Edit/&Copy", 0, my_menu_callback);
[..]
}
Returns
  • 0 : OK (name has menuitem's pathname)
  • -1 : item not found (name="")
  • -2 : 'name' not large enough (name="")
See also
find_item()

Definition at line 65 of file Fl_Menu_.cxx.

References item_pathname_(), menu_, and name.

Referenced by Fl_Comment_Type::open().

◆ item_pathname_()

int Fl_Menu_::item_pathname_ ( char *  name,
int  namelen,
const Fl_Menu_Item finditem,
const Fl_Menu_Item menu = 0 
) const
protected

◆ menu() [1/2]

const Fl_Menu_Item* Fl_Menu_::menu ( ) const
inline

Returns a pointer to the array of Fl_Menu_Items. This will either be the value passed to menu(value) or the private copy.

See also
size() – returns the size of the Fl_Menu_Item array.

Example: How to walk the array:

for ( int t=0; t<menubar->size(); t++ ) { // walk array of items
const Fl_Menu_Item &item = menubar->menu()[t]; // get each item
fprintf(stderr, "item #%d -- label=%s, value=%s type=%s\n",
t,
item.label() ? item.label() : "(Null)", // menu terminators have NULL labels
(item.flags & FL_MENU_VALUE) ? "set" : "clear", // value of toggle or radio items
(item.flags & FL_SUBMENU) ? "Submenu" : "Item"); // see if item is a submenu or actual item
}

Definition at line 110 of file Fl_Menu_.H.

References menu_.

Referenced by align_position_cb(), align_text_image_cb(), Fl_Menu_Type::build_menu(), cb_Save(), copy(), Fl_Menu_Type::copy_properties(), Fl_Menu_Bar::draw(), Fl_File_Chooser::favoritesButtonCB(), Fl_Color_Chooser::Fl_Color_Chooser(), Fl_Menu_Bar::handle(), Fl_Menu_Button::handle(), Fl_Choice::handle(), item_pathname_(), make_data_panel(), make_decl_panel(), make_declblock_panel(), make_function_panel(), make_global_settings_window(), make_main_window(), make_print_panel(), make_project_window(), make_settings_window(), make_widget_panel(), Fl_Comment_Type::open(), Fl_Menu_Button::popup(), print_load(), print_update_status(), Fl_PostScript_Printer::start_job(), subtype_cb(), Fl_File_Chooser::update_favorites(), and Fl_Choice_Type::widget().

◆ menu() [2/2]

void Fl_Menu_::menu ( const Fl_Menu_Item m)

Sets the menu array pointer directly. If the old menu is private it is deleted. NULL is allowed and acts the same as a zero-length menu. If you try to modify the array (with add(), replace(), or remove()) a private copy is automatically done.

Definition at line 418 of file Fl_Menu_.cxx.

References clear(), menu_, and value_.

◆ mode() [1/2]

int Fl_Menu_::mode ( int  i) const
inline

Gets the flags of item i. For a list of the flags, see Fl_Menu_Item.

Definition at line 135 of file Fl_Menu_.H.

References Fl_Menu_Item::flags, and menu_.

◆ mode() [2/2]

void Fl_Menu_::mode ( int  i,
int  fl 
)
inline

Sets the flags of item i. For a list of the flags, see Fl_Menu_Item.

Definition at line 133 of file Fl_Menu_.H.

References Fl_Menu_Item::flags, and menu_.

◆ mvalue()

const Fl_Menu_Item* Fl_Menu_::mvalue ( ) const
inline

◆ picked()

const Fl_Menu_Item * Fl_Menu_::picked ( const Fl_Menu_Item v)

When user picks a menu item, call this. It will do the callback. Unfortunately this also casts away const for the checkboxes, but this was necessary so non-checkbox menus can really be declared const...

Definition at line 288 of file Fl_Menu_.cxx.

References Fl_Menu_Item::callback_, Fl_Widget::changed(), Fl_Menu_Item::do_callback(), Fl_Widget::do_callback(), FL_MENU_TOGGLE, FL_MENU_VALUE, FL_WHEN_CHANGED, FL_WHEN_NOT_CHANGED, FL_WHEN_RELEASE, Fl_Menu_Item::flags, Fl_Menu_Item::radio(), Fl_Widget::redraw(), Fl_Widget::set_changed(), setonly(), Fl_Menu_Item::value(), value_, and Fl_Widget::when().

Referenced by Fl_Menu_Bar::handle(), Fl_Choice::handle(), and Fl_Menu_Button::popup().

◆ remove()

void Fl_Menu_::remove ( int  i)

Deletes item i from the menu. If the menu array was directly set with menu(x) then copy() is done to make a private array.

No items must be removed from a menu during a callback to the same menu.

Parameters
iindex into menu array

Definition at line 482 of file Fl_Menu_add.cxx.

References alloc, copy(), free(), menu_, Fl_Menu_Item::next(), and size().

Referenced by clear_submenu(), and Fl_Comment_Type::open().

◆ replace()

void Fl_Menu_::replace ( int  i,
const char *  str 
)

Changes the text of item i. This is the only way to get slash into an add()'ed menu item. If the menu array was directly set with menu(x) then copy() is done to make a private array.

Parameters
iindex into menu array
strnew label for menu item at index i

Definition at line 462 of file Fl_Menu_add.cxx.

References alloc, copy(), free(), menu_, size(), Fl_Menu_Item::text, and text().

◆ setonly()

void Fl_Menu_::setonly ( Fl_Menu_Item item)

Turns the radio item "on" for the menu item and turns "off" adjacent radio items of the same group.

Definition at line 344 of file Fl_Menu_.cxx.

References Fl_Menu_Item::clear(), first, first_submenu_item(), FL_MENU_DIVIDER, FL_MENU_RADIO, FL_MENU_VALUE, Fl_Menu_Item::flags, menu_, Fl_Menu_Item::radio(), and Fl_Menu_Item::text.

Referenced by picked().

◆ shortcut()

void Fl_Menu_::shortcut ( int  i,
int  s 
)
inline

Changes the shortcut of item i to s.

Definition at line 131 of file Fl_Menu_.H.

References menu_, and Fl_Menu_Item::shortcut().

Referenced by add(), and insert().

◆ size() [1/2]

int Fl_Menu_::size ( ) const

This returns the number of Fl_Menu_Item structures that make up the menu, correctly counting submenus. This includes the "terminator" item at the end. To copy a menu array you need to copy size()*sizeof(Fl_Menu_Item) bytes. If the menu is NULL this returns zero (an empty menu will return 1).

Definition at line 407 of file Fl_Menu_.cxx.

References menu_, and Fl_Menu_Item::size().

Referenced by clear(), clear_submenu(), Fl_File_Chooser::favoritesButtonCB(), find_index(), find_item(), insert(), item_pathname_(), Fl_Comment_Type::open(), print_load(), remove(), replace(), Fl_File_Chooser::showChoiceCB(), and Fl_Choice::value().

◆ size() [2/2]

void Fl_Menu_::size ( int  W,
int  H 
)
inline

Definition at line 125 of file Fl_Menu_.H.

References H, and Fl_Widget::size().

◆ test_shortcut()

const Fl_Menu_Item* Fl_Menu_::test_shortcut ( )
inline

Returns the menu item with the entered shortcut (key value).

This searches the complete menu() for a shortcut that matches the entered key value. It must be called for a FL_KEYBOARD or FL_SHORTCUT event.

If a match is found, the menu's callback will be called.

Returns
matched Fl_Menu_Item or NULL.

Definition at line 89 of file Fl_Menu_.H.

References test_shortcut().

Referenced by Fl_Menu_Bar::handle(), Fl_Menu_Button::handle(), and test_shortcut().

◆ text() [1/2]

◆ text() [2/2]

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

Returns the title of item i.

Definition at line 152 of file Fl_Menu_.H.

References menu_, and Fl_Menu_Item::text.

◆ textcolor() [1/2]

Fl_Color Fl_Menu_::textcolor ( ) const
inline

Get the current color of menu item labels.

Definition at line 163 of file Fl_Menu_.H.

Referenced by Fl_Menu_Type::copy_properties(), Fl_Choice::draw(), Fl_Menu_Item::draw(), Fl_Menu_(), Fl_Choice::handle(), and Fl_Menu_Type::textstuff().

◆ textcolor() [2/2]

void Fl_Menu_::textcolor ( Fl_Color  c)
inline

Sets the current color of menu item labels.

Definition at line 165 of file Fl_Menu_.H.

◆ textfont() [1/2]

◆ textfont() [2/2]

void Fl_Menu_::textfont ( Fl_Font  c)
inline

Sets the current font of menu item labels.

Definition at line 157 of file Fl_Menu_.H.

◆ textsize() [1/2]

◆ textsize() [2/2]

void Fl_Menu_::textsize ( Fl_Fontsize  c)
inline

Sets the font size of menu item labels.

Definition at line 161 of file Fl_Menu_.H.

◆ value() [1/3]

int Fl_Menu_::value ( ) const
inline

Returns the index into menu() of the last item chosen by the user. It is zero initially.

Definition at line 140 of file Fl_Menu_.H.

References menu_.

Referenced by Fl_Menu_Type::click_test(), Fl_Input_Choice_Type::click_test(), Fl_File_Chooser::favoritesButtonCB(), Fl_Comment_Type::open(), and Fl_Choice::value().

◆ value() [2/3]

int Fl_Menu_::value ( const Fl_Menu_Item m)

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.

Definition at line 277 of file Fl_Menu_.cxx.

References Fl_Widget::clear_changed(), and value_.

◆ value() [3/3]

int Fl_Menu_::value ( int  i)
inline

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.

Definition at line 148 of file Fl_Menu_.H.

References menu_, and value().

Referenced by value().

Member Data Documentation

◆ alloc

uchar Fl_Menu_::alloc
protected

Definition at line 58 of file Fl_Menu_.H.

Referenced by clear(), copy(), Fl_Menu_(), insert(), remove(), and replace().

◆ down_box_

uchar Fl_Menu_::down_box_
protected

Definition at line 59 of file Fl_Menu_.H.

◆ menu_

Fl_Menu_Item* Fl_Menu_::menu_
private

◆ textcolor_

Fl_Color Fl_Menu_::textcolor_
protected

Definition at line 62 of file Fl_Menu_.H.

◆ textfont_

Fl_Font Fl_Menu_::textfont_
protected

Definition at line 60 of file Fl_Menu_.H.

◆ textsize_

Fl_Fontsize Fl_Menu_::textsize_
protected

Definition at line 61 of file Fl_Menu_.H.

◆ value_

const Fl_Menu_Item* Fl_Menu_::value_
private

Definition at line 54 of file Fl_Menu_.H.

Referenced by clear(), Fl_Menu_(), insert(), menu(), picked(), and value().


The documentation for this class was generated from the following files:
FL_MENU_RADIO
Item is a radio button (one checkbox of many can be on)
Definition: Fl_Menu_Item.H:36
Fl_Menu_::item_pathname
int item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem=0) const
Definition: Fl_Menu_.cxx:65
Fl_Menu_Item::flags
int flags
menu item flags like FL_MENU_TOGGLE, FL_MENU_RADIO
Definition: Fl_Menu_Item.H:117
main
int main()
Definition: posixScandir.cxx:8
Fl_Menu_::menu
const Fl_Menu_Item * menu() const
Definition: Fl_Menu_.H:110
FL_SUBMENU_POINTER
Indicates user_data() is a pointer to another menu array.
Definition: Fl_Menu_Item.H:38
Fl_Menu_Bar
Definition: Fl_Menu_Bar.H:67
FL_MENU_INACTIVE
Deactivate menu item (gray out)
Definition: Fl_Menu_Item.H:33
FL_GREEN
const Fl_Color FL_GREEN
Definition: Enumerations.H:958
Fl_Menu_::add
int add(const char *, int shortcut, Fl_Callback *, void *=0, int=0)
Definition: Fl_Menu_add.cxx:332
Fl_Menu_Item::label
const char * label() const
Definition: Fl_Menu_Item.H:148
FL_SUBMENU
This item is a submenu to other items.
Definition: Fl_Menu_Item.H:39
NULL
#define NULL
Definition: forms.H:34
FL_MENU_TOGGLE
Item is a checkbox toggle (shows checkbox for on/off state)
Definition: Fl_Menu_Item.H:34
FL_MENU_VALUE
The on/off state for checkbox/radio buttons (if set, state is 'on')
Definition: Fl_Menu_Item.H:35
FL_MENU_INVISIBLE
Item will not show up (shortcut will work)
Definition: Fl_Menu_Item.H:37
Fl_Widget
Definition: Fl_Widget.H:101
FL_RED
const Fl_Color FL_RED
Definition: Enumerations.H:957
FL_MENU_DIVIDER
Creates divider line below this item. Also ends a group of radio buttons.
Definition: Fl_Menu_Item.H:40
Fl_Menu_::find_item
const Fl_Menu_Item * find_item(const char *name)
Definition: Fl_Menu_.cxx:151
Fl_Menu_Item
Definition: Fl_Menu_Item.H:112
Fl_Menu_Item::labelcolor
Fl_Color labelcolor() const
Definition: Fl_Menu_Item.H:181
name
static const char * name
Definition: Fl_arg.cxx:53
error
static void error(const char *format,...)
Definition: Fl_abort.cxx:66
Fl_Menu_::size
int size() const
Definition: Fl_Menu_.cxx:407