FLTK 1.3.2
Fl_Menu_Item.H
1 //
2 // "$Id: Fl_Menu_Item.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
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. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 #ifndef Fl_Menu_Item_H
20 #define Fl_Menu_Item_H
21 
22 # include "Fl_Widget.H"
23 # include "Fl_Image.H"
24 
25 # if defined(__APPLE__) && defined(check)
26 # undef check
27 # endif
28 
29 enum { // values for flags:
30  FL_MENU_INACTIVE = 1,
31  FL_MENU_TOGGLE= 2,
32  FL_MENU_VALUE = 4,
33  FL_MENU_RADIO = 8,
34  FL_MENU_INVISIBLE = 0x10,
35  FL_SUBMENU_POINTER = 0x20,
36  FL_SUBMENU = 0x40,
37  FL_MENU_DIVIDER = 0x80,
38  FL_MENU_HORIZONTAL = 0x100
39 };
40 
41 extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
42 
43 class Fl_Menu_;
44 
109 struct FL_EXPORT Fl_Menu_Item {
110  const char *text;
111  int shortcut_;
113  void *user_data_;
114  int flags;
119 
120  // advance N items, skipping submenus:
121  const Fl_Menu_Item *next(int=1) const;
122 
128  Fl_Menu_Item *next(int i=1) {
129  return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));}
130 
132  const Fl_Menu_Item *first() const { return next(0); }
133 
135  Fl_Menu_Item *first() { return next(0); }
136 
137  // methods on menu items:
145  const char* label() const {return text;}
146 
148  void label(const char* a) {text=a;}
149 
151  void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
152 
160  Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
161 
169  void labeltype(Fl_Labeltype a) {labeltype_ = a;}
170 
178  Fl_Color labelcolor() const {return labelcolor_;}
179 
184  void labelcolor(Fl_Color a) {labelcolor_ = a;}
191  Fl_Font labelfont() const {return labelfont_;}
192 
199  void labelfont(Fl_Font a) {labelfont_ = a;}
200 
202  Fl_Fontsize labelsize() const {return labelsize_;}
203 
205  void labelsize(Fl_Fontsize a) {labelsize_ = a;}
206 
214  Fl_Callback_p callback() const {return callback_;}
215 
220  void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
221 
227  void callback(Fl_Callback* c) {callback_=c;}
228 
234  void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
235 
243  void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)p;}
244 
248  void* user_data() const {return user_data_;}
252  void user_data(void* v) {user_data_ = v;}
259  long argument() const {return (long)(fl_intptr_t)user_data_;}
267  void argument(long v) {user_data_ = (void*)v;}
268 
270  int shortcut() const {return shortcut_;}
271 
287  void shortcut(int s) {shortcut_ = s;}
295  int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
300  int checkbox() const {return flags&FL_MENU_TOGGLE;}
307  int radio() const {return flags&FL_MENU_RADIO;}
309  int value() const {return flags&FL_MENU_VALUE;}
314  void set() {flags |= FL_MENU_VALUE;}
315 
317  void clear() {flags &= ~FL_MENU_VALUE;}
318 
319  void setonly();
320 
322  int visible() const {return !(flags&FL_MENU_INVISIBLE);}
323 
325  void show() {flags &= ~FL_MENU_INVISIBLE;}
326 
328  void hide() {flags |= FL_MENU_INVISIBLE;}
329 
331  int active() const {return !(flags&FL_MENU_INACTIVE);}
332 
334  void activate() {flags &= ~FL_MENU_INACTIVE;}
339  void deactivate() {flags |= FL_MENU_INACTIVE;}
341  int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));}
342 
343  // compatibility for FLUID so it can set the image of a menu item...
344 
346  void image(Fl_Image* a) {a->label(this);}
347 
349  void image(Fl_Image& a) {a.label(this);}
350 
351  // used by menubar:
352  int measure(int* h, const Fl_Menu_*) const;
353  void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
354 
355  // popup menus without using an Fl_Menu_ widget:
356  const Fl_Menu_Item* popup(
357  int X, int Y,
358  const char *title = 0,
359  const Fl_Menu_Item* picked=0,
360  const Fl_Menu_* = 0) const;
361  const Fl_Menu_Item* pulldown(
362  int X, int Y, int W, int H,
363  const Fl_Menu_Item* picked = 0,
364  const Fl_Menu_* = 0,
365  const Fl_Menu_Item* title = 0,
366  int menubar=0) const;
367  const Fl_Menu_Item* test_shortcut() const;
368  const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const;
369 
375  void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
376 
382  void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
383 
391  void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)arg);}
392 
393  // back-compatibility, do not use:
394 
396  int checked() const {return flags&FL_MENU_VALUE;}
397 
399  void check() {flags |= FL_MENU_VALUE;}
400 
402  void uncheck() {flags &= ~FL_MENU_VALUE;}
403 
404  int insert(int,const char*,int,Fl_Callback*,void* =0, int =0);
405  int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
406 
408  int add(const char*a, const char* b, Fl_Callback* c,
409  void* d = 0, int e = 0) {
410  return add(a,fl_old_shortcut(b),c,d,e);}
411 
412  int size() const ;
413 };
414 
415 typedef Fl_Menu_Item Fl_Menu; // back compatibility
416 
417 enum { // back-compatibility enum:
418  FL_PUP_NONE = 0,
419  FL_PUP_GREY = FL_MENU_INACTIVE,
420  FL_PUP_GRAY = FL_MENU_INACTIVE,
421  FL_MENU_BOX = FL_MENU_TOGGLE,
422  FL_PUP_BOX = FL_MENU_TOGGLE,
423  FL_MENU_CHECK = FL_MENU_VALUE,
424  FL_PUP_CHECK = FL_MENU_VALUE,
425  FL_PUP_RADIO = FL_MENU_RADIO,
426  FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
427  FL_PUP_SUBMENU = FL_SUBMENU_POINTER
428 };
429 
430 #endif
431 
432 //
433 // End of "$Id: Fl_Menu_Item.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
434 //