FLTK 1.3.0
Fl_Menu_Item.H
1 //
2 // "$Id: Fl_Menu_Item.H 7983 2010-12-09 00:04:06Z AlbrechtS $"
3 //
4 // Menu item 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; 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.
12 //
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.
17 //
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
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 // http://www.fltk.org/str.php
26 //
27 
28 #ifndef Fl_Menu_Item_H
29 #define Fl_Menu_Item_H
30 
31 # include "Fl_Widget.H"
32 # include "Fl_Image.H"
33 
34 # if defined(__APPLE__) && defined(check)
35 # undef check
36 # endif
37 
38 enum { // values for flags:
39  FL_MENU_INACTIVE = 1,
40  FL_MENU_TOGGLE= 2,
41  FL_MENU_VALUE = 4,
42  FL_MENU_RADIO = 8,
43  FL_MENU_INVISIBLE = 0x10,
44  FL_SUBMENU_POINTER = 0x20,
45  FL_SUBMENU = 0x40,
46  FL_MENU_DIVIDER = 0x80,
47  FL_MENU_HORIZONTAL = 0x100
48 };
49 
50 extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
51 
52 class Fl_Menu_;
53 
118 struct FL_EXPORT Fl_Menu_Item {
119  const char *text;
120  int shortcut_;
122  void *user_data_;
123  int flags;
128 
129  // advance N items, skipping submenus:
130  const Fl_Menu_Item *next(int=1) const;
131 
137  Fl_Menu_Item *next(int i=1) {
138  return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));}
139 
141  const Fl_Menu_Item *first() const { return next(0); }
142 
144  Fl_Menu_Item *first() { return next(0); }
145 
146  // methods on menu items:
154  const char* label() const {return text;}
155 
157  void label(const char* a) {text=a;}
158 
160  void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
161 
169  Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
170 
178  void labeltype(Fl_Labeltype a) {labeltype_ = a;}
179 
187  Fl_Color labelcolor() const {return labelcolor_;}
188 
193  void labelcolor(Fl_Color a) {labelcolor_ = a;}
200  Fl_Font labelfont() const {return labelfont_;}
201 
208  void labelfont(Fl_Font a) {labelfont_ = a;}
209 
211  Fl_Fontsize labelsize() const {return labelsize_;}
212 
214  void labelsize(Fl_Fontsize a) {labelsize_ = a;}
215 
223  Fl_Callback_p callback() const {return callback_;}
224 
229  void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
230 
236  void callback(Fl_Callback* c) {callback_=c;}
237 
243  void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
244 
252  void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)p;}
253 
257  void* user_data() const {return user_data_;}
261  void user_data(void* v) {user_data_ = v;}
268  long argument() const {return (long)(fl_intptr_t)user_data_;}
276  void argument(long v) {user_data_ = (void*)v;}
277 
279  int shortcut() const {return shortcut_;}
280 
296  void shortcut(int s) {shortcut_ = s;}
304  int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
309  int checkbox() const {return flags&FL_MENU_TOGGLE;}
316  int radio() const {return flags&FL_MENU_RADIO;}
318  int value() const {return flags&FL_MENU_VALUE;}
323  void set() {flags |= FL_MENU_VALUE;}
324 
326  void clear() {flags &= ~FL_MENU_VALUE;}
327 
328  void setonly();
329 
331  int visible() const {return !(flags&FL_MENU_INVISIBLE);}
332 
334  void show() {flags &= ~FL_MENU_INVISIBLE;}
335 
337  void hide() {flags |= FL_MENU_INVISIBLE;}
338 
340  int active() const {return !(flags&FL_MENU_INACTIVE);}
341 
343  void activate() {flags &= ~FL_MENU_INACTIVE;}
348  void deactivate() {flags |= FL_MENU_INACTIVE;}
350  int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));}
351 
352  // compatibility for FLUID so it can set the image of a menu item...
353 
355  void image(Fl_Image* a) {a->label(this);}
356 
358  void image(Fl_Image& a) {a.label(this);}
359 
360  // used by menubar:
361  int measure(int* h, const Fl_Menu_*) const;
362  void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
363 
364  // popup menus without using an Fl_Menu_ widget:
365  const Fl_Menu_Item* popup(
366  int X, int Y,
367  const char *title = 0,
368  const Fl_Menu_Item* picked=0,
369  const Fl_Menu_* = 0) const;
370  const Fl_Menu_Item* pulldown(
371  int X, int Y, int W, int H,
372  const Fl_Menu_Item* picked = 0,
373  const Fl_Menu_* = 0,
374  const Fl_Menu_Item* title = 0,
375  int menubar=0) const;
376  const Fl_Menu_Item* test_shortcut() const;
377  const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const;
378 
384  void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
385 
391  void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
392 
400  void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)arg);}
401 
402  // back-compatibility, do not use:
403 
405  int checked() const {return flags&FL_MENU_VALUE;}
406 
408  void check() {flags |= FL_MENU_VALUE;}
409 
411  void uncheck() {flags &= ~FL_MENU_VALUE;}
412 
413  int insert(int,const char*,int,Fl_Callback*,void* =0, int =0);
414  int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
415 
417  int add(const char*a, const char* b, Fl_Callback* c,
418  void* d = 0, int e = 0) {
419  return add(a,fl_old_shortcut(b),c,d,e);}
420 
421  int size() const ;
422 };
423 
424 typedef Fl_Menu_Item Fl_Menu; // back compatibility
425 
426 enum { // back-compatibility enum:
427  FL_PUP_NONE = 0,
428  FL_PUP_GREY = FL_MENU_INACTIVE,
429  FL_PUP_GRAY = FL_MENU_INACTIVE,
430  FL_MENU_BOX = FL_MENU_TOGGLE,
431  FL_PUP_BOX = FL_MENU_TOGGLE,
432  FL_MENU_CHECK = FL_MENU_VALUE,
433  FL_PUP_CHECK = FL_MENU_VALUE,
434  FL_PUP_RADIO = FL_MENU_RADIO,
435  FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
436  FL_PUP_SUBMENU = FL_SUBMENU_POINTER
437 };
438 
439 #endif
440 
441 //
442 // End of "$Id: Fl_Menu_Item.H 7983 2010-12-09 00:04:06Z AlbrechtS $".
443 //