edelib: edelib/MenuItem.h Source File

edelib 1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List

MenuItem.h
1 //
2 // "$Id: MenuItem.h 3340 2012-06-06 14:38:11Z 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 // for tooltip support
63 const char *tooltip_;
64
65 // called internally, but for any fiddling with the menu, make sure to call it
66 static void init_extensions(MenuItem *i) {
67 i->image_ = 0;
68 i->tooltip_ = 0;
69 }
70
71 // advance N items, skipping submenus:
72 const MenuItem *next(int=1) const;
73 MenuItem *next(int i=1) { return (MenuItem*)(((const MenuItem*)this)->next(i)); }
74 const MenuItem *first() const { return next(0); }
75 MenuItem *first() { return next(0); }
76
77 // methods on menu items:
78 const char* label() const {return text;}
79 void label(const char* a) {text=a;}
80 void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
81 Fl_Labeltype labeltype() const {return (Fl_Labeltype)labeltype_;}
82 void labeltype(Fl_Labeltype a) {labeltype_ = a;}
83 Fl_Color labelcolor() const {return (Fl_Color)labelcolor_;}
84 void labelcolor(unsigned a) {labelcolor_ = a;}
85 Fl_Font labelfont() const {return (Fl_Font)labelfont_;}
86 void labelfont(uchar a) {labelfont_ = a;}
87 uchar labelsize() const {return labelsize_;}
88 void labelsize(uchar a) {labelsize_ = a;}
89 Fl_Callback_p callback() const {return callback_;}
90 void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
91 void callback(Fl_Callback* c) {callback_=c;}
92 void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
93 void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)p;}
94 void* user_data() const {return user_data_;}
95 void user_data(void* v) {user_data_ = v;}
96 long argument() const {return (long)user_data_;}
97 void argument(long v) {user_data_ = (void*)v;}
98 int shortcut() const {return shortcut_;}
99 void shortcut(int s) {shortcut_ = s;}
100 int submenu() const {return flags&(FL_SUBMENU|FL_SUBMENU_POINTER);}
101 int checkbox() const {return flags&FL_MENU_TOGGLE;}
102 int radio() const {return flags&FL_MENU_RADIO;}
103 int value() const {return flags&FL_MENU_VALUE;}
104 void set() {flags |= FL_MENU_VALUE;}
105 void clear() {flags &= ~FL_MENU_VALUE;}
106 void setonly();
107 int visible() const {return !(flags&FL_MENU_INVISIBLE);}
108 void show() {flags &= ~FL_MENU_INVISIBLE;}
109 void hide() {flags |= FL_MENU_INVISIBLE;}
110 int active() const {return !(flags&FL_MENU_INACTIVE);}
111 void activate() {flags &= ~FL_MENU_INACTIVE;}
112 void deactivate() {flags |= FL_MENU_INACTIVE;}
113 int activevisible() const {return !(flags&0x11);}
114
115 // different from original Fl_Menu_Item
116 void image(Fl_Image* a) { image_ = a; }
117 void image(Fl_Image& a) { image_ = &a; }
118 Fl_Image* image() const { return image_; }
119 void tooltip(const char* t) { tooltip_ = t; }
120 const char* tooltip() const { return tooltip_; }
121
122 // used by menubar:
123 int measure(int* h, const MenuBase*) const;
124 void draw(int x, int y, int w, int h, const MenuBase*, int t=0, int label_gap=0) const;
125
126 // popup menus without using an MenuBase widget:
127 const MenuItem* popup(
128 int X, int Y,
129 const char *title = 0,
130 const MenuItem* picked=0,
131 const MenuBase* = 0) const;
132
133 const MenuItem* pulldown(
134 int X, int Y, int W, int H,
135 const MenuItem* picked = 0,
136 const MenuBase* = 0,
137 const MenuItem* title = 0,
138 int menubar=0) const;
139
140 const MenuItem* test_shortcut() const;
141 const MenuItem* find_shortcut(int *ip=0) const;
142
143 void do_callback(Fl_Widget* o) const {callback_(o, user_data_);}
144 void do_callback(Fl_Widget* o,void* arg) const {callback_(o, arg);}
145 void do_callback(Fl_Widget* o,long arg) const {callback_(o, (void*)arg);}
146
147 // back-compatability, do not use:
148 int checked() const {return flags&FL_MENU_VALUE;}
149 void check() {flags |= FL_MENU_VALUE;}
150 void uncheck() {flags &= ~FL_MENU_VALUE;}
151 int add(const char*, int shortcut, Fl_Callback*, void* =0, int = 0);
152 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); }
153 int size() const ;
154 #endif
155 };
156
157 EDELIB_NS_END
158 #endif
edelib::MenuItem
The item in menu list.
Definition: MenuItem.h:46
edelib::MenuBase
Menu base class.
Definition: MenuBase.h:39