FLTK 1.3.2
Fl_Menu_.H
1 //
2 // "$Id: Fl_Menu_.H 9202 2011-12-08 17:10:11Z greg.ercolano $"
3 //
4 // Menu base class 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 /* \file
20  Fl_Menu_ widget . */
21 
22 #ifndef Fl_Menu__H
23 #define Fl_Menu__H
24 
25 #ifndef Fl_Widget_H
26 #include "Fl_Widget.H"
27 #endif
28 #include "Fl_Menu_Item.H"
29 
39 class FL_EXPORT Fl_Menu_ : public Fl_Widget {
40 
41  Fl_Menu_Item *menu_;
42  const Fl_Menu_Item *value_;
43 
44 protected:
45 
46  uchar alloc; // flag indicates if menu_ is a dynamic copy (=1) or not (=0)
47  uchar down_box_;
48  Fl_Font textfont_;
49  Fl_Fontsize textsize_;
50  Fl_Color textcolor_;
51 
52 public:
53  Fl_Menu_(int,int,int,int,const char * =0);
54  ~Fl_Menu_();
55 
56  int item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem=0) const;
57  const Fl_Menu_Item* picked(const Fl_Menu_Item*);
58  const Fl_Menu_Item* find_item(const char *name);
59  const Fl_Menu_Item* find_item(Fl_Callback*);
60  int find_index(const char *name) const;
61  int find_index(const Fl_Menu_Item *item) const;
62  int find_index(Fl_Callback *cb) const;
63 
75  const Fl_Menu_Item* test_shortcut() {return picked(menu()->test_shortcut());}
76  void global();
77 
96  const Fl_Menu_Item *menu() const {return menu_;}
97  void menu(const Fl_Menu_Item *m);
98  void copy(const Fl_Menu_Item *m, void* user_data = 0);
99  int insert(int index, const char*, int shortcut, Fl_Callback*, void* = 0, int = 0);
100  int add(const char*, int shortcut, Fl_Callback*, void* = 0, int = 0);
102  int add(const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
103  return add(a,fl_old_shortcut(b),c,d,e);
104  }
106  int insert(int index, const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
107  return insert(index,a,fl_old_shortcut(b),c,d,e);
108  }
109  int add(const char *);
110  int size() const ;
111  void size(int W, int H) { Fl_Widget::size(W, H); }
112  void clear();
113  int clear_submenu(int index);
114  void replace(int,const char *);
115  void remove(int);
117  void shortcut(int i, int s) {menu_[i].shortcut(s);}
119  void mode(int i,int fl) {menu_[i].flags = fl;}
121  int mode(int i) const {return menu_[i].flags;}
122 
124  const Fl_Menu_Item *mvalue() const {return value_;}
126  int value() const {return value_ ? (int)(value_-menu_) : -1;}
127  int value(const Fl_Menu_Item*);
134  int value(int i) {return value(menu_+i);}
136  const char *text() const {return value_ ? value_->text : 0;}
138  const char *text(int i) const {return menu_[i].text;}
139 
141  Fl_Font textfont() const {return textfont_;}
143  void textfont(Fl_Font c) {textfont_=c;}
145  Fl_Fontsize textsize() const {return textsize_;}
147  void textsize(Fl_Fontsize c) {textsize_=c;}
149  Fl_Color textcolor() const {return textcolor_;}
151  void textcolor(Fl_Color c) {textcolor_=c;}
152 
159  Fl_Boxtype down_box() const {return (Fl_Boxtype)down_box_;}
161  void down_box(Fl_Boxtype b) {down_box_ = b;}
162 
164  Fl_Color down_color() const {return selection_color();}
166  void down_color(unsigned c) {selection_color(c);}
167 };
168 
169 #endif
170 
171 //
172 // End of "$Id: Fl_Menu_.H 9202 2011-12-08 17:10:11Z greg.ercolano $".
173 //
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:100
Fl_Color selection_color() const
Gets the selection color.
Definition: Fl_Widget.H:384
void textsize(Fl_Fontsize c)
Sets the font size of menu item labels.
Definition: Fl_Menu_.H:147
FL_EXPORT unsigned int fl_old_shortcut(const char *s)
Emulation of XForms named shortcuts.
Definition: fl_shortcut.cxx:275
const char * text() const
Returns the title of the last item chosen.
Definition: Fl_Menu_.H:136
int value() const
Returns the index into menu() of the last item chosen by the user.
Definition: Fl_Menu_.H:126
const Fl_Menu_Item * mvalue() const
Returns a pointer to the last menu item that was picked.
Definition: Fl_Menu_.H:124
void size(int W, int H)
Changes the size of the widget.
Definition: Fl_Widget.H:329
Fl_Fontsize textsize() const
Gets the font size of menu item labels.
Definition: Fl_Menu_.H:145
Fl_Boxtype down_box() const
This box type is used to surround the currently-selected items in the menus.
Definition: Fl_Menu_.H:159
int value(int i)
The value is the index into menu() of the last item chosen by the user.
Definition: Fl_Menu_.H:134
void down_color(unsigned c)
For back compatibility, same as selection_color()
Definition: Fl_Menu_.H:166
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, int flags=0)
Definition: Fl_Menu_.H:102
Fl_Boxtype
Definition: Enumerations.H:469
Fl_Font textfont() const
Gets the current font of menu item labels.
Definition: Fl_Menu_.H:141
int mode(int i) const
Gets the flags of item i.
Definition: Fl_Menu_.H:121
const char * text(int i) const
Returns the title of item i.
Definition: Fl_Menu_.H:138
void( Fl_Callback)(Fl_Widget *, void *)
Default callback type definition for all fltk widgets (by far the most used)
Definition: Fl_Widget.H:49
const Fl_Menu_Item * test_shortcut()
Returns the menu item with the entered shortcut (key value).
Definition: Fl_Menu_.H:75
Fl_Widget, Fl_Label classes .
void shortcut(int i, int s)
Changes the shortcut of item i to n.
Definition: Fl_Menu_.H:117
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:746
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, int flags=0)
Definition: Fl_Menu_.H:106
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 textcolor(Fl_Color c)
Sets the current color of menu item labels.
Definition: Fl_Menu_.H:151
unsigned int Fl_Color
an FLTK color value
Definition: Enumerations.H:774
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:717
void mode(int i, int fl)
Sets the flags of item i.
Definition: Fl_Menu_.H:119
const char * text
menu item text, returned by label()
Definition: Fl_Menu_Item.H:110
Base class of all widgets that have a menu in FLTK.
Definition: Fl_Menu_.H:39
Fl_Color down_color() const
For back compatibility, same as selection_color()
Definition: Fl_Menu_.H:164
void textfont(Fl_Font c)
Sets the current font of menu item labels.
Definition: Fl_Menu_.H:143
unsigned char uchar
unsigned char
Definition: fl_types.h:30
Fl_Color textcolor() const
Get the current color of menu item labels.
Definition: Fl_Menu_.H:149
const Fl_Menu_Item * menu() const
Returns a pointer to the array of Fl_Menu_Items.
Definition: Fl_Menu_.H:96
void down_box(Fl_Boxtype b)
See Fl_Boxtype Fl_Menu_::down_box() const.
Definition: Fl_Menu_.H:161