• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

Fl_Menu_Item.H

Go to the documentation of this file.
00001 //
00002 // "$Id$"
00003 //
00004 // Menu item header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software. Distribution and use rights are outlined in
00009 // the file "COPYING" which should have been included with this file.  If this
00010 // file is missing or damaged, see the license at:
00011 //
00012 //     http://www.fltk.org/COPYING.php
00013 //
00014 // Please report all bugs and problems on the following page:
00015 //
00016 //     http://www.fltk.org/str.php
00017 //
00018 
00019 #ifndef Fl_Menu_Item_H
00020 #define Fl_Menu_Item_H
00021 
00022 #  include "Fl_Widget.H"
00023 #  include "Fl_Image.H"
00024 
00025 #  if defined(__APPLE__) && defined(check)
00026 #    undef check
00027 #  endif
00028 
00029 // doxygen needs the following line to enable e.g. ::FL_MENU_TOGGLE to link to the enums
00031 
00032 enum { // values for flags:
00033   FL_MENU_INACTIVE = 1,         
00034   FL_MENU_TOGGLE= 2,            
00035   FL_MENU_VALUE = 4,            
00036   FL_MENU_RADIO = 8,            
00037   FL_MENU_INVISIBLE = 0x10,     
00038   FL_SUBMENU_POINTER = 0x20,    
00039   FL_SUBMENU = 0x40,            
00040   FL_MENU_DIVIDER = 0x80,       
00041   FL_MENU_HORIZONTAL = 0x100    
00042 };
00043 
00044 extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
00045 
00046 class Fl_Menu_;
00047 
00112 struct FL_EXPORT Fl_Menu_Item {
00113   const char *text;         
00114   int shortcut_;            
00115   Fl_Callback *callback_;   
00116   void *user_data_;         
00117   int flags;                
00118   uchar labeltype_;         
00119   Fl_Font labelfont_;       
00120   Fl_Fontsize labelsize_;   
00121   Fl_Color labelcolor_;     
00122 
00123   // advance N items, skipping submenus:
00124   const Fl_Menu_Item *next(int=1) const;
00125 
00131   Fl_Menu_Item *next(int i=1) {
00132     return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));}
00133 
00135   const Fl_Menu_Item *first() const { return next(0); }
00136 
00138   Fl_Menu_Item *first() { return next(0); }
00139 
00140   // methods on menu items:
00148   const char* label() const {return text;}
00149 
00151   void label(const char* a) {text=a;}
00152 
00154   void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
00155 
00163   Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
00164 
00172   void labeltype(Fl_Labeltype a) {labeltype_ = a;}
00173 
00181   Fl_Color labelcolor() const {return labelcolor_;}
00182 
00187   void labelcolor(Fl_Color a) {labelcolor_ = a;}
00194   Fl_Font labelfont() const {return labelfont_;}
00195 
00202   void labelfont(Fl_Font a) {labelfont_ = a;}
00203 
00205   Fl_Fontsize labelsize() const {return labelsize_;}
00206 
00208   void labelsize(Fl_Fontsize a) {labelsize_ = a;}
00209 
00217   Fl_Callback_p callback() const {return callback_;}
00218 
00223   void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
00224 
00230   void callback(Fl_Callback* c) {callback_=c;}
00231 
00237   void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
00238 
00246   void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)(fl_intptr_t)p;}
00247 
00251   void* user_data() const {return user_data_;}
00255   void user_data(void* v) {user_data_ = v;}
00262   long argument() const {return (long)(fl_intptr_t)user_data_;}
00270   void argument(long v) {user_data_ = (void*)(fl_intptr_t)v;}
00271 
00273   int shortcut() const {return shortcut_;}
00274 
00290   void shortcut(int s) {shortcut_ = s;}
00298   int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
00303   int checkbox() const {return flags&FL_MENU_TOGGLE;}
00310   int radio() const {return flags&FL_MENU_RADIO;}
00318   int value() const {return flags&FL_MENU_VALUE;}
00323   void set() {flags |= FL_MENU_VALUE;}
00324 
00326   void clear() {flags &= ~FL_MENU_VALUE;}
00327 
00328   void setonly();
00329 
00331   int visible() const {return !(flags&FL_MENU_INVISIBLE);}
00332 
00334   void show() {flags &= ~FL_MENU_INVISIBLE;}
00335 
00337   void hide() {flags |= FL_MENU_INVISIBLE;}
00338 
00340   int active() const {return !(flags&FL_MENU_INACTIVE);}
00341 
00343   void activate() {flags &= ~FL_MENU_INACTIVE;}
00348   void deactivate() {flags |= FL_MENU_INACTIVE;}
00350   int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));}
00351 
00352   // compatibility for FLUID so it can set the image of a menu item...
00353 
00355   void image(Fl_Image* a) {a->label(this);}
00356 
00358   void image(Fl_Image& a) {a.label(this);}
00359 
00360   // used by menubar:
00361   int measure(int* h, const Fl_Menu_*) const;
00362   void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const;
00363 
00364   // popup menus without using an Fl_Menu_ widget:
00365   const Fl_Menu_Item* popup(
00366     int X, int Y,
00367     const char *title = 0,
00368     const Fl_Menu_Item* picked=0,
00369     const Fl_Menu_* = 0) const;
00370   const Fl_Menu_Item* pulldown(
00371     int X, int Y, int W, int H,
00372     const Fl_Menu_Item* picked = 0,
00373     const Fl_Menu_* = 0,
00374     const Fl_Menu_Item* title = 0,
00375     int menubar=0) const;
00376   const Fl_Menu_Item* test_shortcut() const;
00377   const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const;
00378 
00384   void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
00385 
00391   void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
00392 
00400   void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)(fl_intptr_t)arg);}
00401 
00402   // back-compatibility, do not use:
00403 
00405   int checked() const {return flags&FL_MENU_VALUE;}
00406 
00408   void check() {flags |= FL_MENU_VALUE;}
00409 
00411   void uncheck() {flags &= ~FL_MENU_VALUE;}
00412 
00413   int insert(int,const char*,int,Fl_Callback*,void* =0, int =0);
00414   int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
00415 
00417   int add(const char*a, const char* b, Fl_Callback* c,
00418           void* d = 0, int e = 0) {
00419     return add(a,fl_old_shortcut(b),c,d,e);}
00420 
00421   int size() const ;
00422 };
00423 
00424 typedef Fl_Menu_Item Fl_Menu; // back compatibility
00425 
00426 enum {  // back-compatibility enum:
00427   FL_PUP_NONE   = 0,
00428   FL_PUP_GREY   = FL_MENU_INACTIVE,
00429   FL_PUP_GRAY   = FL_MENU_INACTIVE,
00430   FL_MENU_BOX   = FL_MENU_TOGGLE,
00431   FL_PUP_BOX    = FL_MENU_TOGGLE,
00432   FL_MENU_CHECK = FL_MENU_VALUE,
00433   FL_PUP_CHECK  = FL_MENU_VALUE,
00434   FL_PUP_RADIO  = FL_MENU_RADIO,
00435   FL_PUP_INVISIBLE = FL_MENU_INVISIBLE,
00436   FL_PUP_SUBMENU = FL_SUBMENU_POINTER
00437 };
00438 
00439 #endif
00440 
00441 //
00442 // End of "$Id$".
00443 //
  • © 1998-2016 by Bill Spitzak and others.     FLTK

  • © 1998-2016 by Bill Spitzak and others.     FLTK

    Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.