FLTK
Fl_Menu_Item.H
Go to the documentation of this file.
1 //
2 // Menu item header file for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2010 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
16 
17 #ifndef Fl_Menu_Item_H
18 #define Fl_Menu_Item_H
19 
20 # include "Fl_Widget.H"
21 # include "Fl_Image.H"
22 # include <FL/platform_types.h> // for FL_COMMAND and FL_CONTROL
23 
24 // doxygen needs the following line to enable e.g. ::FL_MENU_TOGGLE to link to the enums
26 
27 enum { // values for flags:
34  FL_SUBMENU = 0x40,
35  FL_MENU_DIVIDER = 0x80,
37 };
38 
39 extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
40 
41 class Fl_Menu_;
42 
107 struct FL_EXPORT Fl_Menu_Item {
108  const char *text;
109  int shortcut_;
111  void *user_data_;
112  int flags;
117 
118  // advance N items, skipping submenus:
119  const Fl_Menu_Item *next(int=1) const;
120 
126  Fl_Menu_Item *next(int i=1) {
127  return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));}
128 
130  const Fl_Menu_Item *first() const { return next(0); }
131 
133  Fl_Menu_Item *first() { return next(0); }
134 
135  // methods on menu items:
143  const char* label() const {return text;}
144 
146  void label(const char* a) {text=a;}
147 
149  void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
150 
158  Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
159 
167  void labeltype(Fl_Labeltype a) {labeltype_ = a;}
168 
176  Fl_Color labelcolor() const {return labelcolor_;}
177 
182  void labelcolor(Fl_Color a) {labelcolor_ = a;}
189  Fl_Font labelfont() const {return labelfont_;}
190 
197  void labelfont(Fl_Font a) {labelfont_ = a;}
198 
200  Fl_Fontsize labelsize() const {return labelsize_;}
201 
203  void labelsize(Fl_Fontsize a) {labelsize_ = a;}
204 
212  Fl_Callback_p callback() const {return callback_;}
213 
218  void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
219 
225  void callback(Fl_Callback* c) {callback_=c;}
226 
232  void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
233 
241  void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)(fl_intptr_t)p;}
242 
246  void* user_data() const {return user_data_;}
250  void user_data(void* v) {user_data_ = v;}
257  long argument() const {return (long)(fl_intptr_t)user_data_;}
265  void argument(long v) {user_data_ = (void*)(fl_intptr_t)v;}
266 
268  int shortcut() const {return shortcut_;}
269 
285  void shortcut(int s) {shortcut_ = s;}
293  int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
298  int checkbox() const {return flags&FL_MENU_TOGGLE;}
305  int radio() const {return flags&FL_MENU_RADIO;}
313  int value() const {return flags&FL_MENU_VALUE;}
318  void set() {flags |= FL_MENU_VALUE;}
319 
321  void clear() {flags &= ~FL_MENU_VALUE;}
322 
323  void setonly();
324 
326  int visible() const {return !(flags&FL_MENU_INVISIBLE);}
327 
329  void show() {flags &= ~FL_MENU_INVISIBLE;}
330 
332  void hide() {flags |= FL_MENU_INVISIBLE;}
333 
335  int active() const {return !(flags&FL_MENU_INACTIVE);}
336 
338  void activate() {flags &= ~FL_MENU_INACTIVE;}
343  void deactivate() {flags |= FL_MENU_INACTIVE;}
345  int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));}
346 
347  // compatibility for FLUID so it can set the image of a menu item...
348 
354  void image(Fl_Image* image) {image->label(this);}
355 
361  void image(Fl_Image& image) {image.label(this);}
362 
363  // used by menubar:
364  int measure(int* h, const Fl_Menu_*) const;
365  void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
366 
367  // popup menus without using an Fl_Menu_ widget:
368  const Fl_Menu_Item* popup(
369  int X, int Y,
370  const char *title = 0,
371  const Fl_Menu_Item* picked=0,
372  const Fl_Menu_* = 0) const;
373  const Fl_Menu_Item* pulldown(
374  int X, int Y, int W, int H,
375  const Fl_Menu_Item* picked = 0,
376  const Fl_Menu_* = 0,
377  const Fl_Menu_Item* title = 0,
378  int menubar=0) const;
379  const Fl_Menu_Item* test_shortcut() const;
380  const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const;
381 
387  void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
388 
394  void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
395 
403  void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)(fl_intptr_t)arg);}
404 
405  // back-compatibility, do not use:
406 
408  int checked() const {return flags&FL_MENU_VALUE;}
409 
411  void check() {flags |= FL_MENU_VALUE;}
412 
414  void uncheck() {flags &= ~FL_MENU_VALUE;}
415 
416  int insert(int,const char*,int,Fl_Callback*,void* =0, int =0);
417  int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
418 
420  int add(const char*a, const char* b, Fl_Callback* c,
421  void* d = 0, int e = 0) {
422  return add(a,fl_old_shortcut(b),c,d,e);}
423 
424  int size() const ;
425 };
426 
427 typedef Fl_Menu_Item Fl_Menu; // back compatibility
428 
429 enum { // back-compatibility enum:
430  FL_PUP_NONE = 0,
431  FL_PUP_GREY = FL_MENU_INACTIVE,
432  FL_PUP_GRAY = FL_MENU_INACTIVE,
433  FL_MENU_BOX = FL_MENU_TOGGLE,
434  FL_PUP_BOX = FL_MENU_TOGGLE,
435  FL_MENU_CHECK = FL_MENU_VALUE,
436  FL_PUP_CHECK = FL_MENU_VALUE,
437  FL_PUP_RADIO = FL_MENU_RADIO,
438  FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
439  FL_PUP_SUBMENU = FL_SUBMENU_POINTER
440 };
441 
442 #endif
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
uchar labeltype_
how the menu item text looks like
Definition: Fl_Menu_Item.H:113
int active() const
Gets whether or not the item can be picked.
Definition: Fl_Menu_Item.H:335
Fl_Callback * callback_
menu item callback
Definition: Fl_Menu_Item.H:110
long argument() const
Gets the user_data() argument that is sent to the callback function.
Definition: Fl_Menu_Item.H:257
Item is a checkbox toggle (shows checkbox for on/off state)
Definition: Fl_Menu_Item.H:29
int shortcut_
menu item shortcut
Definition: Fl_Menu_Item.H:109
void() Fl_Callback(Fl_Widget *, void *)
Default callback type definition for all fltk widgets (by far the most used)
Definition: Fl_Widget.H:32
void shortcut(int s)
Sets exactly what key combination will trigger the menu item.
Definition: Fl_Menu_Item.H:285
Fl_Menu_Item * first()
Returns the first menu item, same as next(0).
Definition: Fl_Menu_Item.H:133
void labeltype(Fl_Labeltype a)
Sets the menu item&#39;s labeltype.
Definition: Fl_Menu_Item.H:167
virtual void label(Fl_Widget *w)
The label() methods are an obsolete way to set the image attribute of a widget or menu item...
Definition: Fl_Image.cxx:130
FL_EXPORT Fl_Shortcut fl_old_shortcut(const char *)
Emulation of XForms named shortcuts.
Definition: fl_shortcut.cxx:273
void check()
back compatibility only
Definition: Fl_Menu_Item.H:411
int visible() const
Gets the visibility of an item.
Definition: Fl_Menu_Item.H:326
Fl_Font labelfont_
which font for this menu item text
Definition: Fl_Menu_Item.H:114
void do_callback(Fl_Widget *o, void *arg) const
Calls the Fl_Menu_Item item&#39;s callback, and provides the Fl_Widget argument.
Definition: Fl_Menu_Item.H:394
void callback(Fl_Callback0 *c)
Sets the menu item&#39;s callback function.
Definition: Fl_Menu_Item.H:232
int flags
menu item flags like FL_MENU_TOGGLE, FL_MENU_RADIO
Definition: Fl_Menu_Item.H:112
int radio() const
Returns true if this item is a radio item.
Definition: Fl_Menu_Item.H:305
const Fl_Menu_Item * first() const
Returns the first menu item, same as next(0).
Definition: Fl_Menu_Item.H:130
opaque fl_intptr_t
An integral type large enough to store a pointer or a long value.
Definition: platform_types.h:28
void activate()
Allows a menu item to be picked.
Definition: Fl_Menu_Item.H:338
Creates divider line below this item. Also ends a group of radio buttons.
Definition: Fl_Menu_Item.H:35
Definitions of platform-dependent types.
The on/off state for checkbox/radio buttons (if set, state is &#39;on&#39;)
Definition: Fl_Menu_Item.H:30
Base class for image caching, scaling and drawing.
Definition: Fl_Image.H:62
Fl_Image, Fl_RGB_Image classes.
void labelfont(Fl_Font a)
Sets the menu item&#39;s label font.
Definition: Fl_Menu_Item.H:197
int add(const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
See int add(const char*, int shortcut, Fl_Callback*, void*, int)
Definition: Fl_Menu_Item.H:420
const char * label() const
Returns the title of the item.
Definition: Fl_Menu_Item.H:143
Fl_Callback_p callback() const
Returns the callback function that is set for the menu item.
Definition: Fl_Menu_Item.H:212
Fl_Fontsize labelsize_
size of menu item text
Definition: Fl_Menu_Item.H:115
void do_callback(Fl_Widget *o) const
Calls the Fl_Menu_Item item&#39;s callback, and provides the Fl_Widget argument.
Definition: Fl_Menu_Item.H:387
void uncheck()
back compatibility only
Definition: Fl_Menu_Item.H:414
void image(Fl_Image &image)
Compatibility API for FLUID, same as image.label(this).
Definition: Fl_Menu_Item.H:361
void callback(Fl_Callback1 *c, long p=0)
Sets the menu item&#39;s callback function and userdata() argument.
Definition: Fl_Menu_Item.H:241
void() Fl_Callback0(Fl_Widget *)
One parameter callback type definition passing only the widget.
Definition: Fl_Widget.H:36
void deactivate()
Prevents a menu item from being picked.
Definition: Fl_Menu_Item.H:343
void clear()
Turns the check or radio item "off" for the menu item.
Definition: Fl_Menu_Item.H:321
void callback(Fl_Callback *c, void *p)
Sets the menu item&#39;s callback function and userdata() argument.
Definition: Fl_Menu_Item.H:218
Fl_Menu_Item * next(int i=1)
Advances a pointer by n items through a menu array, skipping the contents of submenus and invisible i...
Definition: Fl_Menu_Item.H:126
Fl_Widget, Fl_Label classes .
void labelsize(Fl_Fontsize a)
Sets the label font pixel size/height.
Definition: Fl_Menu_Item.H:203
Item is a radio button (one checkbox of many can be on)
Definition: Fl_Menu_Item.H:31
void user_data(void *v)
Sets the user_data() argument that is sent to the callback function.
Definition: Fl_Menu_Item.H:250
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
void callback(Fl_Callback *c)
Sets the menu item&#39;s callback function.
Definition: Fl_Menu_Item.H:225
void * user_data() const
Gets the user_data() argument that is sent to the callback function.
Definition: Fl_Menu_Item.H:246
int checked() const
back compatibility only
Definition: Fl_Menu_Item.H:408
int shortcut() const
Gets what key combination shortcut will trigger the menu item.
Definition: Fl_Menu_Item.H:268
int checkbox() const
Returns true if a checkbox will be drawn next to this item.
Definition: Fl_Menu_Item.H:298
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class...
Definition: Fl_Menu_Item.H:107
void hide()
Hides an item in the menu.
Definition: Fl_Menu_Item.H:332
Indicates user_data() is a pointer to another menu array.
Definition: Fl_Menu_Item.H:33
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:1042
Fl_Labeltype
The labeltype() method sets the type of the label.
Definition: Enumerations.H:757
Fl_Callback * Fl_Callback_p
Default callback type pointer definition for all fltk widgets.
Definition: Fl_Widget.H:34
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
void show()
Makes an item visible in the menu.
Definition: Fl_Menu_Item.H:329
Fl_Fontsize labelsize() const
Gets the label font pixel size/height.
Definition: Fl_Menu_Item.H:200
const char * text
menu item text, returned by label()
Definition: Fl_Menu_Item.H:108
int activevisible() const
Returns non 0 if FL_INACTIVE and FL_INVISIBLE are cleared, 0 otherwise.
Definition: Fl_Menu_Item.H:345
Fl_Color labelcolor() const
Gets the menu item&#39;s label color.
Definition: Fl_Menu_Item.H:176
Fl_Color labelcolor_
menu item text color
Definition: Fl_Menu_Item.H:116
Base class of all widgets that have a menu in FLTK.
Definition: Fl_Menu_.H:53
Fl_Labeltype labeltype() const
Returns the menu item&#39;s labeltype.
Definition: Fl_Menu_Item.H:158
void() Fl_Callback1(Fl_Widget *, long)
Callback type definition passing the widget and a long data value.
Definition: Fl_Widget.H:38
void label(const char *a)
See const char* Fl_Menu_Item::label() const.
Definition: Fl_Menu_Item.H:146
void do_callback(Fl_Widget *o, long arg) const
Calls the Fl_Menu_Item item&#39;s callback, and provides the Fl_Widget argument.
Definition: Fl_Menu_Item.H:403
Deactivate menu item (gray out)
Definition: Fl_Menu_Item.H:28
void image(Fl_Image *image)
Compatibility API for FLUID, same as image->label(this).
Definition: Fl_Menu_Item.H:354
Fl_Font labelfont() const
Gets the menu item&#39;s label font.
Definition: Fl_Menu_Item.H:189
void argument(long v)
Sets the user_data() argument that is sent to the callback function.
Definition: Fl_Menu_Item.H:265
int submenu() const
Returns true if either FL_SUBMENU or FL_SUBMENU_POINTER is on in the flags.
Definition: Fl_Menu_Item.H:293
Item will not show up (shortcut will work)
Definition: Fl_Menu_Item.H:32
??? – reserved
Definition: Fl_Menu_Item.H:36
void label(Fl_Labeltype a, const char *b)
See const char* Fl_Menu_Item::label() const.
Definition: Fl_Menu_Item.H:149
int value() const
Returns the current value of the check or radio item.
Definition: Fl_Menu_Item.H:313
void labelcolor(Fl_Color a)
Sets the menu item&#39;s label color.
Definition: Fl_Menu_Item.H:182
unsigned char uchar
unsigned char
Definition: fl_types.h:28
This item is a submenu to other items.
Definition: Fl_Menu_Item.H:34
unsigned int Fl_Shortcut
16-bit Unicode character + 8-bit indicator for keyboard flags.
Definition: fl_types.h:53
void * user_data_
menu item user_data for the menu&#39;s callback
Definition: Fl_Menu_Item.H:111