A menu is an *array* of these structures. The structure is designed so it is relatively easy to define an entire hierarchy of menus with a C initialization constant. This is best described with an example:
![]() |
Fl_Menu popup[] = { {"&alpha", "#a", the_cb, (void *)'a'}, {"&beta", "#b", the_cb, (void *)'b'}, {"_gamma", "#c", the_cb, (void *)'c'}, {"&strange", 0, strange_cb}, {"&charm", 0, charm_cb}, {"&truth", 0, truth_cb}, {"b&eauty", 0, beauty_cb}, {"/sub&menu"}, {"one"}, {"two"}, {"three"}, {0}, {"_inactive","#i", 0, 0, FL_PUP_GREY}, {"invisible","#i", 0, 0, FL_PUP_INVISIBLE}, {"check", "#i", 0, 0, FL_PUP_CHECK|FL_PUP_BOX}, {"box", "#i", 0, 0, FL_PUP_BOX}, {0}}; |
FL_PUP_SUBMENU
flags.
const char *text;
'/'
(slash) submenu starting with next item, through next null
'_'
(underscore) draw a line under this item (may be combined with above)
' '
(space) ignored, quote rest of line
const char *shortcut;
Fl_Callback *callback;
void *argument;
int flags;
FL_PUP_GREY (1)
(also FL_PUP_GRAY
)
Displays the text grayed out and the user cannot pick this item.
FL_PUP_BOX (2)
displays an empty check box.
FL_PUP_BOX|FL_PUP_CHECK (6)
displays a filled check
box.
FL_PUP_RADIO (8)
NYI. Currently this acts like
FL_PUP_BOX.
FL_PUP_INVISIBLE (16)
Acts exactly as though this
item is not in the menu array. If this is a submenu title the entire
submenu is ignored.
FL_PUP_SUBMENU (32)
This item is a submenu title, and
the submenu data can be found at
(Fl_Menu*)(this->argument)
.
There are several methods on an Fl_Menu defined, these are designed so that a pointer to the first item in the array can be considered a pointer to a "menu" object. However it is important to remember that this is an array:
const Fl_Menu *popup(int x, int y, int w, int h,
const Fl_Menu* picked = 0, const char* title = 0) const;
picked may be a pointer to any item in the menu, or in any submenu of it. picked may be null in which case the menu pops up so that the cursor is outside it.
The x,y,w,h define the bounding box of the button that brings up the menu, in root window space. If picked is non-zero that item is centered in this box. If picked is zero the menu appears below this button, like a pull-down. The menu is made at least w wide. Pass the mouse position as x,y and w,h of zero for a "popup" menu.
The title, if nonzero, puts a small title box above the menu, GL style.
const Fl_Menu *popup(int x, int y, const char *title =
0) const;
popup(x,y,0,0,0,title)
.
static void textfont(uchar x);
static void textsize(uchar x);
static uchar textfont();
static uchar textsize();
const Fl_Menu *test_shortcut() const;
int size();
int add(const char *text,const char * shortcut,Fl_Callback *,void
*,int);
If an item exists already with that name then it is replaced with this new one. Otherwise this new one is added to the end of the correct menu or submenu. The return value is the offset into the array that the new entry was placed at.
No bounds checking is done, the table must be big enough for all the entries you plan to add. Don't forget that there is a null terminator on the end, and the first time a item is added to a submenu three items are added (the title and the null terminator, as well as the actual menu item)
This was designed to make a tcl command that would build a menu. Here is all that is necessary to make a tcl-driven menu builder:
static void menu_cb(FL_OBJECT *,void* d) { char *cmd = (char *)d; if (Tcl_Eval(interp,cmd)) fl_message(interp->result); } #define MAXMENUSIZE 256 static Fl_Menu menu[MAXMENUSIZE]; static int menuCmd(ClientData, Tcl_Interp *interp, int argc, char** argv) { if (argc != 3 && argc != 4) { interp->result = "usage: menu name ?shortcut? command"; return TCL_ERROR; } char *text = argv[1]; char *bind = (argc==4) ? strdup(argv[2]) : 0; char *cmd = strdup((argc==4) ? argv[3] : argv[2]); menu->add(text, bind, menu_cb, cmd, 0); return 0; } // add "menuCmd" to tcl as a command
const Fl_Menu *next(int=1) const;
Fl_Menu *next(int=1);
int checked() const;
int checkbox() const;
void check();
void uncheck();
int active() const;
void activate();
void deactivate();
int visible() const;
void show();
void hide();
int submenu() const;