FLTK 1.3.2
|
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 enum { // values for flags: 00030 FL_MENU_INACTIVE = 1, 00031 FL_MENU_TOGGLE= 2, 00032 FL_MENU_VALUE = 4, 00033 FL_MENU_RADIO = 8, 00034 FL_MENU_INVISIBLE = 0x10, 00035 FL_SUBMENU_POINTER = 0x20, 00036 FL_SUBMENU = 0x40, 00037 FL_MENU_DIVIDER = 0x80, 00038 FL_MENU_HORIZONTAL = 0x100 00039 }; 00040 00041 extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*); 00042 00043 class Fl_Menu_; 00044 00109 struct FL_EXPORT Fl_Menu_Item { 00110 const char *text; 00111 int shortcut_; 00112 Fl_Callback *callback_; 00113 void *user_data_; 00114 int flags; 00115 uchar labeltype_; 00116 Fl_Font labelfont_; 00117 Fl_Fontsize labelsize_; 00118 Fl_Color labelcolor_; 00119 00120 // advance N items, skipping submenus: 00121 const Fl_Menu_Item *next(int=1) const; 00122 00128 Fl_Menu_Item *next(int i=1) { 00129 return (Fl_Menu_Item*)(((const Fl_Menu_Item*)this)->next(i));} 00130 00132 const Fl_Menu_Item *first() const { return next(0); } 00133 00135 Fl_Menu_Item *first() { return next(0); } 00136 00137 // methods on menu items: 00145 const char* label() const {return text;} 00146 00148 void label(const char* a) {text=a;} 00149 00151 void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;} 00152 00160 Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;} 00161 00169 void labeltype(Fl_Labeltype a) {labeltype_ = a;} 00170 00178 Fl_Color labelcolor() const {return labelcolor_;} 00179 00184 void labelcolor(Fl_Color a) {labelcolor_ = a;} 00191 Fl_Font labelfont() const {return labelfont_;} 00192 00199 void labelfont(Fl_Font a) {labelfont_ = a;} 00200 00202 Fl_Fontsize labelsize() const {return labelsize_;} 00203 00205 void labelsize(Fl_Fontsize a) {labelsize_ = a;} 00206 00214 Fl_Callback_p callback() const {return callback_;} 00215 00220 void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;} 00221 00227 void callback(Fl_Callback* c) {callback_=c;} 00228 00234 void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;} 00235 00243 void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)p;} 00244 00248 void* user_data() const {return user_data_;} 00252 void user_data(void* v) {user_data_ = v;} 00259 long argument() const {return (long)(fl_intptr_t)user_data_;} 00267 void argument(long v) {user_data_ = (void*)v;} 00268 00270 int shortcut() const {return shortcut_;} 00271 00287 void shortcut(int s) {shortcut_ = s;} 00295 int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);} 00300 int checkbox() const {return flags&FL_MENU_TOGGLE;} 00307 int radio() const {return flags&FL_MENU_RADIO;} 00309 int value() const {return flags&FL_MENU_VALUE;} 00314 void set() {flags |= FL_MENU_VALUE;} 00315 00317 void clear() {flags &= ~FL_MENU_VALUE;} 00318 00319 void setonly(); 00320 00322 int visible() const {return !(flags&FL_MENU_INVISIBLE);} 00323 00325 void show() {flags &= ~FL_MENU_INVISIBLE;} 00326 00328 void hide() {flags |= FL_MENU_INVISIBLE;} 00329 00331 int active() const {return !(flags&FL_MENU_INACTIVE);} 00332 00334 void activate() {flags &= ~FL_MENU_INACTIVE;} 00339 void deactivate() {flags |= FL_MENU_INACTIVE;} 00341 int activevisible() const {return !(flags & (FL_MENU_INACTIVE|FL_MENU_INVISIBLE));} 00342 00343 // compatibility for FLUID so it can set the image of a menu item... 00344 00346 void image(Fl_Image* a) {a->label(this);} 00347 00349 void image(Fl_Image& a) {a.label(this);} 00350 00351 // used by menubar: 00352 int measure(int* h, const Fl_Menu_*) const; 00353 void draw(int x, int y, int w, int h, const Fl_Menu_*, int t=0) const; 00354 00355 // popup menus without using an Fl_Menu_ widget: 00356 const Fl_Menu_Item* popup( 00357 int X, int Y, 00358 const char *title = 0, 00359 const Fl_Menu_Item* picked=0, 00360 const Fl_Menu_* = 0) const; 00361 const Fl_Menu_Item* pulldown( 00362 int X, int Y, int W, int H, 00363 const Fl_Menu_Item* picked = 0, 00364 const Fl_Menu_* = 0, 00365 const Fl_Menu_Item* title = 0, 00366 int menubar=0) const; 00367 const Fl_Menu_Item* test_shortcut() const; 00368 const Fl_Menu_Item* find_shortcut(int *ip=0, const bool require_alt = false) const; 00369 00375 void do_callback(Fl_Widget* o) const {callback_(o, user_data_);} 00376 00382 void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);} 00383 00391 void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)arg);} 00392 00393 // back-compatibility, do not use: 00394 00396 int checked() const {return flags&FL_MENU_VALUE;} 00397 00399 void check() {flags |= FL_MENU_VALUE;} 00400 00402 void uncheck() {flags &= ~FL_MENU_VALUE;} 00403 00404 int insert(int,const char*,int,Fl_Callback*,void* =0, int =0); 00405 int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0); 00406 00408 int add(const char*a, const char* b, Fl_Callback* c, 00409 void* d = 0, int e = 0) { 00410 return add(a,fl_old_shortcut(b),c,d,e);} 00411 00412 int size() const ; 00413 }; 00414 00415 typedef Fl_Menu_Item Fl_Menu; // back compatibility 00416 00417 enum { // back-compatibility enum: 00418 FL_PUP_NONE = 0, 00419 FL_PUP_GREY = FL_MENU_INACTIVE, 00420 FL_PUP_GRAY = FL_MENU_INACTIVE, 00421 FL_MENU_BOX = FL_MENU_TOGGLE, 00422 FL_PUP_BOX = FL_MENU_TOGGLE, 00423 FL_MENU_CHECK = FL_MENU_VALUE, 00424 FL_PUP_CHECK = FL_MENU_VALUE, 00425 FL_PUP_RADIO = FL_MENU_RADIO, 00426 FL_PUP_INVISIBLE = FL_MENU_INVISIBLE, 00427 FL_PUP_SUBMENU = FL_SUBMENU_POINTER 00428 }; 00429 00430 #endif 00431 00432 // 00433 // End of "$Id$". 00434 //