FLTK 1.4.0
Fl_Menu_.H
1 //
2 // Menu base class header file for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2019 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 /* \file
18  Fl_Menu_ widget . */
19 
20 #ifndef Fl_Menu__H
21 #define Fl_Menu__H
22 
23 #ifndef Fl_Widget_H
24 #include "Fl_Widget.H"
25 #endif
26 #include "Fl_Menu_Item.H"
27 
53 class FL_EXPORT Fl_Menu_ : public Fl_Widget {
54 
55  Fl_Menu_Item *menu_;
56  const Fl_Menu_Item *value_;
57 
58 protected:
59 
60  uchar alloc; // flag indicates if menu_ is a dynamic copy (=1) or not (=0)
61  uchar down_box_;
62  Fl_Font textfont_;
63  Fl_Fontsize textsize_;
64  Fl_Color textcolor_;
65 
66  int item_pathname_(char *name, int namelen, const Fl_Menu_Item *finditem,
67  const Fl_Menu_Item *menu=0) const;
68 public:
69  Fl_Menu_(int,int,int,int,const char * =0);
70  ~Fl_Menu_();
71 
72  int item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem=0) const;
73  const Fl_Menu_Item* picked(const Fl_Menu_Item*);
74  const Fl_Menu_Item* find_item(const char *name);
75  const Fl_Menu_Item* find_item(Fl_Callback*);
76  int find_index(const char *name) const;
77  int find_index(const Fl_Menu_Item *item) const;
78  int find_index(Fl_Callback *cb) const;
79 
91  const Fl_Menu_Item* test_shortcut() {return picked(menu()->test_shortcut());}
92  void global();
93 
129  const Fl_Menu_Item *menu() const {return menu_;}
130  const Fl_Menu_Item *menu_end(); // in src/Fl_Menu_add.cxx
131  void menu(const Fl_Menu_Item *m);
132  void copy(const Fl_Menu_Item *m, void* user_data = 0);
133  int insert(int index, const char*, int shortcut, Fl_Callback*, void* = 0, int = 0);
134  int add(const char*, int shortcut, Fl_Callback*, void* = 0, int = 0); // see src/Fl_Menu_add.cxx
136  int add(const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
137  return add(a,fl_old_shortcut(b),c,d,e);
138  }
140  int insert(int index, const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
141  return insert(index,a,fl_old_shortcut(b),c,d,e);
142  }
143  int add(const char *);
144  int size() const ;
145  void size(int W, int H) { Fl_Widget::size(W, H); }
146  void clear();
147  int clear_submenu(int index);
148  void replace(int,const char *);
149  void remove(int);
151  void shortcut(int i, int s) {menu_[i].shortcut(s);}
153  void mode(int i,int fl) {menu_[i].flags = fl;}
155  int mode(int i) const {return menu_[i].flags;}
156 
158  const Fl_Menu_Item *mvalue() const {return value_;}
160  int value() const {return value_ ? (int)(value_-menu_) : -1;}
161  int value(const Fl_Menu_Item*);
168  int value(int i) {return value(menu_+i);}
170  const char *text() const {return value_ ? value_->text : 0;}
172  const char *text(int i) const {return menu_[i].text;}
173 
175  Fl_Font textfont() const {return textfont_;}
177  void textfont(Fl_Font c) {textfont_=c;}
179  Fl_Fontsize textsize() const {return textsize_;}
181  void textsize(Fl_Fontsize c) {textsize_=c;}
183  Fl_Color textcolor() const {return textcolor_;}
185  void textcolor(Fl_Color c) {textcolor_=c;}
186 
193  Fl_Boxtype down_box() const {return (Fl_Boxtype)down_box_;}
195  void down_box(Fl_Boxtype b) {down_box_ = b;}
196 
198  Fl_Color down_color() const {return selection_color();}
200  void down_color(unsigned c) {selection_color(c);}
201  void setonly(Fl_Menu_Item* item);
202 };
203 
204 #endif
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition: Enumerations.H:1042
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
Fl_Boxtype
FLTK standard box types.
Definition: Enumerations.H:598
Fl_Widget, 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:32
Base class of all widgets that have a menu in FLTK.
Definition: Fl_Menu_.H:53
const Fl_Menu_Item * mvalue() const
Returns a pointer to the last menu item that was picked.
Definition: Fl_Menu_.H:158
Fl_Color down_color() const
For back compatibility, same as selection_color()
Definition: Fl_Menu_.H:198
void mode(int i, int fl)
Sets the flags of item i.
Definition: Fl_Menu_.H:153
const char * text(int i) const
Returns the title of item i.
Definition: Fl_Menu_.H:172
void down_color(unsigned c)
For back compatibility, same as selection_color()
Definition: Fl_Menu_.H:200
const Fl_Menu_Item * menu() const
Returns a pointer to the array of Fl_Menu_Items.
Definition: Fl_Menu_.H:129
const Fl_Menu_Item * test_shortcut()
Returns the menu item with the entered shortcut (key value).
Definition: Fl_Menu_.H:91
Fl_Font textfont() const
Gets the current font of menu item labels.
Definition: Fl_Menu_.H:175
void textsize(Fl_Fontsize c)
Sets the font size of menu item labels.
Definition: Fl_Menu_.H:181
int value() const
Returns the index into menu() of the last item chosen by the user.
Definition: Fl_Menu_.H:160
void down_box(Fl_Boxtype b)
See Fl_Boxtype Fl_Menu_::down_box() const
Definition: Fl_Menu_.H:195
int insert(int index, const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
See int Fl_Menu_::insert(const char* label, int shortcut, Fl_Callback*, void *user_data=0,...
Definition: Fl_Menu_.H:140
int value(int i)
The value is the index into menu() of the last item chosen by the user.
Definition: Fl_Menu_.H:168
Fl_Fontsize textsize() const
Gets the font size of menu item labels.
Definition: Fl_Menu_.H:179
void textcolor(Fl_Color c)
Sets the current color of menu item labels.
Definition: Fl_Menu_.H:185
int add(const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
See int Fl_Menu_::add(const char* label, int shortcut, Fl_Callback*, void *user_data=0,...
Definition: Fl_Menu_.H:136
void shortcut(int i, int s)
Changes the shortcut of item i to s.
Definition: Fl_Menu_.H:151
int mode(int i) const
Gets the flags of item i.
Definition: Fl_Menu_.H:155
Fl_Boxtype down_box() const
This box type is used to surround the currently-selected items in the menus.
Definition: Fl_Menu_.H:193
void textfont(Fl_Font c)
Sets the current font of menu item labels.
Definition: Fl_Menu_.H:177
Fl_Color textcolor() const
Get the current color of menu item labels.
Definition: Fl_Menu_.H:183
const char * text() const
Returns the title of the last item chosen.
Definition: Fl_Menu_.H:170
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
Fl_Color selection_color() const
Gets the selection color.
Definition: Fl_Widget.H:402
void size(int W, int H)
Changes the size of the widget.
Definition: Fl_Widget.H:347
unsigned char uchar
unsigned char
Definition: fl_types.h:28
FL_EXPORT unsigned int fl_old_shortcut(const char *s)
Emulation of XForms named shortcuts.
Definition: fl_shortcut.cxx:273
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class.
Definition: Fl_Menu_Item.H:114
const char * text
menu item text, returned by label()
Definition: Fl_Menu_Item.H:115