FLTK 1.5.0
Loading...
Searching...
No Matches
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-2024 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/Fl_Widget.H>
21#include <FL/Fl_Image.H>
22#include <FL/Fl_Multi_Label.H>
23#include <FL/platform_types.h> // for FL_COMMAND and FL_CONTROL
24
25// doxygen needs the following line to enable e.g. ::FL_MENU_TOGGLE to link to the enums
27
28enum { // values for flags:
35 FL_SUBMENU = 0x40,
37 FL_MENU_HORIZONTAL = 0x100
39};
40
41extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
42
43class Fl_Menu_;
44
124struct FL_EXPORT Fl_Menu_Item {
125 const char *text;
129 int flags;
134
135 // advance N items, skipping submenus:
136 const Fl_Menu_Item *next(int=1) const;
137
143 Fl_Menu_Item *next(int i=1) {
144 return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));}
145
147 const Fl_Menu_Item *first() const { return next(0); }
148
150 Fl_Menu_Item *first() { return next(0); }
151
152 // methods on menu items:
177 const char* label() const { return text; }
178
191 void label(const char* a) { text = a; }
192
208 void label(Fl_Labeltype a, const char* b) {
209 labeltype_ = a;
210 text = b;
211 }
212
227 void multi_label(const Fl_Multi_Label *ml) {
228 label(FL_MULTI_LABEL, (const char *)ml);
229 }
230
245 void image_label(const Fl_Image *image) {
246 label(FL_IMAGE_LABEL, (const char *)image);
247 }
248
256 Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
257
265 void labeltype(Fl_Labeltype a) {labeltype_ = a;}
266
274 Fl_Color labelcolor() const {return labelcolor_;}
275
280 void labelcolor(Fl_Color a) {labelcolor_ = a;}
287 Fl_Font labelfont() const {return labelfont_;}
288
295 void labelfont(Fl_Font a) {labelfont_ = a;}
296
298 Fl_Fontsize labelsize() const {return labelsize_;}
299
301 void labelsize(Fl_Fontsize a) {labelsize_ = a;}
302
310 Fl_Callback_p callback() const {return callback_;}
311
316 void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
317
323 void callback(Fl_Callback* c) {callback_=c;}
324
331 callback_ = (Fl_Callback *)(void *)c;
332 }
333
340 void callback(Fl_Callback1 *c, long p = 0) {
341 callback_ = (Fl_Callback *)(void *)c;
342 user_data_ = (void *)(fl_intptr_t)p;
343 }
344
348 void* user_data() const {return user_data_;}
352 void user_data(void* v) {user_data_ = v;}
359 long argument() const {return (long)(fl_intptr_t)user_data_;}
367 void argument(long v) {user_data_ = (void*)(fl_intptr_t)v;}
368
370 int shortcut() const {return shortcut_;}
371
387 void shortcut(int s) {shortcut_ = s;}
395 int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
400 int checkbox() const {return flags&FL_MENU_TOGGLE;}
407 int radio() const {return flags&FL_MENU_RADIO;}
415 int value() const {return (flags & FL_MENU_VALUE) ? 1 : 0;}
416
418 void value(int v) { v ? set() : clear(); }
419
424 void set() {flags |= FL_MENU_VALUE;}
425
427 void clear() {flags &= ~FL_MENU_VALUE;}
428
429 void setonly(Fl_Menu_Item const* first = NULL);
430
432 int visible() const {return !(flags&FL_MENU_INVISIBLE);}
433
435 void show() {flags &= ~FL_MENU_INVISIBLE;}
436
438 void hide() {flags |= FL_MENU_INVISIBLE;}
439
441 int active() const {return !(flags&FL_MENU_INACTIVE);}
442
444 void activate() {flags &= ~FL_MENU_INACTIVE;}
449 void deactivate() {flags |= FL_MENU_INACTIVE;}
451 int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));}
452
453 // compatibility for FLUID so it can set the image of a menu item...
454
460 void image(Fl_Image* image) {image->label(this);}
461
467 void image(Fl_Image& image) {image.label(this);}
468
469 // used by menubar:
470 int measure(int* h, const Fl_Menu_*) const;
471 void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
472
473 // popup menus without using an Fl_Menu_ widget:
474 const Fl_Menu_Item* popup(
475 int X, int Y,
476 const char *title = 0,
477 const Fl_Menu_Item* picked=0,
478 const Fl_Menu_* = 0) const;
479 const Fl_Menu_Item* pulldown(
480 int X, int Y, int W, int H,
481 const Fl_Menu_Item* picked = 0,
482 const Fl_Menu_* = 0,
483 const Fl_Menu_Item* title = 0,
484 int menubar=0) const;
485 const Fl_Menu_Item* test_shortcut() const;
486 const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const;
487
493 void do_callback(Fl_Widget* o) const {Fl::callback_reason_=FL_REASON_SELECTED; callback_(o, user_data_);}
494
500 void do_callback(Fl_Widget* o,void* arg) const {Fl::callback_reason_=FL_REASON_SELECTED; callback_(o, arg);}
501
509 void do_callback(Fl_Widget* o,long arg) const {Fl::callback_reason_=FL_REASON_SELECTED; callback_(o, (void*)(fl_intptr_t)arg);}
510
517 inline int checked() const {return value();}
518
525 inline void check() {set();}
526
533 inline void uncheck() {clear();}
534
535 int insert(int,const char*,int,Fl_Callback*,void* =0, int =0);
536 int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
537
539 int add(const char*a, const char* b, Fl_Callback* c,
540 void* d = 0, int e = 0) {
541 return add(a,fl_old_shortcut(b),c,d,e);}
542
543 int size() const ;
544};
545
546typedef Fl_Menu_Item Fl_Menu; // back compatibility
547
548enum { // back-compatibility enum:
549 FL_PUP_NONE = 0,
550 FL_PUP_GREY = FL_MENU_INACTIVE,
551 FL_PUP_GRAY = FL_MENU_INACTIVE,
552 FL_MENU_BOX = FL_MENU_TOGGLE,
553 FL_PUP_BOX = FL_MENU_TOGGLE,
554 FL_MENU_CHECK = FL_MENU_VALUE,
555 FL_PUP_CHECK = FL_MENU_VALUE,
556 FL_PUP_RADIO = FL_MENU_RADIO,
557 FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
558 FL_PUP_SUBMENU = FL_SUBMENU_POINTER
559};
560
561#endif
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1057
#define FL_MULTI_LABEL
Draws a label that can comprise several parts like text and images.
Definition Enumerations.H:893
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:1114
#define FL_IMAGE_LABEL
Draws an image (Fl_Image) as the label.
Definition Enumerations.H:916
Fl_Labeltype
The labeltype() method sets the type of the label.
Definition Enumerations.H:829
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1086
@ FL_REASON_SELECTED
an item was selected
Definition Enumerations.H:451
Fl_Image, Fl_RGB_Image classes.
@ FL_MENU_RADIO
Item is a radio button (one checkbox of many can be on)
Definition Fl_Menu_Item.H:32
@ FL_SUBMENU
Item is a submenu to other items.
Definition Fl_Menu_Item.H:35
@ FL_MENU_DIVIDER
Creates divider line below this item. Also ends a group of radio buttons.
Definition Fl_Menu_Item.H:36
@ FL_MENU_TOGGLE
Item is a checkbox toggle (shows checkbox for on/off state)
Definition Fl_Menu_Item.H:30
@ FL_SUBMENU_POINTER
Indicates user_data() is a pointer to another menu array.
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:31
@ FL_MENU_INVISIBLE
Item will not show up (shortcut will work)
Definition Fl_Menu_Item.H:33
@ FL_MENU_INACTIVE
Deactivate menu item (gray out)
Definition Fl_Menu_Item.H:29
@ FL_MENU_HORIZONTAL
??? – reserved, internal (do not use)
Definition Fl_Menu_Item.H:37
Fl_Widget and Fl_Label classes.
void Fl_Callback(Fl_Widget *, void *)
Default callback type definition for all fltk widgets (by far the most used)
Definition Fl_Widget.H:33
void Fl_Callback0(Fl_Widget *)
One parameter callback type definition passing only the widget.
Definition Fl_Widget.H:37
void Fl_Callback1(Fl_Widget *, long)
Callback type definition passing the widget and a long data value.
Definition Fl_Widget.H:39
Fl_Callback * Fl_Callback_p
Default callback type pointer definition for all fltk widgets.
Definition Fl_Widget.H:35
Base class for image caching, scaling and drawing.
Definition Fl_Image.H:60
virtual void label(Fl_Widget *w)
This method is an obsolete way to set the image attribute of a widget or menu item.
Definition Fl_Image.cxx:163
Base class of all widgets that have a menu in FLTK.
Definition Fl_Menu_.H:53
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:112
unsigned int Fl_Shortcut
16-bit Unicode character + 8-bit indicator for keyboard flags.
Definition fl_types.h:55
unsigned char uchar
unsigned char
Definition fl_types.h:30
Fl_Shortcut fl_old_shortcut(const char *)
Emulation of XForms named shortcuts.
Definition fl_shortcut.cxx:275
Definitions of platform-dependent types.
opaque fl_intptr_t
An integral type large enough to store a pointer or a long value.
Definition platform_types.h:31
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class.
Definition Fl_Menu_Item.H:124
int shortcut() const
Gets what key combination shortcut will trigger the menu item.
Definition Fl_Menu_Item.H:370
Fl_Callback * callback_
menu item callback
Definition Fl_Menu_Item.H:127
long argument() const
Gets the user_data() argument that is sent to the callback function.
Definition Fl_Menu_Item.H:359
const char * text
menu item text, returned by label()
Definition Fl_Menu_Item.H:125
void clear()
Turns the check or radio item "off" for the menu item.
Definition Fl_Menu_Item.H:427
void argument(long v)
Sets the user_data() argument that is sent to the callback function.
Definition Fl_Menu_Item.H:367
Fl_Fontsize labelsize_
size of menu item text
Definition Fl_Menu_Item.H:132
void * user_data() const
Gets the user_data() argument that is sent to the callback function.
Definition Fl_Menu_Item.H:348
void callback(Fl_Callback *c, void *p)
Sets the menu item's callback function and userdata() argument.
Definition Fl_Menu_Item.H:316
void labelcolor(Fl_Color a)
Sets the menu item's label color.
Definition Fl_Menu_Item.H:280
int checked() const
Back compatibility only.
Definition Fl_Menu_Item.H:517
void deactivate()
Prevents a menu item from being picked.
Definition Fl_Menu_Item.H:449
void set()
Turns the check or radio item "on" for the menu item.
Definition Fl_Menu_Item.H:424
void labelsize(Fl_Fontsize a)
Sets the label font pixel size/height.
Definition Fl_Menu_Item.H:301
const Fl_Menu_Item * first() const
Returns the first menu item, same as next(0).
Definition Fl_Menu_Item.H:147
void value(int v)
Sets the current value of the check or radio item.
Definition Fl_Menu_Item.H:418
void callback(Fl_Callback1 *c, long p=0)
Sets the menu item's callback function and userdata() argument.
Definition Fl_Menu_Item.H:340
void user_data(void *v)
Sets the user_data() argument that is sent to the callback function.
Definition Fl_Menu_Item.H:352
int active() const
Gets whether or not the item can be picked.
Definition Fl_Menu_Item.H:441
void do_callback(Fl_Widget *o, long arg) const
Calls the Fl_Menu_Item item's callback, and provides the Fl_Widget argument.
Definition Fl_Menu_Item.H:509
int value() const
Returns the current value of the check or radio item.
Definition Fl_Menu_Item.H:415
void shortcut(int s)
Sets exactly what key combination will trigger the menu item.
Definition Fl_Menu_Item.H:387
const char * label() const
Returns the title (label) of the menu item.
Definition Fl_Menu_Item.H:177
Fl_Callback_p callback() const
Returns the callback function that is set for the menu item.
Definition Fl_Menu_Item.H:310
void callback(Fl_Callback *c)
Sets the menu item's callback function.
Definition Fl_Menu_Item.H:323
void check()
Back compatibility only.
Definition Fl_Menu_Item.H:525
void image(Fl_Image *image)
Compatibility API for FLUID, same as image->label(this).
Definition Fl_Menu_Item.H:460
Fl_Menu_Item * first()
Returns the first menu item, same as next(0).
Definition Fl_Menu_Item.H:150
void labeltype(Fl_Labeltype a)
Sets the menu item's labeltype.
Definition Fl_Menu_Item.H:265
Fl_Color labelcolor_
menu item text color
Definition Fl_Menu_Item.H:133
void hide()
Hides an item in the menu.
Definition Fl_Menu_Item.H:438
void labelfont(Fl_Font a)
Sets the menu item's label font.
Definition Fl_Menu_Item.H:295
int shortcut_
menu item shortcut
Definition Fl_Menu_Item.H:126
Fl_Fontsize labelsize() const
Gets the label font pixel size/height.
Definition Fl_Menu_Item.H:298
void callback(Fl_Callback0 *c)
Sets the menu item's callback function.
Definition Fl_Menu_Item.H:330
Fl_Font labelfont() const
Gets the menu item's label font.
Definition Fl_Menu_Item.H:287
void do_callback(Fl_Widget *o, void *arg) const
Calls the Fl_Menu_Item item's callback, and provides the Fl_Widget argument.
Definition Fl_Menu_Item.H:500
void * user_data_
menu item user_data for the menu's callback
Definition Fl_Menu_Item.H:128
Fl_Color labelcolor() const
Gets the menu item's label color.
Definition Fl_Menu_Item.H:274
void do_callback(Fl_Widget *o) const
Calls the Fl_Menu_Item item's callback, and provides the Fl_Widget argument.
Definition Fl_Menu_Item.H:493
int flags
menu item flags like FL_MENU_TOGGLE, FL_MENU_RADIO
Definition Fl_Menu_Item.H:129
void show()
Makes an item visible in the menu.
Definition Fl_Menu_Item.H:435
uchar labeltype_
how the menu item text looks like
Definition Fl_Menu_Item.H:130
void label(Fl_Labeltype a, const char *b)
Sets the title (label) and the label type of the menu item.
Definition Fl_Menu_Item.H:208
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:539
int radio() const
Returns true if this item is a radio item.
Definition Fl_Menu_Item.H:407
Fl_Labeltype labeltype() const
Returns the menu item's labeltype.
Definition Fl_Menu_Item.H:256
Fl_Font labelfont_
which font for this menu item text
Definition Fl_Menu_Item.H:131
int submenu() const
Returns true if either FL_SUBMENU or FL_SUBMENU_POINTER is on in the flags.
Definition Fl_Menu_Item.H:395
int visible() const
Gets the visibility of an item.
Definition Fl_Menu_Item.H:432
void activate()
Allows a menu item to be picked.
Definition Fl_Menu_Item.H:444
int checkbox() const
Returns true if a checkbox will be drawn next to this item.
Definition Fl_Menu_Item.H:400
void label(const char *a)
Sets the title (label) of the menu item.
Definition Fl_Menu_Item.H:191
void image_label(const Fl_Image *image)
Sets the title (label()) to an icon or image.
Definition Fl_Menu_Item.H:245
void uncheck()
Back compatibility only.
Definition Fl_Menu_Item.H:533
void image(Fl_Image &image)
Compatibility API for FLUID, same as image.label(this).
Definition Fl_Menu_Item.H:467
int activevisible() const
Returns non 0 if FL_INACTIVE and FL_INVISIBLE are cleared, 0 otherwise.
Definition Fl_Menu_Item.H:451
void multi_label(const Fl_Multi_Label *ml)
Sets the title (label()) and labeltype() to an Fl_Multi_Label.
Definition Fl_Menu_Item.H:227
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:143
Allows a mixed text and/or graphics label to be applied to an Fl_Menu_Item or Fl_Widget.
Definition Fl_Multi_Label.H:76