summaryrefslogtreecommitdiffstats
path: root/fltk/fltk/compat/FL/menubar.h
blob: 83b3af80cd5356c864be3bcc2ca42eac86cc800d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// This is an additional header file for "DDForms", which was our internal
// enhancement of Forms.  This defines the precursor of the Fl_Menu class.
//
// Unfortunately it defined the callbacks as taking a long rather
// than a void* argument, requiring some dubious casts to emulate it:

#include "Fl_Menu_Bar.h"

struct FL_API MenuEntry {
  const char *text;	/*initial character indicates "type", 0 = end of menu*/
  ulong bind;	/* key binding in forms format (#x, etc) */
  void (*cb)(Fl_Widget *,long);	/* callback */
  long data;		/* value for callback */
  int flags;		/* see below for flags */
  uchar labeltype;
  uchar labelfont;
  uchar labelsize;
  uchar labelcolor;
};

#define CHECKED FL_MENU_CHECK
#define UNCHECKED FL_MENU_BOX
#define DISABLED FL_MENU_INACTIVE

/* Turn a box into a menu bar: */
inline void MenuBar(Fl_Widget *o,MenuEntry *m) {
    Fl_Menu_Bar *mb = new Fl_Menu_Bar(o->x(),o->y(),o->w(),o->h());
    mb->menu((Fl_Menu_Item*)m);
    mb->box(0);
    Fl_Group *g = (Fl_Group *)(o->parent());
    int i = g->find(*o);
    g->insert(*mb, i<g->children()-1 ? g->child(i+1) : 0);
}

/* advance to the Nth item in menu, skipping submenus: */
inline MenuEntry *MenuGetEntry(MenuEntry *m,int i) {
    return (MenuEntry*)(((Fl_Menu_Item*)m)->next(i));
}

/* Init the shortcuts for a widget with a popup menu: */
inline void MenuSetShortcuts(Fl_Widget *, MenuEntry *) {}

inline void MenuAdd(
    MenuEntry m[],
    int, /* number of entries in menutable, ignored here */
    const char *text,
    const char *bind,
    void (*cb)(Fl_Widget *,long),
    long data,
    int flags) {
    ((Fl_Menu_Item*)m)->add(text,bind,(Fl_Callback*)cb,(void *)data,flags);
}

inline MenuEntry *MenuPopup(Fl_Widget *o,const char *title,MenuEntry *m,
			    int x, int y) {
    const Fl_Menu_Item* v = ((Fl_Menu_Item*)m)->popup(x,y,title);
    if (v && v->callback_) v->do_callback(o);
    return (MenuEntry *)v;
}

inline MenuEntry *MenuHandleShortcut(Fl_Widget *o,MenuEntry *m,char) {
    const Fl_Menu_Item* v = ((Fl_Menu_Item*)m)->test_shortcut();
    if (v && v->callback_) v->do_callback(o);
    return (MenuEntry *)v;
}