2 // "$Id: Fl_Menu_Item.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $"
4 // Menu item header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2002 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 to "fltk-bugs@fltk.org".
26 #ifndef Fl_Menu_Item_H
27 #define Fl_Menu_Item_H
29 # include "Fl_Widget.H"
30 # include "Fl_Image.H"
32 # if defined(__APPLE__) && defined(__MWERKS__) && defined(check)
36 enum { // values for flags:
41 FL_MENU_INVISIBLE = 0x10,
42 FL_SUBMENU_POINTER = 0x20,
44 FL_MENU_DIVIDER = 0x80,
45 FL_MENU_HORIZONTAL = 0x100
48 extern FL_EXPORT int fl_old_shortcut(const char*);
52 struct FL_EXPORT Fl_Menu_Item {
53 const char *text; // label()
55 Fl_Callback *callback_;
63 // advance N items, skipping submenus:
64 const Fl_Menu_Item *next(int=1) const;
65 Fl_Menu_Item *next(int i=1) {
66 return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));}
68 // methods on menu items:
69 const char* label() const {return text;}
70 void label(const char* a) {text=a;}
71 void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
72 Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
73 void labeltype(Fl_Labeltype a) {labeltype_ = a;}
74 Fl_Color labelcolor() const {return (Fl_Color)labelcolor_;}
75 void labelcolor(unsigned a) {labelcolor_ = a;}
76 Fl_Font labelfont() const {return (Fl_Font)labelfont_;}
77 void labelfont(uchar a) {labelfont_ = a;}
78 uchar labelsize() const {return labelsize_;}
79 void labelsize(uchar a) {labelsize_ = a;}
80 Fl_Callback_p callback() const {return callback_;}
81 void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
82 void callback(Fl_Callback* c) {callback_=c;}
83 void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
84 void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)p;}
85 void* user_data() const {return user_data_;}
86 void user_data(void* v) {user_data_ = v;}
87 long argument() const {return (long)user_data_;}
88 void argument(long v) {user_data_ = (void*)v;}
89 int shortcut() const {return shortcut_;}
90 void shortcut(int s) {shortcut_ = s;}
91 int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
92 int checkbox() const {return flags&FL_MENU_TOGGLE;}
93 int radio() const {return flags&FL_MENU_RADIO;}
94 int value() const {return flags&FL_MENU_VALUE;}
95 void set() {flags |= FL_MENU_VALUE;}
96 void clear() {flags &= ~FL_MENU_VALUE;}
98 int visible() const {return !(flags&FL_MENU_INVISIBLE);}
99 void show() {flags &= ~FL_MENU_INVISIBLE;}
100 void hide() {flags |= FL_MENU_INVISIBLE;}
101 int active() const {return !(flags&FL_MENU_INACTIVE);}
102 void activate() {flags &= ~FL_MENU_INACTIVE;}
103 void deactivate() {flags |= FL_MENU_INACTIVE;}
104 int activevisible() const {return !(flags&0x11);}
106 // compatibility for FLUID so it can set the image of a menu item...
107 void image(Fl_Image* a) {a->label(this);}
108 void image(Fl_Image& a) {a.label(this);}
111 int measure(int* h, const Fl_Menu_*) const;
112 void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
114 // popup menus without using an Fl_Menu_ widget:
115 const Fl_Menu_Item* popup(
117 const char *title = 0,
118 const Fl_Menu_Item* picked=0,
119 const Fl_Menu_* = 0) const;
120 const Fl_Menu_Item* pulldown(
121 int X, int Y, int W, int H,
122 const Fl_Menu_Item* picked = 0,
124 const Fl_Menu_Item* title = 0,
125 int menubar=0) const;
126 const Fl_Menu_Item* test_shortcut() const;
127 const Fl_Menu_Item* find_shortcut(int *ip=0) const;
129 void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
130 void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
131 void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)arg);}
133 // back-compatability, do not use:
134 int checked() const {return flags&FL_MENU_VALUE;}
135 void check() {flags |= FL_MENU_VALUE;}
136 void uncheck() {flags &= ~FL_MENU_VALUE;}
137 int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
138 int add(const char*a, const char* b, Fl_Callback* c,
139 void* d = 0, int e = 0) {
140 return add(a,fl_old_shortcut(b),c,d,e);}
144 typedef Fl_Menu_Item Fl_Menu; // back compatability
146 enum { // back-compatability enum:
148 FL_PUP_GREY = FL_MENU_INACTIVE,
149 FL_PUP_GRAY = FL_MENU_INACTIVE,
150 FL_MENU_BOX = FL_MENU_TOGGLE,
151 FL_PUP_BOX = FL_MENU_TOGGLE,
152 FL_MENU_CHECK = FL_MENU_VALUE,
153 FL_PUP_CHECK = FL_MENU_VALUE,
154 FL_PUP_RADIO = FL_MENU_RADIO,
155 FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
156 FL_PUP_SUBMENU = FL_SUBMENU_POINTER
162 // End of "$Id: Fl_Menu_Item.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $".