edelib  0.0
MenuItem.h
1 //
2 // "$Id: MenuItem.h 2839 2009-09-28 11:36:20Z karijes $"
3 //
4 // Menu item header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2005 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 #ifndef __EDELIB_MENUITEM_H__
24 #define __EDELIB_MENUITEM_H__
25 
26 #include "edelib-global.h"
27 
28 #include <FL/Fl_Widget.H>
29 #include <FL/Fl_Image.H>
30 #include <FL/Fl_Menu_Item.H>
31 
32 #if defined(__APPLE__) && defined(check)
33 # undef check
34 #endif
35 
36 EDELIB_NS_BEGIN
37 
38 class MenuBase;
39 
46 struct EDELIB_API MenuItem {
47 #ifndef SKIP_DOCS
48  const char *text; // label()
49  int shortcut_;
50  Fl_Callback *callback_;
51  void *user_data_;
52  int flags;
53  uchar labeltype_;
54  uchar labelfont_;
55  uchar labelsize_;
56  unsigned labelcolor_;
57 
58  // image used menu entries; ignored if entry is title
59  // additional field can be used in struct generated from FLUID
60  Fl_Image *image_;
61 
62  // advance N items, skipping submenus:
63  const MenuItem *next(int=1) const;
64  MenuItem *next(int i=1) { return (MenuItem*)(((const MenuItem*)this)->next(i)); }
65  const MenuItem *first() const { return next(0); }
66  MenuItem *first() { return next(0); }
67 
68  // methods on menu items:
69  const char* label() const {return text;}
70  void label(const char* a) {text=a;}
71  void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
72  Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
73  void labeltype(Fl_Labeltype a) {labeltype_ = a;}
74  Fl_Color labelcolor() const {return (Fl_Color)labelcolor_;}
75  void labelcolor(unsigned a) {labelcolor_ = a;}
76  Fl_Font labelfont() const {return (Fl_Font)labelfont_;}
77  void labelfont(uchar a) {labelfont_ = a;}
78  uchar labelsize() const {return labelsize_;}
79  void labelsize(uchar a) {labelsize_ = a;}
80  Fl_Callback_p callback() const {return callback_;}
81  void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
82  void callback(Fl_Callback* c) {callback_=c;}
83  void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
84  void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)p;}
85  void* user_data() const {return user_data_;}
86  void user_data(void* v) {user_data_ = v;}
87  long argument() const {return (long)user_data_;}
88  void argument(long v) {user_data_ = (void*)v;}
89  int shortcut() const {return shortcut_;}
90  void shortcut(int s) {shortcut_ = s;}
91  int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
92  int checkbox() const {return flags&FL_MENU_TOGGLE;}
93  int radio() const {return flags&FL_MENU_RADIO;}
94  int value() const {return flags&FL_MENU_VALUE;}
95  void set() {flags |= FL_MENU_VALUE;}
96  void clear() {flags &= ~FL_MENU_VALUE;}
97  void setonly();
98  int visible() const {return !(flags&FL_MENU_INVISIBLE);}
99  void show() {flags &= ~FL_MENU_INVISIBLE;}
100  void hide() {flags |= FL_MENU_INVISIBLE;}
101  int active() const {return !(flags&FL_MENU_INACTIVE);}
102  void activate() {flags &= ~FL_MENU_INACTIVE;}
103  void deactivate() {flags |= FL_MENU_INACTIVE;}
104  int activevisible() const {return !(flags&0x11);}
105 
106  // different from original Fl_Menu_Item
107  void image(Fl_Image* a) { image_ = a; }
108  void image(Fl_Image& a) { image_ = &a; }
109  Fl_Image* image() const { return image_; }
110 
111  // used by menubar:
112  int measure(int* h, const MenuBase*) const;
113  void draw(int x, int y, int w, int h, const MenuBase*, int t=0, int label_gap=0) const;
114 
115  // popup menus without using an MenuBase widget:
116  const MenuItem* popup(
117  int X, int Y,
118  const char *title = 0,
119  const MenuItem* picked=0,
120  const MenuBase* = 0) const;
121 
122  const MenuItem* pulldown(
123  int X, int Y, int W, int H,
124  const MenuItem* picked = 0,
125  const MenuBase* = 0,
126  const MenuItem* title = 0,
127  int menubar=0) const;
128 
129  const MenuItem* test_shortcut() const;
130  const MenuItem* find_shortcut(int *ip=0) const;
131 
132  void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
133  void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
134  void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)arg);}
135 
136  // back-compatability, do not use:
137  int checked() const {return flags&FL_MENU_VALUE;}
138  void check() {flags |= FL_MENU_VALUE;}
139  void uncheck() {flags &= ~FL_MENU_VALUE;}
140  int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
141  int add(const char*a, const char* b, Fl_Callback* c, void* d = 0, int e = 0) { return add(a,fl_old_shortcut(b),c,d,e); }
142  int size() const ;
143 #endif
144 };
145 
146 EDELIB_NS_END
147 #endif