FLTK 1.3.3
Fl_Menu_Item.H
1 //
2 // "$Id: Fl_Menu_Item.H 10282 2014-09-06 19:03:43Z 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. 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;}
315  int value() const {return flags&FL_MENU_VALUE;}
320  void set() {flags |= FL_MENU_VALUE;}
321 
323  void clear() {flags &= ~FL_MENU_VALUE;}
324 
325  void setonly();
326 
328  int visible() const {return !(flags&FL_MENU_INVISIBLE);}
329 
331  void show() {flags &= ~FL_MENU_INVISIBLE;}
332 
334  void hide() {flags |= FL_MENU_INVISIBLE;}
335 
337  int active() const {return !(flags&FL_MENU_INACTIVE);}
338 
340  void activate() {flags &= ~FL_MENU_INACTIVE;}
345  void deactivate() {flags |= FL_MENU_INACTIVE;}
347  int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));}
348 
349  // compatibility for FLUID so it can set the image of a menu item...
350 
352  void image(Fl_Image* a) {a->label(this);}
353 
355  void image(Fl_Image& a) {a.label(this);}
356 
357  // used by menubar:
358  int measure(int* h, const Fl_Menu_*) const;
359  void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
360 
361  // popup menus without using an Fl_Menu_ widget:
362  const Fl_Menu_Item* popup(
363  int X, int Y,
364  const char *title = 0,
365  const Fl_Menu_Item* picked=0,
366  const Fl_Menu_* = 0) const;
367  const Fl_Menu_Item* pulldown(
368  int X, int Y, int W, int H,
369  const Fl_Menu_Item* picked = 0,
370  const Fl_Menu_* = 0,
371  const Fl_Menu_Item* title = 0,
372  int menubar=0) const;
373  const Fl_Menu_Item* test_shortcut() const;
374  const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const;
375 
381  void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
382 
388  void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
389 
397  void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)arg);}
398 
399  // back-compatibility, do not use:
400 
402  int checked() const {return flags&FL_MENU_VALUE;}
403 
405  void check() {flags |= FL_MENU_VALUE;}
406 
408  void uncheck() {flags &= ~FL_MENU_VALUE;}
409 
410  int insert(int,const char*,int,Fl_Callback*,void* =0, int =0);
411  int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
412 
414  int add(const char*a, const char* b, Fl_Callback* c,
415  void* d = 0, int e = 0) {
416  return add(a,fl_old_shortcut(b),c,d,e);}
417 
418  int size() const ;
419 };
420 
421 typedef Fl_Menu_Item Fl_Menu; // back compatibility
422 
423 enum { // back-compatibility enum:
424  FL_PUP_NONE = 0,
425  FL_PUP_GREY = FL_MENU_INACTIVE,
426  FL_PUP_GRAY = FL_MENU_INACTIVE,
427  FL_MENU_BOX = FL_MENU_TOGGLE,
428  FL_PUP_BOX = FL_MENU_TOGGLE,
429  FL_MENU_CHECK = FL_MENU_VALUE,
430  FL_PUP_CHECK = FL_MENU_VALUE,
431  FL_PUP_RADIO = FL_MENU_RADIO,
432  FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
433  FL_PUP_SUBMENU = FL_SUBMENU_POINTER
434 };
435 
436 #endif
437 
438 //
439 // End of "$Id: Fl_Menu_Item.H 10282 2014-09-06 19:03:43Z AlbrechtS $".
440 //