2 // "$Id: Fl_Menu_.H 7903 2010-11-28 21:06:39Z matt $"
4 // Menu base class header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
35 #include "Fl_Widget.H"
37 #include "Fl_Menu_Item.H"
40 Base class of all widgets that have a menu in FLTK.
41 Currently FLTK provides you with
42 Fl_Menu_Button, Fl_Menu_Bar, and Fl_Choice.
44 <P>The class contains a pointer to an array of structures of type Fl_Menu_Item. The
45 array may either be supplied directly by the user program, or it may
46 be "private": a dynamically allocated array managed by the Fl_Menu_.
48 class FL_EXPORT Fl_Menu_ : public Fl_Widget {
51 const Fl_Menu_Item *value_;
55 uchar alloc; // flag indicates if menu_ is a dynamic copy (=1) or not (=0)
58 Fl_Fontsize textsize_;
62 Fl_Menu_(int,int,int,int,const char * =0);
65 int item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem=0) const;
66 const Fl_Menu_Item* picked(const Fl_Menu_Item*);
67 const Fl_Menu_Item* find_item(const char *name);
68 const Fl_Menu_Item* find_item(Fl_Callback*);
69 int find_index(const char *name) const;
70 int find_index(const Fl_Menu_Item *item) const;
71 int find_index(Fl_Callback *cb) const;
74 Returns the menu item with the entered shortcut (key value).
76 This searches the complete menu() for a shortcut that matches the
77 entered key value. It must be called for a FL_KEYBOARD or FL_SHORTCUT
80 If a match is found, the menu's callback will be called.
82 \return matched Fl_Menu_Item or NULL.
84 const Fl_Menu_Item* test_shortcut() {return picked(menu()->test_shortcut());}
88 Returns a pointer to the array of Fl_Menu_Items. This will either be
89 the value passed to menu(value) or the private copy.
91 const Fl_Menu_Item *menu() const {return menu_;}
92 void menu(const Fl_Menu_Item *m);
93 void copy(const Fl_Menu_Item *m, void* user_data = 0);
94 int insert(int index, const char*, int shortcut, Fl_Callback*, void* = 0, int = 0);
95 int add(const char*, int shortcut, Fl_Callback*, void* = 0, int = 0);
96 /** See int Fl_Menu_::add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0) */
97 int add(const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
98 return add(a,fl_old_shortcut(b),c,d,e);
100 /** See int Fl_Menu_::insert(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0) */
101 int insert(int index, const char* a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) {
102 return insert(index,a,fl_old_shortcut(b),c,d,e);
104 int add(const char *);
106 void size(int W, int H) { Fl_Widget::size(W, H); }
108 int clear_submenu(int index);
109 void replace(int,const char *);
111 /** Changes the shortcut of item i to n. */
112 void shortcut(int i, int s) {menu_[i].shortcut(s);}
113 /** Sets the flags of item i. For a list of the flags, see Fl_Menu_Item. */
114 void mode(int i,int fl) {menu_[i].flags = fl;}
115 /** Gets the flags of item i. For a list of the flags, see Fl_Menu_Item. */
116 int mode(int i) const {return menu_[i].flags;}
118 /** Returns a pointer to the last menu item that was picked. */
119 const Fl_Menu_Item *mvalue() const {return value_;}
120 /** Returns the index into menu() of the last item chosen by the user. It is zero initially. */
121 int value() const {return value_ ? (int)(value_-menu_) : -1;}
122 int value(const Fl_Menu_Item*);
124 The value is the index into menu() of the last item chosen by
125 the user. It is zero initially. You can set it as an integer, or set
126 it with a pointer to a menu item. The set routines return non-zero if
127 the new value is different than the old one.
129 int value(int i) {return value(menu_+i);}
130 /** Returns the title of the last item chosen. */
131 const char *text() const {return value_ ? value_->text : 0;}
132 /** Returns the title of item i. */
133 const char *text(int i) const {return menu_[i].text;}
135 /** Gets the current font of menu item labels. */
136 Fl_Font textfont() const {return textfont_;}
137 /** Sets the current font of menu item labels. */
138 void textfont(Fl_Font c) {textfont_=c;}
139 /** Gets the font size of menu item labels. */
140 Fl_Fontsize textsize() const {return textsize_;}
141 /** Sets the font size of menu item labels. */
142 void textsize(Fl_Fontsize c) {textsize_=c;}
143 /** Get the current color of menu item labels. */
144 Fl_Color textcolor() const {return textcolor_;}
145 /** Sets the current color of menu item labels. */
146 void textcolor(Fl_Color c) {textcolor_=c;}
149 This box type is used to surround the currently-selected items in the
150 menus. If this is FL_NO_BOX then it acts like
151 FL_THIN_UP_BOX and selection_color() acts like
152 FL_WHITE, for back compatibility.
154 Fl_Boxtype down_box() const {return (Fl_Boxtype)down_box_;}
155 /** See Fl_Boxtype Fl_Menu_::down_box() const */
156 void down_box(Fl_Boxtype b) {down_box_ = b;}
158 /** For back compatibility, same as selection_color() */
159 Fl_Color down_color() const {return selection_color();}
160 /** For back compatibility, same as selection_color() */
161 void down_color(unsigned c) {selection_color(c);}
167 // End of "$Id: Fl_Menu_.H 7903 2010-11-28 21:06:39Z matt $".