FLTK 1.3.2
Fl_Menu_Item.H
1 //
2 // "$Id: Fl_Menu_Item.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
3 //
4 // Menu item header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 #ifndef Fl_Menu_Item_H
20 #define Fl_Menu_Item_H
21 
22 # include "Fl_Widget.H"
23 # include "Fl_Image.H"
24 
25 # if defined(__APPLE__) && defined(check)
26 # undef check
27 # endif
28 
29 enum { // values for flags:
30  FL_MENU_INACTIVE = 1,
31  FL_MENU_TOGGLE= 2,
32  FL_MENU_VALUE = 4,
33  FL_MENU_RADIO = 8,
34  FL_MENU_INVISIBLE = 0x10,
35  FL_SUBMENU_POINTER = 0x20,
36  FL_SUBMENU = 0x40,
37  FL_MENU_DIVIDER = 0x80,
38  FL_MENU_HORIZONTAL = 0x100
39 };
40 
41 extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
42 
43 class Fl_Menu_;
44 
109 struct FL_EXPORT Fl_Menu_Item {
110  const char *text;
111  int shortcut_;
113  void *user_data_;
114  int flags;
119 
120  // advance N items, skipping submenus:
121  const Fl_Menu_Item *next(int=1) const;
122 
128  Fl_Menu_Item *next(int i=1) {
129  return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));}
130 
132  const Fl_Menu_Item *first() const { return next(0); }
133 
135  Fl_Menu_Item *first() { return next(0); }
136 
137  // methods on menu items:
145  const char* label() const {return text;}
146 
148  void label(const char* a) {text=a;}
149 
151  void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
152 
160  Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
161 
169  void labeltype(Fl_Labeltype a) {labeltype_ = a;}
170 
178  Fl_Color labelcolor() const {return labelcolor_;}
179 
184  void labelcolor(Fl_Color a) {labelcolor_ = a;}
191  Fl_Font labelfont() const {return labelfont_;}
192 
199  void labelfont(Fl_Font a) {labelfont_ = a;}
200 
202  Fl_Fontsize labelsize() const {return labelsize_;}
203 
205  void labelsize(Fl_Fontsize a) {labelsize_ = a;}
206 
214  Fl_Callback_p callback() const {return callback_;}
215 
220  void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
221 
227  void callback(Fl_Callback* c) {callback_=c;}
228 
234  void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
235 
243  void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)p;}
244 
248  void* user_data() const {return user_data_;}
252  void user_data(void* v) {user_data_ = v;}
259  long argument() const {return (long)(fl_intptr_t)user_data_;}
267  void argument(long v) {user_data_ = (void*)v;}
268 
270  int shortcut() const {return shortcut_;}
271 
287  void shortcut(int s) {shortcut_ = s;}
295  int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
300  int checkbox() const {return flags&FL_MENU_TOGGLE;}
307  int radio() const {return flags&FL_MENU_RADIO;}
309  int value() const {return flags&FL_MENU_VALUE;}
314  void set() {flags |= FL_MENU_VALUE;}
315 
317  void clear() {flags &= ~FL_MENU_VALUE;}
318 
319  void setonly();
320 
322  int visible() const {return !(flags&FL_MENU_INVISIBLE);}
323 
325  void show() {flags &= ~FL_MENU_INVISIBLE;}
326 
328  void hide() {flags |= FL_MENU_INVISIBLE;}
329 
331  int active() const {return !(flags&FL_MENU_INACTIVE);}
332 
334  void activate() {flags &= ~FL_MENU_INACTIVE;}
339  void deactivate() {flags |= FL_MENU_INACTIVE;}
341  int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));}
342 
343  // compatibility for FLUID so it can set the image of a menu item...
344 
346  void image(Fl_Image* a) {a->label(this);}
347 
349  void image(Fl_Image& a) {a.label(this);}
350 
351  // used by menubar:
352  int measure(int* h, const Fl_Menu_*) const;
353  void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
354 
355  // popup menus without using an Fl_Menu_ widget:
356  const Fl_Menu_Item* popup(
357  int X, int Y,
358  const char *title = 0,
359  const Fl_Menu_Item* picked=0,
360  const Fl_Menu_* = 0) const;
361  const Fl_Menu_Item* pulldown(
362  int X, int Y, int W, int H,
363  const Fl_Menu_Item* picked = 0,
364  const Fl_Menu_* = 0,
365  const Fl_Menu_Item* title = 0,
366  int menubar=0) const;
367  const Fl_Menu_Item* test_shortcut() const;
368  const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const;
369 
375  void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
376 
382  void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
383 
391  void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)arg);}
392 
393  // back-compatibility, do not use:
394 
396  int checked() const {return flags&FL_MENU_VALUE;}
397 
399  void check() {flags |= FL_MENU_VALUE;}
400 
402  void uncheck() {flags &= ~FL_MENU_VALUE;}
403 
404  int insert(int,const char*,int,Fl_Callback*,void* =0, int =0);
405  int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
406 
408  int add(const char*a, const char* b, Fl_Callback* c,
409  void* d = 0, int e = 0) {
410  return add(a,fl_old_shortcut(b),c,d,e);}
411 
412  int size() const ;
413 };
414 
415 typedef Fl_Menu_Item Fl_Menu; // back compatibility
416 
417 enum { // back-compatibility enum:
418  FL_PUP_NONE = 0,
419  FL_PUP_GREY = FL_MENU_INACTIVE,
420  FL_PUP_GRAY = FL_MENU_INACTIVE,
421  FL_MENU_BOX = FL_MENU_TOGGLE,
422  FL_PUP_BOX = FL_MENU_TOGGLE,
423  FL_MENU_CHECK = FL_MENU_VALUE,
424  FL_PUP_CHECK = FL_MENU_VALUE,
425  FL_PUP_RADIO = FL_MENU_RADIO,
426  FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
427  FL_PUP_SUBMENU = FL_SUBMENU_POINTER
428 };
429 
430 #endif
431 
432 //
433 // End of "$Id: Fl_Menu_Item.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
434 //
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:100
uchar labeltype_
how the menu item text looks like
Definition: Fl_Menu_Item.H:115
void set()
Turns the check or radio item "on" for the menu item.
Definition: Fl_Menu_Item.H:314
Fl_Callback * callback_
menu item callback
Definition: Fl_Menu_Item.H:112
long argument() const
Gets the user_data() argument that is sent to the callback function.
Definition: Fl_Menu_Item.H:259
int shortcut_
menu item shortcut
Definition: Fl_Menu_Item.H:111
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:391
void shortcut(int s)
Sets exactly what key combination will trigger the menu item.
Definition: Fl_Menu_Item.H:287
Fl_Menu_Item * first()
Returns the first menu item, same as next(0).
Definition: Fl_Menu_Item.H:135
void labeltype(Fl_Labeltype a)
Sets the menu item's labeltype.
Definition: Fl_Menu_Item.H:169
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:109
FL_EXPORT Fl_Shortcut fl_old_shortcut(const char *)
Emulation of XForms named shortcuts.
Definition: fl_shortcut.cxx:275
void check()
back compatibility only
Definition: Fl_Menu_Item.H:399
Fl_Font labelfont_
which font for this menu item text
Definition: Fl_Menu_Item.H:116
void callback(Fl_Callback0 *c)
Sets the menu item's callback function.
Definition: Fl_Menu_Item.H:234
int flags
menu item flags like FL_MENU_TOGGLE, FL_MENU_RADIO
Definition: Fl_Menu_Item.H:114
int radio() const
Returns true if this item is a radio item.
Definition: Fl_Menu_Item.H:307
int checked() const
back compatibility only
Definition: Fl_Menu_Item.H:396
void activate()
Allows a menu item to be picked.
Definition: Fl_Menu_Item.H:334
int activevisible() const
Returns non 0 if FL_INACTIVE and FL_INVISIBLE are cleared, 0 otherwise.
Definition: Fl_Menu_Item.H:341
int shortcut() const
Gets what key combination shortcut will trigger the menu item.
Definition: Fl_Menu_Item.H:270
Fl_Image is the base class used for caching and drawing all kinds of images in FLTK.
Definition: Fl_Image.H:44
void labelfont(Fl_Font a)
Sets the menu item's label font.
Definition: Fl_Menu_Item.H:199
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:408
Fl_Callback_p callback() const
Returns the callback function that is set for the menu item.
Definition: Fl_Menu_Item.H:214
const Fl_Menu_Item * first() const
Returns the first menu item, same as next(0).
Definition: Fl_Menu_Item.H:132
Fl_Fontsize labelsize_
size of menu item text
Definition: Fl_Menu_Item.H:117
long fl_intptr_t
Definition: Fl_Widget.H:39
Fl_Font labelfont() const
Gets the menu item's label font.
Definition: Fl_Menu_Item.H:191
int checkbox() const
Returns true if a checkbox will be drawn next to this item.
Definition: Fl_Menu_Item.H:300
void uncheck()
back compatibility only
Definition: Fl_Menu_Item.H:402
void( Fl_Callback1)(Fl_Widget *, long)
Callback type definition passing the widget and a long data value.
Definition: Fl_Widget.H:55
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:375
void callback(Fl_Callback1 *c, long p=0)
Sets the menu item's callback function and userdata() argument.
Definition: Fl_Menu_Item.H:243
int visible() const
Gets the visibility of an item.
Definition: Fl_Menu_Item.H:322
void deactivate()
Prevents a menu item from being picked.
Definition: Fl_Menu_Item.H:339
void clear()
Turns the check or radio item "off" for the menu item.
Definition: Fl_Menu_Item.H:317
void( Fl_Callback)(Fl_Widget *, void *)
Default callback type definition for all fltk widgets (by far the most used)
Definition: Fl_Widget.H:49
void callback(Fl_Callback *c, void *p)
Sets the menu item's callback function and userdata() argument.
Definition: Fl_Menu_Item.H:220
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:128
Fl_Widget, Fl_Label classes .
void image(Fl_Image *a)
compatibility api for FLUID, same as a->label(this)
Definition: Fl_Menu_Item.H:346
void labelsize(Fl_Fontsize a)
Sets the label font pixel size/height.
Definition: Fl_Menu_Item.H:205
int active() const
Gets whether or not the item can be picked.
Definition: Fl_Menu_Item.H:331
void user_data(void *v)
Sets the user_data() argument that is sent to the callback function.
Definition: Fl_Menu_Item.H:252
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:746
void( Fl_Callback0)(Fl_Widget *)
One parameter callback type definition passing only the widget.
Definition: Fl_Widget.H:53
void callback(Fl_Callback *c)
Sets the menu item's callback function.
Definition: Fl_Menu_Item.H:227
void * user_data() const
Gets the user_data() argument that is sent to the callback function.
Definition: Fl_Menu_Item.H:248
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class...
Definition: Fl_Menu_Item.H:109
void hide()
Hides an item in the menu.
Definition: Fl_Menu_Item.H:328
unsigned int Fl_Color
an FLTK color value
Definition: Enumerations.H:774
Fl_Labeltype
The labeltype() method sets the type of the label.
Definition: Enumerations.H:611
Fl_Callback * Fl_Callback_p
Default callback type pointer definition for all fltk widgets.
Definition: Fl_Widget.H:51
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:717
void show()
Makes an item visible in the menu.
Definition: Fl_Menu_Item.H:325
const char * text
menu item text, returned by label()
Definition: Fl_Menu_Item.H:110
Fl_Color labelcolor_
menu item text color
Definition: Fl_Menu_Item.H:118
Base class of all widgets that have a menu in FLTK.
Definition: Fl_Menu_.H:39
void label(const char *a)
See const char* Fl_Menu_Item::label() const.
Definition: Fl_Menu_Item.H:148
int value() const
Returns the current value of the check or radio item.
Definition: Fl_Menu_Item.H:309
Fl_Labeltype labeltype() const
Returns the menu item's labeltype.
Definition: Fl_Menu_Item.H:160
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:382
void argument(long v)
Sets the user_data() argument that is sent to the callback function.
Definition: Fl_Menu_Item.H:267
int submenu() const
Returns true if either FL_SUBMENU or FL_SUBMENU_POINTER is on in the flags.
Definition: Fl_Menu_Item.H:295
void image(Fl_Image &a)
compatibility api for FLUID, same as a.label(this)
Definition: Fl_Menu_Item.H:349
Fl_Color labelcolor() const
Gets the menu item's label color.
Definition: Fl_Menu_Item.H:178
void label(Fl_Labeltype a, const char *b)
See const char* Fl_Menu_Item::label() const.
Definition: Fl_Menu_Item.H:151
Fl_Fontsize labelsize() const
Gets the label font pixel size/height.
Definition: Fl_Menu_Item.H:202
const char * label() const
Returns the title of the item.
Definition: Fl_Menu_Item.H:145
void labelcolor(Fl_Color a)
Sets the menu item's label color.
Definition: Fl_Menu_Item.H:184
unsigned char uchar
unsigned char
Definition: fl_types.h:30
unsigned int Fl_Shortcut
24-bit Unicode character + 8-bit indicator for keyboard flags
Definition: fl_types.h:46
void * user_data_
menu item user_data for the menu's callback
Definition: Fl_Menu_Item.H:113